/** * Construct this renderable. * * @param \core_competency\competency $competency Competency persistent. * @param \core_competency\competency_framework $framework framework persistent. * @param boolean $includerelated Include or not related competencies. * @param boolean $includecourses Include or not competency courses. */ public function __construct($competency, $framework, $includerelated, $includecourses) { $this->competency = $competency; $this->framework = $framework; if ($includerelated) { $this->relatedcompetencies = api::list_related_competencies($competency->get_id()); } if ($includecourses) { $this->courses = api::list_courses_using_competency($competency->get_id()); } }
/** * Count the courses (visible to this user) that use this competency. * * @param int $competencyid Competency id. * @return array */ public static function list_courses_using_competency($competencyid) { global $PAGE; $params = self::validate_parameters(self::list_courses_using_competency_parameters(), array('id' => $competencyid)); $competency = api::read_competency($params['id']); self::validate_context($competency->get_context()); $output = $PAGE->get_renderer('tool_lp'); $results = array(); $courses = api::list_courses_using_competency($params['id']); foreach ($courses as $course) { $context = context_course::instance($course->id); $exporter = new course_summary_exporter($course, array('context' => $context)); $result = $exporter->export($output); array_push($results, $result); } return $results; }
/** * 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; }