Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 a competency.
19
 *
20
 * @package    tool_lp
21
 * @copyright  2015 David Monllao
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 core_competency\api;
33
use core_competency\external\competency_exporter;
34
 
35
/**
36
 * Class containing data for related competencies.
37
 *
38
 * @package    tool_lp
39
 * @copyright  2015 David Monllao
40
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class related_competencies implements renderable, templatable {
43
 
44
    /** @var array Related competencies. */
45
    protected $relatedcompetencies = null;
46
 
47
    /** @var \core_competency\competency|null */
48
    protected $competency = null;
49
 
50
    /** @var \context|null */
51
    protected $context = null;
52
 
53
    /**
54
     * Construct this renderable.
55
     *
56
     * @param int $competencyid
57
     */
58
    public function __construct($competencyid) {
59
        $this->competency = api::read_competency($competencyid);
60
        $this->context = $this->competency->get_context();
61
        $this->relatedcompetencies = api::list_related_competencies($competencyid);
62
    }
63
 
64
    /**
65
     * Export this data so it can be used as the context for a mustache template.
66
     *
67
     * @param renderer_base $output
68
     * @return stdClass
69
     */
70
    public function export_for_template(renderer_base $output) {
71
        $data = new stdClass();
72
        $data->relatedcompetencies = array();
73
        if ($this->relatedcompetencies) {
74
            foreach ($this->relatedcompetencies as $competency) {
75
                $exporter = new competency_exporter($competency, array('context' => $this->context));
76
                $record = $exporter->export($output);
77
                $data->relatedcompetencies[] = $record;
78
            }
79
        }
80
 
81
        // We checked the user permissions in the constructor.
82
        $data->showdeleterelatedaction = true;
83
 
84
        return $data;
85
    }
86
}