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 /** 19 * Site competencies element. 20 * 21 * @package tool_lp 22 * @copyright 2019 Damyon Wiese 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 30 require_once($CFG->libdir . '/form/hidden.php'); 31 32 /** 33 * Site competencies element. 34 * 35 * @package tool_lp 36 * @copyright 2019 Damyon Wiese 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class tool_lp_site_competencies_form_element extends MoodleQuickForm_hidden { 40 41 /** 42 * Constructor 43 * 44 * @param string $elementname Element name. 45 * @param string $value The element value. 46 * @param mixed $attributes Either a typical HTML attribute string or an associative array. 47 */ 48 public function __construct($elementname=null, $value='', $attributes=null) { 49 if ($elementname == null) { 50 // This is broken quickforms messing with the constructors. 51 return; 52 } 53 $attributes = array_merge(['data-action' => 'competencies'], $attributes ? $attributes : []); 54 55 parent::__construct($elementname, $value, $attributes); 56 $this->setType('hidden'); 57 } 58 59 /** 60 * Generate the hidden field and the controls to show and pick the competencies. 61 */ 62 public function toHtml() { 63 global $PAGE; 64 65 $html = parent::toHTML(); 66 67 if (!$this->isFrozen()) { 68 $context = context_system::instance(); 69 $params = [$context->id]; 70 // Require some JS to select the competencies. 71 $PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params); 72 $html .= '<div class="form-group row">'; 73 $html .= '<div class="col-md-3"></div>'; 74 $html .= '<div class="col-md-9">'; 75 $html .= '<div data-region="competencies"></div>'; 76 $html .= '<div class="mt-3">'; 77 $html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">'; 78 $html .= get_string('addcompetency', 'tool_lp'); 79 $html .= '</a>'; 80 $html .= '</div>'; 81 $html .= '</div>'; 82 $html .= '</div>'; 83 } 84 return $html; 85 } 86 87 /** 88 * Accepts a renderer 89 * 90 * @param HTML_QuickForm_Renderer $renderer the renderer for the element. 91 * @param boolean $required not used. 92 * @param string $error not used. 93 * @return void 94 */ 95 public function accept(&$renderer, $required=false, $error=null) { 96 $renderer->renderElement($this, false, ''); 97 } 98 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body