ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilCtrl,$tpl;
65
66 $this->ctrl->saveParameter($this, 'seed');
67
68 $next_class = $ilCtrl->getNextClass();
69 switch ($next_class) {
70 case "ilcalendarappointmentpresentationgui":
71 $this->ctrl->setReturn($this, "");
72 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
74 $this->ctrl->forwardCommand($gui);
75 break;
76 case 'ilcalendarappointmentgui':
77 $this->ctrl->setReturn($this, '');
78 $this->tabs_gui->setSubTabActive($_SESSION['cal_last_tab']);
79
80 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentGUI.php');
81
82 // initial date for new calendar appointments
83 $idate = new ilDate($_REQUEST['idate'], IL_CAL_DATE);
84
85 $app = new ilCalendarAppointmentGUI($this->seed, $idate, (int) $_GET['app_id']);
86 $this->ctrl->forwardCommand($app);
87 break;
88
89 default:
90 $time = microtime(true);
91 $cmd = $this->ctrl->getCmd("show");
92 $this->$cmd();
93 $tpl->setContent($this->tpl->get());
94
95 #echo "Zeit: ".(microtime(true) - $time);
96 break;
97 }
98 return true;
99 }
100
107 {
108 $this->schedule_filters[] = $a_filter;
109 }
110
117 public function show()
118 {
122 global $DIC;
123
124 $ui_factory = $DIC->ui()->factory();
125 $renderer = $DIC->ui()->renderer();
126
127 $this->tpl = new ilTemplate('tpl.month_view.html', true, true, 'Services/Calendar');
128
129 include_once('./Services/YUI/classes/class.ilYuiUtil.php');
131
132 $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::MONTH);
133 $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
134
135 for ($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++) {
136 $this->tpl->setCurrentBlock('month_header_col');
137 $this->tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, true));
138 $this->tpl->parseCurrentBlock();
139 }
140
141 if (isset($_GET["bkid"])) {
142 $user_id = $_GET["bkid"];
143 $disable_empty = true;
144 $no_add = true;
145 } else {
146 if ($this->user->getId() == ANONYMOUS_USER_ID) {
147 $user_id = $this->user->getId();
148 $disable_empty = false;
149 $no_add = true;
150 } else {
151 $user_id = $this->user->getId();
152 $disable_empty = false;
153 $no_add = false;
154 }
155 }
156
157 $is_portfolio_embedded = false;
159 $no_add = true;
160 $is_portfolio_embedded = true;
161 }
162
163 include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
164 $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
165 $this->scheduler->addSubitemCalendars(true);
166 if (sizeof($this->schedule_filters)) {
167 foreach ($this->schedule_filters as $filter) {
168 $this->scheduler->addFilter($filter);
169 }
170 }
171 $this->scheduler->calculate();
172
173 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
175
176 $counter = 0;
178 $this->seed->get(IL_CAL_FKT_DATE, 'm'),
179 $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
180 $this->user_settings->getWeekStart()
181 )->get() as $date) {
182 $counter++;
183 $has_events = (bool) $this->showEvents($date);
184
185 if (!$this->view_with_appointments && $has_events) {
186 $this->view_with_appointments = true;
187 }
188
189 if (!$no_add) {
190 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
191 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
192 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
193 $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
194
195 if ($settings->getEnableGroupMilestones()) {
196 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
197 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
198 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
199 $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'addMilestone');
200
201 $this->tpl->setCurrentBlock("new_ms");
202 $this->tpl->setVariable('DD_ID', $date->get(IL_CAL_UNIX));
203 $this->tpl->setVariable('DD_TRIGGER', $renderer->render($ui_factory->glyph()->add()));
204 $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
205 $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
206 $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
207 $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
208 $this->tpl->parseCurrentBlock();
209 } else {
210 $this->tpl->setCurrentBlock("new_app");
211 $this->tpl->setVariable('NEW_GLYPH', $renderer->render($ui_factory->glyph()->add($new_app_url)));
212 $this->tpl->parseCurrentBlock();
213 }
214 }
215
216
217 $day = $date->get(IL_CAL_FKT_DATE, 'j');
218 $month = $date->get(IL_CAL_FKT_DATE, 'n');
219
220 if ($day == 1) {
221 $month_day = '1 ' . ilCalendarUtil::_numericMonthToString($month, false);
222 } else {
223 $month_day = $day;
224 }
225
226 if (!$is_portfolio_embedded &&
227 (!$disable_empty || $has_events)) {
228 $this->tpl->setCurrentBlock('month_day_link');
229 $this->ctrl->clearParametersByClass('ilcalendardaygui');
230 $this->ctrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
231 $this->tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass('ilcalendardaygui', ''));
232 $this->ctrl->clearParametersByClass('ilcalendardaygui');
233 } else {
234 $this->tpl->setCurrentBlock('month_day_no_link');
235 }
236
237 $this->tpl->setVariable('MONTH_DAY', $month_day);
238
239 $this->tpl->parseCurrentBlock();
240
241
242 $this->tpl->setCurrentBlock('month_col');
243
244 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
245 if (ilCalendarUtil::_isToday($date)) {
246 $this->tpl->setVariable('TD_CLASS', 'caltoday');
247 }
248 #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
249 #{
250 # $this->tpl->setVariable('TD_CLASS','calnow');
251 #}
252 elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
253 $this->tpl->setVariable('TD_CLASS', 'calstd');
254 } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
255 $this->tpl->setVariable('TD_CLASS', 'calprev');
256 } else {
257 $this->tpl->setVariable('TD_CLASS', 'calnext');
258 }
259
260 $this->tpl->parseCurrentBlock();
261
262
263 if ($counter and !($counter % 7)) {
264 $this->tpl->setCurrentBlock('month_row');
265 $this->tpl->parseCurrentBlock();
266 }
267 }
268 }
269
270 // used in portfolio
271 public function getHTML()
272 {
273 $this->show();
274 return $this->tpl->get();
275 }
276
283 protected function showEvents(ilDate $date)
284 {
285 global $tree;
286
289
290 $count = 0;
291
292
293 foreach ($this->scheduler->getByDay($date, $this->timezone) as $item) {
294 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
295 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $item['event']->getEntryId());
296
297 $event_tpl = new ilTemplate('tpl.month_event_view.html', true, true, 'Services/Calendar');
298 // milestone icon
299 if ($item['event']->isMilestone()) {
300 $event_tpl->setCurrentBlock('fullday_ms_icon');
301 $event_tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
302 $event_tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
303 $event_tpl->parseCurrentBlock();
304 }
305
306
307
308 $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
309 ? " (" . $item['event']->getCompletion() . "%)"
310 : "";
311
312 if (!$item['event']->isFullDay()) {
313 switch ($this->user_settings->getTimeFormat()) {
315 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
316 break;
317
319 $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
320 break;
321 }
322 }
323
324 //plugins can change the modal title.
325 $shy = $this->getAppointmentShyButton($item['event'], $item['dstart'], "");
326
327 $title = ($time != "")? $time . " " . $shy : $shy;
328
329 $event_html = $title . $compl;
330
331 $event_tpl->setCurrentBlock('il_event');
332
333 //Start configuring the default template
334 $event_tpl->setVariable('EVENT_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
335 $event_tpl->setVariable('EVENT_NUM', $item['event']->getEntryId());
336 $event_tpl->setVariable('EVENT_CONTENT', $event_html);
337 $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
338 $event_tpl->setVariable('EVENT_BGCOLOR', $color);
339 $event_tpl->setVariable('EVENT_ADD_STYLES', $item['event']->getPresentationStyle());
340 $event_tpl->setVariable('EVENT_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
341
342 //plugins can override the previous template variables. The plugin slot parses the current block because
343 //it needs to call the template get method to use the resulting HTML in the replaceContent method.
344 if ($event_html_by_plugin = $this->getContentByPlugins($item['event'], $item['dstart'], $event_html, $event_tpl)) {
345 $event_body_html = $event_html_by_plugin;
346 } else {
347 $event_tpl->parseCurrentBlock();
348 $event_body_html = $event_tpl->get();
349 }
350
351 $this->tpl->setCurrentBlock("event_nfd");
352 $this->tpl->setVariable("EVENT_CONTENT", $event_body_html);
353 $this->tpl->parseCurrentBlock();
354
355 $this->num_appointments++;
356 $count++;
357 }
358 return $count;
359 }
360}
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.
$counter
$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