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
/**
18
 * Database activity renderer.
19
 *
20
 * @copyright 2010 Sam Hemelryk
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @package mod_data
23
 */
24
 
25
use mod_data\manager;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
class mod_data_renderer extends plugin_renderer_base {
30
 
31
    /**
32
     * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more.
33
     */
1441 ariadna 34
     #[\core\attribute\deprecated('mod_data_renderer::importing_preset()', since: '4.1', mdl: 'MDL-75140', final: true)]
35
    public function import_setting_mappings(): void {
36
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
1 efrain 37
    }
38
 
39
    /**
40
     * Importing a preset on a database module.
41
     *
42
     * @param stdClass $datamodule  Database module to import to.
43
     * @param \mod_data\local\importer\preset_importer $importer Importer instance to use for the importing.
44
     *
45
     * @return string
46
     */
47
    public function importing_preset(stdClass $datamodule, \mod_data\local\importer\preset_importer $importer): string {
48
 
49
        $strwarning = get_string('mappingwarning', 'data');
50
 
51
        $params = $importer->settings;
52
        $newfields = $params->importfields;
53
        $currentfields = $params->currentfields;
54
 
55
        $html = html_writer::start_tag('div', ['class' => 'presetmapping']);
56
        $html .= html_writer::start_tag('form', ['method' => 'post', 'action' => '']);
57
        $html .= html_writer::start_tag('div');
58
        $html .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'action', 'value' => 'finishimport']);
59
        $html .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
60
        $html .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'd', 'value' => $datamodule->id]);
61
 
62
        $inputselector = $importer->get_preset_selector();
63
        $html .= html_writer::empty_tag(
64
                'input',
65
                ['type' => 'hidden', 'name' => $inputselector['name'], 'value' => $inputselector['value']]
66
        );
67
 
68
        if (!empty($newfields)) {
69
            $table = new html_table();
70
            $table->data = array();
71
 
72
            foreach ($newfields as $nid => $newfield) {
73
                $row = array();
74
                $row[0] = html_writer::tag('label', $newfield->name, array('for'=>'id_'.$newfield->name));
1441 ariadna 75
                $attrs = ['name' => 'field_' . $nid, 'id' => 'id_' . $newfield->name, 'class' => 'form-select'];
1 efrain 76
                $row[1] = html_writer::start_tag('select', $attrs);
77
 
78
                $selected = false;
79
                foreach ($currentfields as $cid => $currentfield) {
80
                    if ($currentfield->type != $newfield->type) {
81
                        continue;
82
                    }
83
                    if ($currentfield->name == $newfield->name) {
84
                        $row[1] .= html_writer::tag(
85
                            'option',
86
                            get_string('mapexistingfield', 'data', $currentfield->name),
87
                            ['value' => $cid, 'selected' => 'selected']
88
                        );
89
                        $selected = true;
90
                    } else {
91
                        $row[1] .= html_writer::tag(
92
                            'option',
93
                            get_string('mapexistingfield', 'data', $currentfield->name),
94
                            ['value' => $cid]
95
                        );
96
                    }
97
                }
98
 
99
                if ($selected) {
100
                    $row[1] .= html_writer::tag('option', get_string('mapnewfield', 'data'), array('value'=>'-1'));
101
                } else {
102
                    $row[1] .= html_writer::tag('option', get_string('mapnewfield', 'data'), array('value'=>'-1', 'selected'=>'selected'));
103
                }
104
 
105
                $row[1] .= html_writer::end_tag('select');
106
                $table->data[] = $row;
107
            }
108
            $html .= html_writer::table($table);
109
            $html .= html_writer::tag('p', $strwarning);
110
        } else {
111
            $html .= $this->output->notification(get_string('nodefinedfields', 'data'));
112
        }
113
 
114
        $html .= html_writer::start_tag('div', array('class'=>'overwritesettings'));
1441 ariadna 115
        $attrs = ['type' => 'checkbox', 'name' => 'overwritesettings', 'id' => 'overwritesettings', 'class' => 'me-2'];
