ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarWeekGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
34 include_once('Services/Calendar/classes/class.ilDate.php');
35 include_once('Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
36 include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
37 include_once('Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
38 
39 
40 
42 {
43  protected $num_appointments = 1;
44  protected $seed = null;
45  protected $user_settings = null;
46  protected $weekdays = array();
47 
48  protected $lng;
49  protected $ctrl;
50  protected $tabs_gui;
51  protected $tpl;
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,'','UTC');
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  $this->ctrl->saveParameter($this,'seed');
91 
92 
93  $next_class = $ilCtrl->getNextClass();
94  switch($next_class)
95  {
96  case 'ilcalendarappointmentgui':
97  $this->ctrl->setReturn($this,'');
98  $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
99 
100  // initial date for new calendar appointments
101  $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
102 
103  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
104  $app = new ilCalendarAppointmentGUI($this->seed,$idate,(int) $_GET['app_id']);
105  $this->ctrl->forwardCommand($app);
106  break;
107 
108  default:
109  $time = microtime(true);
110  $cmd = $this->ctrl->getCmd("show");
111  $this->$cmd();
112  $tpl->setContent($this->tpl->get());
113  #echo "Zeit: ".(microtime(true) - $time);
114  break;
115  }
116 
117  return true;
118  }
119 
126  public function show()
127  {
128  global $ilUser, $lng;
129 
130  $this->tpl = new ilTemplate('tpl.week_view.html',true,true,'Services/Calendar');
131 
132  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
135 
136 
137  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::WEEK);
138  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
139 
140  if(isset($_GET["bkid"]))
141  {
142  $user_id = $_GET["bkid"];
143  $disable_empty = true;
144  $no_add = true;
145  }
146  else
147  {
148  $user_id = $ilUser->getId();
149  $disable_empty = false;
150  $no_add = false;
151  }
152  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
153  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_WEEK,$user_id,$disable_empty);
154  $this->scheduler->addSubitemCalendars(true);
155  $this->scheduler->calculate();
156 
157  $counter = 0;
158  $hours = null;
159  $all_fullday = array();
160  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
161  {
162  $daily_apps = $this->scheduler->getByDay($date,$this->timezone);
163  $hours = $this->parseHourInfo($daily_apps,$date,$counter,$hours,
164  $this->user_settings->getDayStart(),
165  $this->user_settings->getDayEnd()
166  );
167  $this->weekdays[] = $date;
168 
169  $num_apps[$date->get(IL_CAL_DATE)] = count($daily_apps);
170 
171  $all_fullday[] = $daily_apps;
172  $counter++;
173  }
174 
175  $colspans = $this->calculateColspans($hours);
176 
177  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
178  $settings = ilCalendarSettings::_getInstance();
179 
180  // Table header
181  $counter = 0;
182  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
183  {
184  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
185  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
186  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
187  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
188 
189  if(!$no_add)
190  {
191  if ($settings->getEnableGroupMilestones())
192  {
193  $this->tpl->setCurrentBlock("new_ms");
194  $this->tpl->setVariable('H_NEW_MS_SRC', ilUtil::getImagePath('ms_add.gif'));
195  $this->tpl->setVariable('H_NEW_MS_ALT', $this->lng->txt('cal_new_ms'));
196  $this->tpl->setVariable('NEW_MS_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
197  $this->tpl->parseCurrentBlock();
198  }
199 
200 
201  $this->tpl->setCurrentBlock("new_app");
202  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
203  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
204  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
205  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
206  $this->tpl->parseCurrentBlock();
207  }
208 
209  $dayname = ilCalendarUtil::_numericDayToString($date->get(IL_CAL_FKT_DATE,'w'),true);
210  $daydate = $date_info['mday'].' '.ilCalendarUtil::_numericMonthToString($date_info['mon'],false);
211 
212  if(!$disable_empty || $num_apps[$date->get(IL_CAL_DATE)] > 0)
213  {
214  $link = $this->ctrl->getLinkTargetByClass('ilcalendardaygui','');
215  $this->ctrl->clearParametersByClass('ilcalendardaygui');
216 
217  $this->tpl->setCurrentBlock("day_view1_link");
218  $this->tpl->setVariable('HEADER_DATE',$daydate);
219  $this->tpl->setVariable('DAY_VIEW_LINK',$link);
220  $this->tpl->parseCurrentBlock();
221 
222  $this->tpl->setCurrentBlock("day_view2_link");
223  $this->tpl->setVariable('DAYNAME',$dayname);
224  $this->tpl->setVariable('DAY_VIEW_LINK',$link);
225  $this->tpl->parseCurrentBlock();
226  }
227  else
228  {
229  $this->tpl->setCurrentBlock("day_view1_no_link");
230  $this->tpl->setVariable('HEADER_DATE',$daydate);
231  $this->tpl->parseCurrentBlock();
232 
233  $this->tpl->setCurrentBlock("day_view2_no_link");
234  $this->tpl->setVariable('DAYNAME',$dayname);
235  $this->tpl->parseCurrentBlock();
236  }
237 
238  $this->tpl->setCurrentBlock('day_header_row');
239  $this->tpl->setVariable('DAY_COLSPAN',max($colspans[$counter],1));
240  $this->tpl->parseCurrentBlock();
241 
242  $counter++;
243  }
244 
245  // show fullday events
246  $counter = 0;
247  foreach($all_fullday as $daily_apps)
248  {
249  foreach($daily_apps as $event)
250  {
251  if($event['fullday'])
252  {
253  $this->showFulldayAppointment($event);
254  }
255  }
256  $this->tpl->setCurrentBlock('f_day_row');
257  $this->tpl->setVariable('COLSPAN',max($colspans[$counter],1));
258  $this->tpl->parseCurrentBlock();
259  $counter++;
260  }
261  $this->tpl->setCurrentBlock('fullday_apps');
262  $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
263  $this->tpl->parseCurrentBlock();
264 
265  $new_link_counter = 0;
266  foreach($hours as $num_hour => $hours_per_day)
267  {
268  foreach($hours_per_day as $num_day => $hour)
269  {
270  foreach($hour['apps_start'] as $app)
271  {
272  $this->showAppointment($app);
273  }
274 
275  // screen reader: appointments are divs, now output cell
276  if ($ilUser->prefs["screen_reader_optimization"])
277  {
278  $this->tpl->setCurrentBlock('scrd_day_cell');
279  $this->tpl->setVariable('TD_CLASS','calstd');
280  $this->tpl->parseCurrentBlock();
281  }
282 
283 
284  #echo "NUMDAY: ".$num_day;
285  #echo "COLAPANS: ".max($colspans[$num_day],1).'<br />';
286  $num_apps = $hour['apps_num'];
287  $colspan = max($colspans[$num_day],1);
288 
289 
290  // Show new apointment link
291  if(!$hour['apps_num'] && !$ilUser->prefs["screen_reader_optimization"] && !$no_add)
292  {
293  $this->tpl->setCurrentBlock('new_app_link');
294  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$this->weekdays[$num_day]->get(IL_CAL_DATE));
295  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
296  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$num_hour);
297  $this->tpl->setVariable('DAY_NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
298  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
299 
300  $this->tpl->setVariable('DAY_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
301  $this->tpl->setVariable('DAY_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
302  $this->tpl->setVariable('DAY_NEW_ID',++$new_link_counter);
303  $this->tpl->parseCurrentBlock();
304  }
305 
306  for($i = $colspan;$i > $hour['apps_num'];$i--)
307  {
308  if ($ilUser->prefs["screen_reader_optimization"])
309  {
310  continue;
311  }
312  $this->tpl->setCurrentBlock('day_cell');
313 
314  if($i == ($hour['apps_num'] + 1))
315  {
316  $this->tpl->setVariable('TD_CLASS','calempty calrightborder');
317  #$this->tpl->setVariable('TD_STYLE',$add_style);
318  }
319  else
320  {
321  $this->tpl->setVariable('TD_CLASS','calempty');
322  #$this->tpl->setVariable('TD_STYLE',$add_style);
323  }
324 
325  if(!$hour['apps_num'])
326  {
327  $this->tpl->setVariable('DAY_ID',$new_link_counter);
328  }
329  $this->tpl->setVariable('TD_ROWSPAN',1);
330  $this->tpl->parseCurrentBlock();
331  }
332 
333  }
334  $this->tpl->setCurrentBlock('time_row');
335  $this->tpl->setVariable('TIME',$hour['txt']);
336  $this->tpl->parseCurrentBlock();
337  }
338 
339  $this->tpl->setVariable("TXT_TIME", $lng->txt("time"));
340  }
341 
349  protected function showFulldayAppointment($a_app)
350  {
351  $this->tpl->setCurrentBlock('panel_code');
352  $this->tpl->setVariable('NUM',$this->num_appointments);
353  $this->tpl->parseCurrentBlock();
354 
355  // milestone icon
356  if ($a_app['event']->isMilestone())
357  {
358  $this->tpl->setCurrentBlock('fullday_ms_icon');
359  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
360  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
361  $this->tpl->parseCurrentBlock();
362  }
363 
364  $this->tpl->setCurrentBlock('fullday_app');
365 
366  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
367  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
368  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
369 
370  $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
371  ? " (".$a_app['event']->getCompletion()."%)"
372  : "";
373 
374  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle().$compl);
375 
376  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
377  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
378  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
379 
380  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
381  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
382  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
383 
384  $this->tpl->parseCurrentBlock();
385 
386  $this->num_appointments++;
387  }
388 
395  protected function showAppointment($a_app)
396  {
397  global $ilUser;
398 
399  $this->tpl->setCurrentBlock('panel_code');
400  $this->tpl->setVariable('NUM',$this->num_appointments);
401  $this->tpl->parseCurrentBlock();
402 
403  if (!$ilUser->prefs["screen_reader_optimization"])
404  {
405  $this->tpl->setCurrentBLock('not_empty');
406  }
407  else
408  {
409  $this->tpl->setCurrentBLock('scrd_not_empty');
410  }
411 
412  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
413  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
414 
415  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
416  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
417  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
418 
419  if($a_app['event']->isFullDay())
420  {
421  $title = $a_app['event']->getPresentationTitle();
422  }
423  else
424  {
425  switch($this->user_settings->getTimeFormat())
426  {
428  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
429  break;
430 
432  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
433  break;
434  }
435  // add end time for screen readers
436  if ($ilUser->prefs["screen_reader_optimization"])
437  {
438  switch($this->user_settings->getTimeFormat())
439  {
441  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
442  break;
443 
445  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
446  break;
447  }
448  }
449 
450  // booking
451  if($a_app['category_type'] == ilCalendarCategory::TYPE_CH)
452  {
453  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
454  $entry = new ilBookingEntry($a_app['event']->getContextId());
455  if($entry)
456  {
457  $title .= ' '.$a_app['event']->getTitle();
458  if($entry->isOwner())
459  {
460  $max = (int)$entry->getNumberOfBookings();
461  $current = (int)$entry->getCurrentNumberOfBookings($a_app['event']->getEntryId());
462  if($max > 1)
463  {
464  $title .= ' ('.$current.'/'.$max.')';
465  }
466  else if($current == $max)
467  {
468  $title .= ' ('.$this->lng->txt('cal_booked_out').')';
469  }
470  else
471  {
472  $title .= ' ('.$this->lng->txt('cal_book_free').')';
473  }
474  }
475  else if($entry->hasBooked($a_app['event']->getEntryId()))
476  {
477  $title .= ' ('.$this->lng->txt('cal_date_booked').')';
478  }
479  }
480  }
481  else
482  {
483  $title .= (' '.$a_app['event']->getPresentationTitle());
484  }
485  }
486 
487  $this->tpl->setVariable('APP_TITLE',$title);
488 
489  $this->tpl->setVariable('LINK_NUM',$this->num_appointments);
490 
491  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
492  $style = 'background-color: '.$color.';';
493  $style .= ('color:'.ilCalendarUtil::calculateFontColor($color));
494  $this->tpl->setVariable('LINK_STYLE',$style);
495 
496  if (!$ilUser->prefs["screen_reader_optimization"])
497  {
498  // provide table cell attributes
499  $this->tpl->parseCurrentBlock();
500 
501  $this->tpl->setCurrentBlock('day_cell');
502 
503  $this->tpl->setVariable('DAY_CELL_NUM',$this->num_appointments);
504  $this->tpl->setVariable('TD_ROWSPAN',$a_app['rowspan']);
505  $this->tpl->setVariable('TD_STYLE',$style);
506  $this->tpl->setVariable('TD_CLASS','calevent');
507 
508  $this->tpl->parseCurrentBlock();
509  }
510  else
511  {
512  // screen reader: work on div attributes
513  $this->tpl->setVariable('DIV_STYLE',$style);
514  $this->tpl->parseCurrentBlock();
515  }
516 
517  $this->num_appointments++;
518 
519  }
520 
521 
522 
529  protected function parseHourInfo($daily_apps,$date,$num_day,$hours = null,
530  $morning_aggr = 7, $evening_aggr = 20)
531  {
532  global $ilUser;
533 
534  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
535  {
536  $hours[$i][$num_day]['apps_start'] = array();
537  $hours[$i][$num_day]['apps_num'] = 0;
538  switch($this->user_settings->getTimeFormat())
539  {
541  if ($morning_aggr > 0 && $i == $morning_aggr)
542  {
543  $hours[$i][$num_day]['txt'] = sprintf('%02d:00',0)."-";
544  }
545  $hours[$i][$num_day]['txt'].= sprintf('%02d:00',$i);
546  if ($evening_aggr < 23 && $i == $evening_aggr)
547  {
548  $hours[$i][$num_day]['txt'].= "-".sprintf('%02d:00',23);
549  }
550  break;
551 
553  if ($morning_aggr > 0 && $i == $morning_aggr)
554  {
555  $hours[$i][$num_day]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
556  }
557  $hours[$i][$num_day]['txt'].= date('h a',mktime($i,0,0,1,1,2000));
558  if ($evening_aggr < 23 && $i == $evening_aggr)
559  {
560  $hours[$i][$num_day]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
561  }
562  break;
563  }
564  }
565 
566  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
567 
568 
569  foreach($daily_apps as $app)
570  {
571  // fullday appointment are not relavant
572  if($app['fullday'])
573  {
574  continue;
575  }
576  // start hour for this day
577  if($app['start_info']['mday'] != $date_info['mday'])
578  {
579  $start = 0;
580  }
581  else
582  {
583  $start = $app['start_info']['hours'];
584  }
585  // end hour for this day
586  if($app['end_info']['mday'] != $date_info['mday'])
587  {
588  $end = 23;
589  }
590  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
591  {
592  $end = $start +1;
593  }
594 
595  else
596  {
597  $end = $app['end_info']['hours'];
598  }
599 
600  // set end to next hour for screen readers
601  if ($ilUser->prefs["screen_reader_optimization"])
602  {
603  $end = $start +1;
604  }
605 
606  if ($start < $morning_aggr)
607  {
608  $start = $morning_aggr;
609  }
610  if ($end <= $morning_aggr)
611  {
612  $end = $morning_aggr+1;
613  }
614  if ($start > $evening_aggr)
615  {
616  $start = $evening_aggr;
617  }
618  if ($end > $evening_aggr+1)
619  {
620  $end = $evening_aggr+1;
621  }
622  if ($end <= $start)
623  {
624  $end = $start + 1;
625  }
626 
627  $first = true;
628  for($i = $start;$i < $end;$i++)
629  {
630  if($first)
631  {
632  if (!$ilUser->prefs["screen_reader_optimization"])
633  {
634  $app['rowspan'] = $end - $start;
635  }
636  else // screen readers get always a rowspan of 1
637  {
638  $app['rowspan'] = 1;
639  }
640  $hours[$i][$num_day]['apps_start'][] = $app;
641  $first = false;
642  }
643  $hours[$i][$num_day]['apps_num']++;
644  }
645  }
646  return $hours;
647  }
648 
656  protected function calculateColspans($hours)
657  {
658  global $ilUser;
659 
660  foreach($hours as $hour_num => $hours_per_day)
661  {
662  foreach($hours_per_day as $num_day => $hour)
663  {
664  $colspans[$num_day] = max($colspans[$num_day],$hour['apps_num']);
665 
666  // screen reader: always one col
667  if ($ilUser->prefs["screen_reader_optimization"])
668  {
669  $colspans[$num_day] = 1;
670  }
671  }
672  }
673  return $colspans;
674  }
675 
676 
677 }
678 
679 ?>