ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAppointmentPresentationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as RefineryFactory;
24use ILIAS\HTTP\Services as HttpServices;
26
34{
35 protected static self $instance;
36
37 protected array $appointment;
38
41 protected ilLanguage $lng;
42 protected ilTree $tree;
43 protected UIServices $ui;
47 protected ilObjUser $user;
48 protected RefineryFactory $refinery;
49 protected HttpServices $http;
50
51
52 protected ?Item $list_item = null;
53
54 protected array $info_items = [];
55 protected array $list_properties = [];
56 protected array $actions = [];
57
61 protected array $readable_ref_ids;
62
63 protected bool $has_files = false;
64 protected int $obj_id = 0;
65 private \ilGlobalTemplateInterface $main_tpl;
66
67 public function __construct(
68 array $a_appointment,
69 ?ilInfoScreenGUI $a_info_screen,
70 ?ilToolbarGUI $a_toolbar,
71 ?Item $a_list_item
72 ) {
73 global $DIC;
74 $this->main_tpl = $DIC->ui()->mainTemplate();
75
76 $this->http = $DIC->http();
77 $this->refinery = $DIC->refinery();
78 $this->appointment = $a_appointment;
79 $this->infoscreen = $a_info_screen;
80 $this->info_items = [];
81 $this->toolbar = $a_toolbar;
82 $this->lng = $DIC->language();
83 $this->lng->loadLanguageModule("dateplaner");
84 $this->tree = $DIC->repositoryTree();
85 $this->ui = $DIC->ui();
86 $this->list_item = $a_list_item;
87 $this->ctrl = $DIC->ctrl();
88 $this->access = $DIC->access();
89 $this->rbacsystem = $DIC->rbac()->system();
90 $this->user = $DIC->user();
92 }
93
94 public function getObjIdForAppointment(): int
95 {
96 return $this->obj_id;
97 }
98
102 protected function readObjIdForAppointment(): void
103 {
104 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
106 $this->obj_id = $category->getObjId();
107 }
108
109 public static function getInstance(
110 array $a_appointment,
111 ?ilInfoScreenGUI $a_info_screen,
112 ?ilToolbarGUI $a_toolbar,
113 ?Item $a_list_item
115 return new static($a_appointment, $a_info_screen, $a_toolbar, $a_list_item);
116 }
117
118 public function getToolbar(): ?ilToolbarGUI
119 {
120 return $this->toolbar;
121 }
122
127 public function getListItem(): ?Item
128 {
129 return $this->list_item;
130 }
131
135 public function getInfoScreen(): ?ilInfoScreenGUI
136 {
137 return $this->infoscreen;
138 }
139
140 public function getCatId(int $a_entry_id): int
141 {
143 }
144
145 public function getCatInfo(): array
146 {
147 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
148 return ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
149 }
150
151 public function executeCommand(): void
152 {
153 $next_class = $this->ctrl->getNextClass();
154 $cmd = $this->ctrl->getCmd("getHTML");
155 switch ($next_class) {
156 default:
157 $this->$cmd();
158 }
159 }
160
161 public function getHTML(): string
162 {
163 $this->collectStandardPropertiesAndActions();
164 $this->collectPropertiesAndActions();
165 $ui = $this->ui;
166
167 $infoscreen = $this->getInfoScreen();
168 if ($infoscreen instanceof ilInfoScreenGUI) {
169 foreach ($this->info_items as $i) {
170 switch ($i["type"]) {
171 case "section":
172 $infoscreen->addSection($i["txt"]);
173 break;
174 case "property":
175 $infoscreen->addProperty($i["txt"], $i["val"]);
176 break;
177 }
178 }
179 }
180
181 $toolbar = $this->getToolbar();
182 if ($toolbar instanceof ilToolbarGUI) {
183 //todo: duplicated from ilcalendarviewgui.
185 if ($settings->isBatchFileDownloadsEnabled() && $this->has_files) {
186 // file download
187 $this->ctrl->setParameter($this, "app_id", $this->appointment['event']->getEntryId());
188 $download_btn = $ui->factory()->button()->standard(
189 $this->lng->txt("cal_download_files"),
190 $this->ctrl->getLinkTarget($this, 'downloadFiles')
191 );
192 $this->ctrl->setParameter($this, "app_id", '');
193 $toolbar->addComponent($download_btn);
194 $toolbar->addSeparator();
195 }
196
197 foreach ($this->actions as $a) {
198 $btn = $this->ui->factory()->button()->standard(
199 $a["txt"],
200 $a["link"]
201 );
202 // all buttons are sticky
203 $toolbar->addStickyItem($btn);
204 }
205 }
206
207 $list_item = $this->getListItem();
208 if ($list_item instanceof \ILIAS\UI\Component\Item\Standard) {
209 $dd = $list_item->getActions();
210 if ($dd === null) {
211 $actions = array();
212 $label = "";
213 } else {
214 $actions = $dd->getItems();
215 $label = $dd->getLabel();
216 }
217 $properties = $list_item->getProperties();
218
219 foreach ($this->actions as $a) {
220 $actions[] = $ui->factory()->button()->shy($a["txt"], $a["link"]);
221 }
222 foreach ($this->list_properties as $lp) {
223 $properties[$lp["txt"]] = $lp["val"];
224 }
225
226 $new_dd = $ui->factory()->dropdown()
227 ->standard($actions)
228 ->withLabel($label);
229 $this->list_item = $list_item
230 ->withActions($new_dd)
231 ->withProperties($properties);
232 }
233 return '';
234 }
235
239 public function addContainerInfo(int $a_obj_id): void
240 {
241 $refs = $this->getReadableRefIds($a_obj_id);
242 $ref_id = current($refs);
243 if (count($refs) == 1 && $ref_id > 0) {
244 $tree = $this->tree;
245 $f = $this->ui->factory();
246 $r = $this->ui->renderer();
247
248 //parent course or group title
249 $cont_ref_id = $tree->checkForParentType($ref_id, 'grp');
250 if ($cont_ref_id == 0) {
251 $cont_ref_id = $tree->checkForParentType($ref_id, 'crs');
252 }
253
254 if ($cont_ref_id > 0) {
255 $type = ilObject::_lookupType($cont_ref_id, true);
256 $href = ilLink::_getStaticLink($cont_ref_id);
257 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjectId($cont_ref_id));
258 $this->addInfoProperty(
259 $this->lng->txt("obj_" . $type),
260 $r->render($f->button()->shy($parent_title, $href))
261 );
262 $this->addListItemProperty(
263 $this->lng->txt("obj_" . $type),
264 $r->render($f->button()->shy($parent_title, $href))
265 );
266 }
267 }
268 }
269
273 public function addInfoSection(string $a_txt): void
274 {
275 $this->info_items[] = array("type" => "section", "txt" => $a_txt);
276 }
277
281 public function addInfoProperty(string $a_txt, string $a_val): void
282 {
283 $this->info_items[] = array("type" => "property", "txt" => $a_txt, "val" => $a_val);
284 }
285
289 public function addListItemProperty(string $a_txt, string $a_val): void
290 {
291 #22638
292 $this->list_properties[] = array("txt" => $a_txt, "val" => $a_val);
293 }
294
298 public function addAction(string $a_txt, string $a_link): void
299 {
300 $this->actions[] = array("txt" => $a_txt, "link" => $a_link);
301 }
302
306 public function collectPropertiesAndActions(): void
307 {
308 }
309
314 {
315 $cat_info = $this->getCatInfo();
316
317 //we can move this to the factory.
318 if ($cat_info['editable'] && !$this->appointment['event']->isAutoGenerated()) {
319 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
320 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed', $this->getSeed()->get(IL_CAL_DATE));
321 $this->ctrl->setParameterByClass(
322 'ilcalendarappointmentgui',
323 'app_id',
324 $this->appointment['event']->getEntryId()
325 );
326 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
327
328 $this->addAction(
329 $this->lng->txt("edit"),
330 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askEdit')
331 );
332
333 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
334 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->getSeed()->get(IL_CAL_DATE));
335 $this->ctrl->setParameterByClass(
336 'ilcalendarappointmentgui',
337 'app_id',
338 $this->appointment['event']->getEntryId()
339 );
340 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
341
342 $this->addAction(
343 $this->lng->txt("delete"),
344 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askDelete')
345 );
346 }
347 }
348
352 public function addObjectLinks(int $obj_id, ?array $a_appointment = null): void
353 {
354 $refs = $this->getReadableRefIds($obj_id);
355 reset($refs);
356 $title = ilObject::_lookupTitle($obj_id);
357 $buttons = array();
358 foreach ($refs as $ref_id) {
359 $link_title = $title;
360 if (count($refs) > 1) {
361 $par_ref = $this->tree->getParentId($ref_id);
362 $link_title .= " (" . ilObject::_lookupTitle(ilObject::_lookupObjId($par_ref)) . ")";
363 }
364
365 $link = $this->buildDirectLinkForAppointment($ref_id, $a_appointment);
366
367 $buttons[] = $this->ui->renderer()->render(
368 $this->ui->factory()->button()->shy($link_title, $link)
369 );
370 }
371 if ($refs == 0) {
372 $prop_value = $title;
373 } else {
374 $prop_value = implode("<br>", $buttons);
375 }
376 if ($prop_value != '') {
377 $this->addInfoProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
378 $this->addListItemProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
379 }
380 }
381
385 protected function buildDirectLinkForAppointment(int $a_ref_id, ?array $a_appointment = null): string
386 {
387 return ilLink::_getStaticLink($a_ref_id);
388 }
389
394 public function getReadableRefIds(int $a_obj_id): array
395 {
396 if (!isset($this->readable_ref_ids[$a_obj_id])) {
397 $ref_ids = array();
398 foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
399 if ($this->access->checkAccess("read", "", $ref_id)) {
400 $ref_ids[] = $ref_id;
401 }
402 }
403 $this->readable_ref_ids[$a_obj_id] = $ref_ids;
404 }
405 return $this->readable_ref_ids[$a_obj_id];
406 }
407
411 public function addEventDescription(array $a_app): void
412 {
413 if ($a_app['event']->getDescription()) {
414 $this->addInfoProperty(
415 $this->lng->txt("description"),
416 ilUtil::makeClickable(nl2br($a_app['event']->getDescription()))
417 );
418 }
419 }
420
424 public function addEventLocation(array $a_app): void
425 {
426 if ($a_app['event']->getLocation()) {
427 $this->addInfoProperty($this->lng->txt("cal_where"), $a_app['event']->getLocation());
428 $this->addListItemProperty($this->lng->txt("location"), $a_app['event']->getLocation());
429 }
430 }
431
435 public function addLastUpdate(array $a_app): void
436 {
437 $update = new ilDateTime(
438 $a_app["event"]->getLastUpdate()->get(IL_CAL_UNIX),
440 $this->user->getTimeZone()
441 );
442 $this->addListItemProperty($this->lng->txt('last_update'), ilDatePresentation::formatDate($update));
443 }
444
445 public function addCalendarInfo(array $cat_info): void
446 {
447 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", $cat_info["cat_id"]);
448
449 $link = $this->ui->renderer()->render(
450 $this->ui->factory()->button()->shy(
451 $cat_info["title"],
452 $this->ctrl->getLinkTargetByClass(array("ilDashboardGUI", "ilCalendarPresentationGUI"), "")
453 )
454 );
455
456 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", '');
457 $this->addInfoProperty($this->lng->txt("calendar"), $link);
458 $this->addListItemProperty($this->lng->txt("calendar"), $link);
459 }
460
461 public function addCommonSection(
462 array $a_app,
463 int $a_obj_id = 0,
464 ?array $cat_info = null,
465 bool $a_container_info = false
466 ): void {
467 // event title
468 $this->addInfoSection($a_app["event"]->getPresentationTitle(false));
469
470 // event description
471 $this->addEventDescription($a_app);
472
473 // course title (linked of accessible)
474 if ($a_obj_id > 0) {
475 $this->addObjectLinks($a_obj_id, $a_app);
476 }
477
478 // container info (course groups)
479 if ($a_container_info) {
480 $this->addContainerInfo($a_obj_id);
481 }
482
483 // event location
484 $this->addEventLocation($a_app);
485
486 // calendar info
487 if ($cat_info != null) {
488 $this->addCalendarInfo($cat_info);
489 }
490 }
491
492 public function addMetaData(
493 string $a_obj_type,
494 int $a_obj_id,
495 ?string $a_sub_obj_type = null,
496 ?int $a_sub_obj_id = null
497 ): void {
498 //TODO: Remove the hack in ilADTActiveRecordByType.php.
499 $record_gui = new ilAdvancedMDRecordGUI(
500 ilAdvancedMDRecordGUI::MODE_APP_PRESENTATION,
501 $a_obj_type,
502 $a_obj_id,
503 (string) $a_sub_obj_type,
504 (int) $a_sub_obj_id
505 );
506 $md_items = $record_gui->parse();
507 if (count($md_items)) {
508 foreach ($md_items as $md_item) {
509 $this->addInfoProperty($md_item['title'], $md_item['value']);
510 $this->addListItemProperty($md_item['title'], $md_item['value']);
511 }
512 }
513 }
514
518 public function getUserName(int $a_user_id, bool $a_force_name = false): string
519 {
520 $ref_id = 0;
521 if ($this->http->wrapper()->query()->has('ref_id')) {
522 $ref_id = $this->http->wrapper()->query()->retrieve(
523 'ref_id',
524 $this->refinery->kindlyTo()->int()
525 );
526 }
527 $type = ilObject::_lookupType($ref_id, true);
528 $ctrl_path = array();
529 if ($type == "crs") {
530 $ctrl_path[] = "ilobjcoursegui";
531 }
532 if ($type == "grp") {
533 $ctrl_path[] = "ilobjgroupgui";
534 }
535 $baseClass = '';
536 if ($this->http->wrapper()->query()->has('baseClass')) {
537 $baseClass = $this->http->wrapper()->query()->retrieve(
538 'baseClass',
539 $this->refinery->kindlyTo()->string()
540 );
541 }
542 if (strtolower($baseClass) == "ildashboardgui") {
543 $ctrl_path[] = "ildashboardgui";
544 }
545 $ctrl_path[] = "ilCalendarPresentationGUI";
546 $ctrl_path[] = PublicProfileGUI::class;
547
549 $a_user_id,
550 false,
551 true,
552 $this->ctrl->getParentReturn($this),
553 $a_force_name,
554 false,
555 true,
556 false,
557 $ctrl_path
558 );
559 }
560
564 public function downloadFiles(): void
565 {
566 //calendar in the sidebar (marginal calendar)
567 if (empty($this->appointment)) {
568 $entry_id = 0;
569 if ($this->http->wrapper()->query()->has('app_id')) {
570 $entry_id = $this->http->wrapper()->query()->retrieve(
571 'app_id',
572 $this->refinery->kindlyTo()->int()
573 );
574 }
575 $entry = new ilCalendarEntry($entry_id);
576 //if the entry exists
577 if ($entry->getStart()) {
578 $this->appointment = array(
579 "event" => $entry,
580 "dstart" => $entry->getStart(),
581 "dend" => $entry->getEnd(),
582 "fullday" => $entry->isFullday()
583 );
584 } else {
585 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("obj_not_found"), true);
586 $this->ctrl->returnToParent($this);
587 }
588 }
589 $download_job = new ilDownloadFilesBackgroundTask($this->user->getId());
590
591 $download_job->setBucketTitle($this->lng->txt("cal_calendar_download") . " " . $this->appointment['event']->getTitle());
592 $download_job->setEvents(array($this->appointment));
593 if ($download_job->run()) {
594 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('cal_download_files_started'), true);
595 }
596 $this->ctrl->returnToParent($this);
597 }
598}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:36
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
GUI class for public user profile presentation.
const IL_CAL_UNIX
addContainerInfo(int $a_obj_id)
Add course/group container info.
addInfoProperty(string $a_txt, string $a_val)
Add info property.
addMetaData(string $a_obj_type, int $a_obj_id, ?string $a_sub_obj_type=null, ?int $a_sub_obj_id=null)
readObjIdForAppointment()
read obj_id for appointment
addEventLocation(array $a_app)
Add event location.
addCommonSection(array $a_app, int $a_obj_id=0, ?array $cat_info=null, bool $a_container_info=false)
addEventDescription(array $a_app)
Add event description.
buildDirectLinkForAppointment(int $a_ref_id, ?array $a_appointment=null)
Build direct link for appointment.
downloadFiles()
Download files from an appointment ( Modals )
collectStandardPropertiesAndActions()
Collect standard properties and actions.
addObjectLinks(int $obj_id, ?array $a_appointment=null)
Add object link.
addAction(string $a_txt, string $a_link)
Add action.
getUserName(int $a_user_id, bool $a_force_name=false)
Get (linked if possible) user name.
collectPropertiesAndActions()
Collect properties and actions.
addInfoSection(string $a_txt)
Add info section.
addListItemProperty(string $a_txt, string $a_val)
Add list item property.
static getInstance(array $a_appointment, ?ilInfoScreenGUI $a_info_screen, ?ilToolbarGUI $a_toolbar, ?Item $a_list_item)
__construct(array $a_appointment, ?ilInfoScreenGUI $a_info_screen, ?ilToolbarGUI $a_toolbar, ?Item $a_list_item)
static _getInstance($a_usr_id=0)
get singleton instance
static getInstanceByCategoryId(int $a_cat_id)
Model for a calendar entry.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
Class ilInfoScreenGUI.
addSection(string $a_title)
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
language handling
User class.
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addComponent(\ILIAS\UI\Component\Component $a_comp)
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
checkForParentType(int $a_ref_id, string $a_type, bool $a_exclude_source_check=false)
Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentTyp...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
static makeClickable(string $a_text, bool $detectGotoLinks=false, ?string $ilias_http_path=null)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Common interface to all items.
Definition: Item.php:32
withProperties(array $properties)
Get a new item with the given properties as key-value pairs.
getProperties()
Get the properties of the appointment.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26