MDL-52104 tool_lp: Improve UI for the change of states in plan
[moodle.git] / admin / tool / lp / classes / output / plan_page.php
blob3cf786829d2b38ade06a4f0e383c887c4336645d
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.
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/>.
17 /**
18 * Plan page output.
20 * @package tool_lp
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;
26 use renderable;
27 use templatable;
28 use stdClass;
29 use tool_lp\api;
30 use tool_lp\plan;
31 use tool_lp\external\competency_exporter;
33 /**
34 * Plan page class.
36 * @package tool_lp
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 {
42 /** @var plan */
43 protected $plan;
45 /**
46 * Construct.
48 * @param plan $plan
50 public function __construct($plan) {
51 $this->plan = $plan;
54 /**
55 * Export the data.
57 * @param renderer_base $output
58 * @return stdClass
60 public function export_for_template(\renderer_base $output) {
61 $frameworks = array();
62 $scales = 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';
77 } else {
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()];
95 // Prepare the data.
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;
103 return $data;