Skip to content

Commit

Permalink
MDL-21781 fixed some more cohort assign issues
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 23, 2010
1 parent b1e2e6b commit c5070d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
62 changes: 33 additions & 29 deletions cohort/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
$PAGE->set_url('/cohort/assign.php', array('id'=>$id));
$PAGE->set_Context($context);

if (optional_param('cancel', false, PARAM_BOOL)) {
redirect(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
}

if ($context->contextlevel == CONTEXT_COURSECAT) {
$category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
$PAGE->navbar->add($category->name, new moodle_url('/course/index.php', array('categoryedit'=>'1')));
Expand All @@ -49,43 +53,41 @@
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('assignto', 'cohort', format_string($cohort->name)));

/// Get the user_selector we will need.
// Get the user_selector we will need.
$potentialuserselector = new cohort_candidate_selector('addselect', array('cohortid'=>$cohort->id));
$existinguserselector = new cohort_existing_selector('removeselect', array('cohortid'=>$cohort->id));

/// Process incoming user assignments to cohorts
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $potentialuserselector->get_selected_users();
if (!empty($userstoassign)) {
// Process incoming user assignments to the cohort

foreach ($userstoassign as $adduser) {
// no duplicates please
if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) {
cohort_add_member($cohort->id, $adduser->id);
}
}
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $potentialuserselector->get_selected_users();
if (!empty($userstoassign)) {

$potentialuserselector->invalidate_selected_users();
$existinguserselector->invalidate_selected_users();
foreach ($userstoassign as $adduser) {
// no duplicates please
if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) {
cohort_add_member($cohort->id, $adduser->id);
}
}

/// Process removing user assignments to the service
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoremove = $existinguserselector->get_selected_users();
if (!empty($userstoremove)) {

foreach ($userstoremove as $removeuser) {
cohort_remove_member($cohort->id, $removeuser->id);
}
$potentialuserselector->invalidate_selected_users();
$existinguserselector->invalidate_selected_users();
}
}

$potentialuserselector->invalidate_selected_users();
$existinguserselector->invalidate_selected_users();
}
// Process removing user assignments to the cohort
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoremove = $existinguserselector->get_selected_users();
if (!empty($userstoremove)) {
foreach ($userstoremove as $removeuser) {
cohort_remove_member($cohort->id, $removeuser->id);
}
/// Print the form.
/// display the UI
$potentialuserselector->invalidate_selected_users();
$existinguserselector->invalidate_selected_users();
}
}

// Print the form.
?>
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
Expand All @@ -98,22 +100,24 @@
</td>
<td id="buttonscell">
<div id="addcontrols">
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.s(get_string('add')); ?>" title="<?php p(get_string('add')); ?>" /><br />
</div>

<div id="removecontrols">
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
<input name="remove" id="remove" type="submit" value="<?php echo s(get_string('remove')).'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php p(get_string('remove')); ?>" />
</div>
</td>
<td id="potentialcell">
<p><label for="addselect"><?php print_string('potusers', 'cohort'); ?></label></p>
<?php $potentialuserselector->display() ?>
</td>
</tr>
<tr><td colspan="3" id='backcell'>
<input type="submit" name="cancel" value="<?php p(get_string('backtocohorts', 'cohort')); ?>" />
</td></tr>
</table>
</div></form>

<?php


echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions lang/en/cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$string['addcohort'] = 'Add new cohort';
$string['assign'] = 'Assign';
$string['assignto'] = 'Cohort \'{$a}\' members';
$string['backtocohorts'] = 'Back to cohorts';
$string['cohort'] = 'Cohort';
$string['cohorts'] = 'Cohorts';
$string['cohortsin'] = '{$a}: available cohorts';
Expand Down

0 comments on commit c5070d0

Please sign in to comment.