2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This page handles listing of assign overrides
21 * @copyright 2016 Ilya Tregubov
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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');
32 $cmid = required_param('cmid', PARAM_INT
);
33 $mode = optional_param('mode', '', PARAM_ALPHA
); // One of 'user' or 'group', default is 'group'.
35 $action = optional_param('action', '', PARAM_ALPHA
);
36 $redirect = $CFG->wwwroot
.'/mod/assign/overrides.php?cmid=' . $cmid . '&mode=group';
38 list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'assign');
39 $assign = $DB->get_record('assign', array('id' => $cm->instance
), '*', MUST_EXIST
);
41 $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assign->id
));
43 // Get the course groups.
44 $groups = groups_get_all_groups($cm->course
);
45 if ($groups === false) {
49 // Default mode is "group", unless there are no groups.
50 if ($mode != "user" and $mode != "group") {
51 if (!empty($groups)) {
57 $groupmode = ($mode == "group");
59 $url = new moodle_url('/mod/assign/overrides.php', array('cmid' => $cm->id
, 'mode' => $mode));
63 require_login($course, false, $cm);
65 $context = context_module
::instance($cm->id
);
67 // Check the user has the required capabilities to list overrides.
68 require_capability('mod/assign:manageoverrides', $context);
70 if ($action == 'movegroupoverride') {
71 $id = required_param('id', PARAM_INT
);
72 $dir = required_param('dir', PARAM_ALPHA
);
74 if (confirm_sesskey()) {
75 move_group_override($id, $dir, $assign->id
);
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)));
87 // Delete orphaned group overrides.
89 FROM {assign_overrides} o LEFT JOIN {groups} g
91 WHERE o.groupid IS NOT NULL
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));
100 // Fetch all overrides.
102 $colname = get_string('group');
103 $sql = 'SELECT o.*, g.name
104 FROM {assign_overrides} o
105 JOIN {groups} g ON o.groupid = g.id
106 WHERE o.assignid = :assignid
107 ORDER BY o.sortorder';
108 $params = array('assignid' => $assign->id
);
110 $colname = get_string('user');
111 list($sort, $params) = users_order_by_sql('u');
112 $sql = 'SELECT o.*, ' . get_all_user_name_fields(true, 'u') . '
113 FROM {assign_overrides} o
114 JOIN {user} u ON o.userid = u.id
115 WHERE o.assignid = :assignid
117 $params['assignid'] = $assign->id
;
120 $overrides = $DB->get_records_sql($sql, $params);
123 $table = new html_table();
124 $table->headspan
= array(1, 2, 1);
125 $table->colclasses
= array('colname', 'colsetting', 'colvalue', 'colaction');
126 $table->head
= array(
128 get_string('overrides', 'assign'),
129 get_string('action'),
132 $userurl = new moodle_url('/user/view.php', array());
133 $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course
));
135 $overridedeleteurl = new moodle_url('/mod/assign/overridedelete.php');
136 $overrideediturl = new moodle_url('/mod/assign/overrideedit.php');
138 $hasinactive = false; // Whether there are any inactive overrides.
140 foreach ($overrides as $override) {
146 // Check for inactive overrides.
148 if (!is_enrolled($context, $override->userid
)) {
149 // User not enrolled.
151 } else if (!\core_availability\info_module
::is_user_visible($cm, $override->userid
)) {
152 // User cannot access the module.
157 // Format allowsubmissionsfromdate.
158 if (isset($override->allowsubmissionsfromdate
)) {
159 $fields[] = get_string('open', 'assign');
160 $values[] = $override->allowsubmissionsfromdate
> 0 ?
userdate($override->allowsubmissionsfromdate
) : get_string('noopen',
165 if (isset($override->duedate
)) {
166 $fields[] = get_string('duedate', 'assign');
167 $values[] = $override->duedate
> 0 ?
userdate($override->duedate
) : get_string('noclose', 'assign');
170 // Format cutoffdate.
171 if (isset($override->cutoffdate
)) {
172 $fields[] = get_string('cutoffdate', 'assign');
173 $values[] = $override->cutoffdate
> 0 ?
userdate($override->cutoffdate
) : get_string('noclose', 'assign');
181 $editurlstr = $overrideediturl->out(true, array('id' => $override->id
));
182 $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' .
183 $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> ';
185 $copyurlstr = $overrideediturl->out(true,
186 array('id' => $override->id
, 'action' => 'duplicate'));
187 $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' .
188 $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> ';
191 $deleteurlstr = $overridedeleteurl->out(true,
192 array('id' => $override->id
, 'sesskey' => sesskey()));
193 $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' .
194 $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> ';
197 $usergroupstr = '<a href="' . $groupurl->out(true,
198 array('group' => $override->groupid
)) . '" >' . $override->name
. '</a>';
201 if ($override->sortorder
> 1) {
202 $iconstr .= '<a title="'.get_string('moveup').'" href="overrides.php?cmid=' . $cmid .
203 '&id=' . $override->id
.'&action=movegroupoverride&dir=up&sesskey='.sesskey().'">' .
204 $OUTPUT->pix_icon('t/up', get_string('moveup')) . '</a> ';
206 $iconstr .= $OUTPUT->spacer() . ' ';
210 if ($override->sortorder
< $overridecountgroup) {
211 $iconstr .= '<a title="'.get_string('movedown').'" href="overrides.php?cmid='.$cmid.
212 '&id=' . $override->id
. '&action=movegroupoverride&dir=down&sesskey='.sesskey().'">' .
213 $OUTPUT->pix_icon('t/down', get_string('movedown')) . '</a> ';
215 $iconstr .= $OUTPUT->spacer() . ' ';
220 $usergroupstr = html_writer
::link($userurl->out(false,
221 array('id' => $override->userid
, 'course' => $course->id
)),
222 fullname($override));
227 $class = "dimmed_text";
228 $usergroupstr .= '*';
232 $usergroupcell = new html_table_cell();
233 $usergroupcell->rowspan
= count($fields);
234 $usergroupcell->text
= $usergroupstr;
235 $actioncell = new html_table_cell();
236 $actioncell->rowspan
= count($fields);
237 $actioncell->text
= $iconstr;
239 for ($i = 0; $i < count($fields); ++
$i) {
240 $row = new html_table_row();
241 $row->attributes
['class'] = $class;
243 $row->cells
[] = $usergroupcell;
245 $cell1 = new html_table_cell();
246 $cell1->text
= $fields[$i];
247 $row->cells
[] = $cell1;
248 $cell2 = new html_table_cell();
249 $cell2->text
= $values[$i];
250 $row->cells
[] = $cell2;
252 $row->cells
[] = $actioncell;
254 $table->data
[] = $row;
258 // Output the table and button.
259 echo html_writer
::start_tag('div', array('id' => 'assignoverrides'));
260 if (count($table->data
)) {
261 echo html_writer
::table($table);
264 echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'assign'), 'dimmed_text');
267 echo html_writer
::start_tag('div', array('class' => 'buttons'));
270 if (empty($groups)) {
271 // There are no groups.
272 echo $OUTPUT->notification(get_string('groupsnone', 'assign'), 'error');
273 $options['disabled'] = true;
275 echo $OUTPUT->single_button($overrideediturl->out(true,
276 array('action' => 'addgroup', 'cmid' => $cm->id
)),
277 get_string('addnewgroupoverride', 'assign'), 'post', $options);
280 // See if there are any users in the assign.
281 $users = get_enrolled_users($context);
282 $info = new \core_availability\
info_module($cm);
283 $users = $info->filter_user_list($users);
286 // There are no users.
287 echo $OUTPUT->notification(get_string('usersnone', 'assign'), 'error');
288 $options['disabled'] = true;
290 echo $OUTPUT->single_button($overrideediturl->out(true,
291 array('action' => 'adduser', 'cmid' => $cm->id
)),
292 get_string('addnewuseroverride', 'assign'), 'get', $options);
294 echo html_writer
::end_tag('div');
295 echo html_writer
::end_tag('div');
298 echo $OUTPUT->footer();