2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
21 * @copyright 2015 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace tool_lp\output
;
31 use tool_lp\external\competency_exporter
;
37 * @copyright 2015 Frédéric Massart - FMCorz.net
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class plan_page
implements renderable
, templatable
{
50 public function __construct($plan) {
57 * @param renderer_base $output
60 public function export_for_template(\renderer_base
$output) {
61 $frameworks = array();
64 $data = new stdClass();
65 $data->competencies
= array();
66 $data->planid
= $this->plan
->get_id();
67 $data->canmanage
= $this->plan
->can_manage() && !$this->plan
->is_based_on_template();
68 $data->canbeedited
= $this->plan
->can_be_edited();
69 $data->contextid
= $this->plan
->get_context()->id
;
71 $pclist = api
::list_plan_competencies($this->plan
);
73 $data->iscompleted
= $this->plan
->get_status() == plan
::STATUS_COMPLETE
;
74 if ($data->iscompleted
) {
75 $ucproperty = 'usercompetencyplan';
76 $ucexporter = 'tool_lp\\external\\user_competency_plan_exporter';
78 $ucproperty = 'usercompetency';
79 $ucexporter = 'tool_lp\\external\\user_competency_exporter';
82 foreach ($pclist as $pc) {
83 $comp = $pc->competency
;
84 $usercomp = $pc->$ucproperty;
86 if (!isset($frameworks[$comp->get_competencyframeworkid()])) {
87 $frameworks[$comp->get_competencyframeworkid()] = $comp->get_framework();
89 $framework = $frameworks[$comp->get_competencyframeworkid()];
90 if (!isset($scales[$framework->get_scaleid()])) {
91 $scales[$framework->get_scaleid()] = $framework->get_scale();
93 $scale = $scales[$framework->get_scaleid()];
96 $exporter = new competency_exporter($comp, array('context' => $framework->get_context()));
97 $competency = $exporter->export($output);
98 $exporter = new $ucexporter($usercomp, array('scale' => $scale));
99 $competency->$ucproperty = $exporter->export($output);
101 $data->competencies
[] = $competency;