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 |
* widget layout definitions.
|
|
|
19 |
*
|
|
|
20 |
* @package block_dash
|
|
|
21 |
* @copyright 2022 bdecent gmbh <https://bdecent.de>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace block_dash\local\widget;
|
|
|
26 |
|
|
|
27 |
use block_dash\local\layout\layout_interface;
|
|
|
28 |
use moodle_exception;
|
|
|
29 |
use block_dash\local\paginator;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* widget layout definitions.
|
|
|
33 |
*/
|
|
|
34 |
abstract class abstract_layout extends \block_dash\local\layout\abstract_layout implements layout_interface, \templatable {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Get data for layout mustache template.
|
|
|
38 |
*
|
|
|
39 |
* @param \renderer_base $output
|
|
|
40 |
* @return array|\stdClass
|
|
|
41 |
* @throws \coding_exception
|
|
|
42 |
*/
|
|
|
43 |
public function export_for_template($output) {
|
|
|
44 |
global $OUTPUT, $PAGE;
|
|
|
45 |
|
|
|
46 |
$config = $this->get_data_source()->get_block_instance()->config;
|
|
|
47 |
$noresulttxt = \html_writer::tag('p', get_string('noresults'), ['class' => 'text-muted']);
|
|
|
48 |
$templatedata = [
|
|
|
49 |
'error' => '',
|
|
|
50 |
'paginator' => '',
|
|
|
51 |
'data' => null,
|
|
|
52 |
'uniqueid' => uniqid(),
|
|
|
53 |
'is_totara' => block_dash_is_totara(),
|
|
|
54 |
'bootstrap3' => get_config('block_dash', 'bootstrap_version') == 3,
|
|
|
55 |
'bootstrap4' => get_config('block_dash', 'bootstrap_version') == 4,
|
|
|
56 |
'noresult' => isset($config->emptystate['text'])
|
|
|
57 |
? format_text($config->emptystate['text'], FORMAT_HTML, ['noclean' => true]) : $noresulttxt,
|
|
|
58 |
'editing' => $PAGE->user_is_editing(),
|
|
|
59 |
];
|
|
|
60 |
|
|
|
61 |
if (!empty($this->get_data_source()->get_all_preferences())) {
|
|
|
62 |
try {
|
|
|
63 |
$templatedata['data'] = $this->get_data_source()->get_widget_data();
|
|
|
64 |
|
|
|
65 |
} catch (\Exception $e) {
|
|
|
66 |
$error = \html_writer::tag('p', get_string('databaseerror', 'block_dash'));
|
|
|
67 |
if (is_siteadmin()) {
|
|
|
68 |
$error .= \html_writer::tag('p', $e->getMessage());
|
|
|
69 |
}
|
|
|
70 |
$templatedata['error'] .= $OUTPUT->notification($error, 'error');
|
|
|
71 |
throw new moodle_exception('datanotfetch', 'block_dash', '', null, $e->getMessage());
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
$formhtml = $this->get_data_source()->get_filter_collection()->create_form_elements();
|
|
|
76 |
|
|
|
77 |
if (!is_null($templatedata['data'])) {
|
|
|
78 |
$templatedata = array_merge($templatedata, [
|
|
|
79 |
'filter_form_html' => $formhtml,
|
|
|
80 |
'supports_filtering' => $this->supports_filtering(),
|
|
|
81 |
'supports_pagination' => $this->supports_pagination(),
|
|
|
82 |
'preferences' => $this->process_preferences($this->get_data_source()->get_all_preferences()),
|
|
|
83 |
]);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
if ($this->get_data_source()->get_paginator()->get_page_count() > 1) {
|
|
|
87 |
$templatedata['paginator'] = $OUTPUT->render_from_template(paginator::TEMPLATE, $this->get_data_source()
|
|
|
88 |
->get_paginator()
|
|
|
89 |
->export_for_template($OUTPUT));
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
return $templatedata;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Is the layout supports the fields method.
|
|
|
97 |
*
|
|
|
98 |
* @return bool
|
|
|
99 |
*/
|
|
|
100 |
public function supports_field_visibility() {
|
|
|
101 |
return true;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Is the layout supports the filter method.
|
|
|
106 |
*
|
|
|
107 |
* @return bool
|
|
|
108 |
*/
|
|
|
109 |
public function supports_filtering() {
|
|
|
110 |
return false;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Is the layout supports the pagination.
|
|
|
115 |
*
|
|
|
116 |
* @return bool
|
|
|
117 |
*/
|
|
|
118 |
public function supports_pagination() {
|
|
|
119 |
return false;
|
|
|
120 |
}
|
|
|
121 |
/**
|
|
|
122 |
* Is the layout supports the sorting.
|
|
|
123 |
*
|
|
|
124 |
* @return bool
|
|
|
125 |
*/
|
|
|
126 |
public function supports_sorting() {
|
|
|
127 |
return false;
|
|
|
128 |
}
|
|
|
129 |
}
|