forked from jrangelardila/moodle-format_buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
334 lines (306 loc) · 10.3 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use core\output\inplace_editable;
/**
* Plugin version and other meta-data are defined here.
*
* @package format_buttons
* @copyright 2023 Jhon Rangel <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_buttons extends core_courseformat\base
{
protected function __construct($format, $courseid)
{
parent::__construct($format, $courseid);
$this->set_section_number(false);
}
/**
* Returns true if this course format uses sections.
*
* @return bool
*/
public function uses_sections()
{
return true;
}
/**
* Retornar si se usa identación
*
* @return bool
*/
public function uses_indentation(): bool
{
return true;
}
/**
* Retornar si usa index
*
* @return true
*/
public function uses_course_index()
{
return true;
}
/**
* Returns the information about the ajax support in the given source format.
*
* The returned object's property (boolean)capable indicates that
* the course format supports Moodle course ajax features.
*
* @return stdClass
*/
public function supports_ajax()
{
$ajaxsupport = new stdClass();
$ajaxsupport->capable = true;
return $ajaxsupport;
}
/**
* Retornar el uso de components
*
* @return true
*/
public function supports_components()
{
return true;
}
/**
* Whether this format allows to delete sections.
*
* Do not call this function directly, instead use {@link course_can_delete_section()}
*
* @param int|stdClass|section_info $section
* @return bool
*/
public function can_delete_section($section)
{
return true;
}
/**
* Indicates whether the course format supports the creation of a news forum.
*
* @return bool
*/
public function supports_news()
{
return true;
}
/**
* Returns the display name of the given section that the course prefers.
*
* This method is required for inplace section name editor.
*
* @param int|stdClass $section Section object from database or just field section.section
* @return string Display name that the course format prefers, e.g. "Topic 2"
*/
public function get_section_name($section)
{
$section = $this->get_section($section);
if ((string)$section->name !== '') {
return format_string(
$section->name,
true,
['context' => context_course::instance($this->courseid)]
);
} else {
return $this->get_default_section_name($section);
}
}
/**
* Opciones personalizadas del curso
*
* @param $foreditform
* @return array
* @throws coding_exception
* @throws dml_exception
*/
public function course_format_options($foreditform = false)
{
global $PAGE;
$courseformatoptionsedit['colorfont'] = array(
'label' => get_string('colorfont', 'format_buttons'),
'help' => 'colorfont',
'help_component' => 'format_buttons',
'element_type' => 'text',
'default' => get_config('format_buttons', 'fontcolor')
);
$courseformatoptionsedit['bgcolor'] = array(
'label' => get_string('bgcolor', 'format_buttons'),
'help' => 'bgcolor',
'help_component' => 'format_buttons',
'element_type' => 'text',
'default' => get_config('format_buttons', 'bgcolor')
);
$courseformatoptionsedit['bgcolor_selected'] = array(
'label' => get_string('bgcolor_selected', 'format_buttons'),
'help' => 'bgcolor',
'help_component' => 'format_buttons',
'element_type' => 'text',
'default' => get_config('format_buttons', 'bgcolor_selected')
);
$courseformatoptionsedit['fontcolor_selected'] = array(
'label' => get_string('fontcolor_selected', 'format_buttons'),
'help' => 'colorfont',
'help_component' => 'format_buttons',
'element_type' => 'text',
'default' => get_config('format_buttons', 'fontcolor_selected')
);
$opt = get_config('format_buttons', 'selectoption');
$courseformatoptionsedit['selectoption'] = array(
'label' => get_string('selectoption', 'format_buttons'),
'help' => 'selectoption',
'help_component' => 'format_buttons',
'element_type' => 'select',
'default' => $opt,
'element_attributes' => array(
array(
'number' => get_string('option1', 'format_buttons'),
'leter_lowercase' => get_string('option2', 'format_buttons'),
'leter_uppercase' => get_string('option3', 'format_buttons'),
'roman_numbers' => get_string('option4', 'format_buttons')
)
)
);
$courseformatoptionsedit['selectform'] = array(
'label' => get_string('selectformbtn', 'format_buttons'),
'help' => 'selectform',
'help_component' => 'format_buttons',
'element_type' => 'select',
'default' => 'rounded',
'element_attributes' => array(
array(
'square' => get_string('square', 'format_buttons'),
'rounded' => get_string('rounded', 'format_buttons'),
)
)
);
$courseformatoptionsedit['title_section_view'] = array(
'label' => get_string('title_section_view', 'format_buttons'),
'help' => 'title_section_view',
'help_component' => 'format_buttons',
'element_type' => 'select',
'default' => '0',
'element_attributes' => array(
array(
'0' => get_string('no'),
'1' => get_string('yes'),
)
)
);
$courseformatoptionsedit['section_zero_ubication'] = array(
'label' => get_string('section_zero_ubication', 'format_buttons'),
'help' => 'section_zero_ubication',
'help_component' => 'format_buttons',
'element_type' => 'select',
'default' => '0',
'element_attributes' => array(
array(
'0' => get_string('no'),
'1' => get_string('yes'),
)
)
);
$max_groups = get_config('format_buttons', 'max_groups');
if ($max_groups != 0) {
$max_sections = $this->get_max_sections();
$numbers = range(0, $max_sections);
for ($i = 0; $i < $max_groups; $i++) {
$courseformatoptionsedit['group_sections' . ($i + 1)] = array(
'label' => get_string('sections_gruping', 'format_buttons', $i + 1),
'help' => 'sections_gruping',
'help_component' => 'format_buttons',
'element_type' => 'select',
'default' => '0',
'element_attributes' => array(
$numbers
)
);
$courseformatoptionsedit['group_title' . ($i + 1)] = array(
'label' => get_string('title_gruping', 'format_buttons', $i + 1),
'help' => 'title_gruping',
'help_component' => 'format_buttons',
'element_type' => 'text',
);
$courseformatoptionsedit['group_colorfont' . ($i + 1)] = array(
'label' => get_string('color_gruping', 'format_buttons', $i + 1),
'help' => 'colorfont',
'help_component' => 'format_buttons',
'element_type' => 'text',
);
}
}
return $courseformatoptionsedit;
}
/**
* Eliminar sección
*
* @param $section
* @param $forcedeleteifnotempty
* @return bool
*/
public function delete_section($section, $forcedeleteifnotempty = false)
{
return parent::delete_section($section, $forcedeleteifnotempty); // TODO: Change the autogenerated stub
}
/**
* Bloques para ubicar
*
* @return array[]
*/
public function get_default_blocks()
{
return [
BLOCK_POS_LEFT => [],
BLOCK_POS_RIGHT => [],
];
}
/**
* Permitir actividades sigilosas
*
* @param $cm
* @param $section
* @return true
*/
public function allow_stealth_module_visibility($cm, $section)
{
return true;
}
}
/**
* Implements callback inplace_editable() allowing to edit values in-place.
*
* This method is required for inplace section name editor.
*
* @param string $itemtype
* @param int $itemid
* @param mixed $newvalue
* @return inplace_editable
*/
function format_buttons_inplace_editable($itemtype, $itemid, $newvalue)
{
global $DB, $CFG;
require_once($CFG->dirroot . '/course/lib.php');
if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
$section = $DB->get_record_sql(
'SELECT s.* FROM {course_sections} s JOIN {course} c ON s.course = c.id WHERE s.id = ? AND c.format = ?',
[$itemid, 'buttons'],
MUST_EXIST
);
$format = core_courseformat\base::instance($section->course);
return $format->inplace_editable_update_section_name($section, $itemtype, $newvalue);
}
}