ILIAS  Release_4_0_x_branch Revision 61816
 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  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
146  $settings = ilCalendarSettings::_getInstance();
147 
148  $counter = 0;
149  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
150  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
151  $this->user_settings->getWeekStart())->get() as $date)
152  {
153  $counter++;
154  $this->showEvents($date);
155 
156  if ($settings->getEnableGroupMilestones())
157  {
158  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
159  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
160  $this->tpl->setCurrentBlock("new_ms");
161  $this->tpl->setVariable('H_NEW_MS_SRC',ilUtil::getImagePath('ms_add.gif'));
162  $this->tpl->setVariable('H_NEW_MS_ALT',$this->lng->txt('cal_new_ms'));
163  $this->tpl->setVariable('NEW_MS_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone'));
164  $this->tpl->parseCurrentBlock();
165  }
166 
167  $this->tpl->setCurrentBlock('month_col');
168 
169  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
170  if(ilCalendarUtil::_isToday($date))
171  {
172  $this->tpl->setVariable('TD_CLASS','caltoday');
173  }
174  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
175  #{
176  # $this->tpl->setVariable('TD_CLASS','calnow');
177  #}
178  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
179  {
180  $this->tpl->setVariable('TD_CLASS','calstd');
181  }
182  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
183  {
184  $this->tpl->setVariable('TD_CLASS','calprev');
185  }
186  else
187  {
188  $this->tpl->setVariable('TD_CLASS','calnext');
189  }
190 
191  $day = $date->get(IL_CAL_FKT_DATE,'j');
192  $month = $date->get(IL_CAL_FKT_DATE,'n');
193 
194  if($day == 1)
195  {
196  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
197  }
198  else
199  {
200  $month_day = $day;
201  }
202 
203  $this->ctrl->clearParametersByClass('ilcalendardaygui');
204  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
205  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
206  $this->ctrl->clearParametersByClass('ilcalendardaygui');
207 
208  $this->tpl->setVariable('MONTH_DAY',$month_day);
209  #$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
210  $this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('date_add.gif'));
211  $this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
212  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
213  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
214  $this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
215 
216  $this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.gif','calendar'));
217  $this->tpl->parseCurrentBlock();
218 
219 
220  if($counter and !($counter % 7))
221  {
222  $this->tpl->setCurrentBlock('month_row');
223  $this->tpl->parseCurrentBlock();
224  }
225  }
226  }
227 
234  protected function showEvents(ilDate $date)
235  {
236  global $tree;
237 
238  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
239  {
240  $this->tpl->setCurrentBlock('panel_code');
241  $this->tpl->setVariable('NUM',$this->num_appointments);
242  $this->tpl->parseCurrentBlock();
243 
244  // milestone icon
245  if ($item['event']->isMilestone())
246  {
247  $this->tpl->setCurrentBlock('fullday_ms_icon');
248  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
249  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms_s.gif"));
250  $this->tpl->parseCurrentBlock();
251  }
252 
253  $this->tpl->setCurrentBlock('il_event');
254 
255  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
256  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance()->getHTML($item));
257  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
258 
259 
260  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
261  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
262  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
263  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
264 
265  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
266  ? " (".$item['event']->getCompletion()."%)"
267  : "";
268 
269  if($item['event']->isFullDay())
270  {
271  $title = $item['event']->getPresentationTitle().$compl;
272  }
273  else
274  {
275  switch($this->user_settings->getTimeFormat())
276  {
278  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
279  break;
280 
282  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
283  break;
284  }
285 
286 
287  $title .= (' '.$item['event']->getPresentationTitle());
288  }
289  $this->tpl->setVariable('EVENT_TITLE',$title);
290  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
291  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
292  $this->tpl->setVariable('EVENT_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
293 
294  $this->tpl->parseCurrentBlock();
295 
296  $this->num_appointments++;
297  }
298  }
299 
300 }
301 
302 
303 ?>