ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
33 include_once('./Services/Calendar/classes/class.ilDate.php');
34 include_once('./Services/Calendar/classes/class.ilCalendarUtil.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 
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  $this->tpl = new ilTemplate('tpl.day_view.html',true,true,'Services/Calendar');
125 
126  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
129 
130  if(isset($_GET["bkid"]))
131  {
132  $user_id = $_GET["bkid"];
133  $no_add = true;
134  }
135  else
136  {
137  $user_id = $ilUser->getId();
138  $no_add = false;
139  }
140  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
141  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_DAY,$user_id);
142  $this->scheduler->addSubitemCalendars(true);
143  $this->scheduler->calculate();
144  $daily_apps = $this->scheduler->getByDay($this->seed,$this->timezone);
145  $hours = $this->parseHourInfo($daily_apps,
146  $this->user_settings->getDayStart(),
147  $this->user_settings->getDayEnd()
148  );
149 
150  $colspan = $this->calculateColspan($hours);
151 
152  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::DAY);
153  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
154 
155  // add milestone link
156  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
157  $settings = ilCalendarSettings::_getInstance();
158 
159  if(!$no_add)
160  {
161  if ($settings->getEnableGroupMilestones())
162  {
163  $this->tpl->setCurrentBlock("new_ms");
164  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.gif'));
165  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
166  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
167  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $this->seed->get(IL_CAL_DATE));
168  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
169  $this->tpl->parseCurrentBlock();
170  }
171 
172  $this->tpl->setCurrentBlock("new_app1");
173  $this->tpl->setVariable('H_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
174  $this->tpl->setVariable('H_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
175  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
176  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $this->seed->get(IL_CAL_DATE));
177  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
178  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
179  $this->tpl->parseCurrentBlock();
180  }
181 
182  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
183 
184  $this->tpl->setVariable('HEADER_DATE',$this->seed_info['mday'].' '.ilCalendarUtil::_numericMonthToString($this->seed_info['mon'],false));
185  $this->tpl->setVariable('HEADER_DAY',ilCalendarUtil::_numericDayToString($this->seed_info['wday'],true));
186  $this->tpl->setVariable('HCOLSPAN',$colspan - 1);
187 
188  $this->tpl->setVariable('TXT_TIME', $lng->txt("time"));
189 
190  // show fullday events
191  foreach($daily_apps as $event)
192  {
193  if($event['fullday'])
194  {
195  $this->showFulldayAppointment($event);
196  }
197  }
198  $this->tpl->setCurrentBlock('fullday_apps');
199  $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
200  $this->tpl->setVariable('COLSPAN',$colspan - 1);
201  $this->tpl->parseCurrentBlock();
202 
203 
204  // parse the hour rows
205  foreach($hours as $numeric => $hour)
206  {
207  if(!$no_add)
208  {
209  $this->tpl->setCurrentBlock("new_app2");
210  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
211  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
212  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$this->seed->get(IL_CAL_DATE));
213  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$numeric);
214  $this->tpl->setVariable('NEW_APP_HOUR_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
215  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
216  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
217  $this->tpl->parseCurrentBlock();
218  }
219 
220  foreach($hour['apps_start'] as $app)
221  {
222  $this->showAppointment($app);
223  }
224 
225  if ($ilUser->prefs["screen_reader_optimization"])
226  {
227  $this->tpl->touchBlock('scrd_app_cell');
228  }
229 
230  for($i = ($colspan - 1);$i > $hour['apps_num'];$i--)
231  {
232  $this->tpl->setCurrentBlock('empty_cell');
233  $this->tpl->setVariable('EMPTY_WIDTH',(100 / (int) ($colspan - 1)).'%');
234  $this->tpl->parseCurrentBlock();
235  }
236  $this->tpl->setCurrentBlock('time_row');
237  $this->tpl->setVariable('TIME',$hour['txt']);
238  $this->tpl->parseCurrentBlock();
239 
240  }
241  }
242 
250  protected function showFulldayAppointment($a_app)
251  {
252  $this->tpl->setCurrentBlock('panel_code');
253  $this->tpl->setVariable('NUM',$this->num_appointments);
254  $this->tpl->parseCurrentBlock();
255 
256  // milestone icon
257  if ($a_app['event']->isMilestone())
258  {
259  $this->tpl->setCurrentBlock('fullday_ms_icon');
260  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
261  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
262  $this->tpl->parseCurrentBlock();
263  }
264 
265  $this->tpl->setCurrentBlock('fullday_app');
266  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
267  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
268  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
269 
270  $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
271  ? " (".$a_app['event']->getCompletion()."%)"
272  : "";
273  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle().$compl);
274  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
275  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
276  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
277 
278  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
279  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
280  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
281  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
282 
283  $this->tpl->parseCurrentBlock();
284 
285 
286  $this->num_appointments++;
287  }
288 
295  protected function showAppointment($a_app)
296  {
297  global $ilUser;
298 
299  $this->tpl->setCurrentBlock('panel_code');
300  $this->tpl->setVariable('NUM',$this->num_appointments);
301  $this->tpl->parseCurrentBlock();
302 
303  if (!$ilUser->prefs["screen_reader_optimization"])
304  {
305  $this->tpl->setCurrentBlock('app');
306  }
307  else
308  {
309  $this->tpl->setCurrentBlock('scrd_app');
310  }
311 
312  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
313  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
314  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
315 
316  $this->tpl->setVariable('APP_ROWSPAN',$a_app['rowspan']);
317  $this->tpl->setVariable('APP_TITLE',$a_app['event']->getPresentationTitle());
318 
319  switch($this->user_settings->getTimeFormat())
320  {
322  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
323  break;
324 
326  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
327  break;
328  }
329 
330  // add end time for screen readers
331  if ($ilUser->prefs["screen_reader_optimization"])
332  {
333  switch($this->user_settings->getTimeFormat())
334  {
336  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
337  break;
338 
340  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
341  break;
342  }
343  }
344 
345 
346  // booking
347  if($a_app['category_type'] == ilCalendarCategory::TYPE_CH)
348  {
349  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
350  $entry = new ilBookingEntry($a_app['event']->getContextId());
351  if($entry)
352  {
353  $title .= ' '.$a_app['event']->getTitle();
354  if($entry->isOwner())
355  {
356  $max = (int)$entry->getNumberOfBookings();
357  $current = (int)$entry->getCurrentNumberOfBookings($a_app['event']->getEntryId());
358  if($max > 1)
359  {
360  $title .= ' ('.$current.'/'.$max.')';
361  }
362  else if($current == $max)
363  {
364  $title .= ' ('.$this->lng->txt('cal_booked_out').')';
365  }
366  else
367  {
368  $title .= ' ('.$this->lng->txt('cal_book_free').')';
369  }
370  }
371  else if($entry->hasBooked($a_app['event']->getEntryId()))
372  {
373  $title .= ' ('.$this->lng->txt('cal_date_booked').')';
374  }
375  }
376  }
377  else
378  {
379  $title .= (' '.$a_app['event']->getPresentationTitle());
380  }
381 
382  $this->tpl->setVariable('APP_TITLE',$title);
383 
384  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
385  $this->tpl->setVariable('APP_BGCOLOR',$color);
386  $this->tpl->setVariable('APP_COLOR',ilCalendarUtil::calculateFontColor($color));
387 
388  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
389  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
390  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
391  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
392 
393  $this->tpl->parseCurrentBlock();
394 
395  $this->num_appointments++;
396  }
397 
404  protected function parseHourInfo($daily_apps, $morning_aggr = 7,$evening_aggr = 20)
405  {
406  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
407  {
408  $hours[$i]['apps_start'] = array();
409  $hours[$i]['apps_num'] = 0;
410 
411  switch($this->user_settings->getTimeFormat())
412  {
414  if ($morning_aggr > 0 && $i == $morning_aggr)
415  {
416  $hours[$i]['txt'] = sprintf('%02d:00',0)."-";
417  }
418  $hours[$i]['txt'].= sprintf('%02d:00',$i);
419  if ($evening_aggr < 23 && $i == $evening_aggr)
420  {
421  $hours[$i]['txt'].= "-".sprintf('%02d:00',23);
422  }
423  break;
424 
426  if ($morning_aggr > 0 && $i == $morning_aggr)
427  {
428  $hours[$i]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
429  }
430  $hours[$i]['txt'] = date('h a',mktime($i,0,0,1,1,2000));
431  if ($evening_aggr < 23 && $i == $evening_aggr)
432  {
433  $hours[$i]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
434  }
435  break;
436  }
437  }
438 
439 
440  foreach($daily_apps as $app)
441  {
442  global $ilUser;
443 
444  // fullday appointment are not relavant
445  if($app['fullday'])
446  {
447  continue;
448  }
449  // start hour for this day
450  if($app['start_info']['mday'] != $this->seed_info['mday'])
451  {
452  $start = 0;
453  }
454  else
455  {
456  $start = $app['start_info']['hours'];
457  }
458  // end hour for this day
459  if($app['end_info']['mday'] != $this->seed_info['mday'])
460  {
461  $end = 23;
462  }
463  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
464  {
465  $end = $start +1;
466  }
467  else
468  {
469  $end = $app['end_info']['hours'];
470  }
471 
472  // set end to next hour for screen readers
473  if ($ilUser->prefs["screen_reader_optimization"])
474  {
475  $end = $start +1;
476  }
477 
478  if ($start < $morning_aggr)
479  {
480  $start = $morning_aggr;
481  }
482  if ($end <= $morning_aggr)
483  {
484  $end = $morning_aggr+1;
485  }
486  if ($start > $evening_aggr)
487  {
488  $start = $evening_aggr;
489  }
490  if ($end > $evening_aggr+1)
491  {
492  $end = $evening_aggr+1;
493  }
494  if ($end <= $start)
495  {
496  $end = $start + 1;
497  }
498 
499  $first = true;
500  for($i = $start;$i < $end;$i++)
501  {
502  if($first)
503  {
504  if (!$ilUser->prefs["screen_reader_optimization"])
505  {
506  $app['rowspan'] = $end - $start;
507  }
508  else // screen readers get always a rowspan of 1
509  {
510  $app['rowspan'] = 1;
511  }
512  $hours[$i]['apps_start'][] = $app;
513  $first = false;
514  }
515  $hours[$i]['apps_num']++;
516  }
517  }
518  return $hours;
519  }
520 
528  protected function calculateColspan($hours)
529  {
530  global $ilUser;
531 
532  $colspan = 1;
533  foreach($hours as $hour)
534  {
535  $colspan = max($colspan,$hour['apps_num'] + 1);
536  }
537 
538  // screen reader: always two cols (time and event col)
539  if ($ilUser->prefs["screen_reader_optimization"])
540  {
541  $colspan = 2;
542  }
543 
544  return max($colspan,2);
545  }
546 
547 }
548 ?>