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
/**
18
 * Contains event class for displaying a calendar event's icon.
19
 *
20
 * @package   core_calendar
21
 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_calendar\external;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
use \core\external\exporter;
30
use \core_calendar\local\event\entities\event_interface;
31
 
32
/**
33
 * Class for displaying a calendar event's icon.
34
 *
35
 * @package   core_calendar
36
 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class event_icon_exporter extends exporter {
40
 
41
    /**
42
     * Constructor.
43
     *
44
     * @param event_interface $event
45
     * @param array $related The related data.
46
     */
47
    public function __construct(event_interface $event, $related = []) {
48
        global $PAGE;
49
        $coursemodule = $event->get_course_module();
50
        $category = $event->get_category();
51
        $categoryid = $category ? $category->get('id') : null;
52
        $course = $event->get_course();
53
        $courseid = $course ? $course->get('id') : null;
54
        $group = $event->get_group();
55
        $groupid = $group ? $group->get('id') : null;
56
        $user = $event->get_user();
57
        $userid = $user ? $user->get('id') : null;
58
        $isactivityevent = !empty($coursemodule);
59
        $issiteevent = ($course && $courseid == SITEID);
60
        $iscategoryevent = ($category && !empty($categoryid));
61
        $iscourseevent = ($course && !empty($courseid) && $courseid != SITEID && empty($groupid));
62
        $isgroupevent = ($group && !empty($groupid));
63
        $isuserevent = ($user && !empty($userid));
64
        $iconurl = '';
65
        $iconclass = '';
66
 
67
        if ($isactivityevent) {
68
            $key = 'monologo';
69
            $component = $coursemodule->get('modname');
70
 
71
            $iconurl = get_fast_modinfo($courseid)->get_cm($coursemodule->get('id'))->get_icon_url();
72
            $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
73
            $iconurl = $iconurl->out(false);
74
            if (get_string_manager()->string_exists($event->get_type(), $component)) {
75
                $alttext = get_string($event->get_type(), $component);
76
            } else {
77
                $alttext = get_string('activityevent', 'calendar');
78
            }
79
        } else if ($event->get_component()) {
80
            // Guess the icon and the title for the component event. By default display calendar icon and the
81
            // plugin name as the alttext.
82
            if ($PAGE->theme->resolve_image_location($event->get_type(), $event->get_component())) {
83
                $key = $event->get_type();
84
                $component = $event->get_component();
85
            } else {
86
                $key = 'i/otherevent';
87
                $component = 'core';
88
            }
89
 
90
            if (get_string_manager()->string_exists($event->get_type(), $event->get_component())) {
91
                $alttext = get_string($event->get_type(), $event->get_component());
92
            } else {
93
                $alttext = get_string('pluginname', $event->get_component());
94
            }
95
        } else if ($issiteevent) {
96
            $key = 'i/siteevent';
97
            $component = 'core';
98
            $alttext = get_string('typesite', 'calendar');
99
        } else if ($iscategoryevent) {
100
            $key = 'i/categoryevent';
101
            $component = 'core';
102
            $alttext = get_string('typecategory', 'calendar');
103
        } else if ($iscourseevent) {
104
            $key = 'i/courseevent';
105
            $component = 'core';
106
            $alttext = get_string('typecourse', 'calendar');
107
        } else if ($isgroupevent) {
108
            $key = 'i/groupevent';
109
            $component = 'core';
110
            $alttext = get_string('typegroup', 'calendar');
111
        } else if ($isuserevent) {
112
            $key = 'i/userevent';
113
            $component = 'core';
114
            $alttext = get_string('typeuser', 'calendar');
115
        } else {
116
            // Default to site event icon?
117
            $key = 'i/siteevent';
118
            $component = 'core';
119
            $alttext = get_string('typesite', 'calendar');
120
        }
121
 
122
        $data = new \stdClass();
123
        $data->key = $key;
124
        $data->component = $component;
125
        $data->alttext = $alttext;
126
        $data->iconurl = $iconurl;
127
        $data->iconclass = $iconclass;
128
 
129
        parent::__construct($data, $related);
130
    }
131
 
132
    /**
133
     * Return the list of properties.
134
     *
135
     * @return array
136
     */
137
    protected static function define_properties() {
138
        return [
139
            'key' => ['type' => PARAM_TEXT],
140
            'component' => ['type' => PARAM_TEXT],
141
            'alttext' => ['type' => PARAM_TEXT],
142
            'iconurl' => ['type' => PARAM_TEXT],
143
            'iconclass' => ['type' => PARAM_TEXT],
144
        ];
145
    }
146
 
147
    /**
148
     * Returns a list of objects that are related.
149
     *
150
     * @return array
151
     */
152
    protected static function define_related() {
153
        return [
154
            'context' => 'context',
155
        ];
156
    }
157
}