/** * 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) { $related = array('context' => $this->framework->get_context(), 'framework' => $this->framework, 'linkedcourses' => $this->courses, 'relatedcompetencies' => $this->relatedcompetencies, 'competency' => $this->competency); $exporter = new competency_summary_exporter($this->competency, $related); $data = $exporter->export($output); return $data; }
/** * Returns description of data_for_report() result value. * * @return \external_description */ public static function data_for_report_returns() { return new external_single_structure(array('courseid' => new external_value(PARAM_INT, 'Course id'), 'user' => user_summary_exporter::get_read_structure(), 'course' => course_summary_exporter::get_read_structure(), 'usercompetencies' => new external_multiple_structure(new external_single_structure(array('usercompetencycourse' => user_competency_course_exporter::get_read_structure(), 'competency' => competency_summary_exporter::get_read_structure()))), 'pushratingstouserplans' => new external_value(PARAM_BOOL, 'True if rating is push to user plans'))); }
protected function get_other_values(renderer_base $output) { global $DB; $result = new stdClass(); $result->showrelatedcompetencies = true; $competency = $this->related['competency']; $exporter = new competency_summary_exporter(null, array('competency' => $competency, 'context' => $competency->get_context(), 'framework' => $competency->get_framework(), 'linkedcourses' => array(), 'relatedcompetencies' => $this->related['relatedcompetencies'])); $result->competency = $exporter->export($output); $result->cangrade = user_competency::can_grade_user($this->related['user']->id); if ($this->related['user']) { $exporter = new user_summary_exporter($this->related['user']); $result->user = $exporter->export($output); } $related = array('scale' => $competency->get_scale()); if ($this->related['usercompetency']) { $exporter = new user_competency_exporter($this->related['usercompetency'], $related); $result->usercompetency = $exporter->export($output); } if ($this->related['usercompetencyplan']) { $exporter = new user_competency_plan_exporter($this->related['usercompetencyplan'], $related); $result->usercompetencyplan = $exporter->export($output); } if ($this->related['usercompetencycourse']) { $exporter = new user_competency_course_exporter($this->related['usercompetencycourse'], $related); $result->usercompetencycourse = $exporter->export($output); } $allevidence = array(); $usercache = array(); $scale = $competency->get_scale(); $result->evidence = array(); if (count($this->related['evidence'])) { foreach ($this->related['evidence'] as $evidence) { $actionuserid = $evidence->get_actionuserid(); if (!empty($actionuserid)) { $usercache[$evidence->get_actionuserid()] = true; } } $users = array(); if (!empty($usercache)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($usercache)); $users = $DB->get_records_select('user', 'id ' . $sql, $params); } foreach ($users as $user) { $usercache[$user->id] = $user; } foreach ($this->related['evidence'] as $evidence) { $actionuserid = $evidence->get_actionuserid(); $related = array('scale' => $scale, 'usercompetency' => $this->related['usercompetency'] ? $this->related['usercompetency'] : null, 'usercompetencyplan' => $this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null); $related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null; $exporter = new evidence_exporter($evidence, $related); $allevidence[] = $exporter->export($output); } $result->evidence = $allevidence; } $usercompetency = !empty($this->related['usercompetency']) ? $this->related['usercompetency'] : null; if (!empty($usercompetency) && $usercompetency->can_read_comments()) { $commentareaexporter = new comment_area_exporter($usercompetency->get_comment_object()); $result->commentarea = $commentareaexporter->export($output); } return (array) $result; }
/** * Returns description of data_for_template_competencies_page() result value. * * @return \external_description */ public static function data_for_template_competencies_page_returns() { return new external_single_structure(array('template' => template_exporter::get_read_structure(), 'pagecontextid' => new external_value(PARAM_INT, 'Context ID'), 'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'), 'canmanagetemplatecompetencies' => new external_value(PARAM_BOOL, 'User can manage learning plan templates'), 'competencies' => new external_multiple_structure(competency_summary_exporter::get_read_structure()), 'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'), 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Base URL of the plugin.'), 'statistics' => template_statistics_exporter::get_read_structure())); }
/** * Export this data so it can be used as the context for a mustache template. * * @param \renderer_base $output * @return stdClass */ public function export_for_template(renderer_base $output) { $data = new stdClass(); $data->template = (new template_exporter($this->template))->export($output); $data->pagecontextid = $this->pagecontext->id; $data->competencies = array(); $contextcache = array(); $frameworkcache = array(); foreach ($this->competencies as $competency) { if (!isset($contextcache[$competency->get_competencyframeworkid()])) { $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context(); } $context = $contextcache[$competency->get_competencyframeworkid()]; if (!isset($frameworkcache[$competency->get_competencyframeworkid()])) { $frameworkcache[$competency->get_competencyframeworkid()] = $competency->get_framework(); } $framework = $frameworkcache[$competency->get_competencyframeworkid()]; $courses = api::list_courses_using_competency($competency->get_id()); $relatedcompetencies = api::list_related_competencies($competency->get_id()); $related = array('competency' => $competency, 'linkedcourses' => $courses, 'context' => $context, 'relatedcompetencies' => $relatedcompetencies, 'framework' => $framework); $exporter = new competency_summary_exporter(null, $related); $record = $exporter->export($output); array_push($data->competencies, $record); } $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false); $data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks; $data->canmanagetemplatecompetencies = $this->canmanagetemplatecompetencies; $data->manageurl = $this->manageurl->out(true); $exporter = new template_statistics_exporter($this->templatestatistics); $data->statistics = $exporter->export($output); $data->showcompetencylinks = true; return $data; }
/** * Export this data so it can be used as the context for a mustache template. * * @param \renderer_base $output * @return stdClass */ public function export_for_template(renderer_base $output) { global $DB; $data = new stdClass(); $data->courseid = $this->courseid; $course = $DB->get_record('course', array('id' => $this->courseid)); $coursecontext = context_course::instance($course->id); $exporter = new course_summary_exporter($course, array('context' => $coursecontext)); $coursecompetencysettings = api::read_course_competency_settings($course->id); $data->pushratingstouserplans = $coursecompetencysettings->get_pushratingstouserplans(); $data->course = $exporter->export($output); $data->usercompetencies = array(); $scalecache = array(); $frameworkcache = array(); $user = core_user::get_user($this->userid); $exporter = new user_summary_exporter($user); $data->user = $exporter->export($output); $data->usercompetencies = array(); $coursecompetencies = api::list_course_competencies($this->courseid); $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id); foreach ($usercompetencycourses as $usercompetencycourse) { $onerow = new stdClass(); $competency = null; foreach ($coursecompetencies as $coursecompetency) { if ($coursecompetency['competency']->get_id() == $usercompetencycourse->get_competencyid()) { $competency = $coursecompetency['competency']; break; } } if (!$competency) { continue; } // Fetch the framework. if (!isset($frameworkcache[$competency->get_competencyframeworkid()])) { $frameworkcache[$competency->get_competencyframeworkid()] = $competency->get_framework(); } $framework = $frameworkcache[$competency->get_competencyframeworkid()]; // Fetch the scale. $scaleid = $competency->get_scaleid(); if ($scaleid === null) { $scaleid = $framework->get_scaleid(); if (!isset($scalecache[$scaleid])) { $scalecache[$competency->get_scaleid()] = $framework->get_scale(); } } else { if (!isset($scalecache[$scaleid])) { $scalecache[$competency->get_scaleid()] = $competency->get_scale(); } } $scale = $scalecache[$competency->get_scaleid()]; $exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale)); $record = $exporter->export($output); $onerow->usercompetencycourse = $record; $exporter = new competency_summary_exporter(null, array('competency' => $competency, 'framework' => $framework, 'context' => $framework->get_context(), 'relatedcompetencies' => array(), 'linkedcourses' => array())); $onerow->competency = $exporter->export($output); array_push($data->usercompetencies, $onerow); } return $data; }