ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAppointmentPresentationGUI.php
Go to the documentation of this file.
1<?php
2include_once './Services/Calendar/interfaces/interface.ilCalendarAppointmentPresentation.php';
3include_once './Services/Calendar/classes/class.ilCalendarViewGUI.php';
4
14{
15 protected static $instance; // [ilCalendarAppointmentPresentationFactory]
16
20 protected $toolbar;
21
26 protected $appointment;
27
31 protected $infoscreen;
32
36 protected $lng;
37
41 protected $tree;
42
46 protected $ui;
47
51 protected $list_item = null;
52
56 protected $info_items = array();
57
61 protected $list_properties = array();
62
66 protected $actions = array();
67
71 protected $ctrl;
72
76 protected $access;
77
82
86 protected $has_files = false;
87
91 protected $obj_id = 0;
92
98 public function __construct($a_appointment, $a_info_screen, $a_toolbar, $a_list_item)
99 {
100 global $DIC;
101 $this->appointment = $a_appointment;
102 $this->infoscreen = $a_info_screen;
103 $this->toolbar = $a_toolbar;
104 $this->lng = $DIC->language();
105 $this->lng->loadLanguageModule("dateplaner");
106 $this->tree = $DIC->repositoryTree();
107 $this->ui = $DIC->ui();
108 $this->list_item = $a_list_item;
109 $this->ctrl = $DIC->ctrl();
110 $this->access = $DIC->access();
111 $this->rbacsystem = $DIC->rbac()->system();
112 $this->user = $DIC->user();
113
115 }
116
120 public function getObjIdForAppointment()
121 {
122 return $this->obj_id;
123 }
124
128 protected function readObjIdForAppointment()
129 {
130 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
132 $this->obj_id = $category->getObjId();
133 }
134
135
140 public static function getInstance($a_appointment, $a_info_screen, $a_toolbar, $a_list_item)
141 {
142 return new static($a_appointment, $a_info_screen, $a_toolbar, $a_list_item);
143 }
144
148 public function getToolbar()
149 {
150 return $this->toolbar;
151 }
152
158 public function getListItem()
159 {
160 return $this->list_item;
161 }
162
163
167 public function getInfoScreen()
168 {
169 return $this->infoscreen;
170 }
171
172 public function getCatId($a_entry_id)
173 {
175 }
176
180 public function getCatInfo()
181 {
182 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
183 return ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
184 }
185
186 public function executeCommand()
187 {
188 global $DIC;
189
190 $ilCtrl = $DIC['ilCtrl'];
191
192 $next_class = $ilCtrl->getNextClass();
193 $cmd = $ilCtrl->getCmd("getHTML");
194
195 switch ($next_class) {
196 default:
197 return $this->$cmd();
198 }
199 }
200
204 public function getHTML()
205 {
208 $ui = $this->ui;
209
210 $infoscreen = $this->getInfoScreen();
211 if ($infoscreen instanceof ilInfoScreenGUI) {
212 foreach ($this->info_items as $i) {
213 switch ($i["type"]) {
214 case "section":
215 $infoscreen->addSection($i["txt"]);
216 break;
217 case "property":
218 $infoscreen->addProperty($i["txt"], $i["val"]);
219 break;
220 }
221 }
222 }
223
224 $toolbar = $this->getToolbar();
225 if ($toolbar instanceof ilToolbarGUI) {
226 //todo: duplicated from ilcalendarviewgui.
228 if ($settings->isBatchFileDownloadsEnabled() && $this->has_files) {
229 // file download
230 $this->ctrl->setParameter($this, "app_id", $this->appointment['event']->getEntryId());
231
232 $download_btn = ilLinkButton::getInstance();
233 $download_btn->setCaption($this->lng->txt("cal_download_files"), false);
234 $download_btn->setUrl(
235 $this->ctrl->getLinkTarget($this, 'downloadFiles')
236 );
237 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
238
239 $toolbar->addButtonInstance($download_btn);
240 $toolbar->addSeparator();
241 }
242
243 foreach ($this->actions as $a) {
245 $btn->setCaption($a["txt"], false);
246 $btn->setUrl($a["link"]);
247 // all buttons are sticky
248 $toolbar->addStickyItem($btn);
249 }
250 }
251
252 $list_item = $this->getListItem();
253 if ($list_item instanceof \ILIAS\UI\Component\Item\Standard) {
254 $dd = $list_item->getActions();
255 if ($dd === null) {
256 $actions = array();
257 $label = "";
258 } else {
259 $actions = $dd->getItems();
260 $label = $dd->getLabel();
261 }
262 $properties = $list_item->getProperties();
263
264 foreach ($this->actions as $a) {
265 $actions[] = $ui->factory()->button()->shy($a["txt"], $a["link"]);
266 }
267 foreach ($this->list_properties as $lp) {
268 $properties[$lp["txt"]] = $lp["val"];
269 }
270
271 $new_dd = $ui->factory()->dropdown()->standard($actions)
272 ->withLabel($label);
273 $this->list_item = $list_item->withActions($new_dd)->withProperties($properties);
274 }
275 }
276
282 public function addContainerInfo($a_obj_id)
283 {
284 $refs = $this->getReadableRefIds($a_obj_id);
285 $ref_id = current($refs);
286 if (count($refs) == 1 && $ref_id > 0) {
288 $f = $this->ui->factory();
289 $r = $this->ui->renderer();
290
291 //parent course or group title
292 $cont_ref_id = $tree->checkForParentType($ref_id, 'grp');
293 if ($cont_ref_id == 0) {
294 $cont_ref_id = $tree->checkForParentType($ref_id, 'crs');
295 }
296
297 if ($cont_ref_id > 0) {
298 $type = ilObject::_lookupType($cont_ref_id, true);
299 $href = ilLink::_getStaticLink($cont_ref_id);
300 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjectId($cont_ref_id));
301 $this->addInfoProperty($this->lng->txt("obj_" . $type), $r->render($f->button()->shy($parent_title, $href)));
302 $this->addListItemProperty($this->lng->txt("obj_" . $type), $r->render($f->button()->shy($parent_title, $href)));
303 }
304 }
305 }
306
312 public function addInfoSection($a_txt)
313 {
314 $this->info_items[] = array("type" => "section", "txt" => $a_txt);
315 }
316
323 public function addInfoProperty($a_txt, $a_val)
324 {
325 $this->info_items[] = array("type" => "property", "txt" => $a_txt, "val" => $a_val);
326 }
327
334 public function addListItemProperty($a_txt, $a_val)
335 {
336 #22638
337 $this->list_properties[] = array("txt" => $a_txt, "val" => $a_val);
338 }
339
346 public function addAction($a_txt, $a_link)
347 {
348 $this->actions[] = array("txt" => $a_txt, "link" => $a_link);
349 }
350
351
356 {
357 }
358
363 {
364 $cat_info = $this->getCatInfo();
365
366 //we can move this to the factory.
367 if ($cat_info['editable'] and !$this->appointment['event']->isAutoGenerated()) {
368 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
369 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed', $this->getSeed()->get(IL_CAL_DATE));
370 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $this->appointment['event']->getEntryId());
371 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
372
373 $this->addAction(
374 $this->lng->txt("edit"),
375 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askEdit')
376 );
377
378 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
379 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->getSeed()->get(IL_CAL_DATE));
380 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $this->appointment['event']->getEntryId());
381 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
382
383 $this->addAction(
384 $this->lng->txt("delete"),
385 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askDelete')
386 );
387 }
388 }
389
396 public function addObjectLinks($obj_id, $a_appointment = null)
397 {
398 $refs = $this->getReadableRefIds($obj_id);
399 reset($refs);
401 $buttons = array();
402 foreach ($refs as $ref_id) {
403 $link_title = $title;
404 if (count($refs) > 1) {
405 $par_ref = $this->tree->getParentId($ref_id);
406 $link_title .= " (" . ilObject::_lookupTitle(ilObject::_lookupObjId($par_ref)) . ")";
407 }
408
409 $link = $this->buildDirectLinkForAppointment($ref_id, $a_appointment);
410
411 $buttons[] = $this->ui->renderer()->render(
412 $this->ui->factory()->button()->shy($link_title, $link)
413 );
414 }
415 if ($refs == 0) {
416 $prop_value = $title;
417 } else {
418 $prop_value = implode("<br>", $buttons);
419 }
420 if ($prop_value != '') {
421 $this->addInfoProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
422 $this->addListItemProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
423 }
424 }
425
432 protected function buildDirectLinkForAppointment($a_ref_id, $a_appointment = null)
433 {
434 return ilLink::_getStaticLink($a_ref_id);
435 }
436
443 public function getReadableRefIds($a_obj_id)
444 {
445 if (!isset($this->readable_ref_ids[$a_obj_id])) {
446 $ref_ids = array();
447 foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
448 if ($this->access->checkAccess("read", "", $ref_id)) {
449 $ref_ids[] = $ref_id;
450 }
451 }
452 $this->readable_ref_ids[$a_obj_id] = $ref_ids;
453 }
454 return $this->readable_ref_ids[$a_obj_id];
455 }
456
462 public function addEventDescription($a_app)
463 {
464 if ($a_app['event']->getDescription()) {
465 $this->addInfoProperty($this->lng->txt("description"), ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
466 }
467 }
468
474 public function addEventLocation($a_app)
475 {
476 if ($a_app['event']->getLocation()) {
477 $this->addInfoProperty($this->lng->txt("cal_where"), $a_app['event']->getLocation());
478 $this->addListItemProperty($this->lng->txt("location"), $a_app['event']->getLocation());
479 }
480 }
481
487 public function addLastUpdate($a_app)
488 {
489 $update = new ilDateTime($a_app["event"]->getLastUpdate()->get(IL_CAL_UNIX), IL_CAL_UNIX, $this->user->getTimeZone());
490 $this->addListItemProperty($this->lng->txt('last_update'), ilDatePresentation::formatDate($update));
491 }
492
498 public function addCalendarInfo($cat_info)
499 {
500 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", $cat_info["cat_id"]);
501
502 $link = $this->ui->renderer()->render(
503 $this->ui->factory()->button()->shy(
504 $cat_info["title"],
505 $this->ctrl->getLinkTargetByClass(array("ilPersonalDesktopGUI", "ilCalendarPresentationGUI"), "")
506 )
507 );
508
509 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", $_GET["category_id"]);
510
511 $this->addInfoProperty($this->lng->txt("calendar"), $link);
512 $this->addListItemProperty($this->lng->txt("calendar"), $link);
513 }
514
521 public function addCommonSection($a_app, $a_obj_id = 0, $cat_info = null, $a_container_info = false)
522 {
523 // event title
524 $this->addInfoSection($a_app["event"]->getPresentationTitle(false));
525
526 // event description
527 $this->addEventDescription($a_app);
528
529 // course title (linked of accessible)
530 if ($a_obj_id > 0) {
531 $this->addObjectLinks($a_obj_id, $a_app);
532 }
533
534 // container info (course groups)
535 if ($a_container_info) {
536 $this->addContainerInfo($a_obj_id);
537 }
538
539 // event location
540 $this->addEventLocation($a_app);
541
542 // calendar info
543 if ($cat_info != null) {
544 $this->addCalendarInfo($cat_info);
545 }
546 }
547
551 public function addMetaData($a_obj_type, $a_obj_id, $a_sub_obj_type = null, $a_sub_obj_id = null)
552 {
553 //TODO: Remove the hack in ilADTActiveRecordByType.php.
554 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
555 $record_gui = new ilAdvancedMDRecordGUI(
557 $a_obj_type,
558 $a_obj_id,
559 $a_sub_obj_type,
560 $a_sub_obj_id
561 );
562 $md_items = $record_gui->parse();
563 if (count($md_items)) {
564 foreach ($md_items as $md_item) {
565 $this->addInfoProperty($md_item['title'], $md_item['value']);
566 $this->addListItemProperty($md_item['title'], $md_item['value']);
567 }
568 }
569 }
570
577 public function getUserName($a_user_id, $a_force_name = false)
578 {
579 $type = ilObject::_lookupType((int) $_GET["ref_id"], true);
580 $ctrl_path = array();
581 if ($type == "crs") {
582 $ctrl_path[] = "ilobjcoursegui";
583 }
584 if ($type == "grp") {
585 $ctrl_path[] = "ilobjgroupgui";
586 }
587 if (strtolower($_GET["baseClass"]) == "ilpersonaldesktopgui") {
588 $ctrl_path[] = "ilpersonaldesktopgui";
589 }
590 $ctrl_path[] = "ilCalendarPresentationGUI";
591 $ctrl_path[] = "ilpublicuserprofilegui";
592
594 $a_user_id,
595 false,
596 true,
597 $this->ctrl->getParentReturn($this),
598 $a_force_name,
599 false,
600 true,
601 false,
602 $ctrl_path
603 );
604 }
605
609 public function downloadFiles()
610 {
612
613 //calendar in the sidebar (marginal calendar)
614 if (empty($appointment)) {
615 $entry_id = (int) $_GET['app_id'];
616 $entry = new ilCalendarEntry($entry_id);
617 //if the entry exists
618 if ($entry->getStart()) {
619 $appointment = array(
620 "event" => $entry,
621 "dstart" => $entry->getStart(),
622 "dend" => $entry->getEnd(),
623 "fullday" => $entry->isFullday()
624 );
625 } else {
626 ilUtil::sendFailure($this->lng->txt("obj_not_found"), true);
627 $this->ctrl->returnToParent($this);
628 }
629 }
630
631 include_once './Services/Calendar/classes/BackgroundTasks/class.ilDownloadFilesBackgroundTask.php';
632 $download_job = new ilDownloadFilesBackgroundTask($this->user->getId());
633
634 $download_job->setBucketTitle($this->lng->txt("cal_calendar_download") . " " . $appointment['event']->getTitle());
635 $download_job->setEvents(array($appointment));
636 if ($download_job->run()) {
637 ilUtil::sendSuccess($this->lng->txt('cal_download_files_started'), true);
638 }
639 $this->ctrl->returnToParent($this);
640 }
641}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
buildDirectLinkForAppointment($a_ref_id, $a_appointment=null)
Build direct link for appointment.
readObjIdForAppointment()
read obj_id for appointment
addMetaData($a_obj_type, $a_obj_id, $a_sub_obj_type=null, $a_sub_obj_id=null)
Add metadata.
__construct($a_appointment, $a_info_screen, $a_toolbar, $a_list_item)
addObjectLinks($obj_id, $a_appointment=null)
Add object link.
addContainerInfo($a_obj_id)
Add course/group container info.
addEventDescription($a_app)
Add event description.
downloadFiles()
Download files from an appointment ( Modals )
addListItemProperty($a_txt, $a_val)
Add list item property.
collectStandardPropertiesAndActions()
Collect standard properties and actions.
getReadableRefIds($a_obj_id)
Get readable ref ids.
getUserName($a_user_id, $a_force_name=false)
Get (linked if possible) user name.
addCommonSection($a_app, $a_obj_id=0, $cat_info=null, $a_container_info=false)
Add common section.
collectPropertiesAndActions()
Collect properties and actions.
static getInstance($a_appointment, $a_info_screen, $a_toolbar, $a_list_item)
addInfoProperty($a_txt, $a_val)
Add info property.
static _getInstance($a_usr_id=0)
get singleton instance
static _lookupCategory($a_cal_id)
Lookup category id.
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
Model for a calendar entry.
static _getInstance()
get singleton instance
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Class ilInfoScreenGUI.
static getInstance()
Factory.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
$i
Definition: disco.tpl.php:19
$r
Definition: example_031.php:79
global $ilCtrl
Definition: ilias.php:18
static getDescription()
Definition: Php.php:51
Class BaseForm.
Class Factory.
$type
global $DIC
Definition: saml.php:7