1 efrain 116
        $html .= html_writer::empty_tag('input', $attrs);
117
        $html .= html_writer::tag('label', get_string('overwritesettings', 'data'), ['for' => 'overwritesettings']);
118
        $html .= html_writer::end_tag('div');
119
 
120
        $actionbuttons = html_writer::start_div();
121
        $cancelurl = new moodle_url('/mod/data/field.php', ['d' => $datamodule->id]);
122
        $actionbuttons .= html_writer::tag('a', get_string('cancel') , [
123
            'href' => $cancelurl->out(false),
124
            'class' => 'btn btn-secondary mx-1',
125
            'role' => 'button',
126
        ]);
127
        $actionbuttons .= html_writer::empty_tag('input', [
128
            'type' => 'submit',
129
            'class' => 'btn btn-primary mx-1',
130
            'value' => get_string('continue'),
131
        ]);
132
        $actionbuttons .= html_writer::end_div();
133
 
134
        $stickyfooter = new core\output\sticky_footer($actionbuttons);
135
        $html .= $this->render($stickyfooter);
136
 
137
        $html .= html_writer::end_tag('div');
138
        $html .= html_writer::end_tag('form');
139
        $html .= html_writer::end_tag('div');
140
 
141
        return $html;
142
    }
143
 
144
    /**
145
     * Renders the action bar for the field page.
146
     *
147
     * @param \mod_data\output\fields_action_bar $actionbar
148
     * @return string The HTML output
149
     */
150
    public function render_fields_action_bar(\mod_data\output\fields_action_bar $actionbar): string {
151
        $data = $actionbar->export_for_template($this);
152
        return $this->render_from_template('mod_data/action_bar', $data);
153
    }
154
 
155
    /**
156
     * Renders the fields page footer.
157
     *
158
     * @param manager $manager the instance manager
159
     * @return string The HTML output
1441 ariadna 160
     *
161
     * @deprecated since Moodle 4.5 - please do not use this function anymore
1 efrain 162
     */
1441 ariadna 163
    #[\core\attribute\deprecated(null, reason: 'It is no longer used', since: '4.5')]
1 efrain 164
    public function render_fields_footer(manager $manager): string {
1441 ariadna 165
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
166
 
1 efrain 167
        $cm = $manager->get_coursemodule();
168
        $pageurl = new moodle_url('/mod/data/templates.php', ['id' => $cm->id]);
169
        return $this->render_from_template('mod_data/fields_footer', [
170
            'pageurl' => $pageurl->out(false),
171
        ]);
172
    }
173
 
174
    /**
175
     * Renders the action bar for the view page.
176
     *
177
     * @param \mod_data\output\view_action_bar $actionbar
178
     * @return string The HTML output
179
     */
180
    public function render_view_action_bar(\mod_data\output\view_action_bar $actionbar): string {
181
        $data = $actionbar->export_for_template($this);
182
        return $this->render_from_template('mod_data/view_action_bar', $data);
183
    }
184
 
185
    /**
186
     * Renders the action bar for the template page.
187
     *
188
     * @param \mod_data\output\templates_action_bar $actionbar
189
     * @return string The HTML output
190
     */
191
    public function render_templates_action_bar(\mod_data\output\templates_action_bar $actionbar): string {
192
        $data = $actionbar->export_for_template($this);
193
        return $this->render_from_template('mod_data/templates_action_bar', $data);
194
    }
195
 
196
    /**
197
     * Renders the action bar for the preset page.
198
     *
199
     * @param \mod_data\output\presets_action_bar $actionbar
200
     * @return string The HTML output
201
     */
202
    public function render_presets_action_bar(\mod_data\output\presets_action_bar $actionbar): string {
203
        $data = $actionbar->export_for_template($this);
204
        return $this->render_from_template('mod_data/presets_action_bar', $data);
205
    }
206
 
207
    /**
208
     * Renders the presets table in the preset page.
209
     *
210
     * @param \mod_data\output\presets $presets
211
     * @return string The HTML output
212
     */
