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
namespace core_tag\external;
18
 
19
use core_tag_tag;
20
 
21
/**
22
 * Tag external functions utility class.
23
 *
24
 * @package   core_tag
25
 * @copyright 2019 Juan Leyva
26
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @since     Moodle 3.7
28
 */
29
class util {
30
    /**
31
     * Get the array of core_tag_tag objects for external functions associated with an item (instances).
32
     *
33
     * @param string $component component responsible for tagging. For BC it can be empty but in this case the
34
     *               query will be slow because DB index will not be used.
35
     * @param string $itemtype type of the tagged item
36
     * @param int $itemid
37
     * @param int $standardonly wether to return only standard tags or any
38
     * @param int $tiuserid tag instance user id, only needed for tag areas with user tagging
39
     * @return array tags for external functions
40
     */
41
    public static function get_item_tags(
42
        $component,
43
        $itemtype,
44
        $itemid,
45
        $standardonly = core_tag_tag::BOTH_STANDARD_AND_NOT,
46
        $tiuserid = 0
47
    ) {
48
        global $PAGE;
49
 
50
        $output = $PAGE->get_renderer('core');
51
 
52
        $tagitems = core_tag_tag::get_item_tags($component, $itemtype, $itemid, $standardonly, $tiuserid);
53
        $exportedtags = [];
54
        foreach ($tagitems as $tagitem) {
55
            $exporter = new tag_item_exporter($tagitem->to_object());
56
            $exportedtags[] = (array) $exporter->export($output);
57
        }
58
        return $exportedtags;
59
    }
60
}