Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This page handles listing of assign overrides 19 * 20 * @package mod_assign 21 * @copyright 2016 Ilya Tregubov 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 require_once(dirname(__FILE__) . '/../../config.php'); 27 require_once($CFG->dirroot.'/mod/assign/lib.php'); 28 require_once($CFG->dirroot.'/mod/assign/locallib.php'); 29 require_once($CFG->dirroot.'/mod/assign/override_form.php'); 30 31 32 $cmid = required_param('cmid', PARAM_INT); 33 $mode = optional_param('mode', '', PARAM_ALPHA); // One of 'user' or 'group', default is 'group'. 34 35 $action = optional_param('action', '', PARAM_ALPHA); 36 $redirect = $CFG->wwwroot.'/mod/assign/overrides.php?cmid=' . $cmid . '&mode=group'; 37 38 list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'assign'); 39 $assign = $DB->get_record('assign', array('id' => $cm->instance), '*', MUST_EXIST); 40 41 require_login($course, false, $cm); 42 43 $context = context_module::instance($cm->id); 44 45 // Check the user has the required capabilities to list overrides. 46 require_capability('mod/assign:manageoverrides', $context); 47 48 $assigngroupmode = groups_get_activity_groupmode($cm); 49 $accessallgroups = ($assigngroupmode == NOGROUPS) || has_capability('moodle/site:accessallgroups', $context); 50 51 $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assign->id)); 52 53 // Get the course groups that the current user can access. 54 $groups = $accessallgroups ? groups_get_all_groups($cm->course) : groups_get_activity_allowed_groups($cm); 55 56 // Default mode is "group", unless there are no groups. 57 if ($mode != "user" and $mode != "group") { 58 if (!empty($groups)) { 59 $mode = "group"; 60 } else { 61 $mode = "user"; 62 } 63 } 64 $groupmode = ($mode == "group"); 65 66 $url = new moodle_url('/mod/assign/overrides.php', array('cmid' => $cm->id, 'mode' => $mode)); 67 68 $PAGE->set_url($url); 69 70 if ($action == 'movegroupoverride') { 71 $id = required_param('id', PARAM_INT); 72 $dir = required_param('dir', PARAM_ALPHA); 73 74 if (confirm_sesskey()) { 75 move_group_override($id, $dir, $assign->id); 76 } 77 redirect($redirect); 78 } 79 80 // Display a list of overrides. 81 $PAGE->set_pagelayout('admin'); 82 $PAGE->set_title(get_string('overrides', 'assign')); 83 $PAGE->set_heading($course->fullname); 84 echo $OUTPUT->header(); 85 echo $OUTPUT->heading(format_string($assign->name, true, array('context' => $context))); 86 87 // Delete orphaned group overrides. 88 $sql = 'SELECT o.id 89 FROM {assign_overrides} o 90 LEFT JOIN {groups} g ON o.groupid = g.id 91 WHERE o.groupid IS NOT NULL 92 AND g.id IS NULL 93 AND o.assignid = ?'; 94 $params = array($assign->id); 95 $orphaned = $DB->get_records_sql($sql, $params); 96 if (!empty($orphaned)) { 97 $DB->delete_records_list('assign_overrides', 'id', array_keys($orphaned)); 98 } 99 100 $overrides = []; 101 102 // Fetch all overrides. 103 if ($groupmode) { 104 $colname = get_string('group'); 105 // To filter the result by the list of groups that the current user has access to. 106 if ($groups) { 107 $params = ['assignid' => $assign->id]; 108 list($insql, $inparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 109 $params += $inparams; 110 111 $sql = "SELECT o.*, g.name 112 FROM {assign_overrides} o 113 JOIN {groups} g ON o.groupid = g.id 114 WHERE o.assignid = :assignid AND g.id $insql 115 ORDER BY o.sortorder"; 116 117 $overrides = $DB->get_records_sql($sql, $params); 118 } 119 } else { 120 $colname = get_string('user'); 121 list($sort, $params) = users_order_by_sql('u'); 122 $params['assignid'] = $assign->id; 123 124 if ($accessallgroups) { 125 $sql = 'SELECT o.*, ' . get_all_user_name_fields(true, 'u') . ' 126 FROM {assign_overrides} o 127 JOIN {user} u ON o.userid = u.id 128 WHERE o.assignid = :assignid 129 ORDER BY ' . $sort; 130 131 $overrides = $DB->get_records_sql($sql, $params); 132 } else if ($groups) { 133 list($insql, $inparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 134 $params += $inparams; 135 136 $sql = 'SELECT o.*, ' . get_all_user_name_fields(true, 'u') . ' 137 FROM {assign_overrides} o 138 JOIN {user} u ON o.userid = u.id 139 JOIN {groups_members} gm ON u.id = gm.userid 140 WHERE o.assignid = :assignid AND gm.groupid ' . $insql . ' 141 ORDER BY ' . $sort; 142 143 $overrides = $DB->get_records_sql($sql, $params); 144 } 145 } 146 147 // Initialise table. 148 $table = new html_table(); 149 $table->headspan = array(1, 2, 1); 150 $table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction'); 151 $table->head = array( 152 $colname, 153 get_string('overrides', 'assign'), 154 get_string('action'), 155 ); 156 157 $userurl = new moodle_url('/user/view.php', array()); 158 $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course)); 159 160 $overridedeleteurl = new moodle_url('/mod/assign/overridedelete.php'); 161 $overrideediturl = new moodle_url('/mod/assign/overrideedit.php'); 162 163 $hasinactive = false; // Whether there are any inactive overrides. 164 165 foreach ($overrides as $override) { 166 167 $fields = array(); 168 $values = array(); 169 $active = true; 170 171 // Check for inactive overrides. 172 if (!$groupmode) { 173 if (!is_enrolled($context, $override->userid)) { 174 // User not enrolled. 175 $active = false; 176 } else if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) { 177 // User cannot access the module. 178 $active = false; 179 } 180 } 181 182 // Format allowsubmissionsfromdate. 183 if (isset($override->allowsubmissionsfromdate)) { 184 $fields[] = get_string('open', 'assign'); 185 $values[] = $override->allowsubmissionsfromdate > 0 ? userdate($override->allowsubmissionsfromdate) : get_string('noopen', 186 'assign'); 187 } 188 189 // Format duedate. 190 if (isset($override->duedate)) { 191 $fields[] = get_string('duedate', 'assign'); 192 $values[] = $override->duedate > 0 ? userdate($override->duedate) : get_string('noclose', 'assign'); 193 } 194 195 // Format cutoffdate. 196 if (isset($override->cutoffdate)) { 197 $fields[] = get_string('cutoffdate', 'assign'); 198 $values[] = $override->cutoffdate > 0 ? userdate($override->cutoffdate) : get_string('noclose', 'assign'); 199 } 200 201 // Icons. 202 $iconstr = ''; 203 204 // Edit. 205 $editurlstr = $overrideediturl->out(true, array('id' => $override->id)); 206 $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' . 207 $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> '; 208 // Duplicate. 209 $copyurlstr = $overrideediturl->out(true, 210 array('id' => $override->id, 'action' => 'duplicate')); 211 $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' . 212 $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> '; 213 // Delete. 214 $deleteurlstr = $overridedeleteurl->out(true, 215 array('id' => $override->id, 'sesskey' => sesskey())); 216 $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' . 217 $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> '; 218 219 if ($groupmode) { 220 $usergroupstr = '<a href="' . $groupurl->out(true, 221 array('group' => $override->groupid)) . '" >' . $override->name . '</a>'; 222 223 // Move up. 224 if ($override->sortorder > 1) { 225 $iconstr .= '<a title="'.get_string('moveup').'" href="overrides.php?cmid=' . $cmid . 226 '&id=' . $override->id .'&action=movegroupoverride&dir=up&sesskey='.sesskey().'">' . 227 $OUTPUT->pix_icon('t/up', get_string('moveup')) . '</a> '; 228 } else { 229 $iconstr .= $OUTPUT->spacer() . ' '; 230 } 231 232 // Move down. 233 if ($override->sortorder < $overridecountgroup) { 234 $iconstr .= '<a title="'.get_string('movedown').'" href="overrides.php?cmid='.$cmid. 235 '&id=' . $override->id . '&action=movegroupoverride&dir=down&sesskey='.sesskey().'">' . 236 $OUTPUT->pix_icon('t/down', get_string('movedown')) . '</a> '; 237 } else { 238 $iconstr .= $OUTPUT->spacer() . ' '; 239 } 240 241 242 } else { 243 $usergroupstr = html_writer::link($userurl->out(false, 244 array('id' => $override->userid, 'course' => $course->id)), 245 fullname($override)); 246 } 247 248 $class = ''; 249 if (!$active) { 250 $class = "dimmed_text"; 251 $usergroupstr .= '*'; 252 $hasinactive = true; 253 } 254 255 $usergroupcell = new html_table_cell(); 256 $usergroupcell->rowspan = count($fields); 257 $usergroupcell->text = $usergroupstr; 258 $actioncell = new html_table_cell(); 259 $actioncell->rowspan = count($fields); 260 $actioncell->text = $iconstr; 261 262 for ($i = 0; $i < count($fields); ++$i) { 263 $row = new html_table_row(); 264 $row->attributes['class'] = $class; 265 if ($i == 0) { 266 $row->cells[] = $usergroupcell; 267 } 268 $cell1 = new html_table_cell(); 269 $cell1->text = $fields[$i]; 270 $row->cells[] = $cell1; 271 $cell2 = new html_table_cell(); 272 $cell2->text = $values[$i]; 273 $row->cells[] = $cell2; 274 if ($i == 0) { 275 $row->cells[] = $actioncell; 276 } 277 $table->data[] = $row; 278 } 279 } 280 281 // Output the table and button. 282 echo html_writer::start_tag('div', array('id' => 'assignoverrides')); 283 if (count($table->data)) { 284 echo html_writer::table($table); 285 } 286 if ($hasinactive) { 287 echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'assign'), 'dimmed_text'); 288 } 289 290 echo html_writer::start_tag('div', array('class' => 'buttons')); 291 $options = array(); 292 if ($groupmode) { 293 if (empty($groups)) { 294 // There are no groups. 295 echo $OUTPUT->notification(get_string('groupsnone', 'assign'), 'error'); 296 $options['disabled'] = true; 297 } 298 echo $OUTPUT->single_button($overrideediturl->out(true, 299 array('action' => 'addgroup', 'cmid' => $cm->id)), 300 get_string('addnewgroupoverride', 'assign'), 'post', $options); 301 } else { 302 $users = array(); 303 // See if there are any users in the assign. 304 if ($accessallgroups) { 305 $users = get_enrolled_users($context, '', 0, 'u.id'); 306 $nousermessage = get_string('usersnone', 'assign'); 307 } else if ($groups) { 308 $enrolledjoin = get_enrolled_join($context, 'u.id'); 309 list($ingroupsql, $ingroupparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 310 $params = $enrolledjoin->params + $ingroupparams; 311 $sql = "SELECT u.id 312 FROM {user} u 313 JOIN {groups_members} gm ON gm.userid = u.id 314 {$enrolledjoin->joins} 315 WHERE gm.groupid $ingroupsql 316 AND {$enrolledjoin->wheres} 317 ORDER BY $sort"; 318 $users = $DB->get_records_sql($sql, $params); 319 $nousermessage = get_string('usersnone', 'assign'); 320 } else { 321 $nousermessage = get_string('groupsnone', 'assign'); 322 } 323 $info = new \core_availability\info_module($cm); 324 $users = $info->filter_user_list($users); 325 326 if (empty($users)) { 327 // There are no users. 328 echo $OUTPUT->notification($nousermessage, 'error'); 329 $options['disabled'] = true; 330 } 331 echo $OUTPUT->single_button($overrideediturl->out(true, 332 array('action' => 'adduser', 'cmid' => $cm->id)), 333 get_string('addnewuseroverride', 'assign'), 'get', $options); 334 } 335 echo html_writer::end_tag('div'); 336 echo html_writer::end_tag('div'); 337 338 // Finish the page. 339 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body