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