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 | |
37 | * @param string $username | |
38 | * @param string $authtoken | |
39 | * @return string | |
40 | */ | |
41 | public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken) { | |
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'=>'')); | |
89 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'username', 'value'=>$username)); | |
90 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken)); | |
91 | ||
92 | $output .= html_writer::empty_tag('input', array('type'=>'button', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar'))); | |
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 | ||
33e48a1a | 105 | $this->page->requires->yui_module('moodle-calendar-eventmanager', 'M.core_calendar.init_basic_export', array($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken)); |
36dc3b71 SH |
106 | |
107 | return $output; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Starts the standard layout for the page | |
6be8c6b7 | 112 | * |
36dc3b71 SH |
113 | * @return string |
114 | */ | |
115 | public function start_layout() { | |
116 | return html_writer::start_tag('div', array('class'=>'maincalendar')); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Creates the remainder of the layout | |
121 | * | |
122 | * @return string | |
123 | */ | |
124 | public function complete_layout() { | |
125 | return html_writer::end_tag('div'); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Produces the content for the filters block (pretend block) | |
130 | * | |
131 | * @param int $courseid | |
132 | * @param int $day | |
133 | * @param int $month | |
134 | * @param int $year | |
135 | * @param int $view | |
136 | * @param int $courses | |
137 | * @return string | |
138 | */ | |
139 | public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) { | |
140 | $getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$month.'&cal_y='.$year; | |
141 | return html_writer::tag('div', calendar_filter_controls($view, $getvars, NULL, $courses), array('class'=>'calendar_filters filters')); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Produces the content for the three months block (pretend block) | |
146 | * | |
147 | * This includes the previous month, the current month, and the next month | |
148 | * | |
149 | * @param calendar_information $calendar | |
150 | * @return string | |
151 | */ | |
152 | public function fake_block_threemonths(calendar_information $calendar) { | |
153 | ||
154 | list($prevmon, $prevyr) = calendar_sub_month($calendar->month, $calendar->year); | |
155 | list($nextmon, $nextyr) = calendar_add_month($calendar->month, $calendar->year); | |
156 | ||
157 | $content = html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
158 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $prevmon, 'y' => $prevyr)); | |
159 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $prevmon, $prevyr); | |
160 | $content .= html_writer::end_tag('div'); | |
161 | $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
162 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)); | |
163 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $calendar->month, $calendar->year); | |
164 | $content .= html_writer::end_tag('div'); | |
165 | $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock')); | |
166 | $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $nextmon, 'y' => $nextyr)); | |
167 | $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $nextmon, $nextyr); | |
168 | $content .= html_writer::end_tag('div'); | |
169 | return $content; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Adds a pretent calendar block | |
174 | * | |
175 | * @param block_contents $bc | |
176 | * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT | |
177 | */ | |
178 | public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) { | |
d9c26e21 | 179 | $this->page->blocks->add_fake_block($bc, $pos); |
36dc3b71 SH |
180 | } |
181 | ||
182 | /** | |
183 | * Creates a button to add a new event | |
184 | * | |
185 | * @param int $courseid | |
186 | * @param int $day | |
187 | * @param int $month | |
188 | * @param int $year | |
189 | * @return string | |
190 | */ | |
191 | protected function add_event_button($courseid, $day=null, $month=null, $year=null) { | |
192 | $output = html_writer::start_tag('div', array('class'=>'buttons')); | |
193 | $output .= html_writer::start_tag('form', array('action'=>CALENDAR_URL.'event.php', 'method'=>'get')); | |
194 | $output .= html_writer::start_tag('div'); | |
195 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new')); | |
196 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid)); | |
197 | if ($day !== null) { | |
198 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day)); | |
199 | } | |
200 | if ($month !== null) { | |
201 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month)); | |
202 | } | |
203 | if ($year !== null) { | |
204 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year)); | |
205 | } | |
206 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar'))); | |
207 | $output .= html_writer::end_tag('div'); | |
208 | $output .= html_writer::end_tag('form'); | |
209 | $output .= html_writer::end_tag('div'); | |
210 | return $output; | |
211 | } | |
212 | ||
213 | /** | |
214 | * Displays the calendar for a single day | |
215 | * | |
216 | * @param calendar_information $calendar | |
217 | * @return string | |
218 | */ | |
219 | public function show_day(calendar_information $calendar) { | |
220 | $calendar->checkdate(); | |
221 | $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today()); | |
222 | ||
223 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
224 | if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) { | |
225 | $output .= $this->add_event_button($calendar->courseid, $calendar->day, $calendar->month, $calendar->year); | |
226 | } | |
91a774e2 SH |
227 | //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump')); |
228 | $output .= $this->course_filter_selector(array('from'=>'day', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year), get_string('dayview', 'calendar')); | |
36dc3b71 SH |
229 | $output .= html_writer::end_tag('div'); |
230 | // Controls | |
231 | $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')); | |
232 | ||
233 | if (empty($events)) { | |
234 | // There is nothing to display today. | |
235 | $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3); | |
236 | } else { | |
237 | $output .= html_writer::start_tag('div', array('class'=>'eventlist')); | |
238 | $underway = array(); | |
239 | // First, print details about events that start today | |
240 | foreach ($events as $event) { | |
241 | $event = new calendar_event($event); | |
242 | $event->calendarcourseid = $calendar->courseid; | |
243 | if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now | |
0f927f1e | 244 | $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); |
36dc3b71 SH |
245 | $output .= $this->event($event); |
246 | } else { // Save this for later | |
247 | $underway[] = $event; | |
248 | } | |
249 | } | |
250 | ||
251 | // Then, show a list of all events that just span this day | |
252 | if (!empty($underway)) { | |
253 | $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3); | |
254 | foreach ($underway as $event) { | |
0f927f1e | 255 | $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); |
36dc3b71 SH |
256 | $output .= $this->event($event); |
257 | } | |
258 | } | |
259 | ||
260 | $output .= html_writer::end_tag('div'); | |
261 | } | |
262 | ||
263 | return $output; | |
264 | } | |
265 | ||
266 | /** | |
267 | * Displays an event | |
268 | * | |
269 | * @param calendar_event $event | |
270 | * @param bool $showactions | |
271 | * @return string | |
272 | */ | |
273 | public function event(calendar_event $event, $showactions=true) { | |
274 | $event = calendar_add_event_metadata($event); | |
275 | ||
0f927f1e | 276 | $anchor = html_writer::tag('a', '', array('name'=>'event_'.$event->id)); |
36dc3b71 SH |
277 | |
278 | $table = new html_table(); | |
279 | $table->attributes = array('class'=>'event', 'cellspacing'=>'0'); | |
280 | $table->data = array( | |
281 | 0 => new html_table_row(), | |
282 | 1 => new html_table_row(), | |
283 | ); | |
284 | ||
285 | if (!empty($event->icon)) { | |
0f927f1e | 286 | $table->data[0]->cells[0] = new html_table_cell($anchor.$event->icon); |
36dc3b71 | 287 | } else { |
0f927f1e | 288 | $table->data[0]->cells[0] = new html_table_cell($anchor.$this->output->spacer(array('height'=>16, 'width'=>16, 'br'=>true))); |
36dc3b71 SH |
289 | } |
290 | $table->data[0]->cells[0]->attributes['class'] .= ' picture'; | |
291 | ||
292 | $table->data[0]->cells[1] = new html_table_cell(); | |
293 | $table->data[0]->cells[1]->attributes['class'] .= ' topic'; | |
294 | if (!empty($event->referer)) { | |
295 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class'=>'referer')); | |
296 | } else { | |
297 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->name, array('class'=>'name')); | |
298 | } | |
299 | if (!empty($event->courselink)) { | |
300 | $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class'=>'course')); | |
301 | } | |
302 | if (!empty($event->time)) { | |
303 | $table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class'=>'date')); | |
304 | } else { | |
305 | $table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class'=>'date')); | |
306 | } | |
307 | ||
308 | $table->data[1]->cells[0] = new html_table_cell(' '); | |
309 | $table->data[1]->cells[0]->attributes['class'] .= 'side'; | |
310 | ||
311 | $table->data[1]->cells[1] = new html_table_cell($event->description); | |
312 | $table->data[1]->cells[1]->attributes['class'] .= ' description'; | |
313 | if (isset($event->cssclass)) { | |
314 | $table->data[1]->cells[1]->attributes['class'] .= ' '.$event->cssclass; | |
315 | } | |
316 | ||
317 | if (calendar_edit_event_allowed($event) && $showactions) { | |
318 | if (empty($event->cmid)) { | |
319 | $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action'=>'edit', 'id'=>$event->id)); | |
320 | $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id)); | |
321 | if (!empty($event->calendarcourseid)) { | |
322 | $editlink->param('course', $event->calendarcourseid); | |
323 | $deletelink->param('course', $event->calendarcourseid); | |
324 | } | |
325 | } else { | |
326 | $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid, 'return'=>true, 'sesskey'=>sesskey())); | |
327 | $deletelink = null; | |
328 | } | |
329 | ||
330 | $commands = html_writer::start_tag('div', array('class'=>'commands')); | |
331 | $commands .= html_writer::start_tag('a', array('href'=>$editlink)); | |
332 | $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'))); | |
333 | $commands .= html_writer::end_tag('a'); | |
334 | if ($deletelink != null) { | |
335 | $commands .= html_writer::start_tag('a', array('href'=>$deletelink)); | |
336 | $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'))); | |
337 | $commands .= html_writer::end_tag('a'); | |
338 | } | |
339 | $commands .= html_writer::end_tag('div'); | |
340 | $table->data[1]->cells[1]->text .= $commands; | |
341 | } | |
342 | return html_writer::table($table); | |
343 | } | |
344 | ||
345 | /** | |
346 | * Displays a month in detail | |
347 | * | |
348 | * @global array $CALENDARDAYS | |
349 | * @param calendar_information $calendar | |
350 | * @return string | |
351 | */ | |
352 | public function show_month_detailed(calendar_information $calendar) { | |
353 | global $CALENDARDAYS; | |
6be8c6b7 | 354 | |
36dc3b71 | 355 | $date = usergetdate(time()); |
36dc3b71 SH |
356 | |
357 | $display = new stdClass; | |
358 | $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); | |
359 | $display->maxwday = $display->minwday + 6; | |
ac5e0418 SH |
360 | $display->thismonth = ($date['mon'] == $calendar->month); |
361 | $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year); | |
36dc3b71 SH |
362 | |
363 | $startwday = 0; | |
364 | if (get_user_timezone_offset() < 99) { | |
365 | // We 'll keep these values as GMT here, and offset them when the time comes to query the db | |
ac5e0418 SH |
366 | $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT |
367 | $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT | |
36dc3b71 SH |
368 | $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ |
369 | } else { | |
370 | // no timezone info specified | |
ac5e0418 SH |
371 | $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year); |
372 | $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); | |
36dc3b71 SH |
373 | $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() |
374 | } | |
375 | ||
376 | // Align the starting weekday to fall in our display range | |
377 | if ($startwday < $display->minwday) { | |
378 | $startwday += 7; | |
379 | } | |
380 | ||
381 | // Get events from database | |
382 | $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses); | |
383 | if (!empty($events)) { | |
384 | foreach($events as $eventid => $event) { | |
385 | $event = new calendar_event($event); | |
386 | if (!empty($event->modulename)) { | |
387 | $cm = get_coursemodule_from_instance($event->modulename, $event->instance); | |
388 | if (!groups_course_module_visible($cm)) { | |
389 | unset($events[$eventid]); | |
390 | } | |
391 | } | |
392 | } | |
393 | } | |
394 | ||
395 | // Extract information: events vs. time | |
ac5e0418 | 396 | calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); |
36dc3b71 SH |
397 | |
398 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
399 | if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) { | |
400 | $output .= $this->add_event_button($calendar->courseid, null, $calendar->month, $calendar->year); | |
401 | } | |
402 | $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector(array('from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year)); | |
403 | $output .= html_writer::end_tag('div', array('class'=>'header')); | |
404 | // Controls | |
2bf448ca | 405 | $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls')); |
36dc3b71 SH |
406 | |
407 | $table = new html_table(); | |
408 | $table->attributes = array('class'=>'calendarmonth calendartable'); | |
409 | $table->data = array(); | |
410 | ||
411 | $header = new html_table_row(); | |
412 | $header->attributes = array('class'=>'weekdays'); | |
413 | $header->cells = array(); | |
414 | for($i = $display->minwday; $i <= $display->maxwday; ++$i) { | |
415 | // This uses the % operator to get the correct weekday no matter what shift we have | |
416 | // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 | |
417 | $cell = new html_table_cell(get_string($CALENDARDAYS[$i % 7], 'calendar')); | |
418 | $cell->header = true; | |
419 | $header->cells[] = $cell; | |
420 | } | |
421 | ||
422 | // For the table display. $week is the row; $dayweek is the column. | |
423 | $week = 1; | |
424 | $dayweek = $startwday; | |
425 | ||
426 | $row = new html_table_row(array()); | |
427 | // Paddding (the first week may have blank days in the beginning) | |
428 | for($i = $display->minwday; $i < $startwday; ++$i) { | |
429 | $cell = new html_table_cell(' '); | |
430 | $cell->attributes = array('class'=>'nottoday'); | |
431 | $row->cells[] = $cell; | |
432 | } | |
433 | ||
434 | // Now display all the calendar | |
435 | for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) { | |
436 | if($dayweek > $display->maxwday) { | |
437 | // We need to change week (table row) | |
438 | $table->data[] = $row; | |
439 | $row = new html_table_row(array()); | |
440 | $dayweek = $display->minwday; | |
441 | ++$week; | |
442 | } | |
443 | ||
444 | // Reset vars | |
445 | $cell = new html_table_cell(); | |
0f927f1e | 446 | $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 |
447 | |
448 | $cellclasses = array(); | |
449 | ||
450 | if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) { | |
451 | // Weekend. This is true no matter what the exact range is. | |
452 | $cellclasses[] = 'weekend'; | |
453 | } | |
454 | ||
455 | // Special visual fx if an event is defined | |
456 | if (isset($eventsbyday[$calendar->day])) { | |
457 | if(count($eventsbyday[$calendar->day]) == 1) { | |
458 | $title = get_string('oneevent', 'calendar'); | |
459 | } else { | |
460 | $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day])); | |
461 | } | |
462 | $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title'=>$title)), array('class'=>'day')); | |
463 | } else { | |
464 | $cell->text = html_writer::tag('div', $calendar->day, array('class'=>'day')); | |
465 | } | |
466 | ||
467 | // Special visual fx if an event spans many days | |
468 | $durationclass = false; | |
469 | if (isset($typesbyday[$calendar->day]['durationglobal'])) { | |
470 | $durationclass = 'duration_global'; | |
471 | } else if (isset($typesbyday[$calendar->day]['durationcourse'])) { | |
472 | $durationclass = 'duration_course'; | |
473 | } else if (isset($typesbyday[$calendar->day]['durationgroup'])) { | |
474 | $durationclass = 'duration_group'; | |
475 | } else if (isset($typesbyday[$calendar->day]['durationuser'])) { | |
476 | $durationclass = 'duration_user'; | |
477 | } | |
478 | if ($durationclass) { | |
479 | $cellclasses[] = 'duration'; | |
480 | $cellclasses[] = $durationclass; | |
481 | } | |
482 | ||
483 | // Special visual fx for today | |
ac5e0418 | 484 | if($display->thismonth && $calendar->day == $calendar->day) { |
36dc3b71 SH |
485 | $cellclasses[] = 'today'; |
486 | } else { | |
487 | $cellclasses[] = 'nottoday'; | |
488 | } | |
489 | $cell->attributes = array('class'=>join(' ',$cellclasses)); | |
490 | ||
491 | if (isset($eventsbyday[$calendar->day])) { | |
492 | $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new')); | |
493 | foreach($eventsbyday[$calendar->day] as $eventindex) { | |
494 | // If event has a class set then add it to the event <li> tag | |
495 | $attributes = array(); | |
496 | if (!empty($events[$eventindex]->class)) { | |
497 | $attributes['class'] = $events[$eventindex]->class; | |
498 | } | |
0f927f1e SH |
499 | $dayhref->set_anchor('event_'.$events[$eventindex]->id); |
500 | $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true)); | |
36dc3b71 SH |
501 | $cell->text .= html_writer::tag('li', $link, $attributes); |
502 | } | |
503 | $cell->text .= html_writer::end_tag('ul'); | |
504 | } | |
505 | if (isset($durationbyday[$calendar->day])) { | |
506 | $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway')); | |
507 | foreach($durationbyday[$calendar->day] as $eventindex) { | |
508 | $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway')); | |
509 | } | |
510 | $cell->text .= html_writer::end_tag('ul'); | |
511 | } | |
512 | $row->cells[] = $cell; | |
513 | } | |
514 | ||
515 | // Paddding (the last week may have blank days at the end) | |
516 | for($i = $dayweek; $i <= $display->maxwday; ++$i) { | |
517 | $cell = new html_table_cell(' '); | |
518 | $cell->attributes = array('class'=>'nottoday'); | |
519 | $row->cells[] = $cell; | |
520 | } | |
521 | $table->data[] = $row; | |
522 | $output .= html_writer::table($table); | |
523 | ||
524 | // OK, now for the filtering display | |
525 | $output .= $this->filter_selection_table($calendar); | |
526 | return $output; | |
527 | } | |
528 | ||
529 | /** | |
530 | * Displays a filter selection table | |
531 | * | |
532 | * @param calendar_information $calendar | |
533 | * @return string | |
534 | */ | |
535 | protected function filter_selection_table(calendar_information $calendar) { | |
536 | global $SESSION; | |
6be8c6b7 | 537 | |
36dc3b71 SH |
538 | $output = html_writer::start_tag('div', array('class'=>'filters')); |
539 | $output .= html_writer::start_tag('table'); | |
540 | $output .= html_writer::start_tag('tr'); | |
541 | ||
542 | // Global events | |
543 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showglobal', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year)); | |
544 | if($SESSION->cal_show_global) { | |
545 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;')); | |
546 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')'); | |
547 | } else { | |
548 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
549 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')'); | |
550 | } | |
551 | ||
552 | // Course events | |
553 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showcourses', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year)); | |
554 | if(!empty($SESSION->cal_show_course)) { | |
555 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;')); | |
556 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')'); | |
557 | } else { | |
558 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
559 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')'); | |
560 | } | |
561 | $output .= html_writer::end_tag('tr'); | |
562 | ||
563 | if(isloggedin() && !isguestuser()) { | |
564 | $output .= html_writer::start_tag('tr'); | |
565 | // Group events | |
566 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showgroups', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year)); | |
567 | if($SESSION->cal_show_groups) { | |
568 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;')); | |
569 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')'); | |
570 | } else { | |
571 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
572 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')'); | |
573 | } | |
574 | // User events | |
575 | $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showuser', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year)); | |
576 | if($SESSION->cal_show_user) { | |
577 | $output .= html_writer::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;')); | |
578 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')'); | |
579 | } else { | |
580 | $output .= html_writer::tag('td', '', array('style'=>'width:8px;')); | |
581 | $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')'); | |
582 | } | |
583 | $output .= html_writer::end_tag('tr'); | |
584 | } | |
585 | $output .= html_writer::end_tag('table'); | |
586 | $output .= html_writer::end_tag('div'); | |
587 | return $output; | |
588 | } | |
589 | ||
590 | /** | |
591 | * Displays upcoming events | |
592 | * | |
593 | * @param calendar_information $calendar | |
594 | * @param int $futuredays | |
595 | * @param int $maxevents | |
596 | * @return string | |
597 | */ | |
598 | public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents) { | |
599 | $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents); | |
600 | ||
601 | $output = html_writer::start_tag('div', array('class'=>'header')); | |
602 | if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) { | |
603 | $output .= $this->add_event_button($calendar->courseid); | |
604 | } | |
605 | $output .= html_writer::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump')); | |
606 | $output .= $this->course_filter_selector(array('from'=>'upcoming')); | |
607 | $output .= html_writer::end_tag('div'); | |
608 | ||
609 | if ($events) { | |
610 | $output .= html_writer::start_tag('div', array('class'=>'eventlist')); | |
611 | foreach ($events as $event) { | |
612 | // Convert to calendar_event object so that we transform description | |
613 | // accordingly | |
614 | $event = new calendar_event($event); | |
484617d2 | 615 | $event->calendarcourseid = $calendar->courseid; |
36dc3b71 SH |
616 | $output .= $this->event($event); |
617 | } | |
618 | $output .= html_writer::end_tag('div'); | |
619 | } else { | |
620 | $output .= $this->output->heading(get_string('noupcomingevents', 'calendar')); | |
621 | } | |
622 | ||
623 | return $output; | |
624 | } | |
625 | ||
626 | /** | |
627 | * Displays a course filter selector | |
628 | * | |
629 | * @param array $getvars | |
630 | * @return string | |
631 | */ | |
91a774e2 | 632 | protected function course_filter_selector(array $getvars = array(), $label=null) { |
6be8c6b7 | 633 | global $USER, $SESSION, $CFG; |
36dc3b71 SH |
634 | |
635 | if (!isloggedin() or isguestuser()) { | |
636 | return ''; | |
637 | } | |
638 | ||
639 | if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) { | |
640 | $courses = get_courses('all', 'c.shortname','c.id,c.shortname'); | |
641 | } else { | |
642 | $courses = enrol_get_my_courses(); | |
643 | } | |
644 | ||
645 | unset($courses[SITEID]); | |
646 | ||
647 | $courseoptions = array(); | |
648 | $courseoptions[SITEID] = get_string('fulllistofcourses'); | |
649 | foreach ($courses as $course) { | |
650 | $courseoptions[$course->id] = format_string($course->shortname); | |
651 | } | |
652 | ||
653 | if (is_numeric($SESSION->cal_courses_shown)) { | |
654 | $selected = $SESSION->cal_courses_shown; | |
655 | } else { | |
656 | $selected = ''; | |
657 | } | |
658 | $getvars['var'] = 'setcourse'; | |
659 | $select = new single_select(new moodle_url(CALENDAR_URL.'set.php', $getvars), 'id', $courseoptions, $selected, null); | |
660 | $select->class = 'cal_courses_flt'; | |
91a774e2 SH |
661 | if ($label !== null) { |
662 | $select->label = $label; | |
663 | } | |
664 | return $this->output->render($select); | |
36dc3b71 SH |
665 | } |
666 | } |