ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCalendarViewGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
16
20 protected $ui_factory;
21
25 protected $ui_renderer;
26
30 protected $ctrl;
31
36
40 protected $toolbar;
41
45 protected $logger;
46
50 protected $ui;
51
56
60 protected $lng;
61
65 protected $user;
66
70 protected $seed;
71
75 protected $ch_user_id = 0;
76
77
78
85 {
86 $this->seed = $seed;
88 }
89
90
91 public function setConsulationHoursUserId($a_user_id)
92 {
93 $this->ch_user_id = $a_user_id;
94 }
95
100 {
101 return $this->ch_user_id;
102 }
103
104
105
106
107
112 public function initialize($a_calendar_presentation_type)
113 {
114 global $DIC;
115 $this->ui_factory = $DIC->ui()->factory();
116 $this->ui_renderer = $DIC->ui()->renderer();
117 $this->ui = $DIC->ui();
118 $this->ctrl = $DIC->ctrl();
119 $this->lng = $DIC->language();
120 $this->user = $DIC->user();
121 $this->tabs_gui = $DIC->tabs();
122 $this->tpl = $DIC["tpl"];
123 $this->toolbar = $DIC->toolbar();
124 $this->presentation_type = $a_calendar_presentation_type;
125 $this->logger = $GLOBALS['DIC']->logger()->cal();
126 //by default "download files" button is not displayed.
127 $this->view_with_appointments = false;
128
129 if ($this->presentation_type == self::CAL_PRESENTATION_DAY ||
130 $this->presentation_type == self::CAL_PRESENTATION_WEEK) {
131 iljQueryUtil::initjQuery($this->tpl);
132 $this->tpl->addJavaScript('./Services/Calendar/js/calendar_appointment.js');
133 }
134 }
135
142 public function getCurrentApp()
143 {
144 // @todo: this needs optimization
145 $events = $this->getEvents();
146 foreach ($events as $item) {
147 if ($item["event"]->getEntryId() == (int) $_GET["app_id"]) {
148 return $item;
149 }
150 }
151 return null;
152 }
153
160 public function getEvents()
161 {
162 $user = $this->user->getId();
163
164 switch ($this->presentation_type) {
166
167 //if($this->period_end_day == "")
168 //{
169 $this->period = ilCalendarAgendaListGUI::getPeriod();
170
171 $end_date = clone $this->seed;
172 switch ($this->period) {
174 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_DAY, $user, true);
175 $end_date->increment(IL_CAL_DAY, 1);
176 break;
177
179 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_WEEK, $user, true);
180 $end_date->increment(IL_CAL_WEEK, 1);
181 break;
182
184 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user, true);
185 $end_date->increment(IL_CAL_MONTH, 1);
186 break;
187
189 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_HALF_YEAR, $user, true);
190 $end_date->increment(IL_CAL_MONTH, 6);
191 break;
192 default:
193 // default is week ?!
194 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_WEEK, $user, true);
195 $end_date->increment(IL_CAL_WEEK, 1);
196 break;
197 }
198 $this->period_end_day = $end_date->get(IL_CAL_DATE);
199 $schedule->setPeriod($this->seed, $end_date);
200
201 //}
202 /*else
203 {
204 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_PD_UPCOMING);
205 }*/
206
207 break;
209 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_DAY, $user, true);
210 break;
212 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_WEEK, $user, true);
213 break;
215 // if we put the user and true in the call method we will get only events and
216 // files from the current month. Not from 6 days before and after.
217 $schedule = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH);
218 break;
219 }
220
221 $schedule->addSubitemCalendars(true);
222 $schedule->calculate();
223 $ev = $schedule->getScheduledEvents();
224 return $ev;
225 }
226
227
234 public function getDatesForItem($item)
235 {
236 $start = $item["dstart"];
237 $end = $item["dend"];
238 if ($item["fullday"]) {
239 $start = new ilDate($start, IL_CAL_UNIX);
240 $end = new ilDate($end, IL_CAL_UNIX);
241 } else {
242 $start = new ilDateTime($start, IL_CAL_UNIX);
243 $end = new ilDateTime($end, IL_CAL_UNIX);
244 }
245 return array("start" => $start, "end" => $end);
246 }
247
251 public function getModalForApp()
252 {
256
257 // set return class
258 $this->ctrl->setReturn($this, '');
259
260 // @todo: this needs optimization
261 $events = $this->getEvents();
262
263 //item => array containing ilcalendary object, dstart of the event , dend etc.
264 foreach ($events as $item) {
265 if ($item["event"]->getEntryId() == (int) $_GET["app_id"] && $item['dstart'] == (int) $_GET['dt']) {
266 $dates = $this->getDatesForItem($item);
267 // content of modal
268 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
269 $next_gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, $item);
270 $content = $ctrl->getHTML($next_gui);
271
272 //plugins can change the modal title.
273
274 $modal_title = ilDatePresentation::formatPeriod($dates["start"], $dates["end"]);
275 $modal_title = $this->getModalTitleByPlugins($modal_title);
276 $modal = $f->modal()->roundtrip($modal_title, $f->legacy($content))->withCancelButtonLabel("close");
277
278 echo $r->renderAsync($modal);
279 }
280 }
281 exit();
282 }
283
290 public function getAppointmentShyButton($a_calendar_entry, $a_dstart, $a_title_forced = "")
291 {
294
295 $this->ctrl->setParameter($this, "app_id", $a_calendar_entry->getEntryId());
296
297 if ($this->getConsultationHoursUserId()) {
298 $this->ctrl->setParameter($this, 'chuid', $this->getConsultationHoursUserId());
299 }
300 $this->ctrl->setParameter($this, 'dt', $a_dstart);
301 $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
302 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
303 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
304 $this->ctrl->setParameter($this, "dt", $_GET["dt"]);
305 $this->ctrl->setParameter($this, 'seed', $_GET["seed"]);
306
307 $modal = $f->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
308
309 //Day view presents the titles with the full length.(agenda:class.ilCalendarAgendaListGUI.php)
310 if ($this->presentation_type == self::CAL_PRESENTATION_DAY) {
311 $title = ($a_title_forced == "")? $a_calendar_entry->getPresentationTitle(false) : $a_title_forced;
312 } else {
313 $title = ($a_title_forced == "")? $a_calendar_entry->getPresentationTitle() : $a_title_forced;
314 }
315
316
317 $comps = [$f->button()->shy($title, "#")->withOnClick($modal->getShowSignal()), $modal];
318
319 return $r->render($comps);
320 }
321
322 //get active plugins.
323 public function getActivePlugins($a_slot_id)
324 {
325 global $DIC;
326
327 $ilPluginAdmin = $DIC['ilPluginAdmin'];
328
329 $res = array();
330
331 foreach ($ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Calendar", $a_slot_id) as $plugin_name) {
332 $res[] = $ilPluginAdmin->getPluginObject(
334 "Calendar",
335 $a_slot_id,
336 $plugin_name
337 );
338 }
339
340 return $res;
341 }
342
343 public function getModalTitleByPlugins($a_current_title)
344 {
345 $modal_title = $a_current_title;
346 //demo of plugin execution.
347 //"capm" is the plugin slot id for Appointment presentations (modals)
348 foreach ($this->getActivePlugins("capm") as $plugin) {
349 $modal_title = ($new_title = $plugin->editModalTitle($a_current_title))? $new_title : $a_current_title;
350 }
351 return $modal_title;
352 }
353
361 public function getContentByPlugins($a_cal_entry, $a_start_date, $a_content, $a_tpl)
362 {
363 $content = $a_content;
364
365 //"capg" is the plugin slot id for AppointmentCustomGrid
366 foreach ($this->getActivePlugins("capg") as $plugin) {
367 $plugin->setAppointment($a_cal_entry, new ilDateTime($a_start_date));
368
369 if ($new_title = $plugin->editShyButtonTitle()) {
370 $a_tpl->setVariable('EVENT_CONTENT', $this->getAppointmentShyButton($a_cal_entry, $a_start_date, $new_title));
371 }
372
373 if ($glyph = $plugin->addGlyph()) {
374 $a_tpl->setVariable('EXTRA_GLYPH_BY_PLUGIN', $glyph);
375 }
376
377 if ($more_content = $plugin->addExtraContent()) {
378 $a_tpl->setVariable('EXTRA_CONTENT_BY_PLUGIN', $more_content);
379 }
380
381 $a_tpl->parseCurrentBlock();
382 $html_content = $a_tpl->get();
383
384 if ($new_content = $plugin->replaceContent($html_content)) {
385 $content = $new_content;
386 }
387 }
388 if ($content == $a_content) {
389 return false;
390 }
391
392 return $content;
393 }
394
402 public function addToolbarActions()
403 {
405
406 if ($settings->isBatchFileDownloadsEnabled()) {
407 if ($this->presentation_type == self::CAL_PRESENTATION_AGENDA_LIST) {
408 $num_events = $this->countEventsInView();
409 }
410 if ($this->view_with_appointments || $num_events) {
415
416 // file download
417 $add_button = $f->button()->standard(
418 $lng->txt("cal_download_files"),
419 $ctrl->getLinkTarget($this, "downloadFiles")
420 );
421 $toolbar->addSeparator();
422 $toolbar->addComponent($add_button);
423 }
424 }
425 }
426
430 public function downloadFiles()
431 {
432 include_once './Services/Calendar/classes/BackgroundTasks/class.ilDownloadFilesBackgroundTask.php';
433 $download_job = new ilDownloadFilesBackgroundTask($GLOBALS['DIC']->user()->getId());
434
435 $download_job->setBucketTitle($this->getBucketTitle());
436 $download_job->setEvents($this->getEvents());
437 if ($download_job->run()) {
438 ilUtil::sendSuccess($this->lng->txt('cal_download_files_started'), true);
439 }
440 $GLOBALS['DIC']->ctrl()->redirect($this);
441 }
442
447 public function getBucketTitle()
448 {
449 //definition of bucket titles here: 21365
450 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
451 $bucket_title = $this->lng->txt("cal_calendar_download");
452
453 switch ($this->presentation_type) {
455 $bucket_title .= " " . $this->seed->get(IL_CAL_DATE);
456 break;
458 $weekday_list = ilCalendarUtil::_buildWeekDayList($this->seed, $user_settings->getWeekStart())->get();
459 $start = current($weekday_list);
460 $char = strtolower(mb_substr($this->lng->txt("week"), 0, 1));
461 $bucket_title .= " " . $start->get(IL_CAL_DATE) . " 1$char";
462 break;
464 $year_month = $this->seed->get(IL_CAL_FKT_DATE, 'Y-m', 'UTC');
465 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
466 $bucket_title .= " " . $year_month . " 1" . $char;
467 break;
469 $bucket_title .= " " . $this->seed->get(IL_CAL_DATE);
470 $get_list_option = intval($this->user->getPref('cal_list_view'));
471 switch ($get_list_option) {
473 break;
475 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
476 $bucket_title .= " 1$char";
477 break;
479 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
480 $bucket_title .= " 6$char";
481 break;
483 default:
484 $char = strtolower(mb_substr($this->lng->txt("week"), 0, 1));
485 $bucket_title .= " 1$char";
486 break;
487 }
488 }
489
490 return $bucket_title;
491 }
492
497 public function countEventsInView()
498 {
499 $start = $this->seed;
500 $end = clone $start;
501 $get_list_option = ilCalendarAgendaListGUI::getPeriod();
502 switch ($get_list_option) {
504 //$end->increment(IL_CAL_DAY,1);
505 break;
507 $end->increment(IL_CAL_MONTH, 1);
508 break;
510 $end->increment(IL_CAL_MONTH, 6);
511 break;
513 default:
514 $end->increment(IL_CAL_DAY, 7);
515 break;
516 }
517 $events = $this->getEvents();
518 $num_events = 0;
519 foreach ($events as $event) {
520 $event_start = $event['event']->getStart()->get(IL_CAL_DATE);
521
522 if ($event_start >= $start->get(IL_CAL_DATE) && $event_start <= $end->get(IL_CAL_DATE)) {
523 $num_events++;
524 }
525 }
526 return $num_events;
527 }
528}
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const IL_CAL_DATE
const IL_CAL_WEEK
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_FKT_DATE
const IL_CAL_DAY
static getPeriod()
needed in CalendarInboxGUI to get events using a proper period.
static _getInstance(ilDate $seed, $a_app)
get singleton instance
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 _buildWeekDayList($a_day, $a_weekstart)
build week day list
setConsulationHoursUserId($a_user_id)
__construct(ilDate $seed, $presentation_type)
getBucketTitle()
get proper label to add in the background task popover
countEventsInView()
get the events starting between 2 dates based in seed + view options.
initialize($a_calendar_presentation_type)
View initialization.
getAppointmentShyButton($a_calendar_entry, $a_dstart, $a_title_forced="")
addToolbarActions()
Add download link to toolbar.
getModalForApp()
Get modal for appointment (see similar code in ilCalendarBlockGUI)
getCurrentApp()
Get app for id.
downloadFiles()
Download files related to the appointments showed in the current calendar view (day,...
getModalTitleByPlugins($a_current_title)
getContentByPlugins($a_cal_entry, $a_start_date, $a_content, $a_tpl)
getDatesForItem($item)
Get start/end date for item.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Class for single dates.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
global $DIC
Definition: goto.php:24
exit
Definition: login.php:29
$url
foreach($_POST as $key=> $value) $res
ui()
Definition: ui.php:5