Commit | Line | Data |
---|---|---|
36dc3b71 SH |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This file contains the renderers for the calendar within Moodle | |
20 | * | |
21 | * @copyright 2010 Sam Hemelryk | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | * @package calendar | |
24 | */ | |
25 | ||
26 | /** | |
27 | * The primary renderer for the calendar. | |
28 | */ | |
29 | class core_calendar_renderer extends plugin_renderer_base { | |
30 | ||
31 | /** | |
32 | * Creates a basic export form | |
33 | * | |
34 | * @param bool $allowthisweek | |
35 | * @param bool $allownextweek | |
36 | * @param bool $allownextmonth | |
d52777b4 | 37 | * @param int $userid |
36dc3b71 SH |
38 | * @param string $authtoken |
39 | * @return string | |
40 | */ | |
d52777b4 | 41 | public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) { |
36dc3b71 SH |
42 | |
43 | $output = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header')); | |
44 | $output .= html_writer::start_tag('fieldset'); | |
45 | $output .= html_writer::tag('legend', get_string('commontasks', 'calendar')); | |
46 | $output .= html_writer::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get')); | |
47 | ||
48 | $output .= html_writer::tag('div', get_string('iwanttoexport', 'calendar')); | |
6be8c6b7 | 49 | |
36dc3b71 SH |
50 | $output .= html_writer::start_tag('div', array('class'=>'indent')); |
51 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked')); | |
52 | $output .= html_writer::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all')); | |
53 | $output .= html_writer::empty_tag('br'); | |
54 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses')); | |
55 | $output .= html_writer::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course')); | |
56 | $output .= html_writer::empty_tag('br'); | |
57 | $output .= html_writer::end_tag('div'); | |
6be8c6b7 | 58 | |
36dc3b71 SH |
59 | $output .= html_writer::tag('div', get_string('for', 'calendar').':'); |
60 | ||
61 | $output .= html_writer::start_tag('div', array('class'=>'indent')); | |
62 | if ($allowthisweek) { | |
63 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked')); | |
64 | $output .= html_writer::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow')); | |
65 | $output .= html_writer::empty_tag('br'); | |
66 | } | |
67 | if ($allownextweek) { | |
68 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext')); | |
69 | $output .= html_writer::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext')); | |
70 | $output .= html_writer::empty_tag('br'); | |
71 | } | |
72 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow')); | |
73 | $output .= html_writer::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow')); | |
74 | $output .= html_writer::empty_tag('br'); | |
75 | if ($allownextmonth) { | |
76 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext')); | |
77 | $output .= html_writer::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext')); | |
78 | $output .= html_writer::empty_tag('br'); | |
79 | } | |
80 | $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming')); | |
81 | $output .= html_writer::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc')); | |
82 | $output .= html_writer::empty_tag('br'); | |
83 | $output .= html_writer::end_tag('div'); | |
84 | ||
85 | $output .= html_writer::start_tag('div', array('class'=>'rightalign')); | |
86 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>'')); | |
87 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>'')); | |
88 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>'')); | |
d52777b4 | 89 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid)); |
36dc3b71 SH |
90 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken)); |
91 | ||
d52777b4 | 92 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar'))); |
36dc3b71 SH |
93 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar'))); |
94 | ||
95 | $output .= html_writer::end_tag('div'); | |
96 | ||
97 | $output .= html_writer::end_tag('form'); | |
98 | $output .= html_writer::end_tag('fieldset'); | |
99 | ||
100 | $output .= html_writer::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;')); | |
101 | $output .= html_writer::tag('p', get_string('urlforical', 'calendar')); | |
102 | $output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;')); | |
103 | $output .= html_writer::end_tag('div'); | |
104 | ||
36dc3b71 SH |
105 | return $output; |
106 | } | |
107 | ||
108 | /** | |
109 | * Starts the standard layout for the page | |
6be8c6b7 | 110 | * |
36dc3b71 SH |
111 | * @return string |
112 | */ | |
113 | public function start_layout() { | |
114 | return html_writer::start_tag('div', array('class'=>'maincalendar')); | |
115 | } | |
116 | ||
117 | /** | |
118 | * Creates the remainder of the layout | |
119 | * | |
120 | * @return string | |
121 | */ | |
122 | public function complete_layout() { | |
123 | return html_writer::end_tag('div'); | |
124 | } | |
125 | ||
126 | /** | |
127 | * Produces the content for the filters block (pretend block) | |
128 | * | |
129 | * @param int $courseid | |
130 | * @param int $day | |
131 | * @param int $month | |
132 | * @param int $year | |
133 | * @param int $view | |
134 | * @param int $courses | |
135 | * @return string | |
136 | */ | |
137 | public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) { | |
05f9d136 AA |
138 | $returnurl = $this->page->url; |
139 | $returnurl->param('course', $courseid); | |
140 | return html_writer::tag('div', calendar_filter_controls($returnurl), array('class'=>'calendar_filters filters')); | |
36dc3b71 SH |
141 | } |
142 | ||
143 | /** | |
144 | * Produces the content for the three months block (pretend block) | |
145 | * | |
146 | * This includes the previous month, the current month, and the next month | |
147 | * | |
148 | * @param calendar_information $calendar | |
149 | * @return string | |
150 | */ | |
151 | public function fake_block_threemonths(calendar_information $calendar) { | |
152 | ||
153 | list($prevmon, $prevyr) = calendar_sub_month($calendar->month, $calendar->year); | |
154 | list($nextmon, $nextyr) = calendar_add_month($calendar->month, $calendar->year); | |
155 | ||
156 | $content = html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
157 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $prevmon, 'y' => $prevyr)); | |
158 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $prevmon, $prevyr); | |
159 | $content .= html_writer::end_tag('div'); | |
160 | $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
161 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)); | |
162 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $calendar->month, $calendar->year); | |
163 | $content .= html_writer::end_tag('div'); | |
164 | $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
165 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $nextmon, 'y' => $nextyr)); | |
166 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $nextmon, $nextyr); | |
167 | $content .= html_writer::end_tag('div'); | |
168 | return $content; | |
169 | } | |
170 | ||
171 | /** | |
172 | * Adds a pretent calendar block | |
173 | * | |
174 | * @param block_contents $bc | |
175 | * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT | |
176 | */ | |
177 | public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) { | |
d9c26e21 | 178 | $this->page->blocks->add_fake_block($bc, $pos); |
36dc3b71 SH |
179 | } |
180 | ||
181 | /** | |
182 | * Creates a button to add a new event | |
183 | * | |
184 | * @param int $courseid | |
185 | * @param int $day | |
186 | * @param int $month | |
187 | * @param int $year | |
188 | * @return string | |
189 | */ | |
190 | protected function add_event_button($courseid, $day=null, $month=null, $year=null) { | |
191 | $output = html_writer::start_tag('div', array('class'=>'buttons')); | |
192 | $output .= html_writer::start_tag('form', array('action'=>CALENDAR_URL.'event.php', 'method'=>'get')); | |
193 | $output .= html_writer::start_tag('div'); | |
194 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new')); | |
195 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid)); | |
196 | if ($day !== null) { | |
197 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day)); | |
198 | } | |
199 | if ($month !== null) { | |
200 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month)); | |
201 | } | |
202 | if ($year !== null) { | |
203 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year)); | |
204 | } | |
205 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar'))); | |
206 | $output .= html_writer::end_tag('div'); | |
207 | $output .= html_writer::end_tag('form'); | |
208 | $output .= html_writer::end_tag('div'); | |
209 | return $output; | |
210 | } | |
211 | ||
212 | /** | |
213 | * Displays the calendar for a single day | |
214 | * | |
215 | * @param calendar_information $calendar | |
216 | * @return string | |
217 | */ | |
797cedc7 SH |
218 | public function show_day(calendar_information $calendar, moodle_url $returnurl = null) { |
219 | ||
220 | if ($returnurl === null) { | |
221 | $returnurl = $this->page->url; | |
222 | } | |
223 | ||
36dc3b71 SH |
224 | $calendar->checkdate(); |
225 | $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today()); | |
226 | ||
227 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
797cedc7 SH |
228 | if (calendar_user_can_add_event($calendar->course)) { |
229 | $output .= $this->add_event_button($calendar->course->id, $calendar->day, $calendar->month, $calendar->year); | |
36dc3b71 | 230 | } |
91a774e2 | 231 | //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump')); |
797cedc7 | 232 | $output .= $this->course_filter_selector($returnurl, get_string('dayview', 'calendar')); |
36dc3b71 SH |
233 | $output .= html_writer::end_tag('div'); |
234 | // Controls | |
235 | $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'd' => $calendar->day, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls')); | |
236 | ||
237 | if (empty($events)) { | |
238 | // There is nothing to display today. | |
239 | $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3); | |
240 | } else { | |
241 | $output .= html_writer::start_tag('div', array('class'=>'eventlist')); | |
242 | $underway = array(); | |
243 | // First, print details about events that start today | |
244 | foreach ($events as $event) { | |
245 | $event = new calendar_event($event); | |
246 | $event->calendarcourseid = $calendar->courseid; | |
247 | if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now | |
0f927f1e | 248 | $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); |
36dc3b71 SH |
249 | $output .= $this->event($event); |
250 | } else { // Save this for later | |
251 | $underway[] = $event; | |
252 | } | |
253 | } | |
254 | ||
255 | // Then, show a list of all events that just span this day | |
256 | if (!empty($underway)) { | |
257 | $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3); | |
258 | foreach ($underway as $event) { | |
0f927f1e | 259 | $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); |
36dc3b71 SH |
260 | $output .= $this->event($event); |
261 | } | |
262 | } | |
263 | ||
264 | $output .= html_writer::end_tag('div'); | |
265 | } | |
266 | ||
267 | return $output; | |
268 | } | |
269 | ||
270 | /** | |
271 | * Displays an event | |
272 | * | |
273 | * @param calendar_event $event | |
274 | * @param bool $showactions | |
275 | * @return string | |
276 | */ | |
277 | public function event(calendar_event $event, $showactions=true) { | |
278 | $event = calendar_add_event_metadata($event); | |
279 | ||
0f927f1e | 280 | $anchor = html_writer::tag('a', '', array('name'=>'event_'.$event->id)); |
36dc3b71 SH |
281 | |
282 | $table = new html_table(); | |
283 | $table->attributes = array('class'=>'event', 'cellspacing'=>'0'); | |
284 | $table->data = array( | |
285 | 0 => new html_table_row(), | |
286 | 1 => new html_table_row(), | |
287 | ); | |
288 | ||
289 | if (!empty($event->icon)) { | |
0f927f1e | 290 | $table->data[0]->cells[0] = new html_table_cell($anchor.$event->icon); |
36dc3b71 | 291 | } else { |
0f927f1e | 292 | $table->data[0]->cells[0] = new html_table_cell($anchor.$this->output->spacer(array('height'=>16, 'width'=>16, 'br'=>true))); |
36dc3b71 SH |
293 | } |
294 | $table->data[0]->cells[0]->attributes['class'] .= ' picture'; | |
295 | ||
296 | $table->data[0]->cells[1] = new html_table_cell(); | |
297 | $table->data[0]->cells[1]->attributes['class'] .= ' topic'; | |
298 | if (!empty($event->referer)) { | |
299 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class'=>'referer')); | |
300 | } else { | |
301 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->name, array('class'=>'name')); | |
302 | } | |
303 | if (!empty($event->courselink)) { | |
304 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class'=>'course')); | |
305 | } | |
306 | if (!empty($event->time)) { | |
307 | $table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class'=>'date')); | |
308 | } else { | |
309 | $table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class'=>'date')); | |
310 | } | |
311 | ||
312 | $table->data[1]->cells[0] = new html_table_cell(' '); | |
313 | $table->data[1]->cells[0]->attributes['class'] .= 'side'; | |
314 | ||
315 | $table->data[1]->cells[1] = new html_table_cell($event->description); | |
316 | $table->data[1]->cells[1]->attributes['class'] .= ' description'; | |
317 | if (isset($event->cssclass)) { | |
318 | $table->data[1]->cells[1]->attributes['class'] .= ' '.$event->cssclass; | |
319 | } | |
320 | ||
321 | if (calendar_edit_event_allowed($event) && $showactions) { | |
322 | if (empty($event->cmid)) { | |
323 | $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action'=>'edit', 'id'=>$event->id)); | |
324 | $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id)); | |
325 | if (!empty($event->calendarcourseid)) { | |
326 | $editlink->param('course', $event->calendarcourseid); | |
327 | $deletelink->param('course', $event->calendarcourseid); | |
328 | } | |
329 | } else { | |
330 | $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid, 'return'=>true, 'sesskey'=>sesskey())); | |
331 | $deletelink = null; | |
332 | } | |
333 | ||
334 | $commands = html_writer::start_tag('div', array('class'=>'commands')); | |
335 | $commands .= html_writer::start_tag('a', array('href'=>$editlink)); | |
336 | $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/edit'), 'alt'=>get_string('tt_editevent', 'calendar'), 'title'=>get_string('tt_editevent', 'calendar'))); | |
337 | $commands .= html_writer::end_tag('a'); | |
338 | if ($deletelink != null) { | |
339 | $commands .= html_writer::start_tag('a', array('href'=>$deletelink)); | |
340 | $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/delete'), 'alt'=>get_string('tt_deleteevent', 'calendar'), 'title'=>get_string('tt_deleteevent', 'calendar'))); | |
341 | $commands .= html_writer::end_tag('a'); | |
342 | } | |
343 | $commands .= html_writer::end_tag('div'); | |
344 | $table->data[1]->cells[1]->text .= $commands; | |
345 | } | |
346 | return html_writer::table($table); | |
347 | } | |
348 | ||
349 | /** | |
350 | * Displays a month in detail | |
351 | * | |
36dc3b71 SH |
352 | * @param calendar_information $calendar |
353 | * @return string | |
354 | */ | |
797cedc7 SH |
355 | public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { |
356 | global $CFG; | |
357 | ||
358 | if (empty($returnurl)) { | |
359 | $returnurl = $this->page->url; | |
360 | } | |
6be8c6b7 | 361 | |
36dc3b71 | 362 | $date = usergetdate(time()); |
36dc3b71 SH |
363 | |
364 | $display = new stdClass; | |
365 | $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); | |
366 | $display->maxwday = $display->minwday + 6; | |
ac5e0418 SH |
367 | $display->thismonth = ($date['mon'] == $calendar->month); |
368 | $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year); | |
36dc3b71 SH |
369 | |
370 | $startwday = 0; | |
371 | if (get_user_timezone_offset() < 99) { | |
372 | // We 'll keep these values as GMT here, and offset them when the time comes to query the db | |
ac5e0418 SH |
373 | $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT |
374 | $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT | |
36dc3b71 SH |
375 | $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ |
376 | } else { | |
377 | // no timezone info specified | |
ac5e0418 SH |
378 | $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year); |
379 | $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); | |
36dc3b71 SH |
380 | $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() |
381 | } | |
382 | ||
383 | // Align the starting weekday to fall in our display range | |
384 | if ($startwday < $display->minwday) { | |
385 | $startwday += 7; | |
386 | } | |
387 | ||
388 | // Get events from database | |
389 | $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses); | |
390 | if (!empty($events)) { | |
391 | foreach($events as $eventid => $event) { | |
392 | $event = new calendar_event($event); | |
393 | if (!empty($event->modulename)) { | |
394 | $cm = get_coursemodule_from_instance($event->modulename, $event->instance); | |
395 | if (!groups_course_module_visible($cm)) { | |
396 | unset($events[$eventid]); | |
397 | } | |
398 | } | |
399 | } | |
400 | } | |
401 | ||
402 | // Extract information: events vs. time | |
ac5e0418 | 403 | calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); |
36dc3b71 SH |
404 | |
405 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
797cedc7 SH |
406 | if (calendar_user_can_add_event($calendar->course)) { |
407 | $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year); | |
36dc3b71 | 408 | } |
797cedc7 | 409 | $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector($returnurl); |
36dc3b71 SH |
410 | $output .= html_writer::end_tag('div', array('class'=>'header')); |
411 | // Controls | |
2bf448ca | 412 | $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls')); |
36dc3b71 | 413 | |
797cedc7 SH |
414 | $days = calendar_get_days(); |
415 | ||
36dc3b71 SH |
416 | $table = new html_table(); |
417 | $table->attributes = array('class'=>'calendarmonth calendartable'); | |
89c7c7a9 RW |
418 | $time = make_timestamp($calendar->year, $calendar->month); |
419 | $table->summary = get_string('calendarheading', 'calendar', userdate($time, get_string('strftimemonthyear'))); | |
36dc3b71 SH |
420 | $table->data = array(); |
421 | ||
422 | $header = new html_table_row(); | |
423 | $header->attributes = array('class'=>'weekdays'); | |
424 | $header->cells = array(); | |
425 | for($i = $display->minwday; $i <= $display->maxwday; ++$i) { | |
426 | // This uses the % operator to get the correct weekday no matter what shift we have | |
427 | // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 | |
797cedc7 | 428 | $cell = new html_table_cell(get_string($days[$i % 7], 'calendar')); |
36dc3b71 SH |
429 | $cell->header = true; |
430 | $header->cells[] = $cell; | |
431 | } | |
432 | ||
433 | // For the table display. $week is the row; $dayweek is the column. | |
434 | $week = 1; | |
435 | $dayweek = $startwday; | |
436 | ||
2953ad13 JI |
437 | // Create an array of all the week days. |
438 | $wdays = array(0 => '<strong>'. get_string('sunday', 'calendar'). '</strong>', | |
439 | 1 => '<strong>'. get_string('monday', 'calendar'). '</strong>', | |
440 | 2 => '<strong>'. get_string('tuesday', 'calendar'). '</strong>', | |
441 | 3 => '<strong>'. get_string('wednesday', 'calendar'). '</strong>', | |
442 | 4 => '<strong>'. get_string('thursday', 'calendar'). '</strong>', | |
443 | 5 => '<strong>'. get_string('friday', 'calendar'). '</strong>', | |
444 | 6 => '<strong>'. get_string('saturday', 'calendar'). '</strong>'); | |
445 | ||
446 | // Loop only if the day offset is greater than 0. | |
447 | // This loop involves shifting the days around until the desired start day | |
448 | // is at the start of the array. | |
449 | $daycount = 0; | |
450 | while ($display->minwday > $daycount++) { | |
451 | $wdays_end = array_shift($wdays); | |
452 | array_push($wdays, $wdays_end); | |
453 | } | |
454 | ||
043c7cb8 PS |
455 | // Now we set the (modified) array to the table header to be displayed. |
456 | $table->head = $wdays; | |
2953ad13 JI |
457 | |
458 | $row = new html_table_row(array()); | |
459 | ||
36dc3b71 SH |
460 | // Paddding (the first week may have blank days in the beginning) |
461 | for($i = $display->minwday; $i < $startwday; ++$i) { | |
462 | $cell = new html_table_cell(' '); | |
463 | $cell->attributes = array('class'=>'nottoday'); | |
464 | $row->cells[] = $cell; | |
465 | } | |
466 | ||
467 | // Now display all the calendar | |
797cedc7 SH |
468 | $weekend = CALENDAR_DEFAULT_WEEKEND; |
469 | if (isset($CFG->calendar_weekend)) { | |
470 | $weekend = intval($CFG->calendar_weekend); | |
471 | } | |
472 | ||
36dc3b71 SH |
473 | for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) { |
474 | if($dayweek > $display->maxwday) { | |
475 | // We need to change week (table row) | |
476 | $table->data[] = $row; | |
477 | $row = new html_table_row(array()); | |
478 | $dayweek = $display->minwday; | |
479 | ++$week; | |
480 | } | |
481 | ||
482 | // Reset vars | |
483 | $cell = new html_table_cell(); | |
0f927f1e | 484 | $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day', 'course'=>$calendar->courseid)), $calendar->day, $calendar->month, $calendar->year); |
36dc3b71 SH |
485 | |
486 | $cellclasses = array(); | |
487 | ||
797cedc7 | 488 | if ($weekend & (1 << ($dayweek % 7))) { |
36dc3b71 SH |
489 | // Weekend. This is true no matter what the exact range is. |
490 | $cellclasses[] = 'weekend'; | |
491 | } | |
492 | ||
493 | // Special visual fx if an event is defined | |
494 | if (isset($eventsbyday[$calendar->day])) { | |
495 | if(count($eventsbyday[$calendar->day]) == 1) { | |
496 | $title = get_string('oneevent', 'calendar'); | |
497 | } else { | |
498 | $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day])); | |
499 | } | |
500 | $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title'=>$title)), array('class'=>'day')); | |
501 | } else { | |
502 | $cell->text = html_writer::tag('div', $calendar->day, array('class'=>'day')); | |
503 | } | |
504 | ||
505 | // Special visual fx if an event spans many days | |
506 | $durationclass = false; | |
507 | if (isset($typesbyday[$calendar->day]['durationglobal'])) { | |
508 | $durationclass = 'duration_global'; | |
509 | } else if (isset($typesbyday[$calendar->day]['durationcourse'])) { | |
510 | $durationclass = 'duration_course'; | |
511 | } else if (isset($typesbyday[$calendar->day]['durationgroup'])) { | |
512 | $durationclass = 'duration_group'; | |
513 | } else if (isset($typesbyday[$calendar->day]['durationuser'])) { | |
514 | $durationclass = 'duration_user'; | |
515 | } | |
516 | if ($durationclass) { | |
517 | $cellclasses[] = 'duration'; | |
518 | $cellclasses[] = $durationclass; | |
519 | } | |
520 | ||
521 | // Special visual fx for today | |
ac5e0418 | 522 | if($display->thismonth && $calendar->day == $calendar->day) { |
36dc3b71 SH |
523 | $cellclasses[] = 'today'; |
524 | } else { | |
525 | $cellclasses[] = 'nottoday'; | |
526 | } | |
527 | $cell->attributes = array('class'=>join(' ',$cellclasses)); | |
528 | ||
529 | if (isset($eventsbyday[$calendar->day])) { | |
530 | $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new')); | |
531 | foreach($eventsbyday[$calendar->day] as $eventindex) { | |
532 | // If event has a class set then add it to the event <li> tag | |
533 | $attributes = array(); | |
534 | if (!empty($events[$eventindex]->class)) { | |
535 | $attributes['class'] = $events[$eventindex]->class; | |
536 | } | |
0f927f1e SH |
537 | $dayhref->set_anchor('event_'.$events[$eventindex]->id); |
538 | $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true)); | |
36dc3b71 SH |
539 | $cell->text .= html_writer::tag('li', $link, $attributes); |
540 | } | |
541 | $cell->text .= html_writer::end_tag('ul'); | |
542 | } | |
543 | if (isset($durationbyday[$calendar->day])) { | |
544 | $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway')); | |
545 | foreach($durationbyday[$calendar->day] as $eventindex) { | |
546 | $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway')); | |
547 | } | |
548 | $cell->text .= html_writer::end_tag('ul'); | |
549 | } | |
550 | $row->cells[] = $cell; | |
551 | } | |
552 | ||
553 | // Paddding (the last week may have blank days at the end) | |
554 | for($i = $dayweek; $i <= $display->maxwday; ++$i) { | |
555 | $cell = new html_table_cell(' '); | |
556 | $cell->attributes = array('class'=>'nottoday'); | |
557 | $row->cells[] = $cell; | |
558 | } | |
559 | $table->data[] = $row; | |
560 | $output .= html_writer::table($table); | |
561 | ||
36dc3b71 SH |
562 | return $output; |
563 | } | |
564 | ||
565 | /** | |
566 | * Displays a filter selection table | |
567 | * | |
568 | * @param calendar_information $calendar | |
569 | * @return string | |
ef21ad21 FM |
570 | * @deprecated since Moodle 2.4 MDL-32309 |
571 | * @see calendar_filter_controls() | |
36dc3b71 | 572 | */ |
797cedc7 | 573 | protected function filter_selection_table(calendar_information $calendar, moodle_url $returnurl = null) { |
36dc3b71 | 574 | global $SESSION; |
ef21ad21 FM |
575 | debugging('Method core_calendar_renderer::filter_selection_table() is deprecated, please use '. |
576 | 'calendar_filter_controls() instead', DEBUG_DEVELOPER); | |
6be8c6b7 | 577 | |
797cedc7 SH |
578 | if ($returnurl === null) { |
579 | $returnurl = $this->page->url; | |
580 | } | |
581 | ||
36dc3b71 SH |
582 | $output = html_writer::start_tag('div', array('class'=>'filters')); |
583 | $output .= html_writer::start_tag('table'); | |
584 | $output .= html_writer::start_tag('tr'); | |
585 | ||
586 | // Global events | |
eb59a448 | 587 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var' => 'showglobal', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey())); |
675715a7 | 588 | $strglobalevents = get_string('globalevents', 'calendar'); |
797cedc7 | 589 | if (calendar_show_event_type(CALENDAR_EVENT_GLOBAL)) { |
36dc3b71 | 590 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;')); |
675715a7 | 591 | $output .= html_writer::tag('td', html_writer::tag('strong', $strglobalevents).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strglobalevents.'</span>').')'); |
36dc3b71 SH |
592 | } else { |
593 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
675715a7 | 594 | $output .= html_writer::tag('td', html_writer::tag('strong', $strglobalevents).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strglobalevents.'</span>').')'); |
36dc3b71 SH |
595 | } |
596 | ||
597 | // Course events | |
eb59a448 | 598 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showcourses', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey())); |
675715a7 | 599 | $strcourseevents = get_string('courseevents', 'calendar'); |
797cedc7 | 600 | if (calendar_show_event_type(CALENDAR_EVENT_COURSE)) { |
36dc3b71 | 601 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;')); |
675715a7 | 602 | $output .= html_writer::tag('td', html_writer::tag('strong', $strcourseevents).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strcourseevents.'</span>').')'); |
36dc3b71 SH |
603 | } else { |
604 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
675715a7 | 605 | $output .= html_writer::tag('td', html_writer::tag('strong', $strcourseevents).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strcourseevents.'</span>').')'); |
36dc3b71 SH |
606 | } |
607 | $output .= html_writer::end_tag('tr'); | |
608 | ||
609 | if(isloggedin() && !isguestuser()) { | |
610 | $output .= html_writer::start_tag('tr'); | |
611 | // Group events | |
eb59a448 | 612 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showgroups', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey())); |
675715a7 | 613 | $strgroupevents = get_string('groupevents', 'calendar'); |
797cedc7 | 614 | if (calendar_show_event_type(CALENDAR_EVENT_GROUP)) { |
36dc3b71 | 615 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;')); |
675715a7 | 616 | $output .= html_writer::tag('td', html_writer::tag('strong', $strgroupevents).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strgroupevents.'</span>').')'); |
36dc3b71 SH |
617 | } else { |
618 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
675715a7 | 619 | $output .= html_writer::tag('td', html_writer::tag('strong', $strgroupevents).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strgroupevents.'</span>').')'); |
36dc3b71 SH |
620 | } |
621 | // User events | |
eb59a448 | 622 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showuser', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey())); |
675715a7 | 623 | $struserevents = get_string('userevents', 'calendar'); |
797cedc7 | 624 | if (calendar_show_event_type(CALENDAR_EVENT_USER)) { |
36dc3b71 | 625 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;')); |
675715a7 | 626 | $output .= html_writer::tag('td', html_writer::tag('strong', $struserevents).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$struserevents.'</span>').')'); |
36dc3b71 SH |
627 | } else { |
628 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
675715a7 | 629 | $output .= html_writer::tag('td', html_writer::tag('strong', $struserevents).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$struserevents.'</span>').')'); |
36dc3b71 SH |
630 | } |
631 | $output .= html_writer::end_tag('tr'); | |
632 | } | |
633 | $output .= html_writer::end_tag('table'); | |
634 | $output .= html_writer::end_tag('div'); | |
635 | return $output; | |
636 | } | |
637 | ||
638 | /** | |
639 | * Displays upcoming events | |
640 | * | |
641 | * @param calendar_information $calendar | |
642 | * @param int $futuredays | |
643 | * @param int $maxevents | |
644 | * @return string | |
645 | */ | |
797cedc7 SH |
646 | public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents, moodle_url $returnurl = null) { |
647 | ||
648 | if ($returnurl === null) { | |
649 | $returnurl = $this->page->url; | |
650 | } | |
651 | ||
36dc3b71 SH |
652 | $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents); |
653 | ||
654 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
797cedc7 SH |
655 | if (calendar_user_can_add_event($calendar->course)) { |
656 | $output .= $this->add_event_button($calendar->course->id); | |
36dc3b71 SH |
657 | } |
658 | $output .= html_writer::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump')); | |
797cedc7 | 659 | $output .= $this->course_filter_selector($returnurl); |
36dc3b71 SH |
660 | $output .= html_writer::end_tag('div'); |
661 | ||
662 | if ($events) { | |
663 | $output .= html_writer::start_tag('div', array('class'=>'eventlist')); | |
664 | foreach ($events as $event) { | |
665 | // Convert to calendar_event object so that we transform description | |
666 | // accordingly | |
667 | $event = new calendar_event($event); | |
484617d2 | 668 | $event->calendarcourseid = $calendar->courseid; |
36dc3b71 SH |
669 | $output .= $this->event($event); |
670 | } | |
671 | $output .= html_writer::end_tag('div'); | |
672 | } else { | |
673 | $output .= $this->output->heading(get_string('noupcomingevents', 'calendar')); | |
674 | } | |
675 | ||
676 | return $output; | |
677 | } | |
678 | ||
679 | /** | |
680 | * Displays a course filter selector | |
681 | * | |
682 | * @param array $getvars | |
683 | * @return string | |
684 | */ | |
797cedc7 | 685 | protected function course_filter_selector(moodle_url $returnurl, $label=null) { |
6be8c6b7 | 686 | global $USER, $SESSION, $CFG; |
36dc3b71 SH |
687 | |
688 | if (!isloggedin() or isguestuser()) { | |
689 | return ''; | |
690 | } | |
691 | ||
6ca657a7 | 692 | if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) { |
36dc3b71 SH |
693 | $courses = get_courses('all', 'c.shortname','c.id,c.shortname'); |
694 | } else { | |
695 | $courses = enrol_get_my_courses(); | |
696 | } | |
697 | ||
698 | unset($courses[SITEID]); | |
699 | ||
700 | $courseoptions = array(); | |
701 | $courseoptions[SITEID] = get_string('fulllistofcourses'); | |
702 | foreach ($courses as $course) { | |
6ca657a7 | 703 | $coursecontext = context_course::instance($course->id); |
8ebbb06a | 704 | $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); |
36dc3b71 SH |
705 | } |
706 | ||
797cedc7 SH |
707 | if ($this->page->course->id !== SITEID) { |
708 | $selected = $this->page->course->id; | |
36dc3b71 SH |
709 | } else { |
710 | $selected = ''; | |
711 | } | |
eb59a448 | 712 | $select = new single_select(new moodle_url(CALENDAR_URL.'set.php', array('return' => base64_encode($returnurl->out(false)), 'var' => 'setcourse', 'sesskey'=>sesskey())), 'id', $courseoptions, $selected, null); |
36dc3b71 | 713 | $select->class = 'cal_courses_flt'; |
91a774e2 | 714 | if ($label !== null) { |
5c576552 RW |
715 | $select->set_label($label); |
716 | } else { | |
717 | $select->set_label(get_string('listofcourses'), array('class' => 'accesshide')); | |
91a774e2 SH |
718 | } |
719 | return $this->output->render($select); | |
36dc3b71 SH |
720 | } |
721 | } |