Proyectos de Subversion Moodle

Rev

| 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 core_grades\output;
18
 
19
use moodle_url;
20
use html_writer;
21
 
22
/**
23
 * Renderable class for the action bar elements in the gradebook setup pages.
24
 *
25
 * @package    core_grades
26
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class gradebook_setup_action_bar extends action_bar {
30
 
31
    /**
32
     * Returns the template for the action bar.
33
     *
34
     * @return string
35
     */
36
    public function get_template(): string {
37
        return 'core_grades/gradebook_setup_action_bar';
38
    }
39
 
40
    /**
41
     * Export the data for the mustache template.
42
     *
43
     * @param \renderer_base $output renderer to be used to render the action bar elements.
44
     * @return array
45
     */
46
    public function export_for_template(\renderer_base $output): array {
47
        global $CFG;
48
 
49
        if ($this->context->contextlevel !== CONTEXT_COURSE) {
50
            return [];
51
        }
52
        $courseid = $this->context->instanceid;
53
        // Get the data used to output the general navigation selector.
54
        $generalnavselector = new general_action_bar($this->context,
55
            new moodle_url('/grade/edit/tree/index.php', ['id' => $courseid]), 'settings', 'setup');
56
        $data = $generalnavselector->export_for_template($output);
57
        $actions = [];
58
        $additemurl = new moodle_url('#');
59
 
60
        // Add a button to the action bar dropdown with a link to the 'add grade item' modal.
61
        $actions[] = new \action_menu_link_secondary(
62
            $additemurl,
63
            null,
64
            get_string('additem', 'grades'),
65
            [
66
                'data-courseid' => $courseid,
67
                'data-itemid' => -1,
68
                'data-trigger' => 'add-item-form',
69
                'data-gprplugin' => 'tree',
70
            ]
71
        );
72
 
73
        // If outcomes are enabled, add a button to the action bar dropdown with a link to the 'add outcome item' modal.
74
        if (!empty($CFG->enableoutcomes) && count(\grade_outcome::fetch_all_available($courseid)) > 0) {
75
            // Add a button to the action bar dropdown with a link to the 'add outcome item' modal.
76
            $actions[] = new \action_menu_link_secondary(
77
                $additemurl,
78
                null,
79
                get_string('addoutcomeitem', 'grades'),
80
                [
81
                    'data-courseid' => $courseid,
82
                    'data-itemid' => -1,
83
                    'data-trigger' => 'add-outcome-form',
84
                    'data-gprplugin' => 'tree',
85
                ]
86
            );
87
        }
88
 
89
        // Add a button to the action bar dropdown with a link to the 'add category' modal.
90
        $actions[] = new \action_menu_link_secondary(
91
            $additemurl,
92
            null,
93
            get_string('addcategory', 'grades'),
94
            [
95
                'data-courseid' => $courseid,
96
                'data-category' => -1,
97
                'data-trigger' => 'add-category-form',
98
                'data-gprplugin' => 'tree',
99
            ]
100
        );
101
 
102
        $addmenu = new \action_menu($actions);
103
        $addmenu->set_menu_trigger(get_string('add'), 'btn font-weight-bold');
104
        $data['addmenu'] = $addmenu->export_for_template($output);
105
 
106
        return $data;
107
    }
108
}