Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
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 $userfieldsapi = \core_user\fields::for_name(); 125 if ($accessallgroups) { 126 $sql = 'SELECT o.*, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects . ' 127 FROM {assign_overrides} o 128 JOIN {user} u ON o.userid = u.id 129 WHERE o.assignid = :assignid 130 ORDER BY ' . $sort; 131 132 $overrides = $DB->get_records_sql($sql, $params); 133 } else if ($groups) { 134 list($insql, $inparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 135 $params += $inparams; 136 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 JOIN {groups_members} gm ON u.id = gm.userid 141 WHERE o.assignid = :assignid AND gm.groupid ' . $insql . ' 142 ORDER BY ' . $sort; 143 144 $overrides = $DB->get_records_sql($sql, $params); 145 } 146 } 147 148 // Initialise table. 149 $table = new html_table(); 150 $table->headspan = array(1, 2, 1); 151 $table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction'); 152 $table->head = array( 153 $colname, 154 get_string('overrides', 'assign'), 155 get_string('action'), 156 ); 157 158 $userurl = new moodle_url('/user/view.php', array()); 159 $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course)); 160 161 $overridedeleteurl = new moodle_url('/mod/assign/overridedelete.php'); 162 $overrideediturl = new moodle_url('/mod/assign/overrideedit.php'); 163 164 $hasinactive = false; // Whether there are any inactive overrides. 165 166 foreach ($overrides as $override) { 167 168 $fields = array(); 169 $values = array(); 170 $active = true; 171 172 // Check for inactive overrides. 173 if (!$groupmode) { 174 if (!is_enrolled($context, $override->userid)) { 175 // User not enrolled. 176 $active = false; 177 } else if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) { 178 // User cannot access the module. 179 $active = false; 180 } 181 } 182 183 // Format allowsubmissionsfromdate. 184 if (isset($override->allowsubmissionsfromdate)) { 185 $fields[] = get_string('open', 'assign'); 186 $values[] = $override->allowsubmissionsfromdate > 0 ? userdate($override->allowsubmissionsfromdate) : get_string('noopen', 187 'assign'); 188 } 189 190 // Format duedate. 191 if (isset($override->duedate)) { 192 $fields[] = get_string('duedate', 'assign'); 193 $values[] = $override->duedate > 0 ? userdate($override->duedate) : get_string('noclose', 'assign'); 194 } 195 196 // Format cutoffdate. 197 if (isset($override->cutoffdate)) { 198 $fields[] = get_string('cutoffdate', 'assign'); 199 $values[] = $override->cutoffdate > 0 ? userdate($override->cutoffdate) : get_string('noclose', 'assign'); 200 } 201 202 // Icons. 203 $iconstr = ''; 204 205 // Edit. 206 $editurlstr = $overrideediturl->out(true, array('id' => $override->id)); 207 $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' . 208 $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> '; 209 // Duplicate. 210 $copyurlstr = $overrideediturl->out(true, 211 array('id' => $override->id, 'action' => 'duplicate')); 212 $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' . 213 $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> '; 214 // Delete. 215 $deleteurlstr = $overridedeleteurl->out(true, 216 array('id' => $override->id, 'sesskey' => sesskey())); 217 $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' . 218 $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> '; 219 220 if ($groupmode) { 221 $usergroupstr = '<a href="' . $groupurl->out(true, 222 array('group' => $override->groupid)) . '" >' . $override->name . '</a>'; 223 224 // Move up. 225 if ($override->sortorder > 1) { 226 $iconstr .= '<a title="'.get_string('moveup').'" href="overrides.php?cmid=' . $cmid . 227 '&id=' . $override->id .'&action=movegroupoverride&dir=up&sesskey='.sesskey().'">' . 228 $OUTPUT->pix_icon('t/up', get_string('moveup')) . '</a> '; 229 } else { 230 $iconstr .= $OUTPUT->spacer() . ' '; 231 } 232 233 // Move down. 234 if ($override->sortorder < $overridecountgroup) { 235 $iconstr .= '<a title="'.get_string('movedown').'" href="overrides.php?cmid='.$cmid. 236 '&id=' . $override->id . '&action=movegroupoverride&dir=down&sesskey='.sesskey().'">' . 237 $OUTPUT->pix_icon('t/down', get_string('movedown')) . '</a> '; 238 } else { 239 $iconstr .= $OUTPUT->spacer() . ' '; 240 } 241 242 243 } else { 244 $usergroupstr = html_writer::link($userurl->out(false, 245 array('id' => $override->userid, 'course' => $course->id)), 246 fullname($override)); 247 } 248 249 $class = ''; 250 if (!$active) { 251 $class = "dimmed_text"; 252 $usergroupstr .= '*'; 253 $hasinactive = true; 254 } 255 256 $usergroupcell = new html_table_cell(); 257 $usergroupcell->rowspan = count($fields); 258 $usergroupcell->text = $usergroupstr; 259 $actioncell = new html_table_cell(); 260 $actioncell->rowspan = count($fields); 261 $actioncell->text = $iconstr; 262 263 for ($i = 0; $i < count($fields); ++$i) { 264 $row = new html_table_row(); 265 $row->attributes['class'] = $class; 266 if ($i == 0) { 267 $row->cells[] = $usergroupcell; 268 } 269 $cell1 = new html_table_cell(); 270 $cell1->text = $fields[$i]; 271 $row->cells[] = $cell1; 272 $cell2 = new html_table_cell(); 273 $cell2->text = $values[$i]; 274 $row->cells[] = $cell2; 275 if ($i == 0) { 276 $row->cells[] = $actioncell; 277 } 278 $table->data[] = $row; 279 } 280 } 281 282 // Output the table and button. 283 echo html_writer::start_tag('div', array('id' => 'assignoverrides')); 284 if (count($table->data)) { 285 echo html_writer::table($table); 286 } 287 if ($hasinactive) { 288 echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'assign'), 'dimmed_text'); 289 } 290 291 echo html_writer::start_tag('div', array('class' => 'buttons')); 292 $options = array(); 293 if ($groupmode) { 294 if (empty($groups)) { 295 // There are no groups. 296 echo $OUTPUT->notification(get_string('groupsnone', 'assign'), 'error'); 297 $options['disabled'] = true; 298 } 299 echo $OUTPUT->single_button($overrideediturl->out(true, 300 array('action' => 'addgroup', 'cmid' => $cm->id)), 301 get_string('addnewgroupoverride', 'assign'), 'post', $options); 302 } else { 303 $users = array(); 304 // See if there are any users in the assign. 305 if ($accessallgroups) { 306 $users = get_enrolled_users($context, '', 0, 'u.id'); 307 $nousermessage = get_string('usersnone', 'assign'); 308 } else if ($groups) { 309 $enrolledjoin = get_enrolled_join($context, 'u.id'); 310 list($ingroupsql, $ingroupparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED); 311 $params = $enrolledjoin->params + $ingroupparams; 312 $sql = "SELECT u.id 313 FROM {user} u 314 JOIN {groups_members} gm ON gm.userid = u.id 315 {$enrolledjoin->joins} 316 WHERE gm.groupid $ingroupsql 317 AND {$enrolledjoin->wheres} 318 ORDER BY $sort"; 319 $users = $DB->get_records_sql($sql, $params); 320 $nousermessage = get_string('usersnone', 'assign'); 321 } else { 322 $nousermessage = get_string('groupsnone', 'assign'); 323 } 324 $info = new \core_availability\info_module($cm); 325 $users = $info->filter_user_list($users); 326 327 if (empty($users)) { 328 // There are no users. 329 echo $OUTPUT->notification($nousermessage, 'error'); 330 $options['disabled'] = true; 331 } 332 echo $OUTPUT->single_button($overrideediturl->out(true, 333 array('action' => 'adduser', 'cmid' => $cm->id)), 334 get_string('addnewuseroverride', 'assign'), 'get', $options); 335 } 336 echo html_writer::end_tag('div'); 337 echo html_writer::end_tag('div'); 338 339 // Finish the page. 340 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body