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