ILIAS  Release_4_0_x_branch Revision 61816
 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  $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  $time = microtime(true);
104  $cmd = $this->ctrl->getCmd("show");
105  $this->$cmd();
106  $tpl->setContent($this->tpl->get());
107  #echo "Zeit: ".(microtime(true) - $time);
108  break;
109  }
110 
111  return true;
112  }
113 
120  public function show()
121  {
122  global $ilUser, $lng;
123 
124  $this->tpl = new ilTemplate('tpl.week_view.html',true,true,'Services/Calendar');
125 
126  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
129 
130 
131  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::WEEK);
132  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
133 
134  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
135  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_WEEK);
136  $this->scheduler->addSubitemCalendars(true);
137  $this->scheduler->calculate();
138 
139  $counter = 0;
140  $hours = null;
141  $all_fullday = array();
142  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
143  {
144  $daily_apps = $this->scheduler->getByDay($date,$this->timezone);
145  $hours = $this->parseHourInfo($daily_apps,$date,$counter,$hours,
146  $this->user_settings->getDayStart(),
147  $this->user_settings->getDayEnd()
148  );
149  $this->weekdays[] = $date;
150 
151  $all_fullday[] = $daily_apps;
152  $counter++;
153  }
154 
155  $colspans = $this->calculateColspans($hours);
156 
157  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
158  $settings = ilCalendarSettings::_getInstance();
159 
160  // Table header
161  $counter = 0;
162  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
163  {
164  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
165  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
166  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
167 
168  if ($settings->getEnableGroupMilestones())
169  {
170  $this->tpl->setCurrentBlock("new_ms");
171  $this->tpl->setVariable('H_NEW_MS_SRC', ilUtil::getImagePath('ms_add.gif'));
172  $this->tpl->setVariable('H_NEW_MS_ALT', $this->lng->txt('cal_new_ms'));
173  $this->tpl->setVariable('NEW_MS_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
174  $this->tpl->parseCurrentBlock();
175  }
176 
177  $this->tpl->setCurrentBlock('day_header_row');
178  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
179  $this->tpl->setVariable('DAY_VIEW_LINK',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
180  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
181  $this->ctrl->clearParametersByClass('ilcalendardaygui');
182 
183  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
184  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
185 
186  $this->tpl->setVariable('DAY_COLSPAN',max($colspans[$counter],1));
187 
188  $this->tpl->setVariable('HEADER_DATE',$date_info['mday'].' '.ilCalendarUtil::_numericMonthToString($date_info['mon'],false));
189  $this->tpl->setVariable('DAYNAME',ilCalendarUtil::_numericDayToString($date->get(IL_CAL_FKT_DATE,'w'),true));
190  $this->tpl->parseCurrentBlock();
191  $counter++;
192  }
193 
194  // show fullday events
195  $counter = 0;
196  foreach($all_fullday as $daily_apps)
197  {
198  foreach($daily_apps as $event)
199  {
200  if($event['fullday'])
201  {
202  $this->showFulldayAppointment($event);
203  }
204  }
205  $this->tpl->setCurrentBlock('f_day_row');
206  $this->tpl->setVariable('COLSPAN',max($colspans[$counter],1));
207  $this->tpl->parseCurrentBlock();
208  $counter++;
209  }
210  $this->tpl->setCurrentBlock('fullday_apps');
211  $this->tpl->setVariable('TXT_F_DAY', $lng->txt("cal_all_day"));
212  $this->tpl->parseCurrentBlock();
213 
214  $new_link_counter = 0;
215  foreach($hours as $num_hour => $hours_per_day)
216  {
217  foreach($hours_per_day as $num_day => $hour)
218  {
219  foreach($hour['apps_start'] as $app)
220  {
221  $this->showAppointment($app);
222  }
223 
224  // screen reader: appointments are divs, now output cell
225  if ($ilUser->prefs["screen_reader_optimization"])
226  {
227  $this->tpl->setCurrentBlock('scrd_day_cell');
228  $this->tpl->setVariable('TD_CLASS','calstd');
229  $this->tpl->parseCurrentBlock();
230  }
231 
232 
233  #echo "NUMDAY: ".$num_day;
234  #echo "COLAPANS: ".max($colspans[$num_day],1).'<br />';
235  $num_apps = $hour['apps_num'];
236  $colspan = max($colspans[$num_day],1);
237 
238 
239  // Show new apointment link
240  if(!$hour['apps_num'] && !$ilUser->prefs["screen_reader_optimization"])
241  {
242  $this->tpl->setCurrentBlock('new_app_link');
243  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->weekdays[$num_day]->get(IL_CAL_DATE));
244  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$num_hour);
245  $this->tpl->setVariable('DAY_NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
246  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
247 
248  $this->tpl->setVariable('DAY_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
249  $this->tpl->setVariable('DAY_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
250  $this->tpl->setVariable('DAY_NEW_ID',++$new_link_counter);
251  $this->tpl->parseCurrentBlock();
252  }
253 
254  for($i = $colspan;$i > $hour['apps_num'];$i--)
255  {
256  if ($ilUser->prefs["screen_reader_optimization"])
257  {
258  continue;
259  }
260  $this->tpl->setCurrentBlock('day_cell');
261 
262  if($i == ($hour['apps_num'] + 1))
263  {
264  $this->tpl->setVariable('TD_CLASS','calempty calrightborder');
265  #$this->tpl->setVariable('TD_STYLE',$add_style);
266  }
267  else
268  {
269  $this->tpl->setVariable('TD_CLASS','calempty');
270  #$this->tpl->setVariable('TD_STYLE',$add_style);
271  }
272 
273  if(!$hour['apps_num'])
274  {
275  $this->tpl->setVariable('DAY_ID',$new_link_counter);
276  }
277  $this->tpl->setVariable('TD_ROWSPAN',1);
278  $this->tpl->parseCurrentBlock();
279  }
280 
281  }
282  $this->tpl->setCurrentBlock('time_row');
283  $this->tpl->setVariable('TIME',$hour['txt']);
284  $this->tpl->parseCurrentBlock();
285  }
286 
287  $this->tpl->setVariable("TXT_TIME", $lng->txt("time"));
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.gif"));
309  $this->tpl->parseCurrentBlock();
310  }
311 
312  $this->tpl->setCurrentBlock('fullday_app');
313 
314  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
315  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
316  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
317 
318  $compl = ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0)
319  ? " (".$a_app['event']->getCompletion()."%)"
320  : "";
321 
322  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle().$compl);
323 
324  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
325  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
326  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
327 
328  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
329  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
330  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
331 
332  $this->tpl->parseCurrentBlock();
333 
334  $this->num_appointments++;
335  }
336 
343  protected function showAppointment($a_app)
344  {
345  global $ilUser;
346 
347  $this->tpl->setCurrentBlock('panel_code');
348  $this->tpl->setVariable('NUM',$this->num_appointments);
349  $this->tpl->parseCurrentBlock();
350 
351  if (!$ilUser->prefs["screen_reader_optimization"])
352  {
353  $this->tpl->setCurrentBLock('not_empty');
354  }
355  else
356  {
357  $this->tpl->setCurrentBLock('scrd_not_empty');
358  }
359 
360  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
361  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
362 
363  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
364  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
365  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
366 
367  if($a_app['event']->isFullDay())
368  {
369  $title = $a_app['event']->getPresentationTitle();
370  }
371  else
372  {
373  switch($this->user_settings->getTimeFormat())
374  {
376  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
377  break;
378 
380  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
381  break;
382  }
383  // add end time for screen readers
384  if ($ilUser->prefs["screen_reader_optimization"])
385  {
386  switch($this->user_settings->getTimeFormat())
387  {
389  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
390  break;
391 
393  $title.= "-".$a_app['event']->getEnd()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
394  break;
395  }
396  }
397 
398 
399  $title .= (' '.$a_app['event']->getPresentationTitle());
400  }
401 
402  $this->tpl->setVariable('APP_TITLE',$title);
403 
404  $this->tpl->setVariable('LINK_NUM',$this->num_appointments);
405 
406  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
407  $style = 'background-color: '.$color.';';
408  $style .= ('color:'.ilCalendarUtil::calculateFontColor($color));
409 
410  if (!$ilUser->prefs["screen_reader_optimization"])
411  {
412  // provide table cell attributes
413  $this->tpl->parseCurrentBlock();
414 
415  $this->tpl->setCurrentBlock('day_cell');
416 
417  if (!$ilUser->prefs["screen_reader_optimization"])
418  {
419  $this->tpl->setVariable('DAY_CELL_NUM',$this->num_appointments);
420  $this->tpl->setVariable('TD_ROWSPAN',$a_app['rowspan']);
421  $this->tpl->setVariable('TD_STYLE',$style);
422  $this->tpl->setVariable('TD_CLASS','calevent');
423  }
424 
425  $this->tpl->parseCurrentBlock();
426  }
427  else
428  {
429  // screen reader: work on div attributes
430  $this->tpl->setVariable('DIV_STYLE',$style);
431  $this->tpl->parseCurrentBlock();
432  }
433 
434  $this->num_appointments++;
435 
436  }
437 
438 
439 
446  protected function parseHourInfo($daily_apps,$date,$num_day,$hours = null,
447  $morning_aggr = 7, $evening_aggr = 20)
448  {
449  global $ilUser;
450 
451  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
452  {
453  $hours[$i][$num_day]['apps_start'] = array();
454  $hours[$i][$num_day]['apps_num'] = 0;
455  switch($this->user_settings->getTimeFormat())
456  {
458  if ($morning_aggr > 0 && $i == $morning_aggr)
459  {
460  $hours[$i][$num_day]['txt'] = sprintf('%02d:00',0)."-";
461  }
462  $hours[$i][$num_day]['txt'].= sprintf('%02d:00',$i);
463  if ($evening_aggr < 23 && $i == $evening_aggr)
464  {
465  $hours[$i][$num_day]['txt'].= "-".sprintf('%02d:00',23);
466  }
467  break;
468 
470  if ($morning_aggr > 0 && $i == $morning_aggr)
471  {
472  $hours[$i][$num_day]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
473  }
474  $hours[$i][$num_day]['txt'].= date('h a',mktime($i,0,0,1,1,2000));
475  if ($evening_aggr < 23 && $i == $evening_aggr)
476  {
477  $hours[$i][$num_day]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
478  }
479  break;
480  }
481  }
482 
483  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
484 
485 
486  foreach($daily_apps as $app)
487  {
488  // fullday appointment are not relavant
489  if($app['fullday'])
490  {
491  continue;
492  }
493  // start hour for this day
494  if($app['start_info']['mday'] != $date_info['mday'])
495  {
496  $start = 0;
497  }
498  else
499  {
500  $start = $app['start_info']['hours'];
501  }
502  // end hour for this day
503  if($app['end_info']['mday'] != $date_info['mday'])
504  {
505  $end = 23;
506  }
507  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
508  {
509  $end = $start +1;
510  }
511 
512  else
513  {
514  $end = $app['end_info']['hours'];
515  }
516 
517  // set end to next hour for screen readers
518  if ($ilUser->prefs["screen_reader_optimization"])
519  {
520  $end = $start +1;
521  }
522 
523  if ($start < $morning_aggr)
524  {
525  $start = $morning_aggr;
526  }
527  if ($end <= $morning_aggr)
528  {
529  $end = $morning_aggr+1;
530  }
531  if ($start > $evening_aggr)
532  {
533  $start = $evening_aggr;
534  }
535  if ($end > $evening_aggr+1)
536  {
537  $end = $evening_aggr+1;
538  }
539  if ($end <= $start)
540  {
541  $end = $start + 1;
542  }
543 
544  $first = true;
545  for($i = $start;$i < $end;$i++)
546  {
547  if($first)
548  {
549  if (!$ilUser->prefs["screen_reader_optimization"])
550  {
551  $app['rowspan'] = $end - $start;
552  }
553  else // screen readers get always a rowspan of 1
554  {
555  $app['rowspan'] = 1;
556  }
557  $hours[$i][$num_day]['apps_start'][] = $app;
558  $first = false;
559  }
560  $hours[$i][$num_day]['apps_num']++;
561  }
562  }
563  return $hours;
564  }
565 
573  protected function calculateColspans($hours)
574  {
575  global $ilUser;
576 
577  foreach($hours as $hour_num => $hours_per_day)
578  {
579  foreach($hours_per_day as $num_day => $hour)
580  {
581  $colspans[$num_day] = max($colspans[$num_day],$hour['apps_num']);
582 
583  // screen reader: always one col
584  if ($ilUser->prefs["screen_reader_optimization"])
585  {
586  $colspans[$num_day] = 1;
587  }
588  }
589  }
590  return $colspans;
591  }
592 
593 
594 }
595 
596 ?>