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 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;
34
use context_system;
35
use core_competency\api;
36
use core_competency\competency_framework;
37
use core_competency\external\competency_framework_exporter;
38
 
39
/**
40
 * Class containing data for managecompetencyframeworks 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_competency_frameworks_page implements renderable, templatable {
46
 
47
    /** @var context The context in which everything is happening. */
48
    protected $pagecontext;
49
 
50
    /** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
51
    protected $navigation = array();
52
 
53
    /** @var array $competencyframeworks List of competency frameworks. */
54
    protected $competencyframeworks = array();
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
    /**
63
     * Construct this renderable.
64
     *
65
     * @param context $pagecontext The page context
66
     */
67
    public function __construct(context $pagecontext) {
68
        $this->pagecontext = $pagecontext;
69
 
70
        if (competency_framework::can_manage_context($this->pagecontext)) {
71
            $addpage = new single_button(
72
                new moodle_url('/admin/tool/lp/editcompetencyframework.php', array('pagecontextid' => $this->pagecontext->id)),
73
                get_string('addnewcompetencyframework', 'tool_lp'),
74
                'get'
75
            );
76
            $this->navigation[] = $addpage;
77
            $competenciesrepository = new single_button(
78
                new moodle_url('https://moodle.net/search', ['q' => 'competency frameworks']),
79
                get_string('competencyframeworksrepository', 'tool_lp'),
80
                'get'
81
            );
82
            $this->navigation[] = $competenciesrepository;
83
        }
84
 
85
        $this->competencyframeworks = api::list_frameworks('shortname', 'ASC', 0, 0, $this->pagecontext);
86
    }
87
 
88
    /**
89
     * Export this data so it can be used as the context for a mustache template.
90
     *
91
     * @param renderer_base $output Renderer base.
92
     * @return stdClass
93
     */
94
    public function export_for_template(renderer_base $output) {
95
        $data = new stdClass();
96
        $data->competencyframeworks = array();
97
        $data->pagecontextid = $this->pagecontext->id;
98
        foreach ($this->competencyframeworks as $framework) {
99
            $exporter = new competency_framework_exporter($framework);
100
            $data->competencyframeworks[] = $exporter->export($output);
101
        }
102
        $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
103
        $data->navigation = array();
104
        foreach ($this->navigation as $button) {
105
            $data->navigation[] = $output->render($button);
106
        }
107
 
108
        return $data;
109
    }
110
}