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 containing data for course competencies page
|
|
|
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\output;
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
use renderable;
|
|
|
28 |
use templatable;
|
|
|
29 |
use renderer_base;
|
|
|
30 |
use stdClass;
|
|
|
31 |
use moodle_url;
|
|
|
32 |
use context_system;
|
|
|
33 |
use context_course;
|
|
|
34 |
use core_competency\api;
|
|
|
35 |
use tool_lp\course_competency_statistics;
|
|
|
36 |
use core_competency\competency;
|
|
|
37 |
use core_competency\course_competency;
|
|
|
38 |
use core_competency\external\performance_helper;
|
|
|
39 |
use core_competency\external\competency_exporter;
|
|
|
40 |
use core_competency\external\course_competency_exporter;
|
|
|
41 |
use core_competency\external\course_competency_settings_exporter;
|
|
|
42 |
use core_competency\external\user_competency_course_exporter;
|
|
|
43 |
use core_competency\external\user_competency_exporter;
|
|
|
44 |
use core_competency\external\plan_exporter;
|
|
|
45 |
use tool_lp\external\competency_path_exporter;
|
|
|
46 |
use tool_lp\external\course_competency_statistics_exporter;
|
|
|
47 |
use core_course\external\course_module_summary_exporter;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Class containing data for course competencies page
|
|
|
51 |
*
|
|
|
52 |
* @copyright 2015 Damyon Wiese
|
|
|
53 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
54 |
*/
|
|
|
55 |
class course_competencies_page implements renderable, templatable {
|
|
|
56 |
|
|
|
57 |
/** @var int $courseid Course id for this page. */
|
|
|
58 |
protected $courseid = null;
|
|
|
59 |
|
|
|
60 |
/** @var int $moduleid Module id for this page. */
|
|
|
61 |
protected $moduleid = null;
|
|
|
62 |
|
|
|
63 |
/** @var context $context The context for this page. */
|
|
|
64 |
protected $context = null;
|
|
|
65 |
|
|
|
66 |
/** @var \core_competency\course_competency[] $competencies List of competencies. */
|
|
|
67 |
protected $coursecompetencylist = array();
|
|
|
68 |
|
|
|
69 |
/** @var bool $canmanagecompetencyframeworks Can the current user manage competency frameworks. */
|
|
|
70 |
protected $canmanagecompetencyframeworks = false;
|
|
|
71 |
|
|
|
72 |
/** @var bool $canmanagecoursecompetencies Can the current user manage course competency frameworks.. */
|
|
|
73 |
protected $canmanagecoursecompetencies = false;
|
|
|
74 |
|
|
|
75 |
/** @var string $manageurl manage url. */
|
|
|
76 |
protected $manageurl = null;
|
|
|
77 |
|
|
|
78 |
/** @var bool */
|
|
|
79 |
protected bool $canconfigurecoursecompetencies = false;
|
|
|
80 |
|
|
|
81 |
/** @var bool */
|
|
|
82 |
protected bool $cangradecompetencies = false;
|
|
|
83 |
|
|
|
84 |
/** @var \core\persistent|null */
|
|
|
85 |
protected $coursecompetencysettings = null;
|
|
|
86 |
|
|
|
87 |
/** @var \tool_lp\course_competency_statistics|null */
|
|
|
88 |
protected $coursecompetencystatistics = null;
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Construct this renderable.
|
|
|
92 |
* @param int $courseid The course record for this page.
|
|
|
93 |
*/
|
|
|
94 |
public function __construct($courseid, $moduleid) {
|
|
|
95 |
$this->context = context_course::instance($courseid);
|
|
|
96 |
$this->courseid = $courseid;
|
|
|
97 |
$this->moduleid = $moduleid;
|
|
|
98 |
$this->coursecompetencylist = api::list_course_competencies($courseid);
|
|
|
99 |
|
|
|
100 |
if ($this->moduleid > 0) {
|
|
|
101 |
$modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
|
|
|
102 |
foreach ($this->coursecompetencylist as $ccid => $coursecompetency) {
|
|
|
103 |
$coursecompetency = $coursecompetency['coursecompetency'];
|
|
|
104 |
$found = false;
|
|
|
105 |
foreach ($modulecompetencies as $mcid => $modulecompetency) {
|
|
|
106 |
if ($modulecompetency->get('competencyid') == $coursecompetency->get('competencyid')) {
|
|
|
107 |
$found = true;
|
|
|
108 |
break;
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
if (!$found) {
|
|
|
113 |
// We need to filter out this competency.
|
|
|
114 |
unset($this->coursecompetencylist[$ccid]);
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
$this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
|
|
|
120 |
$this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
|
|
|
121 |
$this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context);
|
|
|
122 |
$this->coursecompetencysettings = api::read_course_competency_settings($courseid);
|
|
|
123 |
$this->coursecompetencystatistics = new course_competency_statistics($courseid);
|
|
|
124 |
|
|
|
125 |
// Check the lowest level in which the user can manage the competencies.
|
|
|
126 |
$this->manageurl = null;
|
|
|
127 |
$this->canmanagecompetencyframeworks = false;
|
|
|
128 |
$contexts = array_reverse($this->context->get_parent_contexts(true));
|
|
|
129 |
foreach ($contexts as $context) {
|
|
|
130 |
$canmanage = has_capability('moodle/competency:competencymanage', $context);
|
|
|
131 |
if ($canmanage) {
|
|
|
132 |
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
|
|
|
133 |
array('pagecontextid' => $context->id));
|
|
|
134 |
$this->canmanagecompetencyframeworks = true;
|
|
|
135 |
break;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
142 |
*
|
|
|
143 |
* @param renderer_base $output Renderer base.
|
|
|
144 |
* @return stdClass
|
|
|
145 |
*/
|
|
|
146 |
public function export_for_template(renderer_base $output) {
|
|
|
147 |
global $USER;
|
|
|
148 |
|
|
|
149 |
$data = new stdClass();
|
|
|
150 |
$data->courseid = $this->courseid;
|
|
|
151 |
$data->moduleid = $this->moduleid;
|
|
|
152 |
$data->pagecontextid = $this->context->id;
|
|
|
153 |
$data->competencies = array();
|
|
|
154 |
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
|
|
|
155 |
|
|
|
156 |
$gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable');
|
|
|
157 |
if ($gradable) {
|
|
|
158 |
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id);
|
|
|
159 |
$data->gradableuserid = $USER->id;
|
|
|
160 |
|
|
|
161 |
if ($this->moduleid > 0) {
|
|
|
162 |
$modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
|
|
|
163 |
foreach ($usercompetencycourses as $ucid => $usercoursecompetency) {
|
|
|
164 |
$found = false;
|
|
|
165 |
foreach ($modulecompetencies as $mcid => $modulecompetency) {
|
|
|
166 |
if ($modulecompetency->get('competencyid') == $usercoursecompetency->get('competencyid')) {
|
|
|
167 |
$found = true;
|
|
|
168 |
break;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
if (!$found) {
|
|
|
173 |
// We need to filter out this competency.
|
|
|
174 |
unset($usercompetencycourses[$ucid]);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
$ruleoutcomelist = course_competency::get_ruleoutcome_list();
|
|
|
181 |
$ruleoutcomeoptions = array();
|
|
|
182 |
foreach ($ruleoutcomelist as $value => $text) {
|
|
|
183 |
$ruleoutcomeoptions[$value] = array('value' => $value, 'text' => (string) $text, 'selected' => false);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
$helper = new performance_helper();
|
|
|
187 |
foreach ($this->coursecompetencylist as $coursecompetencyelement) {
|
|
|
188 |
$coursecompetency = $coursecompetencyelement['coursecompetency'];
|
|
|
189 |
$competency = $coursecompetencyelement['competency'];
|
|
|
190 |
$context = $helper->get_context_from_competency($competency);
|
|
|
191 |
|
|
|
192 |
$compexporter = new competency_exporter($competency, array('context' => $context));
|
|
|
193 |
$ccexporter = new course_competency_exporter($coursecompetency, array('context' => $context));
|
|
|
194 |
|
|
|
195 |
$ccoutcomeoptions = (array) (object) $ruleoutcomeoptions;
|
|
|
196 |
$ccoutcomeoptions[$coursecompetency->get('ruleoutcome')]['selected'] = true;
|
|
|
197 |
|
|
|
198 |
$coursemodules = api::list_course_modules_using_competency($competency->get('id'), $this->courseid);
|
|
|
199 |
|
|
|
200 |
$fastmodinfo = get_fast_modinfo($this->courseid);
|
|
|
201 |
$exportedmodules = array();
|
|
|
202 |
foreach ($coursemodules as $cmid) {
|
|
|
203 |
$cminfo = $fastmodinfo->cms[$cmid];
|
|
|
204 |
$cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo));
|
|
|
205 |
$exportedmodules[] = $cmexporter->export($output);
|
|
|
206 |
}
|
|
|
207 |
// Competency path.
|
|
|
208 |
$pathexporter = new competency_path_exporter([
|
|
|
209 |
'ancestors' => $competency->get_ancestors(),
|
|
|
210 |
'framework' => $helper->get_framework_from_competency($competency),
|
|
|
211 |
'context' => $context
|
|
|
212 |
]);
|
|
|
213 |
|
|
|
214 |
// User learning plans.
|
|
|
215 |
$plans = api::list_plans_with_competency($USER->id, $competency);
|
|
|
216 |
$exportedplans = array();
|
|
|
217 |
foreach ($plans as $plan) {
|
|
|
218 |
$planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
|
|
|
219 |
$exportedplans[] = $planexporter->export($output);
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
$onerow = array(
|
|
|
223 |
'competency' => $compexporter->export($output),
|
|
|
224 |
'coursecompetency' => $ccexporter->export($output),
|
|
|
225 |
'ruleoutcomeoptions' => $ccoutcomeoptions,
|
|
|
226 |
'coursemodules' => $exportedmodules,
|
|
|
227 |
'comppath' => $pathexporter->export($output),
|
|
|
228 |
'plans' => $exportedplans
|
|
|
229 |
);
|
|
|
230 |
if ($gradable) {
|
|
|
231 |
$foundusercompetencycourse = false;
|
|
|
232 |
foreach ($usercompetencycourses as $usercompetencycourse) {
|
|
|
233 |
if ($usercompetencycourse->get('competencyid') == $competency->get('id')) {
|
|
|
234 |
$foundusercompetencycourse = $usercompetencycourse;
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
if ($foundusercompetencycourse) {
|
|
|
238 |
$related = array(
|
|
|
239 |
'scale' => $helper->get_scale_from_competency($competency)
|
|
|
240 |
);
|
|
|
241 |
$exporter = new user_competency_course_exporter($foundusercompetencycourse, $related);
|
|
|
242 |
$onerow['usercompetencycourse'] = $exporter->export($output);
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
array_push($data->competencies, $onerow);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
$data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks;
|
|
|
249 |
$data->canmanagecoursecompetencies = $this->canmanagecoursecompetencies;
|
|
|
250 |
$data->canconfigurecoursecompetencies = $this->canconfigurecoursecompetencies;
|
|
|
251 |
$data->cangradecompetencies = $this->cangradecompetencies;
|
|
|
252 |
$exporter = new course_competency_settings_exporter($this->coursecompetencysettings);
|
|
|
253 |
$data->settings = $exporter->export($output);
|
|
|
254 |
$related = array('context' => $this->context);
|
|
|
255 |
$exporter = new course_competency_statistics_exporter($this->coursecompetencystatistics, $related);
|
|
|
256 |
$data->statistics = $exporter->export($output);
|
|
|
257 |
$data->manageurl = null;
|
|
|
258 |
if ($this->canmanagecompetencyframeworks) {
|
|
|
259 |
$data->manageurl = $this->manageurl->out(true);
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
return $data;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
}
|