ILIAS  Release_3_10_x_branch Revision 61812
 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  $this->tpl = new ilTemplate('tpl.week_view.html',true,true,'Services/Calendar');
123 
124  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
127 
128 
129  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::WEEK);
130  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
131 
132  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
133  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_WEEK);
134  $this->scheduler->addSubitemCalendars(true);
135  $this->scheduler->calculate();
136 
137  $counter = 0;
138  $hours = null;
139  $all_fullday = array();
140  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
141  {
142  $daily_apps = $this->scheduler->getByDay($date,$this->timezone);
143  $hours = $this->parseHourInfo($daily_apps,$date,$counter,$hours);
144  $this->weekdays[] = $date;
145 
146  $all_fullday[] = $daily_apps;
147  $counter++;
148  }
149 
150  $colspans = $this->calculateColspans($hours);
151 
152  // Table header
153  $counter = 0;
154  foreach(ilCalendarUtil::_buildWeekDayList($this->seed,$this->user_settings->getWeekStart())->get() as $date)
155  {
156  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
157  $this->tpl->setCurrentBlock('day_header_row');
158 
159  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
160  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
161  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
162  $this->tpl->setVariable('DAY_VIEW_LINK',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
163  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
164  $this->ctrl->clearParametersByClass('ilcalendardaygui');
165 
166  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
167  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
168 
169  $this->tpl->setVariable('DAY_COLSPAN',max($colspans[$counter],1));
170 
171  $this->tpl->setVariable('HEADER_DATE',$date_info['mday'].' '.ilCalendarUtil::_numericMonthToString($date_info['mon'],false));
172  $this->tpl->setVariable('DAYNAME',ilCalendarUtil::_numericDayToString($date->get(IL_CAL_FKT_DATE,'w'),true));
173  $this->tpl->parseCurrentBlock();
174  $counter++;
175  }
176 
177  // show fullday events
178  $counter = 0;
179  foreach($all_fullday as $daily_apps)
180  {
181  foreach($daily_apps as $event)
182  {
183  if($event['fullday'])
184  {
185  $this->showFulldayAppointment($event);
186  }
187  }
188  $this->tpl->setCurrentBlock('f_day_row');
189  $this->tpl->setVariable('COLSPAN',max($colspans[$counter],1));
190  $this->tpl->parseCurrentBlock();
191  $counter++;
192  }
193 
194  $new_link_counter = 0;
195  foreach($hours as $num_hour => $hours_per_day)
196  {
197  foreach($hours_per_day as $num_day => $hour)
198  {
199  foreach($hour['apps_start'] as $app)
200  {
201  $this->showAppointment($app);
202  }
203  #echo "NUMDAY: ".$num_day;
204  #echo "COLAPANS: ".max($colspans[$num_day],1).'<br />';
205  $num_apps = $hour['apps_num'];
206  $colspan = max($colspans[$num_day],1);
207 
208 
209  // Show new apointment link
210  if(!$hour['apps_num'])
211  {
212  $this->tpl->setCurrentBlock('new_app_link');
213  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->weekdays[$num_day]->get(IL_CAL_DATE));
214  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$num_hour);
215  $this->tpl->setVariable('DAY_NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
216  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
217 
218  $this->tpl->setVariable('DAY_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
219  $this->tpl->setVariable('DAY_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
220  $this->tpl->setVariable('DAY_NEW_ID',++$new_link_counter);
221  $this->tpl->parseCurrentBlock();
222  }
223 
224  for($i = $colspan;$i > $hour['apps_num'];$i--)
225  {
226  $this->tpl->setCurrentBlock('day_cell');
227  if($i == ($hour['apps_num'] + 1))
228  {
229  $this->tpl->setVariable('TD_CLASS','calempty calrightborder');
230  #$this->tpl->setVariable('TD_STYLE',$add_style);
231  }
232  else
233  {
234  $this->tpl->setVariable('TD_CLASS','calempty');
235  #$this->tpl->setVariable('TD_STYLE',$add_style);
236  }
237 
238  if(!$hour['apps_num'])
239  {
240  $this->tpl->setVariable('DAY_ID',$new_link_counter);
241  }
242  $this->tpl->setVariable('TD_ROWSPAN',1);
243  $this->tpl->parseCurrentBlock();
244  }
245 
246  }
247  $this->tpl->setCurrentBlock('time_row');
248  $this->tpl->setVariable('TIME',$hour['txt']);
249  $this->tpl->parseCurrentBlock();
250  }
251  }
252 
260  protected function showFulldayAppointment($a_app)
261  {
262  $this->tpl->setCurrentBlock('panel_code');
263  $this->tpl->setVariable('NUM',$this->num_appointments);
264  $this->tpl->parseCurrentBlock();
265 
266 
267  $this->tpl->setCurrentBlock('fullday_app');
268 
269  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
270  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
271  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
272 
273  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle());
274 
275  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
276  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
277  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
278 
279  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
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  $this->num_appointments++;
286  }
287 
294  protected function showAppointment($a_app)
295  {
296  $this->tpl->setCurrentBlock('panel_code');
297  $this->tpl->setVariable('NUM',$this->num_appointments);
298  $this->tpl->parseCurrentBlock();
299 
300 
301  $this->tpl->setCurrentBLock('not_empty');
302 
303  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
304  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
305 
306  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
307  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
308  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
309 
310  if($a_app['event']->isFullDay())
311  {
312  $title = $a_app['event']->getPresentationTitle();
313  }
314  else
315  {
316  switch($this->user_settings->getTimeFormat())
317  {
319  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
320  break;
321 
323  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
324  break;
325  }
326 
327 
328  $title .= (' '.$a_app['event']->getPresentationTitle());
329  }
330 
331  $this->tpl->setVariable('APP_TITLE',$title);
332 
333  $this->tpl->setVariable('LINK_NUM',$this->num_appointments);
334  $this->tpl->parseCurrentBlock();
335 
336  $this->tpl->setCurrentBlock('day_cell');
337  $this->tpl->setVariable('DAY_CELL_NUM',$this->num_appointments);
338  $this->tpl->setVariable('TD_ROWSPAN',$a_app['rowspan']);
339 
340  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
341  $style = 'background-color: '.$color.';';
342  $style .= ('color:'.ilCalendarUtil::calculateFontColor($color));
343  $this->tpl->setVariable('TD_STYLE',$style);
344  $this->tpl->setVariable('TD_CLASS','calevent');
345  $this->tpl->parseCurrentBlock();
346 
347  $this->num_appointments++;
348 
349  }
350 
351 
352 
359  protected function parseHourInfo($daily_apps,$date,$num_day,$hours = null,
360  $morning_aggr = 7, $evening_aggr = 20)
361  {
362  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
363  {
364  $hours[$i][$num_day]['apps_start'] = array();
365  $hours[$i][$num_day]['apps_num'] = 0;
366  switch($this->user_settings->getTimeFormat())
367  {
369  if ($morning_aggr > 0 && $i == $morning_aggr)
370  {
371  $hours[$i][$num_day]['txt'] = sprintf('%02d:00',0)."-";
372  }
373  $hours[$i][$num_day]['txt'].= sprintf('%02d:00',$i);
374  if ($evening_aggr < 23 && $i == $evening_aggr)
375  {
376  $hours[$i][$num_day]['txt'].= "-".sprintf('%02d:00',23);
377  }
378  break;
379 
381  if ($morning_aggr > 0 && $i == $morning_aggr)
382  {
383  $hours[$i][$num_day]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
384  }
385  $hours[$i][$num_day]['txt'].= date('h a',mktime($i,0,0,1,1,2000));
386  if ($evening_aggr < 23 && $i == $evening_aggr)
387  {
388  $hours[$i][$num_day]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
389  }
390  break;
391  }
392  }
393 
394  $date_info = $date->get(IL_CAL_FKT_GETDATE,'','UTC');
395 
396 
397  foreach($daily_apps as $app)
398  {
399  // fullday appointment are not relavant
400  if($app['fullday'])
401  {
402  continue;
403  }
404  // start hour for this day
405  if($app['start_info']['mday'] != $date_info['mday'])
406  {
407  $start = 0;
408  }
409  else
410  {
411  $start = $app['start_info']['hours'];
412  }
413  // end hour for this day
414  if($app['end_info']['mday'] != $date_info['mday'])
415  {
416  $end = 23;
417  }
418  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
419  {
420  $end = $start +1;
421  }
422 
423  else
424  {
425  $end = $app['end_info']['hours'];
426  }
427 
428  if ($start < $morning_aggr)
429  {
430  $start = $morning_aggr;
431  }
432  if ($end <= $morning_aggr)
433  {
434  $end = $morning_aggr+1;
435  }
436  if ($start > $evening_aggr)
437  {
438  $start = $evening_aggr;
439  }
440  if ($end > $evening_aggr+1)
441  {
442  $end = $evening_aggr+1;
443  }
444  if ($end <= $start)
445  {
446  $end = $start + 1;
447  }
448 
449  $first = true;
450  for($i = $start;$i < $end;$i++)
451  {
452  if($first)
453  {
454  $app['rowspan'] = $end - $start;
455  $hours[$i][$num_day]['apps_start'][] = $app;
456  $first = false;
457  }
458  $hours[$i][$num_day]['apps_num']++;
459  }
460  }
461  return $hours;
462  }
463 
471  protected function calculateColspans($hours)
472  {
473  foreach($hours as $hour_num => $hours_per_day)
474  {
475  foreach($hours_per_day as $num_day => $hour)
476  {
477  $colspans[$num_day] = max($colspans[$num_day],$hour['apps_num']);
478  }
479  }
480  return $colspans;
481  }
482 
483 
484 }
485 
486 ?>