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 mod_data\output;
18
 
19
use action_link;
20
use core\output\sticky_footer;
21
use html_writer;
22
use mod_data\manager;
23
use mod_data\template;
24
use moodle_url;
25
use renderer_base;
26
 
27
/**
28
 * Renderable class for sticky footer in the view pages of the database activity.
29
 *
30
 * @package    mod_data
31
 * @copyright  2022 Ferran Recio <ferran@moodle.com>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class view_footer extends sticky_footer {
35
 
36
    /** @var int $totalcount the total records count. */
37
    private $totalcount;
38
 
39
    /** @var int $currentpage the current page */
40
    private $currentpage;
41
 
42
    /** @var int $nowperpage the number of elements per page */
43
    private $nowperpage;
44
 
45
    /** @var moodle_url $baseurl the page base url */
46
    private $baseurl;
47
 
48
    /** @var template $parser the template name */
49
    private $parser;
50
 
51
    /** @var manager $manager if the user can manage capabilities or not */
52
    private $manager;
53
 
54
    /**
55
     * The class constructor.
56
     *
57
     * @param manager $manager the activity manager
58
     * @param int $totalcount the total records count
59
     * @param int $currentpage the current page
60
     * @param int $nowperpage the number of elements per page
61
     * @param moodle_url $baseurl the page base url
62
     * @param template $parser the current template name
63
     */
64
    public function __construct(
65
        manager $manager,
66
        int $totalcount,
67
        int $currentpage,
68
        int $nowperpage,
69
        moodle_url $baseurl,
70
        template $parser
71
    ) {
72
        $this->manager = $manager;
73
        $this->totalcount = $totalcount;
74
        $this->currentpage = $currentpage;
75
        $this->nowperpage = $nowperpage;
76
        $this->baseurl = $baseurl;
77
        $this->parser = $parser;
78
    }
79
 
80
    /**
81
     * Export this data so it can be used as the context for a mustache template (core/inplace_editable).
82
     *
83
     * @param renderer_base $output typically, the renderer that's calling this function
84
     * @return array data context for a mustache template
85
     */
86
    public function export_for_template(renderer_base $output) {
87
        $this->set_content(
88
            $this->get_footer_output($output)
89
        );
90
        return parent::export_for_template($output);
91
    }
92
 
93
    /**
94
     * Generate the pre-rendered footer content.
95
     *
96
     * @param \renderer_base $output The renderer to be used to render the action bar elements.
97
     * @return string the rendered content
98
     */
99
    public function get_footer_output(renderer_base $output): string {
100
        $data = [];
101
 
102
        $cm = $this->manager->get_coursemodule();
103
        $instance = $this->manager->get_instance();
104
        $currentgroup = groups_get_activity_group($cm);
105
        $groupmode = groups_get_activity_groupmode($cm);
106
        $context = $this->manager->get_context();
107
        $canmanageentries = has_capability('mod/data:manageentries', $context);
108
        $parser = $this->parser;
109
 
110
        // Sticky footer content.
111
        $data['pagination'] = $output->paging_bar(
112
            $this->totalcount,
113
            $this->currentpage,
114
            $this->nowperpage,
115
            $this->baseurl
116
        );
117
 
118
        if ($parser->get_template_name() != 'singletemplate' && $parser->has_tag('delcheck') && $canmanageentries) {
119
            // Build the select/deselect all control.
120
            $selectallid = 'selectall-listview-entries';
121
            $togglegroup = 'listview-entries';
122
            $mastercheckbox = new \core\output\checkbox_toggleall($togglegroup, true, [
123
                'id' => $selectallid,
124
                'name' => $selectallid,
125
                'value' => 1,
126
                'label' => get_string('selectall'),
127
                'classes' => 'btn-secondary mx-1',
128
            ], true);
129
            $data['selectall'] = $output->render($mastercheckbox);
130
 
131
            $data['deleteselected'] = html_writer::empty_tag('input', [
132
                'class' => 'btn btn-secondary mx-1',
133
                'type' => 'submit',
134
                'value' => get_string('deleteselected'),
135
                'disabled' => true,
136
                'data-action' => 'toggle',
137
                'data-togglegroup' => $togglegroup,
138
                'data-toggle' => 'action',
139
            ]);
140
        }
141
        if (data_user_can_add_entry($instance, $currentgroup, $groupmode, $context)) {
142
            $addentrylink = new moodle_url(
143
                '/mod/data/edit.php',
144
                ['id' => $cm->id, 'backto' => $this->baseurl]
145
            );
146
            $addentrybutton = new action_link(
147
                $addentrylink,
148
                get_string('add', 'mod_data'),
149
                null,
150
                ['class' => 'btn btn-primary mx-1', 'role' => 'button']
151
            );
152
            $data['addentrybutton'] = $addentrybutton->export_for_template($output);
153
        }
154
        return $output->render_from_template('mod_data/view_footer', $data);
155
    }
156
}