ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilCtrl;
189
190 $next_class = $ilCtrl->getNextClass();
191 $cmd = $ilCtrl->getCmd("getHTML");
192
193 switch ($next_class) {
194 default:
195 return $this->$cmd();
196 }
197 }
198
202 public function getHTML()
203 {
206 $ui = $this->ui;
207
208 $infoscreen = $this->getInfoScreen();
209 if ($infoscreen instanceof ilInfoScreenGUI) {
210 foreach ($this->info_items as $i) {
211 switch ($i["type"]) {
212 case "section":
213 $infoscreen->addSection($i["txt"]);
214 break;
215 case "property":
216 $infoscreen->addProperty($i["txt"], $i["val"]);
217 break;
218 }
219 }
220 }
221
222 $toolbar = $this->getToolbar();
223 if ($toolbar instanceof ilToolbarGUI) {
224 //todo: duplicated from ilcalendarviewgui.
226 if ($settings->isBatchFileDownloadsEnabled() && $this->has_files) {
227 // file download
228 $this->ctrl->setParameter($this, "app_id", $this->appointment['event']->getEntryId());
229 $add_button = $this->ui->factory()->button()->standard(
230 $this->lng->txt("cal_download_files"),
231 $this->ctrl->getLinkTarget($this, "downloadFiles")
232 );
233 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
234 $toolbar->addComponent($add_button);
235 $toolbar->addSeparator();
236 }
237
238 foreach ($this->actions as $a) {
240 $btn->setCaption($a["txt"], false);
241 $btn->setUrl($a["link"]);
242 $toolbar->addButtonInstance($btn);
243 }
244 }
245
246 $list_item = $this->getListItem();
247 if ($list_item instanceof \ILIAS\UI\Component\Item\Standard) {
248 $dd = $list_item->getActions();
249 if ($dd === null) {
250 $actions = array();
251 $label = "";
252 } else {
253 $actions = $dd->getItems();
254 $label = $dd->getLabel();
255 }
256 $properties = $list_item->getProperties();
257
258 foreach ($this->actions as $a) {
259 $actions[] = $ui->factory()->button()->shy($a["txt"], $a["link"]);
260 }
261 foreach ($this->list_properties as $lp) {
262 $properties[$lp["txt"]] = $lp["val"];
263 }
264
265 $new_dd = $ui->factory()->dropdown()->standard($actions)
266 ->withLabel($label);
267 $this->list_item = $list_item->withActions($new_dd)->withProperties($properties);
268 }
269 }
270
276 public function addContainerInfo($a_obj_id)
277 {
278 $refs = $this->getReadableRefIds($a_obj_id);
279 $ref_id = current($refs);
280 if (count($refs) == 1 && $ref_id > 0) {
282 $f = $this->ui->factory();
283 $r = $this->ui->renderer();
284
285 //parent course or group title
286 $cont_ref_id = $tree->checkForParentType($ref_id, 'grp');
287 if ($cont_ref_id == 0) {
288 $cont_ref_id = $tree->checkForParentType($ref_id, 'crs');
289 }
290
291 if ($cont_ref_id > 0) {
292 $type = ilObject::_lookupType($cont_ref_id, true);
293 $href = ilLink::_getStaticLink($cont_ref_id);
294 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjectId($cont_ref_id));
295 $this->addInfoProperty($this->lng->txt("obj_" . $type), $r->render($f->button()->shy($parent_title, $href)));
296 $this->addListItemProperty($this->lng->txt("obj_" . $type), $r->render($f->button()->shy($parent_title, $href)));
297 }
298 }
299 }
300
306 public function addInfoSection($a_txt)
307 {
308 $this->info_items[] = array("type" => "section", "txt" => $a_txt);
309 }
310
317 public function addInfoProperty($a_txt, $a_val)
318 {
319 $this->info_items[] = array("type" => "property", "txt" => $a_txt, "val" => $a_val);
320 }
321
328 public function addListItemProperty($a_txt, $a_val)
329 {
330 #22638
331 $this->list_properties[] = array("txt" => $a_txt, "val" => $a_val);
332 }
333
340 public function addAction($a_txt, $a_link)
341 {
342 $this->actions[] = array("txt" => $a_txt, "link" => $a_link);
343 }
344
345
350 {
351 }
352
357 {
358 $cat_info = $this->getCatInfo();
359
360 //we can move this to the factory.
361 if ($cat_info['editable'] and !$this->appointment['event']->isAutoGenerated()) {
362 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
363 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed', $this->getSeed()->get(IL_CAL_DATE));
364 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $this->appointment['event']->getEntryId());
365 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
366
367 $this->addAction(
368 $this->lng->txt("edit"),
369 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askEdit')
370 );
371
372 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
373 // $this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->getSeed()->get(IL_CAL_DATE));
374 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $this->appointment['event']->getEntryId());
375 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $this->appointment['dstart']);
376
377 $this->addAction(
378 $this->lng->txt("delete"),
379 $this->ctrl->getLinkTargetByClass(array('ilcalendarappointmentgui'), 'askDelete')
380 );
381 }
382 }
383
389 public function addObjectLinks($obj_id)
390 {
391 $refs = $this->getReadableRefIds($obj_id);
392 reset($refs);
394 $buttons = array();
395 foreach ($refs as $ref_id) {
396 $link_title = $title;
397 if (count($refs) > 1) {
398 $par_ref = $this->tree->getParentId($ref_id);
399 $link_title.= " (" . ilObject::_lookupTitle(ilObject::_lookupObjId($par_ref)) . ")";
400 }
401 $buttons[] = $this->ui->renderer()->render(
402 $this->ui->factory()->button()->shy($link_title, ilLink::_getStaticLink($ref_id))
403 );
404 }
405 if ($refs == 0) {
406 $prop_value = $title;
407 } else {
408 $prop_value = implode("<br>", $buttons);
409 }
410 if ($prop_value != '') {
411 $this->addInfoProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
412 $this->addListItemProperty($this->lng->txt("obj_" . ilObject::_lookupType($obj_id)), $prop_value);
413 }
414 }
415
422 public function getReadableRefIds($a_obj_id)
423 {
424 if (!isset($this->readable_ref_ids[$a_obj_id])) {
425 $ref_ids = array();
426 foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
427 if ($this->access->checkAccess("read", "", $ref_id)) {
428 $ref_ids[] = $ref_id;
429 }
430 }
431 $this->readable_ref_ids[$a_obj_id] = $ref_ids;
432 }
433 return $this->readable_ref_ids[$a_obj_id];
434 }
435
441 public function addEventDescription($a_app)
442 {
443 if ($a_app['event']->getDescription()) {
444 $this->addInfoProperty($this->lng->txt("description"), ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
445 }
446 }
447
453 public function addEventLocation($a_app)
454 {
455 if ($a_app['event']->getLocation()) {
456 $this->addInfoProperty($this->lng->txt("cal_where"), $a_app['event']->getLocation());
457 $this->addListItemProperty($this->lng->txt("location"), $a_app['event']->getLocation());
458 }
459 }
460
466 public function addLastUpdate($a_app)
467 {
468 $update = new ilDateTime($a_app["event"]->getLastUpdate()->get(IL_CAL_UNIX), IL_CAL_UNIX, $this->user->getTimeZone());
469 $this->addListItemProperty($this->lng->txt('last_update'), ilDatePresentation::formatDate($update));
470 }
471
477 public function addCalendarInfo($cat_info)
478 {
479 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", $cat_info["cat_id"]);
480
481 $link = $this->ui->renderer()->render(
482 $this->ui->factory()->button()->shy(
483 $cat_info["title"],
484 $this->ctrl->getLinkTargetByClass(array("ilPersonalDesktopGUI", "ilCalendarPresentationGUI"), "")
485 )
486 );
487
488 $this->ctrl->setParameterByClass("ilCalendarPresentationGUI", "category_id", $_GET["category_id"]);
489
490 $this->addInfoProperty($this->lng->txt("calendar"), $link);
491 $this->addListItemProperty($this->lng->txt("calendar"), $link);
492 }
493
500 public function addCommonSection($a_app, $a_obj_id = 0, $cat_info = null, $a_container_info = false)
501 {
502 // event title
503 $this->addInfoSection($a_app["event"]->getPresentationTitle(false));
504
505 // event description
506 $this->addEventDescription($a_app);
507
508 // course title (linked of accessible)
509 if ($a_obj_id > 0) {
510 $this->addObjectLinks($a_obj_id);
511 }
512
513 // container info (course groups)
514 if ($a_container_info) {
515 $this->addContainerInfo($a_obj_id);
516 }
517
518 // event location
519 $this->addEventLocation($a_app);
520
521 // calendar info
522 if ($cat_info != null) {
523 $this->addCalendarInfo($cat_info);
524 }
525 }
526
530 public function addMetaData($a_obj_type, $a_obj_id, $a_sub_obj_type = null, $a_sub_obj_id = null)
531 {
532 //TODO: Remove the hack in ilADTActiveRecordByType.php.
533 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
534 $record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_APP_PRESENTATION, $a_obj_type, $a_obj_id, $a_sub_obj_type, $a_sub_obj_id);
535 $md_items = $record_gui->parse();
536 if (count($md_items)) {
537 foreach ($md_items as $md_item) {
538 $this->addInfoProperty($md_item['title'], $md_item['value']);
539 $this->addListItemProperty($md_item['title'], $md_item['value']);
540 }
541 }
542 }
543
550 public function getUserName($a_user_id, $a_force_name = false)
551 {
552 $type = ilObject::_lookupType((int) $_GET["ref_id"], true);
553 $ctrl_path = array();
554 if ($type == "crs") {
555 $ctrl_path[] = "ilobjcoursegui";
556 }
557 if ($type == "grp") {
558 $ctrl_path[] = "ilobjgroupgui";
559 }
560 if (strtolower($_GET["baseClass"]) == "ilpersonaldesktopgui") {
561 $ctrl_path[] = "ilpersonaldesktopgui";
562 }
563 $ctrl_path[] = "ilCalendarPresentationGUI";
564 $ctrl_path[] = "ilpublicuserprofilegui";
565
567 $a_user_id,
568 false,
569 true,
570 $this->ctrl->getParentReturn($this),
571 $a_force_name,
572 false,
573 true,
574 false,
575 $ctrl_path
576 );
577 }
578
582 public function downloadFiles()
583 {
585
586 //calendar in the sidebar (marginal calendar)
587 if (empty($appointment)) {
588 $entry_id = (int) $_GET['app_id'];
589 $entry = new ilCalendarEntry($entry_id);
590 //if the entry exists
591 if ($entry->getStart()) {
592 $appointment = array(
593 "event" => $entry,
594 "dstart" => $entry->getStart(),
595 "dend" => $entry->getEnd(),
596 "fullday" => $entry->isFullday()
597 );
598 } else {
599 ilUtil::sendFailure($this->lng->txt("obj_not_found"), true);
600 $this->ctrl->returnToParent($this);
601 }
602 }
603
604 include_once './Services/Calendar/classes/BackgroundTasks/class.ilDownloadFilesBackgroundTask.php';
605 $download_job = new ilDownloadFilesBackgroundTask($this->user->getId());
606
607 $download_job->setBucketTitle($this->lng->txt("cal_calendar_download") . " " . $appointment['event']->getTitle());
608 $download_job->setEvents(array($appointment));
609 if ($download_job->run()) {
610 ilUtil::sendSuccess($this->lng->txt('cal_download_files_started'), true);
611 }
612 $this->ctrl->returnToParent($this);
613 }
614}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
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)
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)
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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