ILIAS  Release_4_2_x_branch Revision 61807
 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  elseif($ilUser->getId() == ANONYMOUS_USER_ID)
147  {
148  $user_id = $ilUser->getId();
149  $disable_empty = false;
150  $no_add = true;
151  }
152  else
153  {
154  $user_id = $ilUser->getId();
155  $disable_empty = false;
156  $no_add = false;
157  }
158  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
159  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_WEEK,$user_id,$disable_empty);
160  $this->scheduler->addSubitemCalendars(true);
161  $this->scheduler->calculate();
162 
163  $counter = 0;
164  $hours = null;
165  $all_fullday = array();
166  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
167  {
168  $daily_apps = $this->scheduler->getByDay($date,$this->timezone);
169  $hours = $this->parseHourInfo($daily_apps,$date,$counter,$hours,
170  $this->user_settings->getDayStart(),
171  $this->user_settings->getDayEnd()
172  );
173  $this->weekdays[] = $date;
174 
175  $num_apps[$date->get(IL_CAL_DATE)] = count($daily_apps);
176 
177  $all_fullday[] = $daily_apps;
178  $counter++;
179  }
180 
181  $colspans = $this->calculateColspans($hours);
182 
183  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
184  $settings = ilCalendarSettings::_getInstance();
185 
186  // Table header
187  $counter = 0;
188  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
189  {
190  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
191  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
192  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
193  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
194 
195  if(!$no_add)
196  {
197  if ($settings->getEnableGroupMilestones())
198  {
199  $this->tpl->setCurrentBlock("new_ms");
200  $this->tpl->setVariable('H_NEW_MS_SRC', ilUtil::getImagePath('ms_add.gif'));
201  $this->tpl->setVariable('H_NEW_MS_ALT', $this->lng->txt('cal_new_ms'));
202  $this->tpl->setVariable('NEW_MS_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
203  $this->tpl->parseCurrentBlock();
204  }
205 
206 
207  $this->tpl->setCurrentBlock("new_app");
208  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
209  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
210  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
211  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
212  $this->tpl->parseCurrentBlock();
213  }
214 
215  $dayname = ilCalendarUtil::_numericDayToString($date->get(IL_CAL_FKT_DATE,'w'),true);
216  $daydate = $date_info['mday'].' '.ilCalendarUtil::_numericMonthToString($date_info['mon'],false);
217 
218  if(!$disable_empty || $num_apps[$date->get(IL_CAL_DATE)] > 0)
219  {
220  $link = $this->ctrl->getLinkTargetByClass('ilcalendardaygui','');
221  $this->ctrl->clearParametersByClass('ilcalendardaygui');
222 
223  $this->tpl->setCurrentBlock("day_view1_link");
224  $this->tpl->setVariable('HEADER_DATE',$daydate);
225  $this->tpl->setVariable('DAY_VIEW_LINK',$link);
226  $this->tpl->parseCurrentBlock();
227 
228  $this->tpl->setCurrentBlock("day_view2_link");
229  $this->tpl->setVariable('DAYNAME',$dayname);
230  $this->tpl->setVariable('DAY_VIEW_LINK',$link);
231  $this->tpl->parseCurrentBlock();
232  }
233  else
234  {
235  $this->tpl->setCurrentBlock("day_view1_no_link");
236  $this->tpl->setVariable('HEADER_DATE',$daydate);
237  $this->tpl->parseCurrentBlock();
238 
239  $this->tpl->setCurrentBlock("day_view2_no_link");
240  $this->tpl->setVariable('DAYNAME',$dayname);
241  $this->tpl->parseCurrentBlock();
242  }
243 
244  $this->tpl->setCurrentBlock('day_header_row');
245  $this->tpl->setVariable('DAY_COLSPAN',max($colspans[$counter],1));
246  $this->tpl->parseCurrentBlock();
247 
248  $counter++;
249  }
250 
251  // show fullday events
252  $counter = 0;
253  foreach($all_fullday as $daily_apps)
254  {
255  foreach($daily_apps as $event)
256  {
257  if($event['fullday'])
258  {
259  $this->showFulldayAppointment($event);
260  }
261  }
262  $this->tpl->setCurrentBlock('f_day_row');
263  $this->tpl->setVariable('COLSPAN',max($colspans[$counter],1));
264  $this->tpl->parseCurrentBlock();
265  $counter++;
266  }
267  $this->tpl->setCurrentBlock('fullday_apps');
268  $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
269  $this->tpl->parseCurrentBlock();
270 
271  $new_link_counter = 0;
272  foreach($hours as $num_hour => $hours_per_day)
273  {
274  foreach($hours_per_day as $num_day => $hour)
275  {
276  foreach($hour['apps_start'] as $app)
277  {
278  $this->showAppointment($app);
279  }
280 
281  // screen reader: appointments are divs, now output cell
282  if ($ilUser->prefs["screen_reader_optimization"])
283  {
284  $this->tpl->setCurrentBlock('scrd_day_cell');
285  $this->tpl->setVariable('TD_CLASS','calstd');
286  $this->tpl->parseCurrentBlock();
287  }
288 
289 
290  #echo "NUMDAY: ".$num_day;
291  #echo "COLAPANS: ".max($colspans[$num_day],1).'<br />';
292  $num_apps = $hour['apps_num'];
293  $colspan = max($colspans[$num_day],1);
294 
295 
296  // Show new apointment link
297  if(!$hour['apps_num'] && !$ilUser->prefs["screen_reader_optimization"] && !$no_add)
298  {
299  $this->tpl->setCurrentBlock('new_app_link');
300  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$this->weekdays[$num_day]->get(IL_CAL_DATE));
301  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
302  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$num_hour);
303  $this->tpl->setVariable('DAY_NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
304  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
305 
306  $this->tpl->setVariable('DAY_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
307  $this->tpl->setVariable('DAY_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
308  $this->tpl->setVariable('DAY_NEW_ID',++$new_link_counter);
309  $this->tpl->parseCurrentBlock();
310  }
311 
312  for($i = $colspan;$i > $hour['apps_num'];$i--)
313  {
314  if ($ilUser->prefs["screen_reader_optimization"])
315  {
316  continue;
317  }
318  $this->tpl->setCurrentBlock('day_cell');
319 
320  if($i == ($hour['apps_num'] + 1))
321  {
322  $this->tpl->setVariable('TD_CLASS','calempty calrightborder');
323  #$this->tpl->setVariable('TD_STYLE',$add_style);
324  }
325  else
326  {
327  $this->tpl->setVariable('TD_CLASS','calempty');
328  #$this->tpl->setVariable('TD_STYLE',$add_style);
329  }
330 
331  if(!$hour['apps_num'])
332  {
333  $this->tpl->setVariable('DAY_ID',$new_link_counter);
334  }
335  $this->tpl->setVariable('TD_ROWSPAN',1);
336  $this->tpl->parseCurrentBlock();
337  }
338 
339  }
340  $this->tpl->setCurrentBlock('time_row');
341  $this->tpl->setVariable('TIME',$hour['txt']);
342  $this->tpl->parseCurrentBlock();
343  }
344 
345  $this->tpl->setVariable("TXT_TIME", $lng->txt("time"));
346  }
347 
355  protected function showFulldayAppointment($a_app)
356  {
357  $this->tpl->setCurrentBlock('panel_code');
358  $this->tpl->setVariable('NUM',$this->num_appointments);
359  $this->tpl->parseCurrentBlock();
360 
361  // milestone icon
362  if ($a_app['event']->isMilestone())
363  {
364  $this->tpl->setCurrentBlock('fullday_ms_icon');
365  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
366  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
367  $this->tpl->parseCurrentBlock();
368  }
369 
370  $this->tpl->setCurrentBlock('fullday_app');
371 
372  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
373  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
374  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
375 
376  $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
377  ? " (".$a_app['event']->getCompletion()."%)"
378  : "";
379 
380  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle().$compl);
381 
382  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
383  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
384  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
385 
386  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
387  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
388  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
389 
390  $this->tpl->parseCurrentBlock();
391 
392  $this->num_appointments++;
393  }
394 
401  protected function showAppointment($a_app)
402  {
403  global $ilUser;
404 
405  $this->tpl->setCurrentBlock('panel_code');
406  $this->tpl->setVariable('NUM',$this->num_appointments);
407  $this->tpl->parseCurrentBlock();
408 
409  if (!$ilUser->prefs["screen_reader_optimization"])
410  {
411  $this->tpl->setCurrentBLock('not_empty');
412  }
413  else
414  {
415  $this->tpl->setCurrentBLock('scrd_not_empty');
416  }
417 
418  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
419  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
420 
421  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
422  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
423  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
424 
425  if($a_app['event']->isFullDay())
426  {
427  $title = $a_app['event']->getPresentationTitle();
428  }
429  else
430  {
431  switch($this->user_settings->getTimeFormat())
432  {
434  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
435  break;
436 
438  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
439  break;
440  }
441  // add end time for screen readers
442  if ($ilUser->prefs["screen_reader_optimization"])
443  {
444  switch($this->user_settings->getTimeFormat())
445  {
447  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
448  break;
449 
451  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
452  break;
453  }
454  }
455 
456  // booking
457  if($a_app['category_type'] == ilCalendarCategory::TYPE_CH)
458  {
459  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
460  $entry = new ilBookingEntry($a_app['event']->getContextId());
461  if($entry)
462  {
463  $title .= ' '.$a_app['event']->getTitle();
464  if($entry->isOwner())
465  {
466  $max = (int)$entry->getNumberOfBookings();
467  $current = (int)$entry->getCurrentNumberOfBookings($a_app['event']->getEntryId());
468  if($max > 1)
469  {
470  $title .= ' ('.$current.'/'.$max.')';
471  }
472  else if($current == $max)
473  {
474  $title .= ' ('.$this->lng->txt('cal_booked_out').')';
475  }
476  else
477  {
478  $title .= ' ('.$this->lng->txt('cal_book_free').')';
479  }
480  }
481  else if($entry->hasBooked($a_app['event']->getEntryId()))
482  {
483  $title .= ' ('.$this->lng->txt('cal_date_booked').')';
484  }
485  }
486  }
487  else
488  {
489  $title .= (' '.$a_app['event']->getPresentationTitle());
490  }
491  }
492 
493  $this->tpl->setVariable('APP_TITLE',$title);
494 
495  $this->tpl->setVariable('LINK_NUM',$this->num_appointments);
496 
497  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
498  $style = 'background-color: '.$color.';';
499  $style .= ('color:'.ilCalendarUtil::calculateFontColor($color));
500  $this->tpl->setVariable('LINK_STYLE',$style);
501 
502  if (!$ilUser->prefs["screen_reader_optimization"])
503  {
504  // provide table cell attributes
505  $this->tpl->parseCurrentBlock();
506 
507  $this->tpl->setCurrentBlock('day_cell');
508 
509  $this->tpl->setVariable('DAY_CELL_NUM',$this->num_appointments);
510  $this->tpl->setVariable('TD_ROWSPAN',$a_app['rowspan']);
511  $this->tpl->setVariable('TD_STYLE',$style);
512  $this->tpl->setVariable('TD_CLASS','calevent');
513 
514  $this->tpl->parseCurrentBlock();
515  }
516  else
517  {
518  // screen reader: work on div attributes
519  $this->tpl->setVariable('DIV_STYLE',$style);
520  $this->tpl->parseCurrentBlock();
521  }
522 
523  $this->num_appointments++;
524 
525  }
526 
527 
528 
535  protected function parseHourInfo($daily_apps,$date,$num_day,$hours = null,
536  $morning_aggr = 7, $evening_aggr = 20)
537  {
538  global $ilUser;
539 
540  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
541  {
542  $hours[$i][$num_day]['apps_start'] = array();
543  $hours[$i][$num_day]['apps_num'] = 0;
544  switch($this->user_settings->getTimeFormat())
545  {
547  if ($morning_aggr > 0 && $i == $morning_aggr)
548  {
549  $hours[$i][$num_day]['txt'] = sprintf('%02d:00',0)."-";
550  }
551  $hours[$i][$num_day]['txt'].= sprintf('%02d:00',$i);
552  if ($evening_aggr < 23 && $i == $evening_aggr)
553  {
554  $hours[$i][$num_day]['txt'].= "-".sprintf('%02d:00',23);
555  }
556  break;
557 
559  if ($morning_aggr > 0 && $i == $morning_aggr)
560  {
561  $hours[$i][$num_day]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
562  }
563  $hours[$i][$num_day]['txt'].= date('h a',mktime($i,0,0,1,1,2000));
564  if ($evening_aggr < 23 && $i == $evening_aggr)
565  {
566  $hours[$i][$num_day]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
567  }
568  break;
569  }
570  }
571 
572  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
573 
574 
575  foreach($daily_apps as $app)
576  {
577  // fullday appointment are not relavant
578  if($app['fullday'])
579  {
580  continue;
581  }
582  // start hour for this day
583  if($app['start_info']['mday'] != $date_info['mday'])
584  {
585  $start = 0;
586  }
587  else
588  {
589  $start = $app['start_info']['hours'];
590  }
591  // end hour for this day
592  if($app['end_info']['mday'] != $date_info['mday'])
593  {
594  $end = 23;
595  }
596  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
597  {
598  $end = $start +1;
599  }
600 
601  else
602  {
603  $end = $app['end_info']['hours'];
604  }
605 
606  // set end to next hour for screen readers
607  if ($ilUser->prefs["screen_reader_optimization"])
608  {
609  $end = $start +1;
610  }
611 
612  if ($start < $morning_aggr)
613  {
614  $start = $morning_aggr;
615  }
616  if ($end <= $morning_aggr)
617  {
618  $end = $morning_aggr+1;
619  }
620  if ($start > $evening_aggr)
621  {
622  $start = $evening_aggr;
623  }
624  if ($end > $evening_aggr+1)
625  {
626  $end = $evening_aggr+1;
627  }
628  if ($end <= $start)
629  {
630  $end = $start + 1;
631  }
632 
633  $first = true;
634  for($i = $start;$i < $end;$i++)
635  {
636  if($first)
637  {
638  if (!$ilUser->prefs["screen_reader_optimization"])
639  {
640  $app['rowspan'] = $end - $start;
641  }
642  else // screen readers get always a rowspan of 1
643  {
644  $app['rowspan'] = 1;
645  }
646  $hours[$i][$num_day]['apps_start'][] = $app;
647  $first = false;
648  }
649  $hours[$i][$num_day]['apps_num']++;
650  }
651  }
652  return $hours;
653  }
654 
662  protected function calculateColspans($hours)
663  {
664  global $ilUser;
665 
666  foreach($hours as $hour_num => $hours_per_day)
667  {
668  foreach($hours_per_day as $num_day => $hour)
669  {
670  $colspans[$num_day] = max($colspans[$num_day],$hour['apps_num']);
671 
672  // screen reader: always one col
673  if ($ilUser->prefs["screen_reader_optimization"])
674  {
675  $colspans[$num_day] = 1;
676  }
677  }
678  }
679  return $colspans;
680  }
681 
682 
683 }
684 
685 ?>