Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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;
1441 ariadna 31
use action_link;
1 efrain 32
use stdClass;
33
use moodle_url;
34
use context;
35
use context_system;
1441 ariadna 36
use core\output\local\properties\button;
1 efrain 37
use core_competency\api;
38
use core_competency\competency_framework;
39
use core_competency\external\competency_framework_exporter;
40
 
41
/**
42
 * Class containing data for managecompetencyframeworks page
43
 *
44
 * @copyright  2015 Damyon Wiese
45
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46
 */
47
class manage_competency_frameworks_page implements renderable, templatable {
48
 
49
    /** @var context The context in which everything is happening. */
50
    protected $pagecontext;
51
 
52
    /** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
53
    protected $navigation = array();
54
 
55
    /** @var array $competencyframeworks List of competency frameworks. */
56
    protected $competencyframeworks = array();
57
 
58
    /** @var bool $canmanage Result of permissions checks. */
59
    protected $canmanage = false;
60
 
61
    /** @var moodle_url $pluginurlbase Base url to use constructing links. */
62
    protected $pluginbaseurl = null;
63
 
64
    /**
65
     * Construct this renderable.
66
     *
67
     * @param context $pagecontext The page context
68
     */
69
    public function __construct(context $pagecontext) {
1441 ariadna 70
        global $OUTPUT;
71
 
1 efrain 72
        $this->pagecontext = $pagecontext;
73
 
74
        if (competency_framework::can_manage_context($this->pagecontext)) {
75
            $addpage = new single_button(
76
                new moodle_url('/admin/tool/lp/editcompetencyframework.php', array('pagecontextid' => $this->pagecontext->id)),
77
                get_string('addnewcompetencyframework', 'tool_lp'),
78
                'get'
79
            );
80
            $this->navigation[] = $addpage;
1441 ariadna 81
 
82
            $icon = $OUTPUT->pix_icon('i/externallink', get_string('opensinnewwindow'), 'moodle', ['class' => 'ms-1']);
83
            $competenciesrepository = new action_link(
1 efrain 84
                new moodle_url('https://moodle.net/search', ['q' => 'competency frameworks']),
1441 ariadna 85
                get_string('competencyframeworksrepository', 'tool_lp') . $icon,
86
                null,
87
                ['target' => '_blank', 'class' => button::SECONDARY->classes() . ' ms-sm-2'],
1 efrain 88
            );
89
            $this->navigation[] = $competenciesrepository;
90
        }
91
 
92
        $this->competencyframeworks = api::list_frameworks('shortname', 'ASC', 0, 0, $this->pagecontext);
93
    }
94
 
95
    /**
96
     * Export this data so it can be used as the context for a mustache template.
97
     *
98
     * @param renderer_base $output Renderer base.
99
     * @return stdClass
100
     */
101
    public function export_for_template(renderer_base $output) {
102
        $data = new stdClass();
103
        $data->competencyframeworks = array();
104
        $data->pagecontextid = $this->pagecontext->id;
105
        foreach ($this->competencyframeworks as $framework) {
106
            $exporter = new competency_framework_exporter($framework);
107
            $data->competencyframeworks[] = $exporter->export($output);
108
        }
109
        $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
110
        $data->navigation = array();
111
        foreach ($this->navigation as $button) {
112
            $data->navigation[] = $output->render($button);
113
        }
114
 
115
        return $data;
116
    }
117
}