Exemplo n.º 1
0
/**
 * Change the sort order of an override
 *
 * @param int $id of the override
 * @param string $move direction of move
 * @param int $assignid of the assignment
 * @return bool success of operation
 */
function move_group_override($id, $move, $assignid) {
    global $DB;

    // Get the override object.
    if (!$override = $DB->get_record('assign_overrides', array('id' => $id), 'id, sortorder')) {
        return false;
    }
    // Count the number of group overrides.
    $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assignid));

    // Calculate the new sortorder.
    if ( ($move == 'up') and ($override->sortorder > 1)) {
        $neworder = $override->sortorder - 1;
    } else if (($move == 'down') and ($override->sortorder < $overridecountgroup)) {
        $neworder = $override->sortorder + 1;
    } else {
        return false;
    }

    // Retrieve the override object that is currently residing in the new position.
    $params = array('sortorder' => $neworder, 'assignid' => $assignid);
    if ($swapoverride = $DB->get_record('assign_overrides', $params, 'id, sortorder')) {

        // Swap the sortorders.
        $swapoverride->sortorder = $override->sortorder;
        $override->sortorder     = $neworder;

        // Update the override records.
        $DB->update_record('assign_overrides', $override);
        $DB->update_record('assign_overrides', $swapoverride);
    }

    reorder_group_overrides($assignid);
    return true;
}
Exemplo n.º 2
0
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$context = context_module::instance($cm->id);
require_login($course, false, $cm);
// Check the user has the required capabilities to modify an override.
require_capability('mod/assign:manageoverrides', $context);
$url = new moodle_url('/mod/assign/overridedelete.php', array('id' => $override->id));
$confirmurl = new moodle_url($url, array('id' => $override->id, 'confirm' => 1));
$cancelurl = new moodle_url('/mod/assign/overrides.php', array('cmid' => $cm->id));
if (!empty($override->userid)) {
    $cancelurl->param('mode', 'user');
}
// If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
if ($confirm) {
    require_sesskey();
    $assign->delete_override($override->id);
    reorder_group_overrides($assign->get_context()->id);
    redirect($cancelurl);
}
// Prepare the page to show the confirmation form.
$stroverride = get_string('override', 'assign');
$title = get_string('deletecheck', null, $stroverride);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
$PAGE->navbar->add($title);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($assign->get_context()->name, true, array('context' => $context)));
if ($override->groupid) {
    $group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
    $confirmstr = get_string("overridedeletegroupsure", "assign", $group->name);