ILIAS  release_8 Revision v8.24
class.ilAppointmentPresentationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23use ILIAS\Refinery\Factory as RefineryFactory;
24use ILIAS\HTTP\Services as HttpServices;
25
33{
34 protected static self $instance;
35
36 protected array $appointment;
37
40 protected ilLanguage $lng;
41 protected ilTree $tree;
42 protected UIServices $ui;
46 protected ilObjUser $user;
47 protected RefineryFactory $refinery;
48 protected HttpServices $http;
49
50
51 protected ?Item $list_item = null;
52
53 protected array $info_items = [];
54 protected array $list_properties = [];
55 protected array $actions = [];
56
60 protected array $readable_ref_ids;
61
62 protected bool $has_files = false;
63 protected int $obj_id = 0;
64 private \ilGlobalTemplateInterface $main_tpl;
65
66 public function __construct(
67 array $a_appointment,
68 ?ilInfoScreenGUI $a_info_screen,
69 ?ilToolbarGUI $a_toolbar,
70 ?Item $a_list_item
71 ) {
72 global $DIC;
73 $this->main_tpl = $DIC->ui()->mainTemplate();
74
75 $this->http = $DIC->http();
76 $this->refinery = $DIC->refinery();
77 $this->appointment = $a_appointment;
78 $this->infoscreen = $a_info_screen;
79 $this->info_items = [];
80 $this->toolbar = $a_toolbar;
81 $this->lng = $DIC->language();
82 $this->lng->loadLanguageModule("dateplaner");
83 $this->tree = $DIC->repositoryTree();
84 $this->ui = $DIC->ui();
85 $this->list_item = $a_list_item;
86 $this->ctrl = $DIC->ctrl();
87 $this->access = $DIC->access();
88 $this->rbacsystem = $DIC->rbac()->system();
89 $this->user = $DIC->user();
91 }
92
93 public function getObjIdForAppointment(): int
94 {
95 return $this->obj_id;
96 }
97
101 protected function readObjIdForAppointment(): void
102 {
103 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
105 $this->obj_id = $category->getObjId();
106 }
107
108 public static function getInstance(
109 array $a_appointment,
110 ?ilInfoScreenGUI $a_info_screen,
111 ?ilToolbarGUI $a_toolbar,
112 ?Item $a_list_item
114 return new static($a_appointment, $a_info_screen, $a_toolbar, $a_list_item);
115 }
116
117 public function getToolbar(): ?ilToolbarGUI
118 {
119 return $this->toolbar;
120 }
121
126 public function getListItem(): ?Item
127 {
128 return $this->list_item;
129 }
130
134 public function getInfoScreen(): ?ilInfoScreenGUI
135 {
136 return $this->infoscreen;
137 }
138
139 public function getCatId(int $a_entry_id): int
140 {
142 }
143
144 public function getCatInfo(): array
145 {
146 $cat_id = $this->getCatId($this->appointment['event']->getEntryId());
147 return ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
148 }
149
150 public function executeCommand(): void
151 {
152 $next_class = $this->ctrl->getNextClass();
153 $cmd = $this->ctrl->getCmd("getHTML");
154 switch ($next_class) {
155 default:
156 $this->$cmd();
157 }
158 }
159
160 public function getHTML(): string
161 {
162 $this->collectStandardPropertiesAndActions();
163 $this->collectPropertiesAndActions();
164 $ui = $this->ui;
165
166 $infoscreen = $this->getInfoScreen();
167 if ($infoscreen instanceof ilInfoScreenGUI) {
168 foreach ($this->info_items as $i) {
169 switch ($i["type"]) {
170 case "section":
171 $infoscreen->addSection($i["txt"]);
172 break;
173 case "property":
174 $infoscreen->addProperty($i["txt"], $i["val"]);
175 break;
176 }
177 }
178 }
179
180 $toolbar = $this->getToolbar();
181 if ($toolbar instanceof ilToolbarGUI) {
182 //todo: duplicated from ilcalendarviewgui.
184 if ($settings->isBatchFileDownloadsEnabled() && $this->has_files) {
185 // file download
186 $this->ctrl->setParameter($this, "app_id", $this->appointment['event']->getEntryId());
187
188 $download_btn = ilLinkButton::getInstance();
189 $download_btn->setCaption($this->lng->txt("cal_download_files"), false);
190 $download_btn->setUrl(
191 $this->ctrl->getLinkTarget($this, 'downloadFiles')
192 );
193 $this->ctrl->setParameter($this, "app_id", '');
194 $toolbar->addButtonInstance($download_btn);
195 $toolbar->addSeparator();
196 }
197
198 foreach ($this->actions as $a) {
200 $btn->setCaption($a["txt"], false);
201 $btn->setUrl($a["link"]);
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 }
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[] = "ilpublicuserprofilegui";
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:24
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:35
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@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...
addButtonInstance(ilButtonBase $a_button)
Add button instance.
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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="ilpublicuserprofilegui")
Default behaviour is:
static makeClickable(string $a_text, bool $detectGotoLinks=false)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
$update
Definition: imgupload.php:92
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$type