MDL-48273 singleview: add load_user method and other group validations
[moodle.git] / grade / report / singleview / lib.php
CommitLineData
7bd4a361 1<?php
65c134f9
ZD
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 * Base lib class for singleview functionality.
19 *
20 * @package gradereport_singleview
8ec7b088 21 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
65c134f9
ZD
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
7bd4a361 24
57fac09a
DW
25defined('MOODLE_INTERNAL') || die;
26
7bd4a361 27require_once($CFG->dirroot . '/grade/report/lib.php');
7bd4a361 28
57fac09a
DW
29/**
30 * This class is the main class that must be implemented by a grade report plugin.
31 *
32 * @package gradereport_singleview
33 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
8ec7b088 36class gradereport_singleview extends grade_report {
7bd4a361 37
57fac09a
DW
38 /**
39 * Return the list of valid screens, used to validate the input.
40 *
41 * @return array List of screens.
42 */
7bd4a361 43 public static function valid_screens() {
57fac09a
DW
44 // This is a list of all the known classes representing a screen in this plugin.
45 return array('user', 'select', 'grade');
7bd4a361
ZD
46 }
47
57fac09a
DW
48 /**
49 * Process data from a form submission. Delegated to the current screen.
50 *
51 * @param array $data The data from the form
52 * @return array List of warnings
53 */
54 public function process_data($data) {
5f3decb5
ZD
55 if (has_capability('moodle/grade:manage', $this->context)) {
56 return $this->screen->process($data);
57 }
7bd4a361
ZD
58 }
59
57fac09a
DW
60 /**
61 * Unused - abstract function declared in the parent class.
62 *
63 * @param string $target
64 * @param string $action
65 */
66 public function process_action($target, $action) {
7bd4a361
ZD
67 }
68
57fac09a
DW
69 /**
70 * Constructor for this report. Creates the appropriate screen class based on itemtype.
71 *
72 * @param int $courseid The course id.
73 * @param object $gpr grade plugin return tracking object
74 * @param context_course $context
75 * @param string $itemtype Should be user, select or grade
76 * @param int $itemid The id of the user or grade item
aac66bef 77 * @param string $unused Used to be group id but that was removed and this is now unused.
57fac09a 78 */
aac66bef 79 public function __construct($courseid, $gpr, $context, $itemtype, $itemid, $unused = null) {
7bd4a361
ZD
80 parent::__construct($courseid, $gpr, $context);
81
d124a60b 82 $base = '/grade/report/singleview/index.php';
7bd4a361 83
57fac09a 84 $idparams = array('id' => $courseid);
7bd4a361 85
57fac09a 86 $this->baseurl = new moodle_url($base, $idparams);
7bd4a361 87
57fac09a 88 $this->pbarurl = new moodle_url($base, $idparams + array(
aac66bef
SL
89 'item' => $itemtype,
90 'itemid' => $itemid
91 ));
7bd4a361 92
aac66bef 93 // The setup_group method is used to validate group mode and permissions and define the currentgroup value.
7bd4a361 94 $this->setup_groups();
aac66bef
SL
95
96 $screenclass = "\\gradereport_singleview\\local\\screen\\${itemtype}";
97
98 $this->screen = new $screenclass($courseid, $itemid, $this->currentgroup);
99
100 // Load custom or predifined js.
101 $this->screen->js();
7bd4a361
ZD
102 }
103
57fac09a
DW
104 /**
105 * Build the html for the screen.
106 * @return string HTML to display
107 */
108 public function output() {
7bd4a361
ZD
109 global $OUTPUT;
110 return $OUTPUT->box($this->screen->html());
111 }
112}
113