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 simple view - initial view to select your search options
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 */
24
25namespace gradereport_singleview\local\screen;
26
27use gradereport_singleview;
28use moodle_url;
29
30defined('MOODLE_INTERNAL') || die;
31
32/**
33 * The gradebook simple view - initial view to select your search options
34 *
35 * @package   gradereport_singleview
36 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
37 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class select extends screen {
40
41    /**
42     * Initialise this screen
43     *
44     * @param bool $selfitemisempty Has an item been selected (will be false)
45     */
46    public function init($selfitemisempty = false) {
47        global $DB;
48
49        $roleids = explode(',', get_config('moodle', 'gradebookroles'));
50
51        $this->items = array();
52        foreach ($roleids as $roleid) {
53            // Keeping the first user appearance.
54            $this->items = $this->items + get_role_users(
55                $roleid, $this->context, false, '',
56                'u.id, u.lastname, u.firstname', null, $this->groupid,
57                $this->perpage * $this->page, $this->perpage
58            );
59        }
60        $this->item = $DB->get_record('course', array('id' => $this->courseid));
61    }
62
63    /**
64     * Get the type of items on this screen, not valid so return false.
65     *
66     * @return bool
67     */
68    public function item_type() {
69        return false;
70    }
71
72    /**
73     * Return the HTML for the page.
74     *
75     * @return string
76     */
77    public function html() {
78        global $OUTPUT;
79
80        $html = '';
81
82        $types = gradereport_singleview::valid_screens();
83
84        foreach ($types as $type) {
85            $classname = "gradereport_singleview\\local\\screen\\${type}";
86
87            $screen = new $classname($this->courseid, null, $this->groupid);
88
89            if (!$screen instanceof selectable_items) {
90                continue;
91            }
92
93            $options = $screen->options();
94
95            if (empty($options)) {
96                continue;
97            }
98
99            $params = array(
100                'id' => $this->courseid,
101                'item' => $screen->item_type(),
102                'group' => $this->groupid
103            );
104
105            $url = new moodle_url('/grade/report/singleview/index.php', $params);
106
107            $select = new \single_select($url, 'itemid', $options, '', array('' => $screen->select_label()));
108            $select->set_label($screen->select_label(), array('class'=>'accesshide'));
109            $html .= $OUTPUT->render($select);
110        }
111        $html = $OUTPUT->container($html, 'selectitems');
112
113        if (empty($html)) {
114            $OUTPUT->notification(get_string('noscreens', 'gradereport_singleview'));
115        }
116
117        return $html;
118    }
119
120    /**
121     * Should we show the next prev selector?
122     * @return bool
123     */
124    public function supports_next_prev() {
125        return false;
126    }
127}
128