ILIAS  Release_4_0_x_branch Revision 61816
 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  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
98  $app = new ilCalendarAppointmentGUI($this->seed,(int) $_GET['app_id']);
99  $this->ctrl->forwardCommand($app);
100  break;
101 
102  default:
103  $cmd = $this->ctrl->getCmd("show");
104  $this->$cmd();
105  $tpl->setContent($this->tpl->get());
106  break;
107  }
108  return true;
109  }
110 
117  protected function show()
118  {
119  global $lng;
120 
121  $this->tpl = new ilTemplate('tpl.day_view.html',true,true,'Services/Calendar');
122 
123  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
126 
127  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
128  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_DAY);
129  $this->scheduler->addSubitemCalendars(true);
130  $this->scheduler->calculate();
131  $daily_apps = $this->scheduler->getByDay($this->seed,$this->timezone);
132  $hours = $this->parseHourInfo($daily_apps,
133  $this->user_settings->getDayStart(),
134  $this->user_settings->getDayEnd()
135  );
136 
137  $colspan = $this->calculateColspan($hours);
138 
139  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::DAY);
140  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
141 
142  // add milestone link
143  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
144  $settings = ilCalendarSettings::_getInstance();
145 
146  if ($settings->getEnableGroupMilestones())
147  {
148  $this->tpl->setCurrentBlock("new_ms");
149  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.gif'));
150  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
151  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
152  $this->tpl->parseCurrentBlock();
153  }
154 
155  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
156 
157  $this->tpl->setVariable('HEADER_DATE',$this->seed_info['mday'].' '.ilCalendarUtil::_numericMonthToString($this->seed_info['mon'],false));
158  $this->tpl->setVariable('HEADER_DAY',ilCalendarUtil::_numericDayToString($this->seed_info['wday'],true));
159  $this->tpl->setVariable('HCOLSPAN',$colspan - 1);
160 
161  $this->tpl->setVariable('H_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
162  $this->tpl->setVariable('H_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
163 
164  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
165  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
166 
167 
168  $this->tpl->setVariable('TXT_TIME', $lng->txt("time"));
169 
170  // show fullday events
171  foreach($daily_apps as $event)
172  {
173  if($event['fullday'])
174  {
175  $this->showFulldayAppointment($event);
176  }
177  }
178  $this->tpl->setCurrentBlock('fullday_apps');
179  $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
180  $this->tpl->setVariable('COLSPAN',$colspan - 1);
181  $this->tpl->parseCurrentBlock();
182 
183 
184  // parse the hour rows
185  foreach($hours as $numeric => $hour)
186  {
187  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
188  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
189  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$numeric);
190  $this->tpl->setVariable('NEW_APP_HOUR_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
191 
192  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
193  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
194 
195 
196  foreach($hour['apps_start'] as $app)
197  {
198  $this->showAppointment($app);
199  }
200 
201  if ($ilUser->prefs["screen_reader_optimization"])
202  {
203  $this->tpl->touchBlock('scrd_app_cell');
204  }
205 
206  for($i = ($colspan - 1);$i > $hour['apps_num'];$i--)
207  {
208  $this->tpl->setCurrentBlock('empty_cell');
209  $this->tpl->setVariable('EMPTY_WIDTH',(100 / (int) ($colspan - 1)).'%');
210  $this->tpl->parseCurrentBlock();
211  }
212  $this->tpl->setCurrentBlock('time_row');
213  $this->tpl->setVariable('TIME',$hour['txt']);
214  $this->tpl->parseCurrentBlock();
215 
216  }
217  }
218 
226  protected function showFulldayAppointment($a_app)
227  {
228  $this->tpl->setCurrentBlock('panel_code');
229  $this->tpl->setVariable('NUM',$this->num_appointments);
230  $this->tpl->parseCurrentBlock();
231 
232  // milestone icon
233  if ($a_app['event']->isMilestone())
234  {
235  $this->tpl->setCurrentBlock('fullday_ms_icon');
236  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
237  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
238  $this->tpl->parseCurrentBlock();
239  }
240 
241  $this->tpl->setCurrentBlock('fullday_app');
242  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
243  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
244  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
245 
246  $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
247  ? " (".$a_app['event']->getCompletion()."%)"
248  : "";
249  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle().$compl);
250  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
251  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
252  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
253 
254  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
255  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
256  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
257  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
258 
259  $this->tpl->parseCurrentBlock();
260 
261 
262  $this->num_appointments++;
263  }
264 
271  protected function showAppointment($a_app)
272  {
273  global $ilUser;
274 
275  $this->tpl->setCurrentBlock('panel_code');
276  $this->tpl->setVariable('NUM',$this->num_appointments);
277  $this->tpl->parseCurrentBlock();
278 
279  if (!$ilUser->prefs["screen_reader_optimization"])
280  {
281  $this->tpl->setCurrentBlock('app');
282  }
283  else
284  {
285  $this->tpl->setCurrentBlock('scrd_app');
286  }
287 
288  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
289  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
290  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
291 
292  $this->tpl->setVariable('APP_ROWSPAN',$a_app['rowspan']);
293  $this->tpl->setVariable('APP_TITLE',$a_app['event']->getPresentationTitle());
294 
295  switch($this->user_settings->getTimeFormat())
296  {
298  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
299  break;
300 
302  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
303  break;
304  }
305 
306  // add end time for screen readers
307  if ($ilUser->prefs["screen_reader_optimization"])
308  {
309  switch($this->user_settings->getTimeFormat())
310  {
312  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
313  break;
314 
316  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
317  break;
318  }
319  }
320  $title .= (' '.$a_app['event']->getPresentationTitle());
321 
322  $this->tpl->setVariable('APP_TITLE',$title);
323 
324  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
325  $this->tpl->setVariable('APP_BGCOLOR',$color);
326  $this->tpl->setVariable('APP_COLOR',ilCalendarUtil::calculateFontColor($color));
327 
328  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
329  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
330  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
331  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
332 
333  $this->tpl->parseCurrentBlock();
334 
335  $this->num_appointments++;
336  }
337 
344  protected function parseHourInfo($daily_apps, $morning_aggr = 7,
345  $evening_aggr = 20)
346  {
347  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
348  {
349  $hours[$i]['apps_start'] = array();
350  $hours[$i]['apps_num'] = 0;
351 
352  switch($this->user_settings->getTimeFormat())
353  {
355  if ($morning_aggr > 0 && $i == $morning_aggr)
356  {
357  $hours[$i]['txt'] = sprintf('%02d:00',0)."-";
358  }
359  $hours[$i]['txt'].= sprintf('%02d:00',$i);
360  if ($evening_aggr < 23 && $i == $evening_aggr)
361  {
362  $hours[$i]['txt'].= "-".sprintf('%02d:00',23);
363  }
364  break;
365 
367  if ($morning_aggr > 0 && $i == $morning_aggr)
368  {
369  $hours[$i]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
370  }
371  $hours[$i]['txt'] = date('h a',mktime($i,0,0,1,1,2000));
372  if ($evening_aggr < 23 && $i == $evening_aggr)
373  {
374  $hours[$i]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
375  }
376  break;
377  }
378  }
379 
380 
381  foreach($daily_apps as $app)
382  {
383  global $ilUser;
384 
385  // fullday appointment are not relavant
386  if($app['fullday'])
387  {
388  continue;
389  }
390  // start hour for this day
391  if($app['start_info']['mday'] != $this->seed_info['mday'])
392  {
393  $start = 0;
394  }
395  else
396  {
397  $start = $app['start_info']['hours'];
398  }
399  // end hour for this day
400  if($app['end_info']['mday'] != $this->seed_info['mday'])
401  {
402  $end = 23;
403  }
404  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
405  {
406  $end = $start +1;
407  }
408  else
409  {
410  $end = $app['end_info']['hours'];
411  }
412 
413  // set end to next hour for screen readers
414  if ($ilUser->prefs["screen_reader_optimization"])
415  {
416  $end = $start +1;
417  }
418 
419  if ($start < $morning_aggr)
420  {
421  $start = $morning_aggr;
422  }
423  if ($end <= $morning_aggr)
424  {
425  $end = $morning_aggr+1;
426  }
427  if ($start > $evening_aggr)
428  {
429  $start = $evening_aggr;
430  }
431  if ($end > $evening_aggr+1)
432  {
433  $end = $evening_aggr+1;
434  }
435  if ($end <= $start)
436  {
437  $end = $start + 1;
438  }
439 
440  $first = true;
441  for($i = $start;$i < $end;$i++)
442  {
443  if($first)
444  {
445  if (!$ilUser->prefs["screen_reader_optimization"])
446  {
447  $app['rowspan'] = $end - $start;
448  }
449  else // screen readers get always a rowspan of 1
450  {
451  $app['rowspan'] = 1;
452  }
453  $hours[$i]['apps_start'][] = $app;
454  $first = false;
455  }
456  $hours[$i]['apps_num']++;
457  }
458  }
459  return $hours;
460  }
461 
469  protected function calculateColspan($hours)
470  {
471  global $ilUser;
472 
473  $colspan = 1;
474  foreach($hours as $hour)
475  {
476  $colspan = max($colspan,$hour['apps_num'] + 1);
477  }
478 
479  // screen reader: always two cols (time and event col)
480  if ($ilUser->prefs["screen_reader_optimization"])
481  {
482  $colspan = 2;
483  }
484 
485  return max($colspan,2);
486  }
487 
488 }
489 ?>