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
namespace core_tag\output;
18
 
19
use renderable;
20
use templatable;
21
use renderer_base;
22
use stdClass;
23
use core_tag_tag;
24
 
25
/**
26
 * Class to help display tag
27
 *
28
 * @package   core_tag
29
 * @copyright 2015 Marina Glancy
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class tag implements renderable, templatable {
33
 
34
    /** @var core_tag_tag|stdClass */
35
    protected $record;
36
 
37
    /**
38
     * Constructor
39
     *
40
     * @param core_tag_tag|stdClass $tag
41
     */
42
    public function __construct($tag) {
43
        if ($tag instanceof core_tag_tag) {
44
            $this->record = $tag;
45
            return;
46
        }
47
        $tag = (array)$tag +
48
            array(
49
                'name' => '',
50
                'rawname' => '',
51
                'description' => '',
52
                'descriptionformat' => FORMAT_HTML,
53
                'flag' => 0,
54
                'isstandard' => 0,
55
                'id' => 0,
56
                'tagcollid' => 0,
57
            );
58
        $this->record = (object)$tag;
59
    }
60
 
61
    /**
62
     * Export this data so it can be used as the context for a mustache template.
63
     *
64
     * @param renderer_base $output
65
     * @return stdClass
66
     */
67
    public function export_for_template(renderer_base $output) {
68
        $r = new stdClass();
69
        $r->id = (int)$this->record->id;
70
        $r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
71
        $r->rawname = clean_param($this->record->rawname, PARAM_TAG);
72
        $r->name = clean_param($this->record->name, PARAM_TAG);
1441 ariadna 73
        [$r->description, $r->descriptionformat] = \core_external\util::format_text(
74
            $this->record->description,
75
            $this->record->descriptionformat,
76
            \context_system::instance(),
77
            'tag',
78
            'description',
79
            $r->id,
80
        );
81
 
1 efrain 82
        $r->flag = clean_param($this->record->flag, PARAM_INT);
83
        if (isset($this->record->isstandard)) {
84
            $r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0;
85
        }
86
        $r->official = $r->isstandard; // For backwards compatibility.
87
 
88
        $url = core_tag_tag::make_url($r->tagcollid, $r->rawname);
89
        $r->viewurl = $url->out(false);
90
 
91
        return $r;
92
    }
93
}