| Línea 45... |
Línea 45... |
| 45 |
* The label for the setting
|
45 |
* The label for the setting
|
| 46 |
* @var string
|
46 |
* @var string
|
| 47 |
*/
|
47 |
*/
|
| 48 |
protected $label;
|
48 |
protected $label;
|
| 49 |
/**
|
49 |
/**
|
| - |
|
50 |
* The optional accessible label for the setting.
|
| - |
|
51 |
* @var string
|
| - |
|
52 |
*/
|
| - |
|
53 |
protected string $altlabel = '';
|
| - |
|
54 |
/**
|
| 50 |
* An array of HTML attributes to apply to this setting
|
55 |
* An array of HTML attributes to apply to this setting
|
| 51 |
* @var array
|
56 |
* @var array
|
| 52 |
*/
|
57 |
*/
|
| 53 |
protected $attributes = array();
|
58 |
protected $attributes = array();
|
| 54 |
/**
|
59 |
/**
|
| Línea 98... |
Línea 103... |
| 98 |
public function get_label() {
|
103 |
public function get_label() {
|
| 99 |
return $this->label;
|
104 |
return $this->label;
|
| 100 |
}
|
105 |
}
|
| Línea 101... |
Línea 106... |
| 101 |
|
106 |
|
| - |
|
107 |
/**
|
| - |
|
108 |
* Get the visually hidden label for the UI setting.
|
| - |
|
109 |
*
|
| - |
|
110 |
* @return string
|
| - |
|
111 |
*/
|
| - |
|
112 |
public function get_visually_hidden_label(): ?string {
|
| - |
|
113 |
global $PAGE;
|
| - |
|
114 |
if ($this->altlabel === '') {
|
| - |
|
115 |
return null;
|
| - |
|
116 |
}
|
| - |
|
117 |
$renderer = $PAGE->get_renderer('core_backup');
|
| - |
|
118 |
return $renderer->visually_hidden_text($this->altlabel);
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| 102 |
/**
|
121 |
/**
|
| 103 |
* Gets the type of this element
|
122 |
* Gets the type of this element
|
| 104 |
* @return int
|
123 |
* @return int
|
| 105 |
*/
|
124 |
*/
|
| 106 |
public function get_type() {
|
125 |
public function get_type() {
|
| Línea 160... |
Línea 179... |
| 160 |
|
179 |
|
| 161 |
$this->label = $label;
|
180 |
$this->label = $label;
|
| Línea 162... |
Línea 181... |
| 162 |
}
|
181 |
}
|
| - |
|
182 |
|
| - |
|
183 |
/**
|
| - |
|
184 |
* Adds a visually hidden label to the UI setting.
|
| - |
|
185 |
*
|
| - |
|
186 |
* Some backup fields labels have unaccessible labels for screen readers. For example,
|
| - |
|
187 |
* all schema activity user data uses '-' as label. This method adds extra information
|
| - |
|
188 |
* for screen readers.
|
| - |
|
189 |
*
|
| - |
|
190 |
* @param string $label The accessible label to be added.
|
| - |
|
191 |
* @return void
|
| - |
|
192 |
*/
|
| - |
|
193 |
public function set_visually_hidden_label(string $label): void {
|
| - |
|
194 |
$this->altlabel = clean_param($label, PARAM_CLEANHTML);
|
| - |
|
195 |
}
|
| 163 |
|
196 |
|
| 164 |
/**
|
197 |
/**
|
| 165 |
* Disables the UI for this element
|
198 |
* Disables the UI for this element
|
| 166 |
*/
|
199 |
*/
|
| 167 |
public function disable() {
|
200 |
public function disable() {
|
| Línea 210... |
Línea 243... |
| 210 |
* @param backup_setting $setting
|
243 |
* @param backup_setting $setting
|
| 211 |
* @param string $label The label to display with the setting ui
|
244 |
* @param string $label The label to display with the setting ui
|
| 212 |
* @param array $attributes Array of HTML attributes to apply to the element
|
245 |
* @param array $attributes Array of HTML attributes to apply to the element
|
| 213 |
* @param array $options Array of options to apply to the setting ui object
|
246 |
* @param array $options Array of options to apply to the setting ui object
|
| 214 |
*/
|
247 |
*/
|
| 215 |
public function __construct(backup_setting $setting, $label = null, array $attributes = null, array $options = null) {
|
248 |
public function __construct(backup_setting $setting, $label = null, ?array $attributes = null, ?array $options = null) {
|
| 216 |
parent::__construct($setting);
|
249 |
parent::__construct($setting);
|
| 217 |
// Improve the inputs name by appending the level to the name.
|
250 |
// Improve the inputs name by appending the level to the name.
|
| 218 |
switch ($setting->get_level()) {
|
251 |
switch ($setting->get_level()) {
|
| 219 |
case backup_setting::ROOT_LEVEL :
|
252 |
case backup_setting::ROOT_LEVEL :
|
| 220 |
$this->name = 'root_'.$setting->get_name();
|
253 |
$this->name = 'root_'.$setting->get_name();
|
| 221 |
break;
|
254 |
break;
|
| 222 |
case backup_setting::COURSE_LEVEL :
|
255 |
case backup_setting::COURSE_LEVEL :
|
| 223 |
$this->name = 'course_'.$setting->get_name();
|
256 |
$this->name = 'course_'.$setting->get_name();
|
| 224 |
break;
|
257 |
break;
|
| 225 |
case backup_setting::SECTION_LEVEL :
|
258 |
case backup_setting::SECTION_LEVEL :
|
| - |
|
259 |
case backup_setting::SUBSECTION_LEVEL:
|
| 226 |
$this->name = 'section_'.$setting->get_name();
|
260 |
$this->name = 'section_'.$setting->get_name();
|
| 227 |
break;
|
261 |
break;
|
| 228 |
case backup_setting::ACTIVITY_LEVEL :
|
262 |
case backup_setting::ACTIVITY_LEVEL :
|
| - |
|
263 |
case backup_setting::SUBACTIVITY_LEVEL:
|
| 229 |
$this->name = 'activity_'.$setting->get_name();
|
264 |
$this->name = 'activity_'.$setting->get_name();
|
| 230 |
break;
|
265 |
break;
|
| 231 |
}
|
266 |
}
|
| 232 |
$this->label = $label;
|
267 |
$this->label = $label;
|
| 233 |
if (is_array($attributes)) {
|
268 |
if (is_array($attributes)) {
|
| Línea 247... |
Línea 282... |
| 247 |
* @param string $label The label to display with the setting ui
|
282 |
* @param string $label The label to display with the setting ui
|
| 248 |
* @param array $attributes Array of HTML attributes to apply to the element
|
283 |
* @param array $attributes Array of HTML attributes to apply to the element
|
| 249 |
* @param array $options Array of options to apply to the setting ui object
|
284 |
* @param array $options Array of options to apply to the setting ui object
|
| 250 |
* @return backup_setting_ui_text|backup_setting_ui_checkbox|backup_setting_ui_select|backup_setting_ui_radio
|
285 |
* @return backup_setting_ui_text|backup_setting_ui_checkbox|backup_setting_ui_select|backup_setting_ui_radio
|
| 251 |
*/
|
286 |
*/
|
| 252 |
final public static function make(backup_setting $setting, $type, $label, array $attributes = null, array $options = null) {
|
287 |
final public static function make(backup_setting $setting, $type, $label, ?array $attributes = null, ?array $options = null) {
|
| 253 |
// Base the decision we make on the type that was sent.
|
288 |
// Base the decision we make on the type that was sent.
|
| 254 |
switch ($type) {
|
289 |
switch ($type) {
|
| 255 |
case backup_setting::UI_HTML_CHECKBOX :
|
290 |
case backup_setting::UI_HTML_CHECKBOX :
|
| 256 |
return new backup_setting_ui_checkbox($setting, $label, null, (array)$attributes, (array)$options);
|
291 |
return new backup_setting_ui_checkbox($setting, $label, null, (array)$attributes, (array)$options);
|
| 257 |
case backup_setting::UI_HTML_DROPDOWN :
|
292 |
case backup_setting::UI_HTML_DROPDOWN :
|
| Línea 270... |
Línea 305... |
| 270 |
*
|
305 |
*
|
| 271 |
* @param base_task $task
|
306 |
* @param base_task $task
|
| 272 |
* @param renderer_base $output
|
307 |
* @param renderer_base $output
|
| 273 |
* @return array
|
308 |
* @return array
|
| 274 |
*/
|
309 |
*/
|
| 275 |
abstract public function get_element_properties(base_task $task = null, renderer_base $output = null);
|
310 |
abstract public function get_element_properties(?base_task $task = null, ?renderer_base $output = null);
|
| Línea 276... |
Línea 311... |
| 276 |
|
311 |
|
| 277 |
/**
|
312 |
/**
|
| 278 |
* Applies config options to a given properties array and then returns it
|
313 |
* Applies config options to a given properties array and then returns it
|
| 279 |
* @param array $properties
|
314 |
* @param array $properties
|
| Línea 290... |
Línea 325... |
| 290 |
* Gets the label for this item
|
325 |
* Gets the label for this item
|
| 291 |
* @param base_task $task Optional, if provided and the setting is an include
|
326 |
* @param base_task $task Optional, if provided and the setting is an include
|
| 292 |
* $task is used to set the setting label
|
327 |
* $task is used to set the setting label
|
| 293 |
* @return string
|
328 |
* @return string
|
| 294 |
*/
|
329 |
*/
|
| 295 |
public function get_label(base_task $task = null) {
|
330 |
public function get_label(?base_task $task = null) {
|
| 296 |
// If a task has been provided and the label is not already set meaningfully
|
331 |
// If a task has been provided and the label is not already set meaningfully
|
| 297 |
// we will attempt to improve it.
|
332 |
// we will attempt to improve it.
|
| 298 |
if (!is_null($task) && $this->label == $this->setting->get_name() && strpos($this->setting->get_name(), '_include') !== false) {
|
333 |
if (!is_null($task) && $this->label == $this->setting->get_name() && strpos($this->setting->get_name(), '_include') !== false) {
|
| - |
|
334 |
$level = $this->setting->get_level();
|
| 299 |
if ($this->setting->get_level() == backup_setting::SECTION_LEVEL) {
|
335 |
if ($level == backup_setting::SECTION_LEVEL || $level == backup_setting::SUBSECTION_LEVEL) {
|
| 300 |
$this->label = get_string('includesection', 'backup', $task->get_name());
|
336 |
$this->label = get_string('includesection', 'backup', $task->get_name());
|
| 301 |
} else if ($this->setting->get_level() == backup_setting::ACTIVITY_LEVEL) {
|
337 |
} else if ($level == backup_setting::ACTIVITY_LEVEL || $level == backup_setting::SUBACTIVITY_LEVEL) {
|
| 302 |
$this->label = $task->get_name();
|
338 |
$this->label = $task->get_name();
|
| 303 |
}
|
339 |
}
|
| 304 |
}
|
340 |
}
|
| 305 |
return $this->label;
|
341 |
return $this->label;
|
| 306 |
}
|
342 |
}
|
| Línea 363... |
Línea 399... |
| 363 |
* Returns an array of properties suitable for generating a quickforms element
|
399 |
* Returns an array of properties suitable for generating a quickforms element
|
| 364 |
* @param base_task $task
|
400 |
* @param base_task $task
|
| 365 |
* @param renderer_base $output
|
401 |
* @param renderer_base $output
|
| 366 |
* @return array (element, name, label, attributes)
|
402 |
* @return array (element, name, label, attributes)
|
| 367 |
*/
|
403 |
*/
|
| 368 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
404 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 369 |
$icon = $this->get_icon();
|
405 |
$icon = $this->get_icon();
|
| 370 |
$context = context_course::instance($task->get_courseid());
|
406 |
$context = context_course::instance($task->get_courseid());
|
| 371 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
407 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
| 372 |
if (!empty($icon)) {
|
408 |
if (!empty($icon)) {
|
| 373 |
$label .= $output->render($icon);
|
409 |
$label .= $output->render($icon);
|
| Línea 426... |
Línea 462... |
| 426 |
* Returns an array of properties suitable for generating a quickforms element
|
462 |
* Returns an array of properties suitable for generating a quickforms element
|
| 427 |
* @param base_task $task
|
463 |
* @param base_task $task
|
| 428 |
* @param renderer_base $output
|
464 |
* @param renderer_base $output
|
| 429 |
* @return array (element, name, label, text, attributes);
|
465 |
* @return array (element, name, label, text, attributes);
|
| 430 |
*/
|
466 |
*/
|
| 431 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
467 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 432 |
// Name, label, text, attributes.
|
468 |
// Name, label, text, attributes.
|
| 433 |
$icon = $this->get_icon();
|
469 |
$icon = $this->get_icon();
|
| 434 |
$context = context_course::instance($task->get_courseid());
|
470 |
$context = context_course::instance($task->get_courseid());
|
| 435 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
471 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
| 436 |
if (!empty($icon)) {
|
472 |
if (!empty($icon)) {
|
| 437 |
$label .= $output->render($icon);
|
473 |
$label .= $output->render($icon);
|
| 438 |
}
|
474 |
}
|
| - |
|
475 |
$altlabel = $this->get_visually_hidden_label();
|
| - |
|
476 |
if (!empty($altlabel)) {
|
| - |
|
477 |
$label = $altlabel . $label;
|
| - |
|
478 |
}
|
| 439 |
return $this->apply_options(array(
|
479 |
return $this->apply_options(array(
|
| 440 |
'element' => 'checkbox',
|
480 |
'element' => 'checkbox',
|
| 441 |
'name' => self::NAME_PREFIX.$this->name,
|
481 |
'name' => self::NAME_PREFIX.$this->name,
|
| 442 |
'label' => $label,
|
482 |
'label' => $label,
|
| 443 |
'text' => $this->text,
|
483 |
'text' => $this->text,
|
| Línea 538... |
Línea 578... |
| 538 |
* Returns an array of properties suitable for generating a quickforms element
|
578 |
* Returns an array of properties suitable for generating a quickforms element
|
| 539 |
* @param base_task $task
|
579 |
* @param base_task $task
|
| 540 |
* @param renderer_base $output
|
580 |
* @param renderer_base $output
|
| 541 |
* @return array (element, name, label, text, value, attributes)
|
581 |
* @return array (element, name, label, text, value, attributes)
|
| 542 |
*/
|
582 |
*/
|
| 543 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
583 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 544 |
$icon = $this->get_icon();
|
584 |
$icon = $this->get_icon();
|
| 545 |
$context = context_course::instance($task->get_courseid());
|
585 |
$context = context_course::instance($task->get_courseid());
|
| 546 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
586 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
| 547 |
if (!empty($icon)) {
|
587 |
if (!empty($icon)) {
|
| 548 |
$label .= $output->render($icon);
|
588 |
$label .= $output->render($icon);
|
| Línea 616... |
Línea 656... |
| 616 |
* Returns an array of properties suitable for generating a quickforms element
|
656 |
* Returns an array of properties suitable for generating a quickforms element
|
| 617 |
* @param base_task $task
|
657 |
* @param base_task $task
|
| 618 |
* @param renderer_base $output
|
658 |
* @param renderer_base $output
|
| 619 |
* @return array (element, name, label, options, attributes)
|
659 |
* @return array (element, name, label, options, attributes)
|
| 620 |
*/
|
660 |
*/
|
| 621 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
661 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 622 |
$icon = $this->get_icon();
|
662 |
$icon = $this->get_icon();
|
| 623 |
$context = context_course::instance($task->get_courseid());
|
663 |
$context = context_course::instance($task->get_courseid());
|
| 624 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
664 |
$label = format_string($this->get_label($task), true, array('context' => $context));
|
| 625 |
if (!empty($icon)) {
|
665 |
if (!empty($icon)) {
|
| 626 |
$label .= $output->render($icon);
|
666 |
$label .= $output->render($icon);
|
| Línea 689... |
Línea 729... |
| 689 |
* Returns an array of properties suitable for generating a quickforms element
|
729 |
* Returns an array of properties suitable for generating a quickforms element
|
| 690 |
* @param base_task $task
|
730 |
* @param base_task $task
|
| 691 |
* @param renderer_base $output
|
731 |
* @param renderer_base $output
|
| 692 |
* @return array (element, name, label, options, attributes)
|
732 |
* @return array (element, name, label, options, attributes)
|
| 693 |
*/
|
733 |
*/
|
| 694 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
734 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 695 |
if (!array_key_exists('optional', $this->attributes)) {
|
735 |
if (!array_key_exists('optional', $this->attributes)) {
|
| 696 |
$this->attributes['optional'] = false;
|
736 |
$this->attributes['optional'] = false;
|
| 697 |
}
|
737 |
}
|
| 698 |
$properties = parent::get_element_properties($task, $output);
|
738 |
$properties = parent::get_element_properties($task, $output);
|
| 699 |
$properties['element'] = 'date_selector';
|
739 |
$properties['element'] = 'date_selector';
|
| Línea 728... |
Línea 768... |
| 728 |
* @param backup_setting $setting
|
768 |
* @param backup_setting $setting
|
| 729 |
* @param string $label The label to display with the setting ui
|
769 |
* @param string $label The label to display with the setting ui
|
| 730 |
* @param array $attributes Array of HTML attributes to apply to the element
|
770 |
* @param array $attributes Array of HTML attributes to apply to the element
|
| 731 |
* @param array $options Array of options to apply to the setting ui object
|
771 |
* @param array $options Array of options to apply to the setting ui object
|
| 732 |
*/
|
772 |
*/
|
| 733 |
public function __construct(backup_setting $setting, $label = null, array $attributes = null, array $options = null) {
|
773 |
public function __construct(backup_setting $setting, $label = null, ?array $attributes = null, ?array $options = null) {
|
| 734 |
if (!is_array($attributes)) {
|
774 |
if (!is_array($attributes)) {
|
| 735 |
$attributes = [];
|
775 |
$attributes = [];
|
| 736 |
}
|
776 |
}
|
| 737 |
$attributes += ['customlabel' => get_string('overwrite', 'backup'),
|
777 |
$attributes += ['customlabel' => get_string('overwrite', 'backup'),
|
| 738 |
'type' => 'text'];
|
778 |
'type' => 'text'];
|
| Línea 743... |
Línea 783... |
| 743 |
* Returns an array of properties suitable for generating a quickforms element
|
783 |
* Returns an array of properties suitable for generating a quickforms element
|
| 744 |
* @param base_task $task
|
784 |
* @param base_task $task
|
| 745 |
* @param renderer_base $output
|
785 |
* @param renderer_base $output
|
| 746 |
* @return array (element, name, label, options, attributes)
|
786 |
* @return array (element, name, label, options, attributes)
|
| 747 |
*/
|
787 |
*/
|
| 748 |
public function get_element_properties(base_task $task = null, renderer_base $output = null) {
|
788 |
public function get_element_properties(?base_task $task = null, ?renderer_base $output = null) {
|
| 749 |
return ['element' => 'defaultcustom'] + parent::get_element_properties($task, $output);
|
789 |
return ['element' => 'defaultcustom'] + parent::get_element_properties($task, $output);
|
| 750 |
}
|
790 |
}
|
| Línea 751... |
Línea 791... |
| 751 |
|
791 |
|
| 752 |
/**
|
792 |
/**
|