ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCalendarDayGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
33include_once('./Services/Calendar/classes/class.ilDate.php');
34include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
35include_once('./Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
36include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
37include_once('./Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
38
39
41{
42 protected $seed = null;
43 protected $seed_info = array();
44 protected $user_settings = null;
45
46 protected $lng;
47 protected $ctrl;
48 protected $tabs_gui;
49 protected $tpl;
50
51 protected $num_appointments = 1;
52
53 protected $timezone = 'UTC';
54
62 public function __construct(ilDate $seed_date)
63 {
64 global $ilCtrl, $lng, $ilUser,$ilTabs,$tpl;
65
66 $this->seed = $seed_date;
67 $this->seed_info = $this->seed->get(IL_CAL_FKT_GETDATE);
68
69 $this->tpl = $tpl;
70 $this->lng = $lng;
71 $this->ctrl = $ilCtrl;
72 $this->tabs_gui = $ilTabs;
73
74 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
75 $this->app_colors = new ilCalendarAppointmentColors($ilUser->getId());
76
77 $this->timezone = $ilUser->getTimeZone();
78 }
79
86 public function executeCommand()
87 {
88 global $ilCtrl,$tpl;
89
90 $next_class = $ilCtrl->getNextClass();
91 switch($next_class)
92 {
93 case 'ilcalendarappointmentgui':
94 $this->ctrl->setReturn($this,'');
95 $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
96
97 // initial date for new calendar appointments
98 $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
99
100 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
101 $app = new ilCalendarAppointmentGUI($this->seed,$idate,(int) $_GET['app_id']);
102 $this->ctrl->forwardCommand($app);
103 break;
104
105 default:
106 $cmd = $this->ctrl->getCmd("show");
107 $this->$cmd();
108 $tpl->setContent($this->tpl->get());
109 break;
110 }
111 return true;
112 }
113
120 protected function show()
121 {
122 global $lng, $ilUser;
123
124 // config
125 $raster = 15;
126 if($this->user_settings->getDayStart())
127 {
128 // push starting point to last "slot" of hour BEFORE morning aggregation
129 $morning_aggr = ($this->user_settings->getDayStart()-1)*60+(60-$raster);
130 }
131 else
132 {
133 $morning_aggr = 0;
134 }
135 $evening_aggr = $this->user_settings->getDayEnd()*60;
136
137
138 $this->tpl = new ilTemplate('tpl.day_view.html',true,true,'Services/Calendar');
139
140 include_once('./Services/YUI/classes/class.ilYuiUtil.php');
143
144 if(isset($_GET["bkid"]))
145 {
146 $user_id = $_GET["bkid"];
147 $no_add = true;
148 }
149 elseif($ilUser->getId() == ANONYMOUS_USER_ID)
150 {
151 $user_id = $ilUser->getId();
152 $no_add = true;
153 }
154 else
155 {
156 $user_id = $ilUser->getId();
157 $no_add = false;
158 }
159 include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
160 $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_DAY,$user_id);
161 $this->scheduler->addSubitemCalendars(true);
162 $this->scheduler->calculate();
163 $daily_apps = $this->scheduler->getByDay($this->seed,$this->timezone);
164 $hours = $this->parseInfoIntoRaster($daily_apps,
165 $morning_aggr,
166 $evening_aggr,
167 $raster
168 );
169
170 $colspan = $this->calculateColspan($hours);
171
172 $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::DAY);
173 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
174
175 // add milestone link
176 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
178
179 include_once "Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
180
181 if(!$no_add)
182 {
183 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
184 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $this->seed->get(IL_CAL_DATE));
185 $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add');
186
187 if ($settings->getEnableGroupMilestones())
188 {
189 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
190 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $this->seed->get(IL_CAL_DATE));
191 $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone');
192
193 $this->tpl->setCurrentBlock("new_ms");
194 $this->tpl->setVariable('DD_ID', $this->seed->get(IL_CAL_UNIX));
195 $this->tpl->setVariable('DD_TRIGGER', ilGlyphGUI::get(ilGlyphGUI::ADD));
196 $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
197 $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
198 $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
199 $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
200 $this->tpl->parseCurrentBlock();
201 }
202 else
203 {
204 $this->tpl->setCurrentBlock("new_app1");
205 $this->tpl->setVariable('H_NEW_APP_SRC',ilGlyphGUI::get(ilGlyphGUI::ADD, $this->lng->txt('cal_new_app')));
206 $this->tpl->setVariable('NEW_APP_LINK', $new_app_url);
207 $this->tpl->parseCurrentBlock();
208 }
209
210 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
211 }
212
213 $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
214
215 $this->tpl->setVariable('HEADER_DATE',$this->seed_info['mday'].' '.ilCalendarUtil::_numericMonthToString($this->seed_info['mon'],false));
216 $this->tpl->setVariable('HEADER_DAY',ilCalendarUtil::_numericDayToString($this->seed_info['wday'],true));
217 $this->tpl->setVariable('HCOLSPAN',$colspan - 1);
218
219 $this->tpl->setVariable('TXT_TIME', $lng->txt("time"));
220
221 // show fullday events
222 foreach($daily_apps as $event)
223 {
224 if($event['fullday'])
225 {
226 $this->showFulldayAppointment($event);
227 }
228 }
229 $this->tpl->setCurrentBlock('fullday_apps');
230 $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
231 $this->tpl->setVariable('COLSPAN',$colspan - 1);
232 $this->tpl->parseCurrentBlock();
233
234 // parse the hour rows
235 foreach($hours as $numeric => $hour)
236 {
237 if(!($numeric%60) || ($numeric == $morning_aggr && $morning_aggr) ||
238 ($numeric == $evening_aggr && $evening_aggr))
239 {
240 if(!$no_add)
241 {
242 $this->tpl->setCurrentBlock("new_app2");
243 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
244 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
245 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$this->seed->get(IL_CAL_DATE));
246 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',floor($numeric/60));
247 $this->tpl->setVariable('NEW_APP_HOUR_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
248 $this->tpl->setVariable('NEW_APP_SRC', ilGlyphGUI::get(ilGlyphGUI::ADD, $this->lng->txt('cal_new_app')));
249 $this->tpl->parseCurrentBlock();
250 }
251
252 // aggregation rows
253 if(($numeric == $morning_aggr && $morning_aggr) ||
254 ($numeric == $evening_aggr && $evening_aggr))
255 {
256 $this->tpl->setVariable('TIME_ROWSPAN', 1);
257 }
258 // rastered hour
259 else
260 {
261 $this->tpl->setVariable('TIME_ROWSPAN', 60/$raster);
262 }
263
264 $this->tpl->setCurrentBlock('time_txt');
265
266 $this->tpl->setVariable('TIME',$hour['txt']);
267 $this->tpl->parseCurrentBlock();
268 }
269
270 foreach($hour['apps_start'] as $app)
271 {
272 $this->showAppointment($app);
273 }
274
275 if ($ilUser->prefs["screen_reader_optimization"])
276 {
277 $this->tpl->touchBlock('scrd_app_cell');
278 }
279
280 for($i = ($colspan - 1);$i > $hour['apps_num'];$i--)
281 {
282 $this->tpl->setCurrentBlock('empty_cell');
283 $this->tpl->setVariable('EMPTY_WIDTH',(100 / (int) ($colspan - 1)).'%');
284
285 // last "slot" of hour needs border
286 if($numeric%60 == 60-$raster ||
287 ($numeric == $morning_aggr && $morning_aggr) ||
288 ($numeric == $evening_aggr && $evening_aggr))
289 {
290 $this->tpl->setVariable('EMPTY_STYLE', ' calempty_border');
291 }
292
293 $this->tpl->parseCurrentBlock();
294 }
295
296 $this->tpl->touchBlock('time_row');
297 }
298 }
299
307 protected function showFulldayAppointment($a_app)
308 {
309 $this->tpl->setCurrentBlock('panel_code');
310 $this->tpl->setVariable('NUM',$this->num_appointments);
311 $this->tpl->parseCurrentBlock();
312
313 // milestone icon
314 if ($a_app['event']->isMilestone())
315 {
316 $this->tpl->setCurrentBlock('fullday_ms_icon');
317 $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
318 $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
319 $this->tpl->parseCurrentBlock();
320 }
321
322 $this->tpl->setCurrentBlock('fullday_app');
323 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
324 $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
325 $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
326
327 $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
328 ? " (".$a_app['event']->getCompletion()."%)"
329 : "";
330 $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle(false).$compl);
331 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
332 $this->tpl->setVariable('F_APP_BGCOLOR',$color);
333 $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
334
335 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
336 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
337 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
338 $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
339
340 $this->tpl->parseCurrentBlock();
341
342
343 $this->num_appointments++;
344 }
345
352 protected function showAppointment($a_app)
353 {
354 global $ilUser;
355
356 $this->tpl->setCurrentBlock('panel_code');
357 $this->tpl->setVariable('NUM',$this->num_appointments);
358 $this->tpl->parseCurrentBlock();
359
360 if (!$ilUser->prefs["screen_reader_optimization"])
361 {
362 $this->tpl->setCurrentBlock('app');
363 }
364 else
365 {
366 $this->tpl->setCurrentBlock('scrd_app');
367 }
368
369 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
370 $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
371 $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
372
373 $this->tpl->setVariable('APP_ROWSPAN',$a_app['rowspan']);
374 $this->tpl->setVariable('APP_TITLE',$a_app['event']->getPresentationTitle(false));
375
376 switch($this->user_settings->getTimeFormat())
377 {
379 $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
380 break;
381
383 $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
384 break;
385 }
386
387 // add end time for screen readers
388 if ($ilUser->prefs["screen_reader_optimization"])
389 {
390 switch($this->user_settings->getTimeFormat())
391 {
393 $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
394 break;
395
397 $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
398 break;
399 }
400 }
401
402 $title .= (' '.$a_app['event']->getPresentationTitle(false));
403
404 $this->tpl->setVariable('APP_TITLE',$title);
405
406 $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
407 $this->tpl->setVariable('APP_BGCOLOR',$color);
408 $this->tpl->setVariable('APP_COLOR',ilCalendarUtil::calculateFontColor($color));
409 $this->tpl->setVariable('APP_ADD_STYLES',$a_app['event']->getPresentationStyle());
410
411
412 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
413 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
414 $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
415 $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
416
417 $this->tpl->parseCurrentBlock();
418
419 $this->num_appointments++;
420 }
421
428 protected function parseInfoIntoRaster($daily_apps, $morning_aggr, $evening_aggr, $raster)
429 {
430 $hours = array();
431 for($i = $morning_aggr;$i <= $evening_aggr;$i+=$raster)
432 {
433 $hours[$i]['apps_start'] = array();
434 $hours[$i]['apps_num'] = 0;
435
436 switch($this->user_settings->getTimeFormat())
437 {
439 if ($morning_aggr > 0 && $i == $morning_aggr)
440 {
441 $hours[$i]['txt'] = sprintf('%02d:00',0)."-".
442 sprintf('%02d:00',ceil(($i+1)/60));
443 }
444 else
445 {
446 $hours[$i]['txt'].= sprintf('%02d:%02d',floor($i/60),$i%60);
447 }
448 if ($evening_aggr < 23*60 && $i == $evening_aggr)
449 {
450 $hours[$i]['txt'].= "-".sprintf('%02d:00',23);
451 }
452 break;
453
455 if ($morning_aggr > 0 && $i == $morning_aggr)
456 {
457 $hours[$i]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
458 }
459 $hours[$i]['txt'] = date('h a',mktime(floor($i/60),$i%60,0,1,1,2000));
460 if ($evening_aggr < 23*60 && $i == $evening_aggr)
461 {
462 $hours[$i]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
463 }
464 break;
465 }
466 }
467
468
469 foreach($daily_apps as $app)
470 {
471 global $ilUser;
472
473 // fullday appointment are not relavant
474 if($app['fullday'])
475 {
476 continue;
477 }
478 // start hour for this day
479 if($app['start_info']['mday'] != $this->seed_info['mday'])
480 {
481 $start = 0;
482 }
483 else
484 {
485 $start = $app['start_info']['hours']*60+$app['start_info']['minutes'];
486 }
487 // end hour for this day
488 if($app['end_info']['mday'] != $this->seed_info['mday'])
489 {
490 $end = 23*60;
491 }
492 elseif($app['start_info']['hours'] == $app['end_info']['hours'])
493 {
494 $end = $start+$raster;
495 }
496 else
497 {
498 $end = $app['end_info']['hours']*60+$app['end_info']['minutes'];
499 }
500
501 // set end to next hour for screen readers
502 if ($ilUser->prefs["screen_reader_optimization"])
503 {
504 $end = $start+$raster;
505 }
506
507 if ($start < $morning_aggr)
508 {
509 $start = $morning_aggr;
510 }
511 if ($end <= $morning_aggr)
512 {
513 $end = $morning_aggr+$raster;
514 }
515 if ($start > $evening_aggr)
516 {
517 $start = $evening_aggr;
518 }
519 if ($end > $evening_aggr+$raster)
520 {
521 $end = $evening_aggr+$raster;
522 }
523 if ($end <= $start)
524 {
525 $end = $start+$raster;
526 }
527
528 // map start and end to raster
529 $start = floor($start/$raster)*$raster;
530 $end = ceil($end/$raster)*$raster;
531
532 $first = true;
533 for($i = $start;$i < $end;$i+=$raster)
534 {
535 if($first)
536 {
537 if (!$ilUser->prefs["screen_reader_optimization"])
538 {
539 $app['rowspan'] = ceil(($end - $start)/$raster);
540 }
541 else // screen readers get always a rowspan of 1
542 {
543 $app['rowspan'] = 1;
544 }
545 $hours[$i]['apps_start'][] = $app;
546 $first = false;
547 }
548 $hours[$i]['apps_num']++;
549 }
550 }
551
552 return $hours;
553 }
554
562 protected function calculateColspan($hours)
563 {
564 global $ilUser;
565
566 $colspan = 1;
567 foreach($hours as $hour)
568 {
569 $colspan = max($colspan,$hour['apps_num'] + 1);
570 }
571
572 // screen reader: always two cols (time and event col)
573 if ($ilUser->prefs["screen_reader_optimization"])
574 {
575 $colspan = 2;
576 }
577
578 return max($colspan,2);
579 }
580
581}
582?>
$_GET["client_id"]
$_SESSION["AccountId"]
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
Administrate calendar appointments.
static _getInstance(ilDate $seed)
get singleton instance
Presentation day view.
__construct(ilDate $seed_date)
Constructor.
executeCommand()
Execute command.
show()
fill data section
calculateColspan($hours)
calculate colspan
parseInfoIntoRaster($daily_apps, $morning_aggr, $evening_aggr, $raster)
calculate overlapping hours
showFulldayAppointment($a_app)
show fullday appointment
showAppointment($a_app)
show appointment
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
static _getInstance()
get singleton instance
static _getInstanceByUserId($a_user_id)
get singleton instance
static _numericDayToString($a_day, $a_long=true)
get
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
Class for single dates.
get($a_format, $a_format_str='')
get formatted date
static get($a_glyph, $a_text="")
Get glyph html.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initDragDrop()
Init YUI Drag and Drop.
static initPanel($a_resize=false)
Init yui panel.
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilUser
Definition: imgupload.php:15