/** * Export this data so it can be used as the context for a mustache template. * * @param renderer_base $output Renderer base. * @return stdClass */ public function export_for_template(renderer_base $output) { global $USER; $data = new stdClass(); $data->courseid = $this->courseid; $data->pagecontextid = $this->context->id; $data->competencies = array(); $contextcache = array(); $gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable'); if ($gradable) { $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id); $data->gradableuserid = $USER->id; } $ruleoutcomelist = course_competency::get_ruleoutcome_list(); $ruleoutcomeoptions = array(); foreach ($ruleoutcomelist as $value => $text) { $ruleoutcomeoptions[$value] = array('value' => $value, 'text' => (string) $text, 'selected' => false); } foreach ($this->coursecompetencylist as $coursecompetencyelement) { $coursecompetency = $coursecompetencyelement['coursecompetency']; $competency = $coursecompetencyelement['competency']; if (!isset($contextcache[$competency->get_competencyframeworkid()])) { $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context(); } $context = $contextcache[$competency->get_competencyframeworkid()]; $compexporter = new competency_exporter($competency, array('context' => $context)); $ccexporter = new course_competency_exporter($coursecompetency, array('context' => $context)); $ccoutcomeoptions = (array) (object) $ruleoutcomeoptions; $ccoutcomeoptions[$coursecompetency->get_ruleoutcome()]['selected'] = true; $coursemodules = api::list_course_modules_using_competency($competency->get_id(), $this->courseid); $fastmodinfo = get_fast_modinfo($this->courseid); $exportedmodules = array(); foreach ($coursemodules as $cmid) { $cminfo = $fastmodinfo->cms[$cmid]; $cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo)); $exportedmodules[] = $cmexporter->export($output); } // Competency path. $pathexporter = new competency_path_exporter(['ancestors' => $competency->get_ancestors(), 'framework' => $competency->get_framework(), 'context' => $context]); $onerow = array('competency' => $compexporter->export($output), 'coursecompetency' => $ccexporter->export($output), 'ruleoutcomeoptions' => $ccoutcomeoptions, 'coursemodules' => $exportedmodules, 'comppath' => $pathexporter->export($output)); if ($gradable) { $foundusercompetencycourse = false; foreach ($usercompetencycourses as $usercompetencycourse) { if ($usercompetencycourse->get_competencyid() == $competency->get_id()) { $foundusercompetencycourse = $usercompetencycourse; } } if ($foundusercompetencycourse) { $related = array('scale' => $competency->get_scale()); $exporter = new user_competency_course_exporter($foundusercompetencycourse, $related); $onerow['usercompetencycourse'] = $exporter->export($output); } } array_push($data->competencies, $onerow); } $data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks; $data->canmanagecoursecompetencies = $this->canmanagecoursecompetencies; $data->canconfigurecoursecompetencies = $this->canconfigurecoursecompetencies; $data->cangradecompetencies = $this->cangradecompetencies; $exporter = new course_competency_settings_exporter($this->coursecompetencysettings); $data->settings = $exporter->export($output); $related = array('context' => $this->context); $exporter = new course_competency_statistics_exporter($this->coursecompetencystatistics, $related); $data->statistics = $exporter->export($output); $data->manageurl = null; if ($this->canmanagecompetencyframeworks) { $data->manageurl = $this->manageurl->out(true); } return $data; }
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; }
/** * Returns description of data_for_plan_page() result value. * * @return \external_description */ public static function data_for_plan_page_returns() { $uc = user_competency_exporter::get_read_structure(); $ucp = user_competency_plan_exporter::get_read_structure(); $uc->required = VALUE_OPTIONAL; $ucp->required = VALUE_OPTIONAL; return new external_single_structure(array('plan' => plan_exporter::get_read_structure(), 'contextid' => new external_value(PARAM_INT, 'Context ID.'), 'pluginbaseurl' => new external_value(PARAM_URL, 'Plugin base URL.'), 'competencies' => new external_multiple_structure(new external_single_structure(array('competency' => competency_exporter::get_read_structure(), 'comppath' => competency_path_exporter::get_read_structure(), 'usercompetency' => $uc, 'usercompetencyplan' => $ucp))), 'competencycount' => new external_value(PARAM_INT, 'Count of competencies'), 'proficientcompetencycount' => new external_value(PARAM_INT, 'Count of proficientcompetencies'), 'proficientcompetencypercentage' => new external_value(PARAM_FLOAT, 'Percentage of competencies proficient'), 'proficientcompetencypercentageformatted' => new external_value(PARAM_RAW, 'Displayable percentage'))); }
/** * Export the data. * * @param renderer_base $output * @return stdClass */ public function export_for_template(\renderer_base $output) { $frameworks = array(); $scales = array(); $planexporter = new plan_exporter($this->plan, array('template' => $this->plan->get_template())); $data = new stdClass(); $data->plan = $planexporter->export($output); $data->competencies = array(); $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false); $data->contextid = $this->plan->get_context()->id; if ($data->plan->iscompleted) { $ucproperty = 'usercompetencyplan'; $ucexporter = 'core_competency\\external\\user_competency_plan_exporter'; } else { $ucproperty = 'usercompetency'; $ucexporter = 'core_competency\\external\\user_competency_exporter'; } $pclist = api::list_plan_competencies($this->plan); $proficientcount = 0; foreach ($pclist as $pc) { $comp = $pc->competency; $usercomp = $pc->{$ucproperty}; // Get the framework. if (!isset($frameworks[$comp->get_competencyframeworkid()])) { $frameworks[$comp->get_competencyframeworkid()] = $comp->get_framework(); } $framework = $frameworks[$comp->get_competencyframeworkid()]; // Get the scale. $scaleid = $comp->get_scaleid(); if ($scaleid === null) { $scaleid = $framework->get_scaleid(); } if (!isset($scales[$framework->get_scaleid()])) { $scales[$framework->get_scaleid()] = $framework->get_scale(); } $scale = $scales[$framework->get_scaleid()]; // Prepare the data. $record = new stdClass(); $exporter = new competency_exporter($comp, array('context' => $framework->get_context())); $record->competency = $exporter->export($output); // Competency path. $exporter = new competency_path_exporter(['ancestors' => $comp->get_ancestors(), 'framework' => $framework, 'context' => $framework->get_context()]); $record->comppath = $exporter->export($output); $exporter = new $ucexporter($usercomp, array('scale' => $scale)); $record->{$ucproperty} = $exporter->export($output); $data->competencies[] = $record; if ($usercomp->get_proficiency()) { $proficientcount++; } } $data->competencycount = count($data->competencies); $data->proficientcompetencycount = $proficientcount; if ($data->competencycount) { $data->proficientcompetencypercentage = (double) $proficientcount / (double) $data->competencycount * 100.0; } else { $data->proficientcompetencypercentage = 0.0; } $data->proficientcompetencypercentageformatted = format_float($data->proficientcompetencypercentage); return $data; }