ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarMonthGUI.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 
24 include_once('Services/Calendar/classes/class.ilDate.php');
25 include_once('Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
26 include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
27 include_once('Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
28 
29 
42 {
43  protected $num_appointments = 1;
44 
45  protected $seed = null;
46  protected $user_settings = null;
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 
68  $this->tpl = $tpl;
69  $this->lng = $lng;
70  $this->ctrl = $ilCtrl;
71  $this->tabs_gui = $ilTabs;
72  $this->tabs_gui->setSubTabActive('app_month');
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 
108  #echo "Zeit: ".(microtime(true) - $time);
109  break;
110  }
111  return true;
112  }
113 
120  public function show()
121  {
122  global $tpl;
123 
124  $this->tpl = new ilTemplate('tpl.month_view.html',true,true,'Services/Calendar');
125 
126  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
129 
130  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::MONTH);
131  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
132 
133  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
134  {
135  $this->tpl->setCurrentBlock('month_header_col');
136  $this->tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,true));
137  $this->tpl->parseCurrentBlock();
138  }
139 
140  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
141  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH);
142  $this->scheduler->addSubitemCalendars(true);
143  $this->scheduler->calculate();
144 
145  $counter = 0;
146  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
147  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
148  $this->user_settings->getWeekStart())->get() as $date)
149  {
150  $counter++;
151  $this->showEvents($date);
152 
153  $this->tpl->setCurrentBlock('month_col');
154 
155  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
156  if(ilCalendarUtil::_isToday($date))
157  {
158  $this->tpl->setVariable('TD_CLASS','caltoday');
159  }
160  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
161  {
162  $this->tpl->setVariable('TD_CLASS','calnow');
163  }
164  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
165  {
166  $this->tpl->setVariable('TD_CLASS','calstd');
167  }
168  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
169  {
170  $this->tpl->setVariable('TD_CLASS','calprev');
171  }
172  else
173  {
174  $this->tpl->setVariable('TD_CLASS','calnext');
175  }
176 
177  $day = $date->get(IL_CAL_FKT_DATE,'j');
178  $month = $date->get(IL_CAL_FKT_DATE,'n');
179 
180  if($day == 1)
181  {
182  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
183  }
184  else
185  {
186  $month_day = $day;
187  }
188 
189  $this->ctrl->clearParametersByClass('ilcalendardaygui');
190  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
191  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
192  $this->ctrl->clearParametersByClass('ilcalendardaygui');
193 
194  $this->tpl->setVariable('MONTH_DAY',$month_day);
195  #$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
196  $this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('date_add.gif'));
197  $this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
198  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
199  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
200  $this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
201 
202  $this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.gif','calendar'));
203  $this->tpl->parseCurrentBlock();
204 
205 
206  if($counter and !($counter % 7))
207  {
208  $this->tpl->setCurrentBlock('month_row');
209  $this->tpl->parseCurrentBlock();
210  }
211  }
212  }
213 
220  protected function showEvents(ilDate $date)
221  {
222  global $tree;
223 
224  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
225  {
226  $this->tpl->setCurrentBlock('panel_code');
227  $this->tpl->setVariable('NUM',$this->num_appointments);
228  $this->tpl->parseCurrentBlock();
229 
230  $this->tpl->setCurrentBlock('il_event');
231 
232  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
233  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($item));
234  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
235 
236 
237  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
238  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
239  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
240  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
241 
242  if($item['event']->isFullDay())
243  {
244  $title = $item['event']->getPresentationTitle();
245  }
246  else
247  {
248  switch($this->user_settings->getTimeFormat())
249  {
251  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
252  break;
253 
255  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
256  break;
257  }
258 
259 
260  $title .= (' '.$item['event']->getPresentationTitle());
261  }
262  $this->tpl->setVariable('EVENT_TITLE',$title);
263  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
264  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
265  $this->tpl->setVariable('EVENT_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
266 
267  $this->tpl->parseCurrentBlock();
268 
269  $this->num_appointments++;
270  }
271  }
272 
273 }
274 
275 
276 ?>