Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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\output;
18
 
19
use core_block\output\block_contents;
20
use core\exception\coding_exception;
21
use moodle_page;
22
use moodle_url;
23
use stdClass;
24
 
25
/**
26
 * The maintenance renderer.
27
 *
28
 * The purpose of this renderer is to block out the core renderer methods that are not usable when the site
29
 * is running a maintenance related task.
30
 * It must always extend the core_renderer as we switch from the core_renderer to this renderer in a couple of places.
31
 *
32
 * @since Moodle 2.6
33
 * @package core
34
 * @category output
35
 * @copyright 2013 Sam Hemelryk
36
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class core_renderer_maintenance extends core_renderer {
39
    /**
40
     * Initialises the renderer instance.
41
     *
42
     * @param moodle_page $page
43
     * @param string $target
44
     * @throws coding_exception
45
     */
46
    public function __construct(moodle_page $page, $target) {
47
        if ($target !== RENDERER_TARGET_MAINTENANCE || $page->pagelayout !== 'maintenance') {
48
            throw new coding_exception('Invalid request for the maintenance renderer.');
49
        }
50
        parent::__construct($page, $target);
51
    }
52
 
53
    /**
54
     * Does nothing. The maintenance renderer cannot produce blocks.
55
     *
56
     * @param block_contents $bc
57
     * @param string $region
58
     * @return string
59
     */
60
    public function block(block_contents $bc, $region) {
61
        return '';
62
    }
63
 
64
    /**
65
     * Does nothing. The maintenance renderer cannot produce blocks.
66
     *
67
     * @param string $region
68
     * @param array $classes
69
     * @param string $tag
70
     * @param boolean $fakeblocksonly
71
     * @return string
72
     */
73
    public function blocks($region, $classes = [], $tag = 'aside', $fakeblocksonly = false) {
74
        return '';
75
    }
76
 
77
    /**
78
     * Does nothing. The maintenance renderer cannot produce blocks.
79
     *
80
     * @param string $region
81
     * @param boolean $fakeblocksonly Output fake block only.
82
     * @return string
83
     */
84
    public function blocks_for_region($region, $fakeblocksonly = false) {
85
        return '';
86
    }
87
 
88
    /**
89
     * Does nothing. The maintenance renderer cannot produce a course content header.
90
     *
91
     * @param bool $onlyifnotcalledbefore
92
     * @return string
93
     */
94
    public function course_content_header($onlyifnotcalledbefore = false) {
95
        return '';
96
    }
97
 
98
    /**
99
     * Does nothing. The maintenance renderer cannot produce a course content footer.
100
     *
101
     * @param bool $onlyifnotcalledbefore
102
     * @return string
103
     */
104
    public function course_content_footer($onlyifnotcalledbefore = false) {
105
        return '';
106
    }
107
 
108
    /**
109
     * Does nothing. The maintenance renderer cannot produce a course header.
110
     *
111
     * @return string
112
     */
113
    public function course_header() {
114
        return '';
115
    }
116
 
117
    /**
118
     * Does nothing. The maintenance renderer cannot produce a course footer.
119
     *
120
     * @return string
121
     */
122
    public function course_footer() {
123
        return '';
124
    }
125
 
126
    /**
127
     * Does nothing. The maintenance renderer cannot produce a custom menu.
128
     *
129
     * @param string $custommenuitems
130
     * @return string
131
     */
132
    public function custom_menu($custommenuitems = '') {
133
        return '';
134
    }
135
 
136
    /**
137
     * Does nothing. The maintenance renderer cannot produce a file picker.
138
     *
139
     * @param array $options
140
     * @return string
141
     */
142
    public function file_picker($options) {
143
        return '';
144
    }
145
 
146
    /**
147
     * Overridden confirm message for upgrades.
148
     *
149
     * @param string $message The question to ask the user
150
     * @param single_button|moodle_url|string $continue The single_button component representing the Continue answer.
151
     * @param single_button|moodle_url|string $cancel The single_button component representing the Cancel answer.
152
     * @param array $displayoptions optional extra display options
153
     * @return string HTML fragment
154
     */
155
    public function confirm($message, $continue, $cancel, array $displayoptions = []) {
156
        // We need plain styling of confirm boxes on upgrade because we don't know which stylesheet we have (it could be
157
        // from any previous version of Moodle).
158
        if ($continue instanceof single_button) {
159
            $continue->type = single_button::BUTTON_PRIMARY;
160
        } else if (is_string($continue)) {
161
            $continue = new single_button(
162
                new moodle_url($continue),
163
                get_string('continue'),
164
                'post',
165
                $displayoptions['type'] ?? single_button::BUTTON_PRIMARY
166
            );
167
        } else if ($continue instanceof moodle_url) {
168
            $continue = new single_button(
169
                $continue,
170
                get_string('continue'),
171
                'post',
172
                $displayoptions['type'] ?? single_button::BUTTON_PRIMARY
173
            );
174
        } else {
175
            throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL' .
176
                                       ' (string/moodle_url) or a single_button instance.');
177
        }
178
 
179
        if ($cancel instanceof single_button) {
180
            $output = '';
181
        } else if (is_string($cancel)) {
182
            $cancel = new single_button(new moodle_url($cancel), get_string('cancel'), 'get');
183
        } else if ($cancel instanceof moodle_url) {
184
            $cancel = new single_button($cancel, get_string('cancel'), 'get');
185
        } else {
186
            throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL' .
187
                                       ' (string/moodle_url) or a single_button instance.');
188
        }
189
 
190
        $output = $this->box_start('generalbox', 'notice');
191
        $output .= html_writer::tag('h4', get_string('confirm'));
192
        $output .= html_writer::tag('p', $message);
193
        $output .= html_writer::tag('div', $this->render($cancel) . $this->render($continue), ['class' => 'buttons']);
194
        $output .= $this->box_end();
195
        return $output;
196
    }
197
 
198
    /**
199
     * Does nothing. The maintenance renderer does not support JS.
200
     *
201
     * @param block_contents $bc
202
     */
203
    public function init_block_hider_js(block_contents $bc) {
204
        // Does nothing.
205
    }
206
 
207
    /**
208
     * Does nothing. The maintenance renderer cannot produce language menus.
209
     *
210
     * @return string
211
     */
212
    public function lang_menu() {
213
        return '';
214
    }
215
 
216
    /**
217
     * Does nothing. The maintenance renderer has no need for login information.
218
     *
219
     * @param mixed $withlinks
220
     * @return string
221
     */
222
    public function login_info($withlinks = null) {
223
        return '';
224
    }
225
 
226
    /**
227
     * Secure login info.
228
     *
229
     * @return string
230
     */
231
    public function secure_login_info() {
232
        return $this->login_info(false);
233
    }
234
 
235
    /**
236
     * Does nothing. The maintenance renderer cannot produce user pictures.
237
     *
238
     * @param stdClass $user
239
     * @param null|array $options
240
     * @return string
241
     */
242
    public function user_picture(stdClass $user, ?array $options = null) {
243
        return '';
244
    }
245
}
246
 
247
// Alias this class to the old name.
248
// This file will be autoloaded by the legacyclasses autoload system.
249
// In future all uses of this class will be corrected and the legacy references will be removed.
250
class_alias(core_renderer_maintenance::class, \core_renderer_maintenance::class);