mirrored from git://git.moodle.org/moodle.git
/
site_competencies_form_element.php
99 lines (86 loc) · 3.17 KB
/
site_competencies_form_element.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
<?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/>.
/**
* Course competencies element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/form/hidden.php');
/**
* Course competencies element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_site_competencies_form_element extends MoodleQuickForm_hidden {
/**
* Constructor
*
* @param string $elementName Element name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display
* @param mixed $attributes Either a typical HTML attribute string or an associative array.
*/
public function __construct($elementName=null, $value='', $attributes=null) {
global $OUTPUT;
if ($elementName == null) {
// This is broken quickforms messing with the constructors.
return;
}
$attributes = array_merge(['data-action' => 'competencies'], $attributes?$attributes:[]);
parent::__construct($elementName, $value, $attributes);
$this->setType('hidden');
}
/**
* Generate the hidden field and the controls to show and pick the competencies.
*/
function toHtml(){
global $PAGE;
$html = parent::toHTML();
if (!$this->isFrozen()) {
$context = context_system::instance();
$params = [$context->id];
// Require some JS to select the competencies.
$PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params);
$html .= '<div class="form-group row">';
$html .= '<div class="col-md-3"></div>';
$html .= '<div class="col-md-9">';
$html .= '<div data-region="competencies"></div>';
$html .= '<div class="mt-3">';
$html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">' . get_string('addcompetency', 'tool_lp') . '</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}
/**
* Accepts a renderer
*
* @param object An HTML_QuickForm_Renderer object
* @access public
* @return void
*/
function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderElement($this, false, '');
}
}