1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Class for exporting competency data with the set of linked courses.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_lp
|
|
|
21 |
* @copyright 2015 Damyon Wiese
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
namespace tool_lp\external;
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
use context_course;
|
|
|
28 |
use renderer_base;
|
|
|
29 |
use stdClass;
|
|
|
30 |
use moodle_url;
|
|
|
31 |
use core_competency\competency_framework;
|
|
|
32 |
use core_competency\external\competency_exporter;
|
|
|
33 |
use core_competency\external\competency_framework_exporter;
|
|
|
34 |
use core_course\external\course_summary_exporter;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Class for exporting competency data with additional related data.
|
|
|
38 |
*
|
|
|
39 |
* @copyright 2015 Damyon Wiese
|
|
|
40 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
41 |
*/
|
|
|
42 |
class competency_summary_exporter extends \core\external\exporter {
|
|
|
43 |
|
|
|
44 |
protected static function define_related() {
|
|
|
45 |
// We cache the context so it does not need to be retrieved from the framework every time.
|
|
|
46 |
return array('context' => '\\context',
|
|
|
47 |
'competency' => '\\core_competency\\competency',
|
|
|
48 |
'framework' => '\\core_competency\\competency_framework',
|
|
|
49 |
'linkedcourses' => '\\stdClass[]',
|
|
|
50 |
'relatedcompetencies' => '\\core_competency\\competency[]');
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
protected static function define_other_properties() {
|
|
|
54 |
return array(
|
|
|
55 |
'linkedcourses' => array(
|
|
|
56 |
'type' => course_summary_exporter::read_properties_definition(),
|
|
|
57 |
'multiple' => true
|
|
|
58 |
),
|
|
|
59 |
'relatedcompetencies' => array(
|
|
|
60 |
'type' => competency_exporter::read_properties_definition(),
|
|
|
61 |
'multiple' => true
|
|
|
62 |
),
|
|
|
63 |
'competency' => array(
|
|
|
64 |
'type' => competency_exporter::read_properties_definition()
|
|
|
65 |
),
|
|
|
66 |
'framework' => array(
|
|
|
67 |
'type' => competency_framework_exporter::read_properties_definition()
|
|
|
68 |
),
|
|
|
69 |
'hascourses' => array(
|
|
|
70 |
'type' => PARAM_BOOL
|
|
|
71 |
),
|
|
|
72 |
'hasrelatedcompetencies' => array(
|
|
|
73 |
'type' => PARAM_BOOL
|
|
|
74 |
),
|
|
|
75 |
'scaleid' => array(
|
|
|
76 |
'type' => PARAM_INT
|
|
|
77 |
),
|
|
|
78 |
'scaleconfiguration' => array(
|
|
|
79 |
'type' => PARAM_RAW
|
|
|
80 |
),
|
|
|
81 |
'taxonomyterm' => array(
|
|
|
82 |
'type' => PARAM_TEXT
|
|
|
83 |
),
|
|
|
84 |
'comppath' => array(
|
|
|
85 |
'type' => competency_path_exporter::read_properties_definition(),
|
|
|
86 |
),
|
|
|
87 |
'pluginbaseurl' => [
|
|
|
88 |
'type' => PARAM_URL
|
|
|
89 |
]
|
|
|
90 |
);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
protected function get_other_values(renderer_base $output) {
|
|
|
94 |
$result = new stdClass();
|
|
|
95 |
$context = $this->related['context'];
|
|
|
96 |
|
|
|
97 |
$courses = $this->related['linkedcourses'];
|
|
|
98 |
$linkedcourses = array();
|
|
|
99 |
foreach ($courses as $course) {
|
|
|
100 |
$context = context_course::instance($course->id);
|
|
|
101 |
$exporter = new course_summary_exporter($course, array('context' => $context));
|
|
|
102 |
$courseexport = $exporter->export($output);
|
|
|
103 |
array_push($linkedcourses, $courseexport);
|
|
|
104 |
}
|
|
|
105 |
$result->linkedcourses = $linkedcourses;
|
|
|
106 |
$result->hascourses = count($linkedcourses) > 0;
|
|
|
107 |
|
|
|
108 |
$relatedcompetencies = array();
|
|
|
109 |
foreach ($this->related['relatedcompetencies'] as $competency) {
|
|
|
110 |
$exporter = new competency_exporter($competency, array('context' => $context));
|
|
|
111 |
$competencyexport = $exporter->export($output);
|
|
|
112 |
array_push($relatedcompetencies, $competencyexport);
|
|
|
113 |
}
|
|
|
114 |
$result->relatedcompetencies = $relatedcompetencies;
|
|
|
115 |
$result->hasrelatedcompetencies = count($relatedcompetencies) > 0;
|
|
|
116 |
|
|
|
117 |
$competency = $this->related['competency'];
|
|
|
118 |
$exporter = new competency_exporter($competency, array('context' => $context));
|
|
|
119 |
$result->competency = $exporter->export($output);
|
|
|
120 |
|
|
|
121 |
$exporter = new competency_framework_exporter($this->related['framework']);
|
|
|
122 |
$result->framework = $exporter->export($output);
|
|
|
123 |
$scaleconfiguration = $this->related['framework']->get('scaleconfiguration');
|
|
|
124 |
$scaleid = $this->related['framework']->get('scaleid');
|
|
|
125 |
if ($competency->get('scaleid')) {
|
|
|
126 |
$scaleconfiguration = $competency->get('scaleconfiguration');
|
|
|
127 |
$scaleid = $competency->get('scaleid');
|
|
|
128 |
}
|
|
|
129 |
$result->scaleconfiguration = $scaleconfiguration;
|
|
|
130 |
$result->scaleid = $scaleid;
|
|
|
131 |
|
|
|
132 |
$level = $competency->get_level();
|
|
|
133 |
$taxonomy = $this->related['framework']->get_taxonomy($level);
|
|
|
134 |
$result->taxonomyterm = (string) (competency_framework::get_taxonomies_list()[$taxonomy]);
|
|
|
135 |
|
|
|
136 |
// Competency path.
|
|
|
137 |
$exporter = new competency_path_exporter([
|
|
|
138 |
'ancestors' => $competency->get_ancestors(),
|
|
|
139 |
'framework' => $this->related['framework'],
|
|
|
140 |
'context' => $context
|
|
|
141 |
]);
|
|
|
142 |
$result->comppath = $exporter->export($output);
|
|
|
143 |
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
|
|
|
144 |
$result->showlinks = \core_competency\api::show_links();
|
|
|
145 |
|
|
|
146 |
return (array) $result;
|
|
|
147 |
}
|
|
|
148 |
}
|