MDL-57273 core: Exporters support custom formatting parameters

This commit is contained in:
Frederic Massart
2017-01-20 12:56:19 +08:00
committed by Damyon Wiese
parent 268beda8e9
commit 4bc68a416e
16 changed files with 334 additions and 30 deletions
@@ -72,7 +72,7 @@ class competency_path_exporter extends \core\external\exporter {
'type' => path_node_exporter::read_properties_definition()
],
'pluginbaseurl' => [
'type' => PARAM_TEXT
'type' => PARAM_URL
],
'pagecontextid' => [
'type' => PARAM_INT
+29
View File
@@ -24,6 +24,7 @@
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
/**
* Class for exporting path_node data.
@@ -33,6 +34,34 @@ defined('MOODLE_INTERNAL') || die();
*/
class path_node_exporter extends \core\external\exporter {
/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data The data.
* @param array $related Array of relateds.
*/
public function __construct($data, $related = array()) {
if (!isset($related['context'])) {
// Previous code was automatically using the system context which was not always correct.
// We let developers know that they must fix their code without breaking anything,
// and fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5.
debugging('Missing related context in path_node_exporter.', DEBUG_DEVELOPER);
$related['context'] = context_system::instance();
}
parent::__construct($data, $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_related() {
return [
'context' => 'context'
];
}
/**
* Return the list of properties.
*
@@ -154,6 +154,7 @@ class user_competency_summary_exporter extends \core\external\exporter {
'scale' => $scale,
'usercompetency' => ($this->related['usercompetency'] ? $this->related['usercompetency'] : null),
'usercompetencyplan' => ($this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null),
'context' => $evidence->get_context()
);
$related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null;
$exporter = new evidence_exporter($evidence, $related);
+18
View File
@@ -443,6 +443,24 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('A', $summary->usercompetencysummary->evidence[1]->gradename);
}
public function test_data_for_user_competency_summary() {
$this->setUser($this->creator);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
$evidence = \core_competency\external::grade_competency($this->user->id, $c1->get_id(), 1, true);
$evidence = \core_competency\external::grade_competency($this->user->id, $c1->get_id(), 2, true);
$summary = external::data_for_user_competency_summary($this->user->id, $c1->get_id());
$this->assertTrue($summary->cangrade);
$this->assertEquals('B', $summary->usercompetency->gradename);
$this->assertEquals('B', $summary->evidence[0]->gradename);
$this->assertEquals('A', $summary->evidence[1]->gradename);
}
/**
* Search cohorts.
*/