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 managecompetencyframeworks 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 single_button;
|
|
|
31 |
use stdClass;
|
|
|
32 |
use moodle_url;
|
|
|
33 |
use context_system;
|
|
|
34 |
use core_competency\api;
|
|
|
35 |
use core_competency\competency;
|
|
|
36 |
use core_competency\competency_framework;
|
|
|
37 |
use core_competency\external\competency_framework_exporter;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Class containing data for managecompetencies page
|
|
|
41 |
*
|
|
|
42 |
* @copyright 2015 Damyon Wiese
|
|
|
43 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
44 |
*/
|
|
|
45 |
class manage_competencies_page implements renderable, templatable {
|
|
|
46 |
|
|
|
47 |
/** @var \core_competency\competency_framework $framework This competency framework. */
|
|
|
48 |
protected $framework = null;
|
|
|
49 |
|
|
|
50 |
/** @var \core_competency\competency[] $competencies List of competencies. */
|
|
|
51 |
protected $competencies = array();
|
|
|
52 |
|
|
|
53 |
/** @var string $search Text to search for. */
|
|
|
54 |
protected $search = '';
|
|
|
55 |
|
|
|
56 |
/** @var bool $canmanage Result of permissions checks. */
|
|
|
57 |
protected $canmanage = false;
|
|
|
58 |
|
|
|
59 |
/** @var moodle_url $pluginurlbase Base url to use constructing links. */
|
|
|
60 |
protected $pluginbaseurl = null;
|
|
|
61 |
|
|
|
62 |
/** @var \context $pagecontext The page context. */
|
|
|
63 |
protected $pagecontext = null;
|
|
|
64 |
|
|
|
65 |
/** @var \core_competency\competency $competency The competency to show when the page loads. */
|
|
|
66 |
protected $competency = null;
|
|
|
67 |
|
|
|
68 |
/** @var array */
|
|
|
69 |
protected array $navigation = [];
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Construct this renderable.
|
|
|
73 |
*
|
|
|
74 |
* @param \core_competency\competency_framework $framework Competency framework.
|
|
|
75 |
* @param string $search Search string.
|
|
|
76 |
* @param \context $pagecontext The page context.
|
|
|
77 |
* @param \core_competency\competency $competency The core competency to show when the page loads.
|
|
|
78 |
*/
|
|
|
79 |
public function __construct($framework, $search, $pagecontext, $competency) {
|
|
|
80 |
$this->framework = $framework;
|
|
|
81 |
$this->pagecontext = $pagecontext;
|
|
|
82 |
$this->search = $search;
|
|
|
83 |
$this->competency = $competency;
|
|
|
84 |
$addpage = new single_button(
|
|
|
85 |
new moodle_url('/admin/tool/lp/editcompetencyframework.php'),
|
|
|
86 |
get_string('addnewcompetency', 'tool_lp')
|
|
|
87 |
);
|
|
|
88 |
$this->navigation[] = $addpage;
|
|
|
89 |
|
|
|
90 |
$this->canmanage = has_capability('moodle/competency:competencymanage', $framework->get_context());
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
95 |
*
|
|
|
96 |
* @param renderer_base $output Renderer base.
|
|
|
97 |
* @return stdClass
|
|
|
98 |
*/
|
|
|
99 |
public function export_for_template(renderer_base $output) {
|
|
|
100 |
$data = new stdClass();
|
|
|
101 |
$exporter = new competency_framework_exporter($this->framework);
|
|
|
102 |
$data->framework = $exporter->export($output);
|
|
|
103 |
$data->canmanage = $this->canmanage;
|
|
|
104 |
$data->search = $this->search;
|
|
|
105 |
$data->pagecontextid = $this->pagecontext->id;
|
|
|
106 |
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
|
|
|
107 |
|
|
|
108 |
$data->competencyid = 0;
|
|
|
109 |
if ($this->competency) {
|
|
|
110 |
$data->competencyid = $this->competency->get('id');
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
$rulesmodules = array();
|
|
|
114 |
$rules = competency::get_available_rules();
|
|
|
115 |
foreach ($rules as $type => $rulename) {
|
|
|
116 |
|
|
|
117 |
$amd = null;
|
|
|
118 |
if ($type == 'core_competency\\competency_rule_all') {
|
|
|
119 |
$amd = 'tool_lp/competency_rule_all';
|
|
|
120 |
} else if ($type == 'core_competency\\competency_rule_points') {
|
|
|
121 |
$amd = 'tool_lp/competency_rule_points';
|
|
|
122 |
} else {
|
|
|
123 |
// We do not know how to display that rule.
|
|
|
124 |
continue;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
$rulesmodules[] = [
|
|
|
128 |
'name' => (string) $rulename,
|
|
|
129 |
'type' => $type,
|
|
|
130 |
'amd' => $amd,
|
|
|
131 |
];
|
|
|
132 |
}
|
|
|
133 |
$data->rulesmodules = json_encode(array_values($rulesmodules));
|
|
|
134 |
|
|
|
135 |
return $data;
|
|
|
136 |
}
|
|
|
137 |
}
|