213
    public function render_presets(\mod_data\output\presets $presets): string {
214
        $data = $presets->export_for_template($this);
215
        return $this->render_from_template('mod_data/presets', $data);
216
    }
217
 
218
    /**
219
     * Renders the default template.
220
     *
221
     * @param \mod_data\output\defaulttemplate $template
222
     * @return string The HTML output
223
     */
224
    public function render_defaulttemplate(\mod_data\output\defaulttemplate $template): string {
225
        $data = $template->export_for_template($this);
226
        return $this->render_from_template($template->get_templatename(), $data);
227
    }
228
 
229
    /**
230
     * Renders the action bar for the zero state (no fields created) page.
231
     *
232
     * @param \mod_data\manager $manager The manager instance.
233
     *
234
     * @return string The HTML output
235
     */
236
    public function render_database_zero_state(\mod_data\manager $manager): string {
237
        $actionbar = new \mod_data\output\zero_state_action_bar($manager);
238
        $data = $actionbar->export_for_template($this);
239
        if (empty($data)) {
240
            // No actions for the user.
241
            $data['title'] = get_string('activitynotready');
242
            $data['intro'] = get_string('comebacklater');
243
            $data['noitemsimgurl'] = $this->output->image_url('noentries_zero_state', 'mod_data')->out();
244
        } else {
245
            $data['title'] = get_string('startbuilding', 'mod_data');
246
            $data['intro'] = get_string('createactivity', 'mod_data');
247
            $data['noitemsimgurl'] = $this->output->image_url('view_zero_state', 'mod_data')->out();
248
        }
249
 
250
        return $this->render_from_template('mod_data/zero_state', $data);
251
    }
252
 
253
    /**
254
     * Renders the action bar for an empty database view page.
255
     *
256
     * @param \mod_data\manager $manager The manager instance.
257
     *
258
     * @return string The HTML output
259
     */
260
    public function render_empty_database(\mod_data\manager $manager): string {
261
        $actionbar = new \mod_data\output\empty_database_action_bar($manager);
262
        $data = $actionbar->export_for_template($this);
263
        $data['noitemsimgurl'] = $this->output->image_url('view_zero_state', 'mod_data')->out();
264
 
265
        return $this->render_from_template('mod_data/view_noentries', $data);
266
    }
267
 
268
    /**
269
     * Renders the action bar for the zero state (no fields created) page.
270
     *
271
     * @param \mod_data\manager $manager The manager instance.
272
     *
273
     * @return string The HTML output
274
     */
275
    public function render_fields_zero_state(\mod_data\manager $manager): string {
276
        $data = [
277
            'noitemsimgurl' => $this->output->image_url('fields_zero_state', 'mod_data')->out(),
278
            'title' => get_string('nofields', 'mod_data'),
279
            'intro' => get_string('createfields', 'mod_data'),
280
            ];
281
        if ($manager->can_manage_templates()) {
282
            $actionbar = new \mod_data\output\action_bar($manager->get_instance()->id, $this->page->url);
283
            $createfieldbutton = $actionbar->get_create_fields();
284
            $data['createfieldbutton'] = $createfieldbutton->export_for_template($this);
285
        }
286
 
287
        return $this->render_from_template('mod_data/zero_state', $data);
288
    }
289
 
290
    /**
291
     * Renders the action bar for the templates zero state (no fields created) page.
292
     *
293
     * @param \mod_data\manager $manager The manager instance.
294
     *
295
     * @return string The HTML output
296
     */
297
    public function render_templates_zero_state(\mod_data\manager $manager): string {
298
        $actionbar = new \mod_data\output\zero_state_action_bar($manager);
299
        $data = $actionbar->export_for_template($this);
300
        $data['title'] = get_string('notemplates', 'mod_data');
301
        $data['intro'] = get_string('createtemplates', 'mod_data');
302
        $data['noitemsimgurl'] = $this->output->image_url('templates_zero_state', 'mod_data')->out();
303
 
304
        return $this->render_from_template('mod_data/zero_state', $data);
305
    }
306
}