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 the day on month view.
19
 *
20
 * @package   core_calendar
21
 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
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 renderer_base;
30
 
31
/**
32
 * Class for displaying the day on month view.
33
 *
34
 * @package   core_calendar
35
 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class week_day_exporter extends day_exporter {
39
 
40
    /**
41
     * Constructor.
42
     *
43
     * @param \calendar_information $calendar The calendar information for the period being displayed
44
     * @param mixed $data Either an stdClass or an array of values.
45
     * @param array $related Related objects.
46
     */
47
    public function __construct(\calendar_information $calendar, $data, $related) {
48
        parent::__construct($calendar, $data, $related);
49
        // Fix the url for today to be based on the today timestamp
50
        // rather than the calendar_information time set in the parent
51
        // constructor.
52
        $this->url->param('time', $this->data[0]);
53
    }
54
 
55
    /**
56
     * Return the list of properties.
57
     *
58
     * @return array
59
     */
60
    protected static function define_properties() {
61
        $return = parent::define_properties();
62
        $return = array_merge($return, [
63
            // These are additional params.
64
            'istoday' => [
65
                'type' => PARAM_BOOL,
66
                'default' => false,
67
            ],
68
            'isweekend' => [
69
                'type' => PARAM_BOOL,
70
                'default' => false,
71
            ],
72
        ]);
73
 
74
        return $return;
75
    }
76
    /**
77
     * Return the list of additional properties.
78
     *
79
     * @return array
80
     */
81
    protected static function define_other_properties() {
82
        $return = parent::define_other_properties();
83
        $return = array_merge($return, [
84
            'popovertitle' => [
85
                'type' => PARAM_RAW,
86
                'default' => '',
87
            ],
88
            'daytitle' => [
89
                'type' => PARAM_RAW,
90
            ]
91
        ]);
92
 
93
        return $return;
94
    }
95
 
96
    /**
97
     * Get the additional values to inject while exporting.
98
     *
99
     * @param renderer_base $output The renderer.
100
     * @return array Keys are the property names, values are their values.
101
     */
102
    protected function get_other_values(renderer_base $output) {
103
        $return = parent::get_other_values($output);
104
 
105
        if ($popovertitle = $this->get_popover_title()) {
106
            $return['popovertitle'] = $popovertitle;
107
        }
108
 
109
        $return['daytitle'] = $this->get_day_title();
110
 
111
        return $return;
112
    }
113
 
114
    /**
115
     * Returns a list of objects that are related.
116
     *
117
     * @return array
118
     */
119
    protected static function define_related() {
120
        return [
121
            'events' => '\core_calendar\local\event\entities\event_interface[]',
122
            'cache' => '\core_calendar\external\events_related_objects_cache',
123
            'type' => '\core_calendar\type_base',
124
        ];
125
    }
126
 
127
    /**
128
     * Get the title for this popover.
129
     *
130
     * @return string
131
     */
132
    protected function get_popover_title() {
133
        $title = null;
134
 
135
        $userdate = userdate($this->data[0], get_string('strftimedayshort'));
136
        if (count($this->related['events'])) {
137
            $title = get_string('eventsfor', 'calendar', $userdate);
138
        } else if ($this->data['istoday']) {
139
            $title = $userdate;
140
        }
141
 
142
        if ($this->data['istoday']) {
143
            $title = get_string('todayplustitle', 'calendar', $userdate);
144
        }
145
 
146
        return $title;
147
    }
148
 
149
    /**
150
     * Get the title for this day.
151
     *
152
     * @return string
153
     */
154
    protected function get_day_title(): string {
155
        $userdate = userdate($this->data[0], get_string('strftimedayshort'));
156
 
157
        $numevents = count($this->related['events']);
158
        if ($numevents == 1) {
159
            $title = get_string('dayeventsone', 'calendar', $userdate);
160
        } else if ($numevents) {
161
            $title = get_string('dayeventsmany', 'calendar', ['num' => $numevents, 'day' => $userdate]);
162
        } else {
163
            $title = get_string('dayeventsnone', 'calendar', $userdate);
164
        }
165
 
166
        return $title;
167
    }
168
}