ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCalendarMonthGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('Services/Calendar/classes/class.ilDate.php');
5include_once('Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php');
6include_once('Services/Calendar/classes/class.ilCalendarUserSettings.php');
7include_once('Services/Calendar/classes/class.ilCalendarAppointmentColors.php');
8include_once('Services/Calendar/classes/class.ilCalendarViewGUI.php');
9
10
21{
22 protected $num_appointments = 1;
23 protected $schedule_filters = array();
24
25 protected $user_settings = null;
26
27 protected $lng;
28 protected $ctrl;
29 protected $tabs_gui;
30 protected $tpl;
31 protected $ui_factory;
32 protected $ui_renderer;
33 protected $user;
34
35 protected $timezone = 'UTC';
36
44 public function __construct(ilDate $seed_date)
45 {
46 parent::__construct($seed_date, ilCalendarViewGUI::CAL_PRESENTATION_MONTH);
47 $this->tabs_gui->setSubTabActive('app_month');
48
49
50 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
51 $this->app_colors = new ilCalendarAppointmentColors($this->user->getId());
52
53 $this->timezone = $this->user->getTimeZone();
54 }
55
62 public function executeCommand()
63 {
64 global $DIC;
65
66 $ilCtrl = $DIC['ilCtrl'];
67 $tpl = $DIC['tpl'];
68
69 $this->ctrl->saveParameter($this, 'seed');
70
71 $next_class = $ilCtrl->getNextClass();
72 switch ($next_class) {
73 case "ilcalendarappointmentpresentationgui":
74 $this->ctrl->setReturn($this, "");
75 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
77 $this->ctrl->forwardCommand($gui);
78 break;
79 case 'ilcalendarappointmentgui':
80 $this->ctrl->setReturn($this, '');
81 $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
82
83 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
84
85 // initial date for new calendar appointments
86 $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
87
88 $app = new ilCalendarAppointmentGUI($this->seed, $idate, (int) $_GET['app_id']);
89 $this->ctrl->forwardCommand($app);
90 break;
91
92 default:
93 $time = microtime(true);
94 $cmd = $this->ctrl->getCmd("show");
95 $this->$cmd();
96 $tpl->setContent($this->tpl->get());
97
98 #echo "Zeit: ".(microtime(true) - $time);
99 break;
100 }
101 return true;
102 }
103
110 {
111 $this->schedule_filters[] = $a_filter;
112 }
113
120 public function show()
121 {
125 global $DIC;
126
127 $ui_factory = $DIC->ui()->factory();
128 $renderer = $DIC->ui()->renderer();
129
130 $this->tpl = new ilTemplate('tpl.month_view.html', true, true, 'Services/Calendar');
131
132 include_once('./Services/YUI/classes/class.ilYuiUtil.php');
134
135 $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::MONTH);
136 $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
137
138 for ($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++) {
139 $this->tpl->setCurrentBlock('month_header_col');
140 $this->tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, true));
141 $this->tpl->parseCurrentBlock();
142 }
143
144 if (isset($_GET["bkid"])) {
145 $user_id = $_GET["bkid"];
146 $disable_empty = true;
147 $no_add = true;
148 } else {
149 if ($this->user->getId() == ANONYMOUS_USER_ID) {
150 $user_id = $this->user->getId();
151 $disable_empty = false;
152 $no_add = true;
153 } else {
154 $user_id = $this->user->getId();
155 $disable_empty = false;
156 $no_add = false;
157 }
158 }
159
160 $is_portfolio_embedded = false;
162 $no_add = true;
163 $is_portfolio_embedded = true;
164 }
165
166 include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
167 $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
168 $this->scheduler->addSubitemCalendars(true);
169 if (sizeof($this->schedule_filters)) {
170 foreach ($this->schedule_filters as $filter) {
171 $this->scheduler->addFilter($filter);
172 }
173 }
174 $this->scheduler->calculate();
175
176 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
178
179 $counter = 0;
181 $this->seed->get(IL_CAL_FKT_DATE, 'm'),
182 $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
183 $this->user_settings->getWeekStart()
184 )->get() as $date) {
185 $counter++;
186 $has_events = (bool) $this->showEvents($date);
187
188 if (!$this->view_with_appointments && $has_events) {
189 $this->view_with_appointments = true;
190 }
191
192 if (!$no_add) {
193 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
194 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
195 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
196 $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
197
198 if ($settings->getEnableGroupMilestones()) {
199 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
200 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
201 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
202 $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'addMilestone');
203
204 $this->tpl->setCurrentBlock("new_ms");
205 $this->tpl->setVariable('DD_ID', $date->get(IL_CAL_UNIX));
206 $this->tpl->setVariable('DD_TRIGGER', $renderer->render($ui_factory->glyph()->add()));
207 $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
208 $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
209 $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
210 $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
211 $this->tpl->parseCurrentBlock();
212 } else {
213 $this->tpl->setCurrentBlock("new_app");
214 $this->tpl->setVariable('NEW_GLYPH', $renderer->render($ui_factory->glyph()->add($new_app_url)));
215 $this->tpl->parseCurrentBlock();
216 }
217 }
218
219
220 $day = $date->get(IL_CAL_FKT_DATE, 'j');
221 $month = $date->get(IL_CAL_FKT_DATE, 'n');
222
223 if ($day == 1) {
224 $month_day = '1 ' . ilCalendarUtil::_numericMonthToString($month, false);
225 } else {
226 $month_day = $day;
227 }
228
229 if (!$is_portfolio_embedded &&
230 (!$disable_empty || $has_events)) {
231 $this->tpl->setCurrentBlock('month_day_link');
232 $this->ctrl->clearParametersByClass('ilcalendardaygui');
233 $this->ctrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
234 $this->tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass('ilcalendardaygui', ''));
235 $this->ctrl->clearParametersByClass('ilcalendardaygui');
236 } else {
237 $this->tpl->setCurrentBlock('month_day_no_link');
238 }
239
240 $this->tpl->setVariable('MONTH_DAY', $month_day);
241
242 $this->tpl->parseCurrentBlock();
243
244
245 $this->tpl->setCurrentBlock('month_col');
246
247 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
248 if (ilCalendarUtil::_isToday($date)) {
249 $this->tpl->setVariable('TD_CLASS', 'caltoday');
250 }
251 #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
252 #{
253 # $this->tpl->setVariable('TD_CLASS','calnow');
254 #}
255 elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
256 $this->tpl->setVariable('TD_CLASS', 'calstd');
257 } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
258 $this->tpl->setVariable('TD_CLASS', 'calprev');
259 } else {
260 $this->tpl->setVariable('TD_CLASS', 'calnext');
261 }
262
263 $this->tpl->parseCurrentBlock();
264
265
266 if ($counter and !($counter % 7)) {
267 $this->tpl->setCurrentBlock('month_row');
268 $this->tpl->parseCurrentBlock();
269 }
270 }
271 }
272
273 // used in portfolio
274 public function getHTML()
275 {
276 $this->show();
277 return $this->tpl->get();
278 }
279
286 protected function showEvents(ilDate $date)
287 {
288 global $DIC;
289
290 $tree = $DIC['tree'];
291
294
295 $count = 0;
296
297
298 foreach ($this->scheduler->getByDay($date, $this->timezone) as $item) {
299 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
300 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $item['event']->getEntryId());
301
302 $event_tpl = new ilTemplate('tpl.month_event_view.html', true, true, 'Services/Calendar');
303 // milestone icon
304 if ($item['event']->isMilestone()) {
305 $event_tpl->setCurrentBlock('fullday_ms_icon');
306 $event_tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
307 $event_tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
308 $event_tpl->parseCurrentBlock();
309 }
310
311
312
313 $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
314 ? " (" . $item['event']->getCompletion() . "%)"
315 : "";
316
317 if (!$item['event']->isFullDay()) {
318 switch ($this->user_settings->getTimeFormat()) {
320 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
321 break;
322
324 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
325 break;
326 }
327 }
328
329 //plugins can change the modal title.
330 $shy = $this->getAppointmentShyButton($item['event'], $item['dstart'], "");
331
332 $title = ($time != "")? $time . " " . $shy : $shy;
333
334 $event_html = $title . $compl;
335
336 $event_tpl->setCurrentBlock('il_event');
337
338 //Start configuring the default template
339 $event_tpl->setVariable('EVENT_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
340 $event_tpl->setVariable('EVENT_NUM', $item['event']->getEntryId());
341 $event_tpl->setVariable('EVENT_CONTENT', $event_html);
342 $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
343 $event_tpl->setVariable('EVENT_BGCOLOR', $color);
344 $event_tpl->setVariable('EVENT_ADD_STYLES', $item['event']->getPresentationStyle());
345 $event_tpl->setVariable('EVENT_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
346
347 //plugins can override the previous template variables. The plugin slot parses the current block because
348 //it needs to call the template get method to use the resulting HTML in the replaceContent method.
349 if ($event_html_by_plugin = $this->getContentByPlugins($item['event'], $item['dstart'], $event_html, $event_tpl)) {
350 $event_body_html = $event_html_by_plugin;
351 } else {
352 $event_tpl->parseCurrentBlock();
353 $event_body_html = $event_tpl->get();
354 }
355
356 $this->tpl->setCurrentBlock("event_nfd");
357 $this->tpl->setVariable("EVENT_CONTENT", $event_body_html);
358 $this->tpl->parseCurrentBlock();
359
360 $this->num_appointments++;
361 $count++;
362 }
363 return $count;
364 }
365}
user()
Definition: user.php:4
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_FKT_DATE
show()
returns the content of IniFile @access public
Administrate calendar appointments.
static _getInstance(ilDate $seed, $a_app)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
__construct(ilDate $seed_date)
Constructor.
executeCommand()
Execute command.
addScheduleFilter(ilCalendarScheduleFilter $a_filter)
Add schedule filter.
showEvents(ilDate $date)
Show events.
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
static _getInstance()
get singleton instance
static _getInstanceByUserId($a_user_id)
get singleton instance
static _isToday($date)
check if a date is today
static _numericDayToString($a_day, $a_long=true)
get
static _buildMonthDayList($a_month, $a_year, $weekstart)
Build a month day list.
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
getAppointmentShyButton($a_calendar_entry, $a_dstart, $a_title_forced="")
getCurrentApp()
Get app for id.
getContentByPlugins($a_cal_entry, $a_start_date, $a_content, $a_tpl)
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initDragDrop()
Init YUI Drag and Drop.
$i
Definition: disco.tpl.php:19
$r
Definition: example_031.php:79
global $ilCtrl
Definition: ilias.php:18
Calendar schedule filter interface.
$time
Definition: cron.php:21
global $DIC
Definition: saml.php:7