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