ILIAS  Release_3_10_x_branch Revision 61812
 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  $this->tpl = new ilTemplate('tpl.day_view.html',true,true,'Services/Calendar');
120 
121  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
124 
125 
126  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::DAY);
127  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
128 
129  $this->tpl->setVariable('HEADER_DATE',$this->seed_info['mday'].' '.ilCalendarUtil::_numericMonthToString($this->seed_info['mon'],false));
130  $this->tpl->setVariable('HEADER_DAY',ilCalendarUtil::_numericDayToString($this->seed_info['wday'],true));
131 
132  $this->tpl->setVariable('H_NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
133  $this->tpl->setVariable('H_NEW_APP_ALT',$this->lng->txt('cal_new_app'));
134 
135 
136  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
137  $this->tpl->setVariable('NEW_APP_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
138  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
139 
140  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
141  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_DAY);
142  $this->scheduler->addSubitemCalendars(true);
143  $this->scheduler->calculate();
144 
145  $daily_apps = $this->scheduler->getByDay($this->seed,$this->timezone);
146 
147  $hours = $this->parseHourInfo($daily_apps);
148  $colspan = $this->calculateColspan($hours);
149 
150  $this->tpl->setVariable('COLSPAN',$colspan);
151 
152  // show fullday events
153  foreach($daily_apps as $event)
154  {
155  if($event['fullday'])
156  {
157  $this->showFulldayAppointment($event);
158  }
159  }
160 
161  // parse the hour rows
162  foreach($hours as $numeric => $hour)
163  {
164  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
165  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
166  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','hour',$numeric);
167  $this->tpl->setVariable('NEW_APP_HOUR_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
168 
169  $this->tpl->setVariable('NEW_APP_SRC',ilUtil::getImagePath('date_add.gif'));
170  $this->tpl->setVariable('NEW_APP_ALT',$this->lng->txt('cal_new_app'));
171 
172 
173  foreach($hour['apps_start'] as $app)
174  {
175  $this->showAppointment($app);
176  }
177  for($i = ($colspan - 1);$i > $hour['apps_num'];$i--)
178  {
179  $this->tpl->touchBlock('empty_cell');
180  }
181  $this->tpl->setCurrentBlock('time_row');
182  $this->tpl->setVariable('TIME',$hour['txt']);
183  $this->tpl->parseCurrentBlock();
184 
185  }
186  }
187 
195  protected function showFulldayAppointment($a_app)
196  {
197  $this->tpl->setCurrentBlock('panel_code');
198  $this->tpl->setVariable('NUM',$this->num_appointments);
199  $this->tpl->parseCurrentBlock();
200 
201 
202  $this->tpl->setCurrentBlock('fullday_app');
203 
204  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
205  $this->tpl->setVariable('PANEL_F_DAY_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
206  $this->tpl->setVariable('F_DAY_ID',$this->num_appointments);
207 
208  $this->tpl->setVariable('F_APP_TITLE',$a_app['event']->getPresentationTitle());
209  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
210  $this->tpl->setVariable('F_APP_BGCOLOR',$color);
211  $this->tpl->setVariable('F_APP_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
212 
213  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
214  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
215  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
216  $this->tpl->setVariable('F_APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
217 
218  $this->tpl->parseCurrentBlock();
219 
220 
221  $this->num_appointments++;
222  }
223 
230  protected function showAppointment($a_app)
231  {
232  $this->tpl->setCurrentBlock('panel_code');
233  $this->tpl->setVariable('NUM',$this->num_appointments);
234  $this->tpl->parseCurrentBlock();
235 
236 
237 
238  $this->tpl->setCurrentBlock('app');
239 
240  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
241  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($a_app));
242  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
243 
244  $this->tpl->setVariable('APP_ROWSPAN',$a_app['rowspan']);
245  $this->tpl->setVariable('APP_TITLE',$a_app['event']->getPresentationTitle());
246 
247  switch($this->user_settings->getTimeFormat())
248  {
250  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
251  break;
252 
254  $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
255  break;
256  }
257  $title .= (' '.$a_app['event']->getPresentationTitle());
258 
259  $this->tpl->setVariable('APP_TITLE',$title);
260 
261  $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
262  $this->tpl->setVariable('APP_BGCOLOR',$color);
263  $this->tpl->setVariable('APP_COLOR',ilCalendarUtil::calculateFontColor($color));
264 
265  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
266  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
267  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_app['event']->getEntryId());
268  $this->tpl->setVariable('APP_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
269 
270  $this->tpl->parseCurrentBlock();
271 
272  $this->num_appointments++;
273  }
274 
281  protected function parseHourInfo($daily_apps, $morning_aggr = 7,
282  $evening_aggr = 20)
283  {
284  for($i = $morning_aggr;$i <= $evening_aggr;$i++)
285  {
286  $hours[$i]['apps_start'] = array();
287  $hours[$i]['apps_num'] = 0;
288 
289  switch($this->user_settings->getTimeFormat())
290  {
292  if ($morning_aggr > 0 && $i == $morning_aggr)
293  {
294  $hours[$i]['txt'] = sprintf('%02d:00',0)."-";
295  }
296  $hours[$i]['txt'].= sprintf('%02d:00',$i);
297  if ($evening_aggr < 23 && $i == $evening_aggr)
298  {
299  $hours[$i]['txt'].= "-".sprintf('%02d:00',23);
300  }
301  break;
302 
304  if ($morning_aggr > 0 && $i == $morning_aggr)
305  {
306  $hours[$i]['txt'] = date('h a',mktime(0,0,0,1,1,2000))."-";
307  }
308  $hours[$i]['txt'] = date('h a',mktime($i,0,0,1,1,2000));
309  if ($evening_aggr < 23 && $i == $evening_aggr)
310  {
311  $hours[$i]['txt'].= "-".date('h a',mktime(23,0,0,1,1,2000));
312  }
313  break;
314  }
315  }
316 
317 
318  foreach($daily_apps as $app)
319  {
320  // fullday appointment are not relavant
321  if($app['fullday'])
322  {
323  continue;
324  }
325  // start hour for this day
326  if($app['start_info']['mday'] != $this->seed_info['mday'])
327  {
328  $start = 0;
329  }
330  else
331  {
332  $start = $app['start_info']['hours'];
333  }
334  // end hour for this day
335  if($app['end_info']['mday'] != $this->seed_info['mday'])
336  {
337  $end = 23;
338  }
339  elseif($app['start_info']['hours'] == $app['end_info']['hours'])
340  {
341  $end = $start +1;
342  }
343  else
344  {
345  $end = $app['end_info']['hours'];
346  }
347  if ($start < $morning_aggr)
348  {
349  $start = $morning_aggr;
350  }
351  if ($end <= $morning_aggr)
352  {
353  $end = $morning_aggr+1;
354  }
355  if ($start > $evening_aggr)
356  {
357  $start = $evening_aggr;
358  }
359  if ($end > $evening_aggr+1)
360  {
361  $end = $evening_aggr+1;
362  }
363  if ($end <= $start)
364  {
365  $end = $start + 1;
366  }
367 
368  $first = true;
369  for($i = $start;$i < $end;$i++)
370  {
371  if($first)
372  {
373  $app['rowspan'] = $end - $start;
374  $hours[$i]['apps_start'][] = $app;
375  $first = false;
376  }
377  $hours[$i]['apps_num']++;
378  }
379  }
380  return $hours;
381  }
382 
390  protected function calculateColspan($hours)
391  {
392  $colspan = 1;
393  foreach($hours as $hour)
394  {
395  $colspan = max($colspan,$hour['apps_num'] + 1);
396  }
397  return max($colspan,2);
398  }
399 
400 }
401 ?>