Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 * The gradebook user report 19 * 20 * @package gradereport_user 21 * @copyright 2007 Moodle Pty Ltd (http://moodle.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once '../../../config.php'; 26 require_once $CFG->libdir.'/gradelib.php'; 27 require_once $CFG->dirroot.'/grade/lib.php'; 28 require_once $CFG->dirroot.'/grade/report/user/lib.php'; 29 30 $courseid = required_param('id', PARAM_INT); 31 $userid = optional_param('userid', $USER->id, PARAM_INT); 32 $userview = optional_param('userview', 0, PARAM_INT); 33 34 $PAGE->set_url(new moodle_url('/grade/report/user/index.php', array('id'=>$courseid))); 35 36 if ($userview == 0) { 37 $userview = get_user_preferences('gradereport_user_view_user', GRADE_REPORT_USER_VIEW_USER); 38 } else { 39 set_user_preference('gradereport_user_view_user', $userview); 40 } 41 42 /// basic access checks 43 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 44 print_error('invalidcourseid'); 45 } 46 require_login($course); 47 $PAGE->set_pagelayout('report'); 48 49 $context = context_course::instance($course->id); 50 require_capability('gradereport/user:view', $context); 51 52 if (empty($userid)) { 53 require_capability('moodle/grade:viewall', $context); 54 55 } else { 56 if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) { 57 print_error('invaliduser'); 58 } 59 } 60 61 $access = false; 62 if (has_capability('moodle/grade:viewall', $context)) { 63 //ok - can view all course grades 64 $access = true; 65 66 } else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { 67 //ok - can view own grades 68 $access = true; 69 70 } else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades) { 71 // ok - can view grades of this user- parent most probably 72 $access = true; 73 } 74 75 if (!$access) { 76 // no access to grades! 77 print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid); 78 } 79 80 /// return tracking object 81 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$courseid, 'userid'=>$userid)); 82 83 /// last selected report session tracking 84 if (!isset($USER->grade_last_report)) { 85 $USER->grade_last_report = array(); 86 } 87 $USER->grade_last_report[$course->id] = 'user'; 88 89 // First make sure we have proper final grades. 90 grade_regrade_final_grades_if_required($course); 91 92 if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports 93 $groupmode = groups_get_course_groupmode($course); // Groups are being used 94 $currentgroup = $gpr->groupid; 95 96 if (!$currentgroup) { // To make some other functions work better later 97 $currentgroup = NULL; 98 } 99 100 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); 101 102 if ($isseparategroups and (!$currentgroup)) { 103 // no separate group access, can view only self 104 $userid = $USER->id; 105 $user_selector = false; 106 } else { 107 $user_selector = true; 108 } 109 110 $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); 111 $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); 112 $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); 113 114 $renderer = $PAGE->get_renderer('gradereport_user'); 115 116 if ($userview == GRADE_REPORT_USER_VIEW_USER) { 117 $viewasuser = true; 118 } else { 119 $viewasuser = false; 120 } 121 122 if (empty($userid)) { 123 $gui = new graded_users_iterator($course, null, $currentgroup); 124 $gui->require_active_enrolment($showonlyactiveenrol); 125 $gui->init(); 126 // Add tabs 127 print_grade_page_head($courseid, 'report', 'user'); 128 groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); 129 130 if ($user_selector) { 131 echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, true); 132 } 133 134 echo $renderer->view_user_selector($userid, $userview); 135 136 while ($userdata = $gui->next_user()) { 137 $user = $userdata->user; 138 $report = new grade_report_user($courseid, $gpr, $context, $user->id, $viewasuser); 139 140 $studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user)); 141 echo $OUTPUT->heading(get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink); 142 143 if ($report->fill_table()) { 144 echo '<br />'.$report->print_table(true); 145 } 146 echo "<p style = 'page-break-after: always;'></p>"; 147 } 148 $gui->close(); 149 } else { // Only show one user's report 150 $report = new grade_report_user($courseid, $gpr, $context, $userid, $viewasuser); 151 152 $studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user)); 153 print_grade_page_head($courseid, 'report', 'user', get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink, 154 false, false, true, null, null, $report->user); 155 156 groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); 157 158 if ($user_selector) { 159 $showallusersoptions = true; 160 echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, $showallusersoptions); 161 } 162 163 echo $renderer->view_user_selector($userid, $userview); 164 165 if ($currentgroup and !groups_is_member($currentgroup, $userid)) { 166 echo $OUTPUT->notification(get_string('groupusernotmember', 'error')); 167 } else { 168 if ($report->fill_table()) { 169 echo '<br />'.$report->print_table(true); 170 } 171 } 172 } 173 } else { //Students will see just their own report 174 175 // Create a report instance 176 $report = new grade_report_user($courseid, $gpr, $context, $userid); 177 178 // print the page 179 print_grade_page_head($courseid, 'report', 'user', get_string('pluginname', 'gradereport_user'). ' - '.fullname($report->user)); 180 181 if ($report->fill_table()) { 182 echo '<br />'.$report->print_table(true); 183 } 184 } 185 186 if (isset($report)) { 187 // Trigger report viewed event. 188 $report->viewed(); 189 } else { 190 echo html_writer::tag('div', '', array('class' => 'clearfix')); 191 echo $OUTPUT->notification(get_string('nostudentsyet')); 192 } 193 194 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body