ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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);
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 $ilPluginAdmin;
326
327 $res = array();
328
329 foreach ($ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Calendar", $a_slot_id) as $plugin_name) {
330 $res[] = $ilPluginAdmin->getPluginObject(
332 "Calendar",
333 $a_slot_id,
334 $plugin_name
335 );
336 }
337
338 return $res;
339 }
340
341 public function getModalTitleByPlugins($a_current_title)
342 {
343 $modal_title = $a_current_title;
344 //demo of plugin execution.
345 //"capm" is the plugin slot id for Appointment presentations (modals)
346 foreach ($this->getActivePlugins("capm") as $plugin) {
347 $modal_title = ($new_title = $plugin->editModalTitle($a_current_title))? $new_title : $a_current_title;
348 }
349 return $modal_title;
350 }
351
359 public function getContentByPlugins($a_cal_entry, $a_start_date, $a_content, $a_tpl)
360 {
361 $content = $a_content;
362
363 //"capg" is the plugin slot id for AppointmentCustomGrid
364 foreach ($this->getActivePlugins("capg") as $plugin) {
365 $plugin->setAppointment($a_cal_entry, new ilDateTime($a_start_date));
366
367 if ($new_title = $plugin->editShyButtonTitle()) {
368 $a_tpl->setVariable('EVENT_CONTENT', $this->getAppointmentShyButton($a_cal_entry, $a_start_date, $new_title));
369 }
370
371 if ($glyph = $plugin->addGlyph()) {
372 $a_tpl->setVariable('EXTRA_GLYPH_BY_PLUGIN', $glyph);
373 }
374
375 if ($more_content = $plugin->addExtraContent()) {
376 $a_tpl->setVariable('EXTRA_CONTENT_BY_PLUGIN', $more_content);
377 }
378
379 $a_tpl->parseCurrentBlock();
380 $html_content = $a_tpl->get();
381
382 if ($new_content = $plugin->replaceContent($html_content)) {
383 $content = $new_content;
384 }
385 }
386 if ($content == $a_content) {
387 return false;
388 }
389
390 return $content;
391 }
392
400 public function addToolbarActions()
401 {
403
404 if ($settings->isBatchFileDownloadsEnabled()) {
405 if ($this->presentation_type == self::CAL_PRESENTATION_AGENDA_LIST) {
406 $num_events = $this->countEventsInView();
407 }
408 if ($this->view_with_appointments || $num_events) {
413
414 // file download
415 $add_button = $f->button()->standard(
416 $lng->txt("cal_download_files"),
417 $ctrl->getLinkTarget($this, "downloadFiles")
418 );
419 $toolbar->addSeparator();
420 $toolbar->addComponent($add_button);
421 }
422 }
423 }
424
428 public function downloadFiles()
429 {
430 include_once './Services/Calendar/classes/BackgroundTasks/class.ilDownloadFilesBackgroundTask.php';
431 $download_job = new ilDownloadFilesBackgroundTask($GLOBALS['DIC']->user()->getId());
432
433 $download_job->setBucketTitle($this->getBucketTitle());
434 $download_job->setEvents($this->getEvents());
435 if ($download_job->run()) {
436 ilUtil::sendSuccess($this->lng->txt('cal_download_files_started'), true);
437 }
438 $GLOBALS['DIC']->ctrl()->redirect($this);
439 }
440
445 public function getBucketTitle()
446 {
447 //definition of bucket titles here: 21365
448 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
449 $bucket_title = $this->lng->txt("cal_calendar_download");
450
451 switch ($this->presentation_type) {
453 $bucket_title .= " " . $this->seed->get(IL_CAL_DATE);
454 break;
456 $weekday_list = ilCalendarUtil::_buildWeekDayList($this->seed, $user_settings->getWeekStart())->get();
457 $start = current($weekday_list);
458 if (function_exists('mb_substr')) {
459 $char = strtolower(mb_substr($this->lng->txt("week"), 0, 1));
460 } else {
461 $char = strtolower(substr($this->lng->txt("week"), 0, 1));
462 }
463
464 $bucket_title .= " " . $start->get(IL_CAL_DATE) . " 1$char";
465 break;
467 $year_month = $this->seed->get(IL_CAL_FKT_DATE, 'Y-m', 'UTC');
468 if (function_exists('mb_substr')) {
469 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
470 } else {
471 $char = strtolower(substr($this->lng->txt("month"), 0, 1));
472 }
473
474 $bucket_title .= " " . $year_month . " 1" . $char;
475 break;
477 $bucket_title .= " " . $this->seed->get(IL_CAL_DATE);
478 $get_list_option = ilSession::get('cal_list_view');
479 switch ($get_list_option) {
481 break;
483 if (function_exists('mb_substr')) {
484 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
485 } else {
486 $char = strtolower(substr($this->lng->txt("month"), 0, 1));
487 }
488 $bucket_title .= " 1$char";
489 break;
491 if (function_exists('mb_substr')) {
492 $char = strtolower(mb_substr($this->lng->txt("month"), 0, 1));
493 } else {
494 $char = strtolower(substr($this->lng->txt("month"), 0, 1));
495 }
496 $bucket_title .= " 6$char";
497 break;
499 default:
500 if (function_exists('mb_substr')) {
501 $char = strtolower(mb_substr($this->lng->txt("week"), 0, 1));
502 } else {
503 $char = strtolower(substr($this->lng->txt("week"), 0, 1));
504 }
505 $bucket_title .= " 1$char";
506 break;
507 }
508 }
509
510 return $bucket_title;
511 }
512
517 public function countEventsInView()
518 {
519 $start = $this->seed;
520 $end = clone $start;
521 $get_list_option = ilCalendarAgendaListGUI::getPeriod();
522 switch ($get_list_option) {
524 //$end->increment(IL_CAL_DAY,1);
525 break;
527 $end->increment(IL_CAL_MONTH, 1);
528 break;
530 $end->increment(IL_CAL_MONTH, 6);
531 break;
533 default:
534 $end->increment(IL_CAL_DAY, 7);
535 break;
536 }
537 $events = $this->getEvents();
538 $num_events = 0;
539 foreach ($events as $event) {
540 $event_start = $event['event']->getStart()->get(IL_CAL_DATE);
541
542 if ($event_start >= $start->get(IL_CAL_DATE) && $event_start<= $end->get(IL_CAL_DATE)) {
543 $num_events++;
544 }
545 }
546 return $num_events;
547 }
548}
user()
Definition: user.php:4
$_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 get($a_var)
Get a value.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$r
Definition: example_031.php:79
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$end
Definition: saml1-acs.php:18
$url
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$a_content
Definition: workflow.php:93