Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 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 navigation_node::override_active_url(new moodle_url('/mod/assign/overrides.php', ['cmid' => $cmid])); 70 71 if ($action == 'movegroupoverride') { 72 $id = required_param('id', PARAM_INT); 73 $dir = required_param('dir', PARAM_ALPHA); 74 75 if (confirm_sesskey()) { 76 move_group_override($id, $dir, $assign->id); 77 } 78 redirect($redirect); 79 } 80 81 // Display a list of overrides. 82 $PAGE->set_pagelayout('admin'); 83 $PAGE->add_body_class('limitedwidth'); 84 $PAGE->set_title(get_string('overrides', 'assign')); 85 $PAGE->set_heading($course->fullname); 86 $activityheader = $PAGE->activityheader; 87 $activityheader->set_attrs([ 88 'description' => '', 89 'hidecompletion' => true, 90 'title' => $activityheader->is_title_allowed() ? format_string($assign->name, true, ['context' => $context]) : "" 91 ]); 92 echo $OUTPUT->header(); 93 echo $OUTPUT->heading(get_string('overrides', 'mod_assign'), 2); 94 $overridemenu = new \mod_assign\output\override_actionmenu($url, $cm); 95 $renderer = $PAGE->get_renderer('mod_assign'); 96 echo $renderer->render($overridemenu); 97 98 // Delete orphaned group overrides. 99 $sql = 'SELECT o.id 100 FROM {assign_overrides} o 101 LEFT JOIN {groups} g ON o.groupid = g.id 102 WHERE o.groupid IS NOT NULL 103 AND g.id IS NULL 104 AND o.assignid = ?'; 105 $params = array($assign->id); 106 $orphaned = $DB->get_records_sql($sql, $params); 107 if (!empty($orphaned)) { 108 $DB->delete_records_list('assign_overrides', 'id', array_keys($orphaned)); 109 } 110 111 $overrides = []; 112 113 // Fetch all overrides. 114 if ($groupmode) { 115 $colname = get_string('group'); 116 // To filter the result by the list of groups that the current user has access to. 117 if ($groups) { 118 $params = ['assignid' => $assign->id]; 119 list($insql, $inparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 120 $params += $inparams; 121 122 $sql = "SELECT o.*, g.name 123 FROM {assign_overrides} o 124 JOIN {groups} g ON o.groupid = g.id 125 WHERE o.assignid = :assignid AND g.id $insql 126 ORDER BY o.sortorder"; 127 128 $overrides = $DB->get_records_sql($sql, $params); 129 } 130 } else { 131 $colname = get_string('user'); 132 list($sort, $params) = users_order_by_sql('u'); 133 $params['assignid'] = $assign->id; 134 135 $userfieldsapi = \core_user\fields::for_name(); 136 if ($accessallgroups) { 137 $sql = 'SELECT o.*, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects . ' 138 FROM {assign_overrides} o 139 JOIN {user} u ON o.userid = u.id 140 WHERE o.assignid = :assignid 141 ORDER BY ' . $sort; 142 143 $overrides = $DB->get_records_sql($sql, $params); 144 } else if ($groups) { 145 list($insql, $inparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 146 $params += $inparams; 147 148 $sql = 'SELECT o.*, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects . ' 149 FROM {assign_overrides} o 150 JOIN {user} u ON o.userid = u.id 151 JOIN {groups_members} gm ON u.id = gm.userid 152 WHERE o.assignid = :assignid AND gm.groupid ' . $insql . ' 153 ORDER BY ' . $sort; 154 155 $overrides = $DB->get_records_sql($sql, $params); 156 } 157 } 158 159 // Initialise table. 160 $table = new html_table(); 161 $table->headspan = array(1, 2, 1); 162 $table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction'); 163 $table->head = array( 164 $colname, 165 get_string('overrides', 'assign'), 166 get_string('action'), 167 ); 168 169 $userurl = new moodle_url('/user/view.php', array()); 170 $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course)); 171 172 $overridedeleteurl = new moodle_url('/mod/assign/overridedelete.php'); 173 $overrideediturl = new moodle_url('/mod/assign/overrideedit.php'); 174 175 $hasinactive = false; // Whether there are any inactive overrides. 176 177 foreach ($overrides as $override) { 178 179 $fields = array(); 180 $values = array(); 181 $active = true; 182 183 // Check for inactive overrides. 184 if (!$groupmode) { 185 if (!is_enrolled($context, $override->userid)) { 186 // User not enrolled. 187 $active = false; 188 } else if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) { 189 // User cannot access the module. 190 $active = false; 191 } 192 } 193 194 // Format allowsubmissionsfromdate. 195 if (isset($override->allowsubmissionsfromdate)) { 196 $fields[] = get_string('open', 'assign'); 197 $values[] = $override->allowsubmissionsfromdate > 0 ? userdate($override->allowsubmissionsfromdate) : get_string('noopen', 198 'assign'); 199 } 200 201 // Format duedate. 202 if (isset($override->duedate)) { 203 $fields[] = get_string('duedate', 'assign'); 204 $values[] = $override->duedate > 0 ? userdate($override->duedate) : get_string('noclose', 'assign'); 205 } 206 207 // Format cutoffdate. 208 if (isset($override->cutoffdate)) { 209 $fields[] = get_string('cutoffdate', 'assign'); 210 $values[] = $override->cutoffdate > 0 ? userdate($override->cutoffdate) : get_string('noclose', 'assign'); 211 } 212 213 // Format timelimit. 214 if (isset($override->timelimit)) { 215 $fields[] = get_string('timelimit', 'assign'); 216 $values[] = $override->timelimit > 0 ? format_time($override->timelimit) : get_string('none', 'assign'); 217 } 218 219 // Icons. 220 $iconstr = ''; 221 222 // Edit. 223 $editurlstr = $overrideediturl->out(true, array('id' => $override->id)); 224 $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' . 225 $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> '; 226 // Duplicate. 227 $copyurlstr = $overrideediturl->out(true, 228 array('id' => $override->id, 'action' => 'duplicate')); 229 $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' . 230 $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> '; 231 // Delete. 232 $deleteurlstr = $overridedeleteurl->out(true, 233 array('id' => $override->id, 'sesskey' => sesskey())); 234 $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' . 235 $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> '; 236 237 if ($groupmode) { 238 $usergroupstr = '<a href="' . $groupurl->out(true, ['group' => $override->groupid]) . '" >' . 239 format_string($override->name, true, ['context' => $context]) . '</a>'; 240 241 // Move up. 242 if ($override->sortorder > 1) { 243 $iconstr .= '<a title="'.get_string('moveup').'" href="overrides.php?cmid=' . $cmid . 244 '&id=' . $override->id .'&action=movegroupoverride&dir=up&sesskey='.sesskey().'">' . 245 $OUTPUT->pix_icon('t/up', get_string('moveup')) . '</a> '; 246 } else { 247 $iconstr .= $OUTPUT->spacer() . ' '; 248 } 249 250 // Move down. 251 if ($override->sortorder < $overridecountgroup) { 252 $iconstr .= '<a title="'.get_string('movedown').'" href="overrides.php?cmid='.$cmid. 253 '&id=' . $override->id . '&action=movegroupoverride&dir=down&sesskey='.sesskey().'">' . 254 $OUTPUT->pix_icon('t/down', get_string('movedown')) . '</a> '; 255 } else { 256 $iconstr .= $OUTPUT->spacer() . ' '; 257 } 258 259 260 } else { 261 $usergroupstr = html_writer::link($userurl->out(false, 262 array('id' => $override->userid, 'course' => $course->id)), 263 fullname($override)); 264 } 265 266 $class = ''; 267 if (!$active) { 268 $class = "dimmed_text"; 269 $usergroupstr .= '*'; 270 $hasinactive = true; 271 } 272 273 $usergroupcell = new html_table_cell(); 274 $usergroupcell->rowspan = count($fields); 275 $usergroupcell->text = $usergroupstr; 276 $actioncell = new html_table_cell(); 277 $actioncell->rowspan = count($fields); 278 $actioncell->text = $iconstr; 279 280 for ($i = 0; $i < count($fields); ++$i) { 281 $row = new html_table_row(); 282 $row->attributes['class'] = $class; 283 if ($i == 0) { 284 $row->cells[] = $usergroupcell; 285 } 286 $cell1 = new html_table_cell(); 287 $cell1->text = $fields[$i]; 288 $row->cells[] = $cell1; 289 $cell2 = new html_table_cell(); 290 $cell2->text = $values[$i]; 291 $row->cells[] = $cell2; 292 if ($i == 0) { 293 $row->cells[] = $actioncell; 294 } 295 $table->data[] = $row; 296 } 297 } 298 299 // Output the table and button. 300 echo html_writer::start_tag('div', array('id' => 'assignoverrides')); 301 if (count($table->data)) { 302 echo html_writer::table($table); 303 } else { 304 if ($groupmode) { 305 echo $OUTPUT->notification(get_string('nogroupoverrides', 'mod_assign'), 'info'); 306 } else { 307 echo $OUTPUT->notification(get_string('nouseroverrides', 'mod_assign'), 'info'); 308 } 309 } 310 311 if ($hasinactive) { 312 echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'assign'), 'dimmed_text'); 313 } 314 315 echo html_writer::start_tag('div', array('class' => 'buttons')); 316 $options = array(); 317 if ($groupmode) { 318 if (empty($groups)) { 319 // There are no groups. 320 echo $OUTPUT->notification(get_string('groupsnone', 'assign'), 'error'); 321 $options['disabled'] = true; 322 } 323 } else { 324 $users = array(); 325 // See if there are any users in the assign. 326 if ($accessallgroups) { 327 $users = get_enrolled_users($context, '', 0, 'u.id'); 328 $nousermessage = get_string('usersnone', 'assign'); 329 } else if ($groups) { 330 $enrolledjoin = get_enrolled_join($context, 'u.id'); 331 list($ingroupsql, $ingroupparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 332 $params = $enrolledjoin->params + $ingroupparams; 333 $sql = "SELECT u.id 334 FROM {user} u 335 JOIN {groups_members} gm ON gm.userid = u.id 336 {$enrolledjoin->joins} 337 WHERE gm.groupid $ingroupsql 338 AND {$enrolledjoin->wheres} 339 ORDER BY $sort"; 340 $users = $DB->get_records_sql($sql, $params); 341 $nousermessage = get_string('usersnone', 'assign'); 342 } else { 343 $nousermessage = get_string('groupsnone', 'assign'); 344 } 345 $info = new \core_availability\info_module($cm); 346 $users = $info->filter_user_list($users); 347 348 if (empty($users)) { 349 // There are no users. 350 echo $OUTPUT->notification($nousermessage, 'error'); 351 $options['disabled'] = true; 352 } 353 } 354 echo html_writer::end_tag('div'); 355 echo html_writer::end_tag('div'); 356 357 // Finish the page. 358 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body