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 * Displays the Single view
20 * @package gradereport_singleview
21 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../../../config.php');
26 require_once($CFG->dirroot
.'/lib/gradelib.php');
27 require_once($CFG->dirroot
.'/grade/lib.php');
28 require_once($CFG->dirroot
.'/grade/report/singleview/lib.php');
30 $courseid = required_param('id', PARAM_INT
);
31 $groupid = optional_param('group', null, PARAM_INT
);
33 // Making this work with profile reports.
34 $userid = optional_param('userid', null, PARAM_INT
);
36 $defaulttype = $userid ?
'user' : 'select';
38 $itemid = optional_param('itemid', null, PARAM_INT
);
39 $itemtype = optional_param('item', $defaulttype, PARAM_TEXT
);
40 $page = optional_param('page', 0, PARAM_INT
);
41 $perpage = optional_param('perpage', 100, PARAM_INT
);
45 $itemtype = $defaulttype;
48 $courseparams = array('id' => $courseid);
49 $PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $courseparams));
50 $PAGE->set_pagelayout('incourse');
52 if (!$course = $DB->get_record('course', $courseparams)) {
53 print_error('nocourseid');
56 require_login($course);
58 if (!in_array($itemtype, gradereport_singleview
::valid_screens())) {
59 print_error('notvalid', 'gradereport_singleview', '', $itemtype);
62 $context = context_course
::instance($course->id
);
64 // This is the normal requirements.
65 require_capability('gradereport/singleview:view', $context);
66 require_capability('moodle/grade:viewall', $context);
67 require_capability('moodle/grade:edit', $context);
69 $gpr = new grade_plugin_return(array(
71 'plugin' => 'singleview',
72 'courseid' => $courseid
75 // Last selected report session tracking.
76 if (!isset($USER->grade_last_report
)) {
77 $USER->grade_last_report
= array();
79 $USER->grade_last_report
[$course->id
] = 'singleview';
81 // First make sure we have proper final grades -
82 // this must be done before constructing of the grade tree.
83 grade_regrade_final_grades($courseid);
85 $report = new gradereport_singleview($courseid, $gpr, $context, $itemtype, $itemid);
87 $reportname = $report->screen
->heading();
89 $pluginname = get_string('pluginname', 'gradereport_singleview');
101 $currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams);
103 if ($data = data_submitted()) {
104 $PAGE->set_pagelayout('redirect');
105 $PAGE->set_title(get_string('savegrades', 'gradereport_singleview'));
106 echo $OUTPUT->header();
108 require_sesskey(); // Must have a sesskey for all actions.
109 $result = $report->process_data($data);
111 if (!empty($result->warnings
)) {
112 foreach ($result->warnings
as $warning) {
113 echo $OUTPUT->notification($warning);
116 echo $OUTPUT->notification(get_string('savegradessuccess', 'gradereport_singleview', count ((array)$result->changecount
)));
117 echo $OUTPUT->continue_button($currentpage);
118 echo $OUTPUT->footer();
122 $PAGE->set_pagelayout('report');
123 if ($itemtype == 'user') {
124 print_grade_page_head($course->id
, 'report', 'singleview', $reportname, false, false, true, null, null, $report->screen
->item
);
126 print_grade_page_head($course->id
, 'report', 'singleview', $reportname);
129 $graderrightnav = $graderleftnav = null;
131 $options = $report->screen
->options();
133 if (!empty($options)) {
135 $optionkeys = array_keys($options);
136 $optionitemid = array_shift($optionkeys);
138 $relreport = new gradereport_singleview(
139 $courseid, $gpr, $context,
140 $report->screen
->item_type(), $optionitemid
142 $reloptions = $relreport->screen
->options();
143 $reloptionssorting = array_keys($relreport->screen
->options());
145 $i = array_search($itemid, $reloptionssorting);
146 $navparams = array('item' => $itemtype, 'id' => $courseid, 'group' => $groupid);
148 $navparams['itemid'] = $reloptionssorting[$i - 1];
149 $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
150 $navprev = html_writer
::link($link, $OUTPUT->larrow() . ' ' . $reloptions[$reloptionssorting[$i - 1]]);
151 $graderleftnav = html_writer
::tag('div', $navprev, array('class' => 'itemnav previtem'));
153 if ($i < count($reloptionssorting) - 1) {
154 $navparams['itemid'] = $reloptionssorting[$i +
1];
155 $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
156 $navnext = html_writer
::link($link, $reloptions[$reloptionssorting[$i +
1]] . ' ' . $OUTPUT->rarrow());
157 $graderrightnav = html_writer
::tag('div', $navnext, array('class' => 'itemnav nextitem'));
161 if (!is_null($graderleftnav)) {
164 if (!is_null($graderrightnav)) {
165 echo $graderrightnav;
168 if ($report->screen
->supports_paging()) {
169 echo $report->screen
->pager();
172 if ($report->screen
->display_group_selector()) {
173 echo $report->group_selector
;
176 echo $report->output();
178 if ($report->screen
->supports_paging()) {
179 echo $report->screen
->pager();
182 if (!is_null($graderleftnav)) {
185 if (!is_null($graderrightnav)) {
186 echo $graderrightnav;
189 $event = \gradereport_singleview\event\grade_report_viewed
::create(
191 'context' => $context,
192 'courseid' => $courseid,
193 'relateduserid' => $USER->id
,
198 echo $OUTPUT->footer();