[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 lesson overrides 19 * 20 * @package mod_lesson 21 * @copyright 2015 Jean-Michel Vedrine 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 require_once(__DIR__ . '/../../config.php'); 27 require_once($CFG->dirroot.'/mod/lesson/lib.php'); 28 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 29 require_once($CFG->dirroot.'/mod/lesson/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 list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'lesson'); 36 $lesson = $DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST); 37 38 // Get the course groups. 39 $groups = groups_get_all_groups($cm->course); 40 if ($groups === false) { 41 $groups = array(); 42 } 43 44 // Default mode is "group", unless there are no groups. 45 if ($mode != "user" and $mode != "group") { 46 if (!empty($groups)) { 47 $mode = "group"; 48 } else { 49 $mode = "user"; 50 } 51 } 52 $groupmode = ($mode == "group"); 53 54 $url = new moodle_url('/mod/lesson/overrides.php', array('cmid' => $cm->id, 'mode' => $mode)); 55 56 $PAGE->set_url($url); 57 58 require_login($course, false, $cm); 59 60 $context = context_module::instance($cm->id); 61 62 // Check the user has the required capabilities to list overrides. 63 require_capability('mod/lesson:manageoverrides', $context); 64 65 // Display a list of overrides. 66 $PAGE->set_pagelayout('admin'); 67 $PAGE->set_title(get_string('overrides', 'lesson')); 68 $PAGE->set_heading($course->fullname); 69 echo $OUTPUT->header(); 70 echo $OUTPUT->heading(format_string($lesson->name, true, array('context' => $context))); 71 72 // Delete orphaned group overrides. 73 $sql = 'SELECT o.id 74 FROM {lesson_overrides} o LEFT JOIN {groups} g 75 ON o.groupid = g.id 76 WHERE o.groupid IS NOT NULL 77 AND g.id IS NULL 78 AND o.lessonid = ?'; 79 $params = array($lesson->id); 80 $orphaned = $DB->get_records_sql($sql, $params); 81 if (!empty($orphaned)) { 82 $DB->delete_records_list('lesson_overrides', 'id', array_keys($orphaned)); 83 } 84 85 // Fetch all overrides. 86 if ($groupmode) { 87 $colname = get_string('group'); 88 $sql = 'SELECT o.*, g.name 89 FROM {lesson_overrides} o 90 JOIN {groups} g ON o.groupid = g.id 91 WHERE o.lessonid = :lessonid 92 ORDER BY g.name'; 93 $params = array('lessonid' => $lesson->id); 94 } else { 95 $colname = get_string('user'); 96 list($sort, $params) = users_order_by_sql('u'); 97 $sql = 'SELECT o.*, ' . get_all_user_name_fields(true, 'u') . ' 98 FROM {lesson_overrides} o 99 JOIN {user} u ON o.userid = u.id 100 WHERE o.lessonid = :lessonid 101 ORDER BY ' . $sort; 102 $params['lessonid'] = $lesson->id; 103 } 104 105 $overrides = $DB->get_records_sql($sql, $params); 106 107 // Initialise table. 108 $table = new html_table(); 109 $table->headspan = array(1, 2, 1); 110 $table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction'); 111 $table->head = array( 112 $colname, 113 get_string('overrides', 'lesson'), 114 get_string('action'), 115 ); 116 117 $userurl = new moodle_url('/user/view.php', array()); 118 $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course)); 119 120 $overridedeleteurl = new moodle_url('/mod/lesson/overridedelete.php'); 121 $overrideediturl = new moodle_url('/mod/lesson/overrideedit.php'); 122 123 $hasinactive = false; // Whether there are any inactive overrides. 124 125 foreach ($overrides as $override) { 126 127 $fields = array(); 128 $values = array(); 129 $active = true; 130 131 // Check for inactive overrides. 132 if (!$groupmode) { 133 if (!is_enrolled($context, $override->userid)) { 134 // User not enrolled. 135 $active = false; 136 } else if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) { 137 // User cannot access the module. 138 $active = false; 139 } 140 } 141 142 // Format available. 143 if (isset($override->available)) { 144 $fields[] = get_string('lessonopens', 'lesson'); 145 $values[] = $override->available > 0 ? 146 userdate($override->available) : get_string('noopen', 'lesson'); 147 } 148 149 // Format deadline. 150 if (isset($override->deadline)) { 151 $fields[] = get_string('lessoncloses', 'lesson'); 152 $values[] = $override->deadline > 0 ? 153 userdate($override->deadline) : get_string('noclose', 'lesson'); 154 } 155 156 // Format timelimit. 157 if (isset($override->timelimit)) { 158 $fields[] = get_string('timelimit', 'lesson'); 159 $values[] = $override->timelimit > 0 ? 160 format_time($override->timelimit) : get_string('none', 'lesson'); 161 } 162 163 // Format option to try a question again. 164 if (isset($override->review)) { 165 $fields[] = get_string('displayreview', 'lesson'); 166 $values[] = $override->review ? 167 get_string('yes') : get_string('no'); 168 } 169 170 // Format number of attempts. 171 if (isset($override->maxattempts)) { 172 $fields[] = get_string('maximumnumberofattempts', 'lesson'); 173 $values[] = $override->maxattempts > 0 ? 174 $override->maxattempts : get_string('unlimited'); 175 } 176 177 // Format retake allowed. 178 if (isset($override->retake)) { 179 $fields[] = get_string('retakesallowed', 'lesson'); 180 $values[] = $override->retake ? 181 get_string('yes') : get_string('no'); 182 } 183 184 // Format password. 185 if (isset($override->password)) { 186 $fields[] = get_string('usepassword', 'lesson'); 187 $values[] = $override->password !== '' ? 188 get_string('enabled', 'lesson') : get_string('none', 'lesson'); 189 } 190 191 // Icons. 192 $iconstr = ''; 193 194 if ($active) { 195 // Edit. 196 $editurlstr = $overrideediturl->out(true, array('id' => $override->id)); 197 $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' . 198 '<img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . 199 get_string('edit') . '" /></a> '; 200 // Duplicate. 201 $copyurlstr = $overrideediturl->out(true, 202 array('id' => $override->id, 'action' => 'duplicate')); 203 $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' . 204 '<img src="' . $OUTPUT->pix_url('t/copy') . '" class="iconsmall" alt="' . 205 get_string('copy') . '" /></a> '; 206 } 207 // Delete. 208 $deleteurlstr = $overridedeleteurl->out(true, 209 array('id' => $override->id, 'sesskey' => sesskey())); 210 $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' . 211 '<img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . 212 get_string('delete') . '" /></a> '; 213 214 if ($groupmode) { 215 $usergroupstr = '<a href="' . $groupurl->out(true, 216 array('group' => $override->groupid)) . '" >' . $override->name . '</a>'; 217 } else { 218 $usergroupstr = '<a href="' . $userurl->out(true, 219 array('id' => $override->userid)) . '" >' . fullname($override) . '</a>'; 220 } 221 222 $class = ''; 223 if (!$active) { 224 $class = "dimmed_text"; 225 $usergroupstr .= '*'; 226 $hasinactive = true; 227 } 228 229 $usergroupcell = new html_table_cell(); 230 $usergroupcell->rowspan = count($fields); 231 $usergroupcell->text = $usergroupstr; 232 $actioncell = new html_table_cell(); 233 $actioncell->rowspan = count($fields); 234 $actioncell->text = $iconstr; 235 236 for ($i = 0; $i < count($fields); ++$i) { 237 $row = new html_table_row(); 238 $row->attributes['class'] = $class; 239 if ($i == 0) { 240 $row->cells[] = $usergroupcell; 241 } 242 $cell1 = new html_table_cell(); 243 $cell1->text = $fields[$i]; 244 $row->cells[] = $cell1; 245 $cell2 = new html_table_cell(); 246 $cell2->text = $values[$i]; 247 $row->cells[] = $cell2; 248 if ($i == 0) { 249 $row->cells[] = $actioncell; 250 } 251 $table->data[] = $row; 252 } 253 } 254 255 // Output the table and button. 256 echo html_writer::start_tag('div', array('id' => 'lessonoverrides')); 257 if (count($table->data)) { 258 echo html_writer::table($table); 259 } 260 if ($hasinactive) { 261 echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'lesson'), 'dimmed_text'); 262 } 263 264 echo html_writer::start_tag('div', array('class' => 'buttons')); 265 $options = array(); 266 if ($groupmode) { 267 if (empty($groups)) { 268 // There are no groups. 269 echo $OUTPUT->notification(get_string('groupsnone', 'lesson'), 'error'); 270 $options['disabled'] = true; 271 } 272 echo $OUTPUT->single_button($overrideediturl->out(true, 273 array('action' => 'addgroup', 'cmid' => $cm->id)), 274 get_string('addnewgroupoverride', 'lesson'), 'post', $options); 275 } else { 276 $users = array(); 277 // See if there are any users in the lesson. 278 $users = get_enrolled_users($context); 279 $info = new \core_availability\info_module($cm); 280 $users = $info->filter_user_list($users); 281 282 if (empty($users)) { 283 // There are no users. 284 echo $OUTPUT->notification(get_string('usersnone', 'lesson'), 'error'); 285 $options['disabled'] = true; 286 } 287 echo $OUTPUT->single_button($overrideediturl->out(true, 288 array('action' => 'adduser', 'cmid' => $cm->id)), 289 get_string('addnewuseroverride', 'lesson'), 'get', $options); 290 } 291 echo html_writer::end_tag('div'); 292 echo html_writer::end_tag('div'); 293 294 // Finish the page. 295 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |