Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace gradereport_grader\output;
18
 
19
use core\output\comboboxsearch;
1441 ariadna 20
use core_course\output\actionbar\group_selector;
21
use core_course\output\actionbar\initials_selector;
22
use core_course\output\actionbar\user_selector;
1 efrain 23
use core_grades\output\general_action_bar;
24
use moodle_url;
25
 
26
/**
27
 * Renderable class for the action bar elements in the grader report.
28
 *
29
 * @package    gradereport_grader
30
 * @copyright  2022 Mihail Geshoski <mihail@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class action_bar extends \core_grades\output\action_bar {
34
 
35
    /** @var string $usersearch The content that the current user is looking for. */
36
    protected string $usersearch = '';
37
 
38
    /** @var int $userid The ID of the user that the current user is looking for. */
39
    protected int $userid = 0;
40
 
41
    /**
42
     * The class constructor.
43
     *
44
     * @param \context_course $context The context object.
45
     */
46
    public function __construct(\context_course $context) {
47
        parent::__construct($context);
48
 
49
        $this->userid = optional_param('gpr_userid', 0, PARAM_INT);
50
        $this->usersearch = optional_param('gpr_search', '', PARAM_NOTAGS);
51
 
52
        if ($this->userid) {
53
            $user = \core_user::get_user($this->userid);
54
            $this->usersearch = fullname($user);
55
        }
56
    }
57
 
58
    /**
59
     * Returns the template for the action bar.
60
     *
61
     * @return string
62
     */
63
    public function get_template(): string {
64
        return 'gradereport_grader/action_bar';
65
    }
66
 
67
    /**
68
     * Export the data for the mustache template.
69
     *
70
     * @param \renderer_base $output renderer to be used to render the action bar elements.
71
     * @return array
72
     * @throws \moodle_exception
73
     */
74
    public function export_for_template(\renderer_base $output): array {
1441 ariadna 75
        global $SESSION, $USER;
1 efrain 76
        // If in the course context, we should display the general navigation selector in gradebook.
77
        $courseid = $this->context->instanceid;
78
        // Get the data used to output the general navigation selector.
79
        $generalnavselector = new general_action_bar($this->context,
80
            new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]), 'gradereport', 'grader');
81
 
82
        $data = $generalnavselector->export_for_template($output);
83
 
84
        // If the user has the capability to view all grades, display the group selector (if applicable), the user selector
85
        // and the view mode selector (if applicable).
86
        if (has_capability('moodle/grade:viewall', $this->context)) {
87
            $course = get_course($courseid);
88
 
89
            $firstnameinitial = $SESSION->gradereport["filterfirstname-{$this->context->id}"] ?? '';
90
            $lastnameinitial  = $SESSION->gradereport["filtersurname-{$this->context->id}"] ?? '';
1441 ariadna 91
            $additionalparams = [];
1 efrain 92
 
1441 ariadna 93
            if ($this->userid > 0) {
94
                $additionalparams['gpr_userid'] = $this->userid;
95
            } else if (!empty($this->usersearch)) {
96
                $additionalparams['gpr_search'] = $this->usersearch;
97
            }
98
 
99
            $initialselector = new initials_selector(
100
                course: $course,
101
                targeturl: '/grade/report/grader/index.php',
102
                firstinitial: $firstnameinitial,
103
                lastinitial: $lastnameinitial,
104
                additionalparams: $additionalparams,
1 efrain 105
            );
106
            $data['initialselector'] = $initialselector->export_for_template($output);
107
 
1441 ariadna 108
            if ($course->groupmode) {
109
                $gs = new group_selector($this->context);
110
                $data['groupselector'] = $gs->export_for_template($output);
111
            }
112
 
1 efrain 113
            $resetlink = new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]);
1441 ariadna 114
            $userselector = new user_selector(
115
                course: $course,
116
                resetlink: $resetlink,
117
                userid: $this->userid,
118
                groupid: 0,
119
                usersearch: $this->usersearch
1 efrain 120
            );
1441 ariadna 121
            $data['searchdropdown'] = $userselector->export_for_template($output);
1 efrain 122
            // The collapsed column dialog is aligned to the edge of the screen, we need to place it such that it also aligns.
1441 ariadna 123
            $collapsemenudirection = right_to_left() ? 'dropdown-menu-start' : 'dropdown-menu-end';
1 efrain 124
 
125
            $collapse = new comboboxsearch(
126
                true,
127
                get_string('collapsedcolumns', 'gradereport_grader', 0),
128
                null,
129
                'collapse-columns',
130
                'collapsecolumn',
131
                'collapsecolumndropdown p-3 flex-column ' . $collapsemenudirection,
132
                null,
133
                true,
134
                get_string('aria:dropdowncolumns', 'gradereport_grader'),
135
                'collapsedcolumns'
136
            );
137
            $data['collapsedcolumns'] = [
138
                'classes' => 'd-none',
139
                'content' => $collapse->export_for_template($output)
140
            ];
141
 
142
            if ($course->groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $this->context)) {
143
                $allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid);
144
            } else {
145
                $allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid);
146
            }
147
 
148
            if (
149
                $firstnameinitial ||
150
                $lastnameinitial ||
151
                groups_get_course_group($course, true, $allowedgroups) ||
152
                $this->usersearch
153
            ) {
154
                $reset = new moodle_url('/grade/report/grader/index.php', [
155
                    'id' => $courseid,
156
                    'group' => 0,
157
                    'sifirst' => '',
158
                    'silast' => ''
159
                ]);
160
                $data['pagereset'] = $reset->out(false);
161
            }
162
        }
163
 
164
        return $data;
165
    }
166
}