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
 * 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
defined('MOODLE_INTERNAL') || die();
25
 
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
        $iconurl = get_fast_modinfo($this->data->courseid)->cms[$this->data->cmid]->get_icon_url();
55
        $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
56
 
57
        $isbranded = component_callback('mod_' . $this->data->modname, 'is_branded') !== null ? : false;
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),
63
            'icon' => \html_writer::img(
64
                $iconurl,
65
                get_string('pluginname', $this->data->modname),
66
                ['title' => get_string('pluginname', $this->data->modname), 'class' => "icon $iconclass"]
67
            ),
68
            'purpose' => plugin_supports('mod', $this->data->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER),
69
            'branded' => $isbranded,
70
        );
71
    }
72
 
73
    /**
74
     * Return the list of properties.
75
     *
76
     * @return array Properties.
77
     */
78
    public static function define_properties() {
79
        return array(
80
            'id' => array(
81
                'type' => PARAM_INT,
82
            ),
83
            'courseid' => array(
84
                'type' => PARAM_INT,
85
            ),
86
            'cmid' => array(
87
                'type' => PARAM_INT,
88
            ),
89
            'userid' => array(
90
                'type' => PARAM_INT,
91
            ),
92
            'modname' => array(
93
                'type' => PARAM_PLUGIN,
94
            ),
95
            'name' => array(
96
                    'type' => PARAM_TEXT,
97
            ),
98
            'coursename' => array(
99
                'type' => PARAM_TEXT,
100
            ),
101
            'timeaccess' => array(
102
                'type' => PARAM_INT,
103
            )
104
        );
105
    }
106
 
107
    /**
108
     * Return the list of additional properties.
109
     *
110
     * @return array Additional properties.
111
     */
112
    public static function define_other_properties() {
113
        return array(
114
            'viewurl' => array(
115
                'type' => PARAM_RAW,
116
            ),
117
            'courseviewurl' => array(
118
                    'type' => PARAM_URL,
119
            ),
120
            'icon' => array(
121
                'type' => PARAM_RAW,
122
            ),
123
            'purpose' => array(
124
                'type' => PARAM_ALPHA,
125
            ),
126
            'branded' => [
127
                'type' => PARAM_BOOL,
128
                'optional' => true,
129
            ],
130
        );
131
    }
132
}