Esempio n. 1
0
 /**
  * Define the form - called by parent constructor
  */
 public function definition()
 {
     global $PAGE;
     $mform = $this->_form;
     $context = $this->_customdata['context'];
     $framework = $this->get_persistent();
     $mform->addElement('hidden', 'contextid');
     $mform->setType('contextid', PARAM_INT);
     $mform->setConstant('contextid', $context->id);
     $mform->addElement('header', 'generalhdr', get_string('general'));
     // Name.
     $mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"');
     $mform->setType('shortname', PARAM_TEXT);
     $mform->addRule('shortname', null, 'required', null, 'client');
     $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
     // Description.
     $mform->addElement('editor', 'description', get_string('description', 'tool_lp'), array('rows' => 4));
     $mform->setType('description', PARAM_RAW);
     // ID number.
     $mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"');
     $mform->setType('idnumber', PARAM_RAW);
     $mform->addRule('idnumber', null, 'required', null, 'client');
     $mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
     $scales = get_scales_menu();
     $scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales);
     $mform->setType('scaleid', PARAM_INT);
     $mform->addHelpButton('scaleid', 'scale', 'tool_lp');
     $mform->addRule('scaleid', null, 'required', null, 'client');
     if ($framework && $framework->has_user_competencies()) {
         // The scale is used so we "freeze" the element. Though, the javascript code for the scale
         // configuration requires this field so we only disable it. It is fine as setting the value
         // as a constant will ensure that nobody can change it. And it's validated in the persistent anyway.
         $scaleid->updateAttributes(array('readonly' => 'readonly'));
         $mform->setConstant('scaleid', $framework->get_scaleid());
     }
     $mform->addElement('button', 'scaleconfigbutton', get_string('configurescale', 'tool_lp'));
     // Add js.
     $mform->addElement('hidden', 'scaleconfiguration', '', array('id' => 'tool_lp_scaleconfiguration'));
     $mform->setType('scaleconfiguration', PARAM_RAW);
     $PAGE->requires->js_call_amd('tool_lp/scaleconfig', 'init', array('#id_scaleid', '#tool_lp_scaleconfiguration', '#id_scaleconfigbutton'));
     $mform->addElement('selectyesno', 'visible', get_string('visible', 'tool_lp'));
     $mform->setDefault('visible', true);
     $mform->addHelpButton('visible', 'visible', 'tool_lp');
     $mform->addElement('static', 'context', get_string('category', 'tool_lp'));
     $mform->setDefault('context', $context->get_context_name(false));
     $mform->addElement('header', 'taxonomyhdr', get_string('taxonomies', 'tool_lp'));
     $taxonomies = \core_competency\competency_framework::get_taxonomies_list();
     $taxdefaults = array();
     $taxcount = max($framework ? $framework->get_depth() : 4, 4);
     for ($i = 1; $i <= $taxcount; $i++) {
         $mform->addElement('select', "taxonomies[{$i}]", get_string('levela', 'tool_lp', $i), $taxonomies);
         $taxdefaults[$i] = \core_competency\competency_framework::TAXONOMY_COMPETENCY;
     }
     // Not using taxonomies[n] here or it would takes precedence over set_data(array('taxonomies' => ...)).
     $mform->setDefault('taxonomies', $taxdefaults);
     $this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
 }
 protected function get_other_values(renderer_base $output)
 {
     $result = new stdClass();
     $context = $this->related['context'];
     $courses = $this->related['linkedcourses'];
     $linkedcourses = array();
     foreach ($courses as $course) {
         $context = context_course::instance($course->id);
         $exporter = new course_summary_exporter($course, array('context' => $context));
         $courseexport = $exporter->export($output);
         array_push($linkedcourses, $courseexport);
     }
     $result->linkedcourses = $linkedcourses;
     $result->hascourses = count($linkedcourses) > 0;
     $relatedcompetencies = array();
     foreach ($this->related['relatedcompetencies'] as $competency) {
         $exporter = new competency_exporter($competency, array('context' => $context));
         $competencyexport = $exporter->export($output);
         array_push($relatedcompetencies, $competencyexport);
     }
     $result->relatedcompetencies = $relatedcompetencies;
     $result->hasrelatedcompetencies = count($relatedcompetencies) > 0;
     $competency = $this->related['competency'];
     $exporter = new competency_exporter($competency, array('context' => $context));
     $result->competency = $exporter->export($output);
     $exporter = new competency_framework_exporter($this->related['framework']);
     $result->framework = $exporter->export($output);
     $scaleconfiguration = $this->related['framework']->get_scaleconfiguration();
     $scaleid = $this->related['framework']->get_scaleid();
     if ($competency->get_scaleid()) {
         $scaleconfiguration = $competency->get_scaleconfiguration();
         $scaleid = $competency->get_scaleid();
     }
     $result->scaleconfiguration = $scaleconfiguration;
     $result->scaleid = $scaleid;
     $level = $competency->get_level();
     $taxonomy = $this->related['framework']->get_taxonomy($level);
     $result->taxonomyterm = (string) competency_framework::get_taxonomies_list()[$taxonomy];
     // Competency path.
     $exporter = new competency_path_exporter(['ancestors' => $competency->get_ancestors(), 'framework' => $this->related['framework'], 'context' => $context]);
     $result->comppath = $exporter->export($output);
     return (array) $result;
 }