b40711b648e1fef728c2ab8d64f3a4856ba63593
[moodle.git] / grade / report / singleview / lib.php
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/>.
17 /**
18  * Base lib class for singleview functionality.
19  *
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
23  */
25 defined('MOODLE_INTERNAL') || die;
27 require_once($CFG->dirroot . '/grade/report/lib.php');
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  */
36 class gradereport_singleview extends grade_report {
38     /**
39      * Return the list of valid screens, used to validate the input.
40      *
41      * @return array List of screens.
42      */
43     public static function valid_screens() {
44         // This is a list of all the known classes representing a screen in this plugin.
45         return array('user', 'select', 'grade');
46     }
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) {
55         if (has_capability('moodle/grade:manage', $this->context)) {
56             return $this->screen->process($data);
57         }
58     }
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) {
67     }
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
77      * @param string $unused Used to be group id but that was removed and this is now unused.
78      */
79     public function __construct($courseid, $gpr, $context, $itemtype, $itemid, $unused = null) {
80         parent::__construct($courseid, $gpr, $context);
82         $base = '/grade/report/singleview/index.php';
84         $idparams = array('id' => $courseid);
86         $this->baseurl = new moodle_url($base, $idparams);
88         $this->pbarurl = new moodle_url($base, $idparams + array(
89                 'item' => $itemtype,
90                 'itemid' => $itemid
91             ));
93         //  The setup_group method is used to validate group mode and permissions and define the currentgroup value.
94         $this->setup_groups();
96         $screenclass = "\\gradereport_singleview\\local\\screen\\${itemtype}";
98         $this->screen = new $screenclass($courseid, $itemid, $this->currentgroup);
100         // Load custom or predifined js.
101         $this->screen->js();
102     }
104     /**
105      * Build the html for the screen.
106      * @return string HTML to display
107      */
108     public function output() {
109         global $OUTPUT;
110         return $OUTPUT->box($this->screen->html());
111     }