Proyectos de Subversion Moodle

Rev

Rev 1 | Ir a la última revisión | | 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
 * Class for exporting the data needed to render a recent accessed item.
18
 *
19
 * @package    block_recentlyaccesseditems
20
 * @copyright  2018 Victor Deniz <victor@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
namespace block_recentlyaccesseditems\external;
24
 
1441 ariadna 25
use core_course\output\activity_icon;
1 efrain 26
use renderer_base;
27
use moodle_url;
28
 
29
/**
30
 * Class for exporting the data needed to render a recent accessed item.
31
 *
32
 * @copyright  2018 Victor Deniz
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class recentlyaccesseditems_item_exporter extends \core\external\exporter {
36
    /**
37
     * Returns a list of objects that are related to this persistent.
38
     *
39
     */
40
    protected static function define_related() {
41
        // We cache the context so it does not need to be retrieved from the course.
42
        return array('context' => '\\context');
43
    }
44
 
45
    /**
46
     * Get the additional values to inject while exporting.
47
     *
48
     * @param renderer_base $output The renderer
49
     * @return array Additional properties with values
50
     */
51
    protected function get_other_values(renderer_base $output) {
52
        global $CFG;
53
        require_once($CFG->libdir.'/modinfolib.php');
54
 
1441 ariadna 55
        $renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
56
        $cminfo = get_fast_modinfo($this->data->courseid)->get_cm($this->data->cmid);
57
        $icon = activity_icon::from_cm_info($cminfo);
1 efrain 58
 
59
        return array(
60
            'viewurl' => (new moodle_url('/mod/'.$this->data->modname.'/view.php',
61
                array('id' => $this->data->cmid)))->out(false),
62
            'courseviewurl' => (new moodle_url('/course/view.php', array('id' => $this->data->courseid)))->out(false),
1441 ariadna 63
            'icon' => $renderer->render($icon),
1 efrain 64
            'purpose' => plugin_supports('mod', $this->data->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER),
1441 ariadna 65
            'branded' => $icon->is_branded(),
1 efrain 66
        );
67
    }
68
 
69
    /**
70
     * Return the list of properties.
71
     *
72
     * @return array Properties.
73
     */
74
    public static function define_properties() {
75
        return array(
76
            'id' => array(
77
                'type' => PARAM_INT,
78
            ),
79
            'courseid' => array(
80
                'type' => PARAM_INT,
81
            ),
82
            'cmid' => array(
83
                'type' => PARAM_INT,
84
            ),
85
            'userid' => array(
86
                'type' => PARAM_INT,
87
            ),
88
            'modname' => array(
89
                'type' => PARAM_PLUGIN,
90
            ),
91
            'name' => array(
92
                    'type' => PARAM_TEXT,
93
            ),
94
            'coursename' => array(
95
                'type' => PARAM_TEXT,
96
            ),
97
            'timeaccess' => array(
98
                'type' => PARAM_INT,
99
            )
100
        );
101
    }
102
 
103
    /**
104
     * Return the list of additional properties.
105
     *
106
     * @return array Additional properties.
107
     */
108
    public static function define_other_properties() {
109
        return array(
110
            'viewurl' => array(
111
                'type' => PARAM_RAW,
112
            ),
113
            'courseviewurl' => array(
114
                    'type' => PARAM_URL,
115
            ),
116
            'icon' => array(
117
                'type' => PARAM_RAW,
118
            ),
119
            'purpose' => array(
120
                'type' => PARAM_ALPHA,
121
            ),
122
            'branded' => [
123
                'type' => PARAM_BOOL,
124
                'optional' => true,
125
            ],
126
        );
127
    }
128
}