ILIAS  Release_5_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  protected $schedule_filters = array();
45 
46  protected $seed = null;
47  protected $user_settings = null;
48 
49  protected $lng;
50  protected $ctrl;
51  protected $tabs_gui;
52  protected $tpl;
53 
54  protected $timezone = 'UTC';
55 
63  public function __construct(ilDate $seed_date)
64  {
65  global $ilCtrl, $lng, $ilUser,$ilTabs,$tpl;
66 
67  $this->seed = $seed_date;
68 
69  $this->tpl = $tpl;
70  $this->lng = $lng;
71  $this->ctrl = $ilCtrl;
72  $this->tabs_gui = $ilTabs;
73  $this->tabs_gui->setSubTabActive('app_month');
74 
75  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
76  $this->app_colors = new ilCalendarAppointmentColors($ilUser->getId());
77 
78  $this->timezone = $ilUser->getTimeZone();
79  }
80 
87  public function executeCommand()
88  {
89  global $ilCtrl,$tpl;
90 
91  $this->ctrl->saveParameter($this,'seed');
92 
93  $next_class = $ilCtrl->getNextClass();
94  switch($next_class)
95  {
96  case 'ilcalendarappointmentgui':
97  $this->ctrl->setReturn($this,'');
98  $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
99 
100  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
101 
102  // initial date for new calendar appointments
103  $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
104 
105  $app = new ilCalendarAppointmentGUI($this->seed,$idate,(int) $_GET['app_id']);
106  $this->ctrl->forwardCommand($app);
107  break;
108 
109  default:
110  $time = microtime(true);
111  $cmd = $this->ctrl->getCmd("show");
112  $this->$cmd();
113  $tpl->setContent($this->tpl->get());
114 
115  #echo "Zeit: ".(microtime(true) - $time);
116  break;
117  }
118  return true;
119  }
120 
126  public function addScheduleFilter(ilCalendarScheduleFilter $a_filter)
127  {
128  $this->schedule_filters[] = $a_filter;
129  }
130 
137  public function show()
138  {
139  global $tpl, $ilUser;
140 
141  $this->tpl = new ilTemplate('tpl.month_view.html',true,true,'Services/Calendar');
142 
143  include_once('./Services/YUI/classes/class.ilYuiUtil.php');
146 
147  $navigation = new ilCalendarHeaderNavigationGUI($this,$this->seed,ilDateTime::MONTH);
148  $this->tpl->setVariable('NAVIGATION',$navigation->getHTML());
149 
150  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
151  {
152  $this->tpl->setCurrentBlock('month_header_col');
153  $this->tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,true));
154  $this->tpl->parseCurrentBlock();
155  }
156 
157  if(isset($_GET["bkid"]))
158  {
159  $user_id = $_GET["bkid"];
160  $disable_empty = true;
161  $no_add = true;
162  }
163  else
164  {
165  if($ilUser->getId() == ANONYMOUS_USER_ID)
166  {
167  $user_id = $ilUser->getId();
168  $disable_empty = false;
169  $no_add = true;
170  }
171  else
172  {
173  $user_id = $ilUser->getId();
174  $disable_empty = false;
175  $no_add = false;
176  }
177  }
178 
179  $is_portfolio_embedded = false;
181  {
182  $no_add = true;
183  $is_portfolio_embedded = true;
184  }
185 
186  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
187  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH,$user_id);
188  $this->scheduler->addSubitemCalendars(true);
189  if(sizeof($this->schedule_filters))
190  {
191  foreach($this->schedule_filters as $filter)
192  {
193  $this->scheduler->addFilter($filter);
194  }
195  }
196  $this->scheduler->calculate();
197 
198  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
199  $settings = ilCalendarSettings::_getInstance();
200 
201  $counter = 0;
202  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
203  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
204  $this->user_settings->getWeekStart())->get() as $date)
205  {
206  $counter++;
207  $has_events = (bool)$this->showEvents($date);
208 
209  if(!$no_add)
210  {
211  include_once "Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
212 
213  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
214  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
215  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
216  $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add');
217 
218  if ($settings->getEnableGroupMilestones())
219  {
220  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
221  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->seed->get(IL_CAL_DATE));
222  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','idate',$date->get(IL_CAL_DATE));
223  $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','addMilestone');
224 
225  $this->tpl->setCurrentBlock("new_ms");
226  $this->tpl->setVariable('DD_ID', $date->get(IL_CAL_UNIX));
227  $this->tpl->setVariable('DD_TRIGGER', ilGlyphGUI::get(ilGlyphGUI::ADD));
228  $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
229  $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
230  $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
231  $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
232  $this->tpl->parseCurrentBlock();
233  }
234  else
235  {
236  $this->tpl->setCurrentBlock("new_app");
237  $this->tpl->setVariable('ADD_LINK', $new_app_url);
238  $this->tpl->setVariable('NEW_SRC', ilGlyphGUI::get(ilGlyphGUI::ADD, $this->lng->txt('cal_new_app')));
239  $this->tpl->parseCurrentBlock();
240  }
241  }
242 
243 
244  $day = $date->get(IL_CAL_FKT_DATE,'j');
245  $month = $date->get(IL_CAL_FKT_DATE,'n');
246 
247  if($day == 1)
248  {
249  $month_day = '1 '.ilCalendarUtil::_numericMonthToString($month,false);
250  }
251  else
252  {
253  $month_day = $day;
254  }
255 
256  if(!$is_portfolio_embedded &&
257  (!$disable_empty || $has_events))
258  {
259  $this->tpl->setCurrentBlock('month_day_link');
260  $this->ctrl->clearParametersByClass('ilcalendardaygui');
261  $this->ctrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
262  $this->tpl->setVariable('OPEN_DAY_VIEW',$this->ctrl->getLinkTargetByClass('ilcalendardaygui',''));
263  $this->ctrl->clearParametersByClass('ilcalendardaygui');
264  }
265  else
266  {
267  $this->tpl->setCurrentBlock('month_day_no_link');
268  }
269 
270  $this->tpl->setVariable('MONTH_DAY',$month_day);
271 
272  $this->tpl->parseCurrentBlock();
273 
274 
275  $this->tpl->setCurrentBlock('month_col');
276 
277  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
278  if(ilCalendarUtil::_isToday($date))
279  {
280  $this->tpl->setVariable('TD_CLASS','caltoday');
281  }
282  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
283  #{
284  # $this->tpl->setVariable('TD_CLASS','calnow');
285  #}
286  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
287  {
288  $this->tpl->setVariable('TD_CLASS','calstd');
289  }
290  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
291  {
292  $this->tpl->setVariable('TD_CLASS','calprev');
293  }
294  else
295  {
296  $this->tpl->setVariable('TD_CLASS','calnext');
297  }
298 
299  $this->tpl->parseCurrentBlock();
300 
301 
302  if($counter and !($counter % 7))
303  {
304  $this->tpl->setCurrentBlock('month_row');
305  $this->tpl->parseCurrentBlock();
306  }
307  }
308  }
309 
310  // used in portfolio
311  function getHTML()
312  {
313  $this->show();
314  return $this->tpl->get();
315  }
316 
323  protected function showEvents(ilDate $date)
324  {
325  global $tree, $ilUser;
326 
327  $count = 0;
328 
329 
330  foreach($this->scheduler->getByDay($date,$this->timezone) as $item)
331  {
332  $this->tpl->setCurrentBlock('panel_code');
333  $this->tpl->setVariable('NUM',$this->num_appointments);
334  $this->tpl->parseCurrentBlock();
335 
336  // milestone icon
337  if ($item['event']->isMilestone())
338  {
339  $this->tpl->setCurrentBlock('fullday_ms_icon');
340  $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
341  $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
342  $this->tpl->parseCurrentBlock();
343  }
344 
345  $this->tpl->setCurrentBlock('il_event');
346 
347  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php');
348  $this->tpl->setVariable('PANEL_DATA',ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($item));
349  $this->tpl->setVariable('PANEL_NUM',$this->num_appointments);
350 
351  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
352  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$item['event']->getEntryId());
353  $this->tpl->setVariable('EVENT_EDIT_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
354  $this->tpl->setVariable('EVENT_NUM',$item['event']->getEntryId());
355 
356  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
357  ? " (".$item['event']->getCompletion()."%)"
358  : "";
359 
360  if($item['event']->isFullDay())
361  {
362  $title = $item['event']->getPresentationTitle().$compl;
363  }
364  else
365  {
366  switch($this->user_settings->getTimeFormat())
367  {
369  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'H:i',$this->timezone);
370  break;
371 
373  $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE,'h:ia',$this->timezone);
374  break;
375  }
376 
377  $title .= (' '.$item['event']->getPresentationTitle());
378  }
379  $this->tpl->setVariable('EVENT_TITLE',$title);
380  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
381  $this->tpl->setVariable('EVENT_BGCOLOR',$color);
382  $this->tpl->setVariable('EVENT_ADD_STYLES',$item['event']->getPresentationStyle());
383  $this->tpl->setVariable('EVENT_FONTCOLOR',ilCalendarUtil::calculateFontColor($color));
384 
385  $this->tpl->parseCurrentBlock();
386 
387  $this->num_appointments++;
388  $count++;
389  }
390  return $count;
391  }
392 
393 }
394 
395 
396 ?>