MDL-51967 cbe: Use the competency_summary_exporter for the competency dialogue.
This commit is contained in:
committed by
Frederic Massart
parent
2e90c62f79
commit
49c5b8b440
+1
-1
File diff suppressed because one or more lines are too long
@@ -420,12 +420,11 @@ define(['jquery',
|
||||
var deleteCompetencyHandler = function() {
|
||||
var competency = $('[data-region="competencyactions"]').data('competency');
|
||||
|
||||
// We don't need to show related actions when showing the competency info.
|
||||
delete competency.showdeleterelatedaction;
|
||||
delete competency.showrelatedcompetencies;
|
||||
delete competency.showrule;
|
||||
var context = {
|
||||
competency: competency
|
||||
};
|
||||
|
||||
templates.render('tool_lp/competency_summary', competency)
|
||||
templates.render('tool_lp/competency_summary', context)
|
||||
.done(function(html) {
|
||||
|
||||
str.get_strings([
|
||||
@@ -565,8 +564,9 @@ define(['jquery',
|
||||
*/
|
||||
var renderCompetencySummary = function(competency) {
|
||||
var promise = $.Deferred().resolve().promise(),
|
||||
context = $.extend({}, competency);
|
||||
context = {};
|
||||
|
||||
context.competency = competency;
|
||||
context.showdeleterelatedaction = true;
|
||||
context.showrelatedcompetencies = true;
|
||||
context.showrule = false;
|
||||
|
||||
@@ -1045,11 +1045,7 @@ class external extends external_api {
|
||||
'canmanage' => new external_value(PARAM_BOOL, 'True if this user has permission to manage competency frameworks'),
|
||||
'pagecontextid' => new external_value(PARAM_INT, 'Context id for the framework'),
|
||||
'search' => new external_value(PARAM_RAW, 'Current search string'),
|
||||
'rulesmodules' => new external_multiple_structure(new external_single_structure(array(
|
||||
'type' => new external_value(PARAM_RAW, 'The rule type'),
|
||||
'amd' => new external_value(PARAM_RAW, 'The AMD module of the rule'),
|
||||
'name' => new external_value(PARAM_TEXT, 'The name of the rule'),
|
||||
)))
|
||||
'rulesmodules' => new external_value(PARAM_RAW, 'JSON encoded data for rules')
|
||||
));
|
||||
|
||||
}
|
||||
@@ -1119,21 +1115,7 @@ class external extends external_api {
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function data_for_competency_summary_returns() {
|
||||
return new external_single_structure(array (
|
||||
'framework' => competency_Framework_exporter::get_read_structure(),
|
||||
'id' => new external_value(PARAM_INT, 'The competency id'),
|
||||
'shortname' => new external_value(PARAM_TEXT, 'The competency shortname'),
|
||||
'idnumber' => new external_value(PARAM_TEXT, 'The competency idnumber'),
|
||||
'visible' => new external_value(PARAM_BOOL, 'True if competency visible'),
|
||||
'descriptionformatted' => new external_value(PARAM_RAW, 'The competency description'),
|
||||
'relatedcompetencies' => new external_multiple_structure(
|
||||
competency_exporter::get_read_structure()
|
||||
),
|
||||
'courses' => self::list_courses_using_competency_returns(),
|
||||
'showrelatedcompetencies' => new external_value(PARAM_BOOL, 'Show or not the related competencies'),
|
||||
'showcourses' => new external_value(PARAM_BOOL, 'Show or not the linked courses'),
|
||||
));
|
||||
|
||||
return competency_summary_exporter::get_read_structure();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,9 @@ class competency_summary_exporter extends exporter {
|
||||
// We cache the context so it does not need to be retrieved from the framework every time.
|
||||
return array('context' => '\\context',
|
||||
'competency' => '\\tool_lp\\competency',
|
||||
'linkedcourses' => '\\stdClass[]');
|
||||
'framework' => '\\tool_lp\\competency_framework',
|
||||
'linkedcourses' => '\\stdClass[]',
|
||||
'relatedcompetencies' => '\\tool_lp\\competency[]');
|
||||
}
|
||||
|
||||
protected static function define_other_properties() {
|
||||
@@ -48,17 +50,28 @@ class competency_summary_exporter extends exporter {
|
||||
'type' => course_summary_exporter::read_properties_definition(),
|
||||
'multiple' => true
|
||||
),
|
||||
'relatedcompetencies' => array(
|
||||
'type' => competency_exporter::read_properties_definition(),
|
||||
'multiple' => true
|
||||
),
|
||||
'competency' => array(
|
||||
'type' => competency_exporter::read_properties_definition()
|
||||
),
|
||||
'framework' => array(
|
||||
'type' => competency_framework_exporter::read_properties_definition()
|
||||
),
|
||||
'hascourses' => array(
|
||||
'type' => PARAM_BOOL
|
||||
),
|
||||
'hasrelatedcompetencies' => array(
|
||||
'type' => PARAM_BOOL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_other_values(renderer_base $output) {
|
||||
$result = new stdClass();
|
||||
$context = $this->related['context'];
|
||||
|
||||
$courses = $this->related['linkedcourses'];
|
||||
$linkedcourses = array();
|
||||
@@ -71,11 +84,22 @@ class competency_summary_exporter extends exporter {
|
||||
$result->linkedcourses = $linkedcourses;
|
||||
$result->hascourses = count($linkedcourses) > 0;
|
||||
|
||||
$relatedcompetencies = array();
|
||||
foreach ($this->related['relatedcompetencies'] as $competency) {
|
||||
$exporter = new competency_exporter($competency, array('context' => $context));
|
||||
$competencyexport = $exporter->export($output);
|
||||
array_push($relatedcompetencies, $competencyexport);
|
||||
}
|
||||
$result->relatedcompetencies = $relatedcompetencies;
|
||||
$result->hasrelatedcompetencies = count($relatedcompetencies) > 0;
|
||||
|
||||
$competency = $this->related['competency'];
|
||||
$context = $this->related['context'];
|
||||
$exporter = new competency_exporter($competency, array('context' => $context));
|
||||
$result->competency = $exporter->export($output);
|
||||
|
||||
$exporter = new competency_framework_exporter($this->related['framework']);
|
||||
$result->framework = $exporter->export($output);
|
||||
|
||||
return (array) $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ use templatable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
use tool_lp\api;
|
||||
use tool_lp\external\competency_exporter;
|
||||
use tool_lp\external\competency_framework_exporter;
|
||||
use tool_lp\external\competency_summary_exporter;
|
||||
|
||||
/**
|
||||
* Class containing data for competency summary
|
||||
@@ -51,9 +50,6 @@ class competency_summary implements renderable, templatable {
|
||||
/** @var course[] $courses List of courses. */
|
||||
protected $courses = array();
|
||||
|
||||
/** @var stdClass $data result exported to template. */
|
||||
protected $data = null;
|
||||
|
||||
/**
|
||||
* Construct this renderable.
|
||||
*
|
||||
@@ -63,13 +59,10 @@ class competency_summary implements renderable, templatable {
|
||||
* @param boolean $includecourses Include or not competency courses.
|
||||
*/
|
||||
public function __construct($competency, $framework, $includerelated, $includecourses) {
|
||||
$this->data = new stdClass();
|
||||
$this->data->showrelatedcompetencies = $includerelated;
|
||||
$this->data->showrcourses = $includecourses;
|
||||
$this->competency = $competency;
|
||||
$this->framework = $framework;
|
||||
if ($includerelated) {
|
||||
$this->relatedcompetencies = $this->competency->get_related_competencies();
|
||||
$this->relatedcompetencies = api::get_related_competencies($competency->get_id());
|
||||
}
|
||||
|
||||
if ($includecourses) {
|
||||
@@ -84,28 +77,17 @@ class competency_summary implements renderable, templatable {
|
||||
* @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
|
||||
);
|
||||
|
||||
$frameworkexp = new competency_framework_exporter($this->framework, array('context' => $this->framework->get_context()));
|
||||
$this->data->framework = $frameworkexp->export($output);
|
||||
$exporter = new competency_summary_exporter($this->competency, $related);
|
||||
$data = $exporter->export($output);
|
||||
|
||||
$compexp = new competency_exporter($this->competency, array('context' => $this->framework->get_context()));
|
||||
$competency = $compexp->export($output);
|
||||
|
||||
$this->data->id = $competency->id;
|
||||
$this->data->shortname = $competency->shortname;
|
||||
$this->data->visible = $competency->visible;
|
||||
$this->data->idnumber = $competency->idnumber;
|
||||
|
||||
$this->data->relatedcompetencies = array();
|
||||
if ($this->relatedcompetencies) {
|
||||
foreach ($this->relatedcompetencies as $competency) {
|
||||
$compexporter = new competency_exporter($competency, array('context' => $this->framework->get_context()));
|
||||
$this->data->relatedcompetencies[] = $compexporter->export($output);
|
||||
}
|
||||
}
|
||||
|
||||
$this->data->courses = $this->courses;
|
||||
|
||||
return $this->data;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,14 +86,26 @@ class template_competencies_page implements renderable, templatable {
|
||||
$data->templateid = $this->templateid;
|
||||
$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());
|
||||
$related = array('competency' => $competency, 'linkedcourses' => $courses, 'context' => $context);
|
||||
$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);
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<p><strong>{{shortname}} <em>{{idnumber}}</em></strong></p>
|
||||
<p>{{description}}</p>
|
||||
<p><strong>{{competency.shortname}} <em>{{competency.idnumber}}</em></strong></p>
|
||||
<p>{{competency.description}}</p>
|
||||
|
||||
{{#framework}}
|
||||
<p><strong>{{framework.shortname}}</strong></p>
|
||||
<p>{{framework.description}}</p>
|
||||
{{/framework}}
|
||||
|
||||
{{^visible}}
|
||||
{{^competency.visible}}
|
||||
( {{#str}} hidden, tool_lp{{/str}})
|
||||
{{/visible}}
|
||||
{{/competency.visible}}
|
||||
|
||||
{{#showrelatedcompetencies}}
|
||||
{{> tool_lp/related_competencies }}
|
||||
|
||||
Reference in New Issue
Block a user