From 498cf28ce1bb88ff49686bce3ed36a8675aa5bf6 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 20 Nov 2015 15:26:23 +0800 Subject: [PATCH] MDL-51963 tool_lp: Pretend that there is a scale ID on competency The reason why we are doing that is to leave the door open for competency scales later on. Which means that we can write code that will rely on the competency to provide its scale even though the default behaviour will be to use the framework one. --- admin/tool/lp/classes/competency.php | 27 ++++++++++++++++++++++ admin/tool/lp/classes/output/plan_page.php | 7 ++++++ 2 files changed, 34 insertions(+) diff --git a/admin/tool/lp/classes/competency.php b/admin/tool/lp/classes/competency.php index f1c5df7a932..200822be9b2 100644 --- a/admin/tool/lp/classes/competency.php +++ b/admin/tool/lp/classes/competency.php @@ -255,6 +255,33 @@ class competency extends persistent { return new $rule($this); } + /** + * Return the scale. + * + * @return \grade_scale + */ + public function get_scale() { + $scaleid = $this->get_scaleid(); + if ($scaleid === null) { + return $this->get_framework()->get_scale(); + } + $scale = \grade_scale::fetch(array('id' => $scaleid)); + $scale->load_items(); + return $scale; + } + + /** + * Return the scale ID. + * + * Here we pretend that the scale ID can be read from the competency, however it + * only serves as a placeholder in case we want to support competency scales later on. + * + * @return int|null + */ + public function get_scaleid() { + return null; + } + /** * Check if the competency is the parent of passed competencies. * diff --git a/admin/tool/lp/classes/output/plan_page.php b/admin/tool/lp/classes/output/plan_page.php index 3cf786829d2..86be6041107 100644 --- a/admin/tool/lp/classes/output/plan_page.php +++ b/admin/tool/lp/classes/output/plan_page.php @@ -83,10 +83,17 @@ class plan_page implements renderable, templatable { $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(); }