[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * This file contains the form add/update a competency framework. 19 * 20 * @package tool_lp 21 * @copyright 2015 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_lp\form; 26 defined('MOODLE_INTERNAL') || die(); 27 28 use stdClass; 29 30 /** 31 * Competency framework form. 32 * 33 * @package tool_lp 34 * @copyright 2015 Damyon Wiese 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class competency extends persistent { 38 39 /** @var core_competency\competency persistent class for form */ 40 protected static $persistentclass = 'core_competency\\competency'; 41 42 /** 43 * Define the form - called by parent constructor 44 */ 45 public function definition() { 46 global $PAGE, $OUTPUT; 47 48 $mform = $this->_form; 49 $framework = $this->_customdata['competencyframework']; 50 $parent = $this->_customdata['parent']; 51 $pagecontextid = $this->_customdata['pagecontextid']; 52 $competency = $this->get_persistent(); 53 54 $mform->addElement('hidden', 'competencyframeworkid'); 55 $mform->setType('competencyframeworkid', PARAM_INT); 56 $mform->setConstant('competencyframeworkid', $framework->get_id()); 57 58 $mform->addElement('header', 'generalhdr', get_string('general')); 59 60 $mform->addElement('static', 61 'frameworkdesc', 62 get_string('competencyframework', 'tool_lp'), 63 s($framework->get_shortname())); 64 65 $mform->addElement('hidden', 'parentid', '', array('id' => 'tool_lp_parentcompetency')); 66 67 $mform->setType('parentid', PARAM_INT); 68 $mform->setConstant('parentid', ($parent) ? $parent->get_id() : 0); 69 $parentlevel = ($parent) ? $parent->get_level() : 0; 70 $parentname = ($parent) ? $parent->get_shortname() : get_string('competencyframeworkroot', 'tool_lp'); 71 $parentlabel = ($competency->get_id()) ? 72 get_string('taxonomy_parent_' . $framework->get_taxonomy($parentlevel), 'tool_lp') : 73 get_string('parentcompetency', 'tool_lp'); 74 $editaction = ''; 75 if (!$competency->get_id()) { 76 $icon = $OUTPUT->pix_icon('t/editinline', get_string('parentcompetency_edit', 'tool_lp')); 77 $editaction = $OUTPUT->action_link('#', $icon, null, array('id' => 'id_parentcompetencybutton')); 78 } 79 80 $mform->addElement('static', 81 'parentdesc', 82 $parentlabel, 83 "<span id='id_parentdesc'>$parentname</span> ".$editaction); 84 // Set the picker competency when adding new competency. 85 if (!$competency->get_id()) { 86 // Call the parentcompetency_form init to initialize the competency picker for parent competency. 87 $PAGE->requires->js_call_amd('tool_lp/parentcompetency_form', 'init', array('#id_parentcompetencybutton', 88 '#tool_lp_parentcompetency', 89 '#id_parentdesc', 90 $framework->get_id(), 91 $pagecontextid)); 92 } 93 94 // Name. 95 $mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"'); 96 $mform->setType('shortname', PARAM_TEXT); 97 $mform->addRule('shortname', null, 'required', null, 'client'); 98 $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); 99 // Description. 100 $mform->addElement('editor', 'description', 101 get_string('description', 'tool_lp'), array('rows' => 4)); 102 $mform->setType('description', PARAM_RAW); 103 // ID number. 104 $mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"'); 105 $mform->setType('idnumber', PARAM_RAW); 106 $mform->addRule('idnumber', null, 'required', null, 'client'); 107 $mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); 108 109 $scales = array(null => get_string('inheritfromframework', 'tool_lp')) + get_scales_menu(); 110 $scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales); 111 $mform->setType('scaleid', PARAM_INT); 112 $mform->addHelpButton('scaleid', 'scale', 'tool_lp'); 113 114 $mform->addElement('hidden', 'scaleconfiguration', '', array('id' => 'tool_lp_scaleconfiguration')); 115 $mform->setType('scaleconfiguration', PARAM_RAW); 116 117 $mform->addElement('button', 'scaleconfigbutton', get_string('configurescale', 'tool_lp')); 118 $PAGE->requires->js_call_amd('tool_lp/scaleconfig', 'init', array('#id_scaleid', 119 '#tool_lp_scaleconfiguration', '#id_scaleconfigbutton')); 120 121 if ($competency && $competency->has_user_competencies()) { 122 // The scale is used so we "freeze" the element. Though, the javascript code for the scale 123 // configuration requires this field so we only disable it. It is fine as setting the value 124 // as a constant will ensure that nobody can change it. And it's validated in the persistent anyway. 125 $scaleid->updateAttributes(array('disabled' => 'disabled')); 126 $mform->setConstant('scaleid', $competency->get_scaleid()); 127 } 128 129 // Disable short forms. 130 $mform->setDisableShortforms(); 131 $this->add_action_buttons(true, get_string('savechanges', 'tool_lp')); 132 } 133 134 /** 135 * Convert some fields. 136 * 137 * @param stdClass $data 138 * @return object 139 */ 140 protected static function convert_fields(stdClass $data) { 141 $data = parent::convert_fields($data); 142 if (empty($data->scaleid)) { 143 $data->scaleid = null; 144 $data->scaleconfiguration = null; 145 } 146 return $data; 147 } 148 149 /** 150 * Extra validation. 151 * 152 * @param stdClass $data Data to validate. 153 * @param array $files Array of files. 154 * @param array $errors Currently reported errors. 155 * @return array of additional errors, or overridden errors. 156 */ 157 protected function extra_validation($data, $files, array &$errors) { 158 $newerrors = array(); 159 // Move the error from scaleconfiguration to the form element scale ID. 160 if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) { 161 $newerrors['scaleid'] = $errors['scaleconfiguration']; 162 unset($errors['scaleconfiguration']); 163 } 164 return $newerrors; 165 } 166 167 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |