MDL-51647 tool_lp: Fix exporter error when plan completed

This commit is contained in:
Jean-Philippe Gaudreau
2016-04-18 10:58:42 +08:00
committed by Frederic Massart
parent 41682e53e3
commit 5f9fa9f39a
2 changed files with 42 additions and 4 deletions
@@ -23,6 +23,9 @@
*/
namespace tool_lp\external;
use renderer_base;
use stdClass;
/**
* Class for exporting plan competency data.
*
@@ -35,4 +38,39 @@ class user_competency_plan_exporter extends persistent_exporter {
return 'tool_lp\\user_competency_plan';
}
protected static function define_related() {
// We cache the scale so it does not need to be retrieved from the framework every time.
return array('scale' => 'grade_scale');
}
protected function get_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get_grade() === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get_proficiency() === null) {
$proficiencyname = '-';
} else {
$proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
return (array) $result;
}
protected static function define_properties() {
return array(
'gradename' => array(
'type' => PARAM_TEXT
),
'proficiencyname' => array(
'type' => PARAM_RAW
),
);
}
}
+4 -4
View File
@@ -28,8 +28,6 @@ use templatable;
use stdClass;
use tool_lp\api;
use tool_lp\plan;
use tool_lp\user_competency;
use tool_lp\external\user_competency_exporter;
use tool_lp\external\competency_exporter;
/**
@@ -74,8 +72,10 @@ class plan_page implements renderable, templatable {
$data->iscompleted = $this->plan->get_status() == plan::STATUS_COMPLETE;
if ($data->iscompleted) {
$ucproperty = 'usercompetencyplan';
$ucexporter = 'tool_lp\\external\\user_competency_plan_exporter';
} else {
$ucproperty = 'usercompetency';
$ucexporter = 'tool_lp\\external\\user_competency_exporter';
}
foreach ($pclist as $pc) {
@@ -94,8 +94,8 @@ class plan_page implements renderable, templatable {
// Prepare the data.
$exporter = new competency_exporter($comp, array('context' => $framework->get_context()));
$competency = $exporter->export($output);
$exporter = new user_competency_exporter($usercomp, array('scale' => $scale));
$competency->usercompetency = $exporter->export($output);
$exporter = new $ucexporter($usercomp, array('scale' => $scale));
$competency->$ucproperty = $exporter->export($output);
$data->competencies[] = $competency;
}