ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 
39 {
41 
43  '<b>',
44  '<i>',
45  '<strong>',
46  '<em>',
47  '<sub>',
48  '<sup>',
49  '<pre>',
50  '<strike>',
51  '<bdo>'
52  ];
53  public const ADMIN_MODE_NONE = "";
54  public const ADMIN_MODE_SETTINGS = "settings";
55  public const ADMIN_MODE_REPOSITORY = "repository";
56  public const UPLOAD_TYPE_LOCAL = 1;
57  public const UPLOAD_TYPE_UPLOAD_DIRECTORY = 2;
58  public const CFORM_NEW = 1;
59  public const CFORM_IMPORT = 2;
60  public const CFORM_CLONE = 3;
61  protected \ILIAS\Notes\Service $notes_service;
62 
63  protected ServerRequestInterface $request;
65  protected ilObjUser $user;
67  protected ilSetting $settings;
75  protected ilTree $tree;
76  protected ilCtrl $ctrl;
78  protected ilLanguage $lng;
79  protected ilTabsGUI $tabs_gui;
80  protected ILIAS $ilias;
83  protected Factory $refinery;
90 
91  protected ?ilObject $object = null;
92  protected bool $creation_mode = false;
93  protected $data;
94  protected int $id;
95  protected bool $call_by_reference = false;
96  protected bool $prepare_output;
97  protected int $ref_id;
98  protected int $obj_id;
99  protected int $maxcount; // contains number of child objects
100  protected array $form_action = []; // special formation (array "cmd" => "formaction")
101  protected array $return_location = []; // special return location (array "cmd" => "location")
102  protected array $target_frame = []; // special target frame (array "cmd" => "location")
103  protected string $tmp_import_dir; // directory used during import$this->ui_factory = $DIC['ui.factory'];
104  protected string $sub_objects = "";
105  protected bool $omit_locator = false;
106  protected string $type = "";
107  protected string $admin_mode = self::ADMIN_MODE_NONE;
108  protected int $requested_ref_id = 0;
109  protected int $requested_crtptrefid = 0;
110  protected int $requested_crtcb = 0;
111  protected string $requested_new_type = "";
112  protected string $link_params;
113  protected string $html = "";
114 
122  public function __construct($data, int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
123  {
124  global $DIC;
125 
126  $this->request = $DIC->http()->request();
127  $this->locator = $DIC["ilLocator"];
128  $this->user = $DIC->user();
129  $this->access = $DIC->access();
130  $this->settings = $DIC->settings();
131  $this->toolbar = $DIC->toolbar();
132  $this->rbac_admin = $DIC->rbac()->admin();
133  $this->rbac_system = $DIC->rbac()->system();
134  $this->rbac_review = $DIC->rbac()->review();
135  $this->object_service = $DIC->object();
136  $this->obj_definition = $DIC["objDefinition"];
137  $this->tpl = $DIC["tpl"];
138  $this->tree = $DIC->repositoryTree();
139  $this->ctrl = $DIC->ctrl();
140  $this->error = $DIC["ilErr"];
141  $this->lng = $DIC->language();
142  $this->tabs_gui = $DIC->tabs();
143  $this->ilias = $DIC["ilias"];
144  $this->post_wrapper = $DIC->http()->wrapper()->post();
145  $this->request_wrapper = $DIC->http()->wrapper()->query();
146  $this->refinery = $DIC->refinery();
147  $this->retriever = new ilObjectRequestRetriever($DIC->http()->wrapper(), $this->refinery);
148  $this->favourites = new ilFavouritesManager();
149  $this->custom_icon_factory = $DIC['object.customicons.factory'];
150  $this->ui_factory = $DIC['ui.factory'];
151  $this->ui_renderer = $DIC['ui.renderer'];
152 
153  $this->data = $data;
154  $this->id = $id;
155  $this->call_by_reference = $call_by_reference;
156  $this->prepare_output = $prepare_output;
157 
158  $this->lng->loadLanguageModule('obj');
159 
160  $params = ['ref_id'];
161  if (!$call_by_reference) {
162  $params = ['ref_id','obj_id'];
163  }
164  $this->ctrl->saveParameter($this, $params);
165 
166  if ($this->request_wrapper->has('ref_id')) {
167  $this->requested_ref_id = $this->request_wrapper->retrieve('ref_id', $this->refinery->kindlyTo()->int());
168  }
169 
170  $this->obj_id = $this->id;
171  $this->ref_id = $this->requested_ref_id;
172 
173  if ($call_by_reference) {
174  $this->ref_id = $this->id;
175  $this->obj_id = 0;
176  if ($this->request_wrapper->has('obj_id')) {
177  $this->obj_id = $this->request_wrapper->retrieve('obj_id', $this->refinery->kindlyTo()->int());
178  }
179  }
180 
181  // TODO: refactor this with post_wrapper or request_wrapper
182  // callback after creation
183  $this->requested_crtptrefid = $this->retriever->getMaybeInt('crtptrefid', 0);
184  $this->requested_crtcb = $this->retriever->getMaybeInt('crtcb', 0);
185  $this->requested_new_type = $this->retriever->getMaybeString('new_type', '');
186 
187 
188  if ($this->id != 0) {
189  $this->link_params = "ref_id=" . $this->ref_id;
190  }
191 
192  $this->assignObject();
193 
194  if (is_object($this->object)) {
195  if ($this->call_by_reference && $this->ref_id == $this->requested_ref_id) {
196  $this->ctrl->setContextObject(
197  $this->object->getId(),
198  $this->object->getType()
199  );
200  }
201  }
202 
203  if ($prepare_output) {
204  $this->prepareOutput();
205  }
206 
207  $this->notes_service = $DIC->notes();
208  }
209 
211  {
212  if (!isset($this->multi_object_manipulator)) {
213  $this->multi_object_manipulator = ilObjectDIC::dic()['multi_object_properties_manipulator'];
214  }
216  }
217 
218  public function getRefId(): int
219  {
220  return $this->ref_id;
221  }
222 
223  public function setAdminMode(string $mode): void
224  {
225  if (!in_array($mode, [
226  self::ADMIN_MODE_NONE,
227  self::ADMIN_MODE_REPOSITORY,
228  self::ADMIN_MODE_SETTINGS
229  ])) {
230  throw new ilObjectException("Unknown Admin Mode $mode.");
231  }
232  $this->admin_mode = $mode;
233  }
234 
235  public function getAdminMode(): string
236  {
237  return $this->admin_mode;
238  }
239 
240  protected function getObjectService(): ilObjectService
241  {
242  return $this->object_service;
243  }
244 
245  public function getObject(): ?ilObject
246  {
247  return $this->object;
248  }
249 
250  public function executeCommand(): void
251  {
252  $cmd = $this->ctrl->getCmd();
253 
254  $this->prepareOutput();
255  if (!$cmd) {
256  $cmd = "view";
257  }
258  $cmd .= "Object";
259  $this->$cmd();
260  }
261 
265  public function withReferences(): bool
266  {
268  }
269 
275  public function setCreationMode(bool $mode = true): void
276  {
277  $this->creation_mode = $mode;
278  }
279 
280  public function getCreationMode(): bool
281  {
282  return $this->creation_mode;
283  }
284 
285  protected function assignObject(): void
286  {
287  // TODO: it seems that we always have to pass only the ref_id
288  if ($this->id != 0) {
289  if ($this->call_by_reference) {
290  $this->object = ilObjectFactory::getInstanceByRefId($this->id);
291  } else {
292  $this->object = ilObjectFactory::getInstanceByObjId($this->id);
293  }
294  }
295  }
296 
297  public function prepareOutput(bool $show_sub_objects = true): bool
298  {
299  $this->tpl->loadStandardTemplate();
300  $base_class = $this->request_wrapper->retrieve("baseClass", $this->refinery->kindlyTo()->string());
301  if (strtolower($base_class) == "iladministrationgui") {
302  $this->addAdminLocatorItems();
303  $this->tpl->setLocator();
304 
305  $this->setTitleAndDescription();
306 
307  if ($this->getCreationMode() != true) {
308  $this->setAdminTabs();
309  }
310 
311  return false;
312  }
313  $this->setLocator();
314 
315  // in creation mode (parent) object and gui object do not fit
316  if ($this->getCreationMode() === true) {
317  // repository vs. workspace
318  if ($this->call_by_reference) {
319  // get gui class of parent and call their title and description method
320  $obj_type = ilObject::_lookupType($this->requested_ref_id, true);
321  $class_name = $this->obj_definition->getClassName($obj_type);
322  $class = strtolower("ilObj" . $class_name . "GUI");
323  $class_path = $this->ctrl->lookupClassPath($class);
324  $class_name = $this->ctrl->getClassForClasspath($class_path);
325  }
326  } else {
327  $this->setTitleAndDescription();
328 
329  // set tabs
330  $this->setTabs();
331 
332  $file_upload_dropzone = new ilObjFileUploadDropzone($this->ref_id);
333  if ($file_upload_dropzone->isUploadAllowed($this->object->getType())) {
334  $this->enableDragDropFileUpload();
335  }
336  }
337 
338  return true;
339  }
340 
341  protected function setTitleAndDescription(): void
342  {
343  if (!is_object($this->object)) {
344  if ($this->requested_crtptrefid > 0) {
345  $cr_obj_id = ilObject::_lookupObjId($this->requested_crtcb);
346  $this->tpl->setTitle(
347  strip_tags(
348  ilObject::_lookupTitle($cr_obj_id),
349  self::ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
350  )
351  );
352  $this->tpl->setTitleIcon(ilObject::_getIcon($cr_obj_id));
353  }
354  return;
355  }
356  $this->tpl->setTitle(
357  strip_tags(
358  $this->object->getPresentationTitle(),
359  self::ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
360  )
361  );
362  $this->tpl->setDescription(
363  strip_tags(
364  $this->object->getLongDescription(),
365  self::ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
366  )
367  );
368 
369  $base_class = $this->request_wrapper->retrieve("baseClass", $this->refinery->kindlyTo()->string());
370  if (strtolower($base_class) === "iladministrationgui") {
371  // alt text would be same as heading -> empty alt text
372  $this->tpl->setTitleIcon(ilObject::_getIcon(0, "big", $this->object->getType()));
373  } else {
374  $this->tpl->setTitleIcon(
375  ilObject::_getIcon($this->object->getId(), "big", $this->object->getType()),
376  $this->lng->txt("obj_" . $this->object->getType())
377  );
378  }
379  if (!$this->obj_definition->isAdministrationObject($this->object->getType())) {
380  $lgui = ilObjectListGUIFactory::_getListGUIByType($this->object->getType());
381  $lgui->initItem($this->object->getRefId(), $this->object->getId(), $this->object->getType());
382  $this->tpl->setAlertProperties($lgui->getAlertProperties());
383  }
384  }
385 
387  {
388  return new ilCommonActionDispatcherGUI(
390  $this->access,
391  $this->object->getType(),
393  $this->object->getId()
394  );
395  }
396 
400  protected function initHeaderAction(?string $sub_type = null, ?int $sub_id = null): ?ilObjectListGUI
401  {
402  if (!$this->creation_mode && $this->object) {
403  $dispatcher = $this->createActionDispatcherGUI();
404 
405  $dispatcher->setSubObject($sub_type, $sub_id);
406 
408  $this->ctrl->getLinkTarget($this, "redrawHeaderAction", "", true),
409  "",
410  $this->ctrl->getLinkTargetByClass(["ilcommonactiondispatchergui", "iltagginggui"], "", "", true)
411  );
412 
413  $lg = $dispatcher->initHeaderAction();
414 
415  if (is_object($lg)) {
416  // to enable add to desktop / remove from desktop
417  if ($this instanceof ilDesktopItemHandling) {
418  $lg->setContainerObject($this);
419  }
420  // enable multi download
421  $lg->enableMultiDownload(true);
422 
423  // comments settings are always on (for the repository)
424  // should only be shown if active or permission to toggle
425  if (
426  $this->access->checkAccess("write", "", $this->ref_id) ||
427  $this->access->checkAccess("edit_permissions", "", $this->ref_id) ||
428  $this->notes_service->domain()->commentsActive($this->object->getId())
429  ) {
430  $lg->enableComments(true);
431  }
432 
433  $lg->enableNotes(true);
434  $lg->enableTags(true);
435  }
436 
437  return $lg;
438  }
439  return null;
440  }
441 
445  protected function insertHeaderAction(?ilObjectListGUI $list_gui = null): void
446  {
447  if (
448  !is_object($this->object) ||
449  ilContainer::_lookupContainerSetting($this->object->getId(), "hide_top_actions")
450  ) {
451  return;
452  }
453 
454  if (is_object($list_gui)) {
455  $this->tpl->setHeaderActionMenu($list_gui->getHeaderAction());
456  }
457  }
458 
462  protected function addHeaderAction(): void
463  {
464  $this->insertHeaderAction($this->initHeaderAction());
465  }
466 
470  protected function redrawHeaderActionObject(): void
471  {
472  $lg = $this->initHeaderAction();
473  echo $lg->getHeaderAction();
474 
475  // we need to add onload code manually (rating, comments, etc.)
476  echo $this->tpl->getOnLoadCodeForAsynch();
477  exit;
478  }
479 
483  protected function setTabs(): void
484  {
485  $this->getTabs();
486  }
487 
491  final protected function setAdminTabs(): void
492  {
493  $this->getAdminTabs();
494  }
495 
499  public function getAdminTabs(): void
500  {
501  if ($this->checkPermissionBool("visible,read")) {
502  $this->tabs_gui->addTarget(
503  "view",
504  $this->ctrl->getLinkTarget($this, "view"),
505  ["", "view"],
506  get_class($this)
507  );
508  }
509 
510  if ($this->checkPermissionBool("edit_permission")) {
511  $this->tabs_gui->addTarget(
512  "perm_settings",
513  $this->ctrl->getLinkTargetByClass([get_class($this), 'ilpermissiongui'], "perm"),
514  "",
515  "ilpermissiongui"
516  );
517  }
518  }
519 
520  public function getHTML(): string
521  {
522  return $this->html;
523  }
524 
525  protected function setLocator(): void
526  {
527  $ilLocator = $this->locator;
528  $tpl = $this->tpl;
529 
530  if ($this->omit_locator) {
531  return;
532  }
533 
534  // repository vs. workspace
535  if ($this->call_by_reference) {
536  // todo: admin workaround
537  // in the future, object gui classes should not be called in
538  // admin section anymore (rbac/trash handling in own classes)
539  $ref_id = $this->requested_ref_id;
540  if ($this->requested_ref_id === 0) {
541  $ref_id = $this->object->getRefId();
542  }
543  $ilLocator->addRepositoryItems($ref_id);
544  }
545 
546  if (!$this->creation_mode) {
547  $this->addLocatorItems();
548  }
549 
550  $tpl->setLocator();
551  }
552 
557  protected function addLocatorItems(): void
558  {
559  }
560 
561  protected function omitLocator(bool $omit = true): void
562  {
563  $this->omit_locator = $omit;
564  }
565 
570  protected function addAdminLocatorItems(bool $do_not_add_object = false): void
571  {
572  if ($this->admin_mode == self::ADMIN_MODE_SETTINGS) {
573  $this->ctrl->setParameterByClass(
574  "ilobjsystemfoldergui",
575  "ref_id",
577  );
578  $this->locator->addItem(
579  $this->lng->txt("administration"),
580  $this->ctrl->getLinkTargetByClass(["iladministrationgui", "ilobjsystemfoldergui"], "")
581  );
582  if ($this->object && ($this->object->getRefId() != SYSTEM_FOLDER_ID && !$do_not_add_object)) {
583  $this->locator->addItem(
584  $this->object->getTitle(),
585  $this->ctrl->getLinkTarget($this, "view")
586  );
587  }
588  } else {
589  $this->ctrl->setParameterByClass(
590  "iladministrationgui",
591  "ref_id",
592  ""
593  );
594  $this->ctrl->setParameterByClass(
595  "iladministrationgui",
596  "admin_mode",
597  "settings"
598  );
599  $this->ctrl->clearParametersByClass("iladministrationgui");
600  $this->locator->addAdministrationItems();
601  }
602  }
603 
608  public function confirmedDeleteObject(): void
609  {
610  if (!$this->request_wrapper->has('id')) {
611  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'), true);
612  $this->ctrl->returnToParent($this);
613  }
614 
615  $data = $this->buildDeleletionModal(
616  explode(
617  ',',
618  $this->request_wrapper->retrieve(
619  'id',
620  $this->refinery->kindlyTo()->string()
621  )
622  )
623  )->withRequest($this->request)->getData();
624 
625  if ($data === null) {
626  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'), true);
627  $this->ctrl->returnToParent($this);
628  }
629 
630  $ru = new ilRepositoryTrashGUI($this);
631  $ru->deleteObjects($this->requested_ref_id, $this->buildRefIdsFromData($data));
632 
633  $this->ctrl->redirectByClass(static::class);
634  }
635 
636  private function buildRefIdsFromData(array $data): array
637  {
638  return array_reduce(
639  $data,
640  function (array $c, array|int|null $v): array {
641  if ($v === null) {
642  return $c;
643  }
644 
645  if (is_array($v)) {
646  return array_merge(
647  $c,
648  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($v)
649  );
650  }
651 
652  $c[] = $this->refinery->kindlyTo()->int()->transform($v);
653  return $c;
654  },
655  []
656  );
657  }
658 
662  public function cancelObject(): void
663  {
664  ilSession::clear("saved_post");
665  $this->ctrl->returnToParent($this);
666  }
667 
671  public function createObject(): void
672  {
673  $new_type = $this->requested_new_type;
674 
675  // add new object to custom parent container
676  $this->ctrl->saveParameter($this, "crtptrefid");
677  // use forced callback after object creation
678  $this->ctrl->saveParameter($this, "crtcb");
679 
680  if (!$this->checkPermissionBool("create", "", $new_type)) {
681  $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
682  } else {
683  $this->lng->loadLanguageModule($new_type);
684  $this->ctrl->setParameter($this, "new_type", $new_type);
685 
686  $forms = $this->initCreationForms($new_type);
687 
688  // copy form validation error: do not show other creation forms
689  if ($this->request_wrapper->has("cpfl") && isset($forms[self::CFORM_CLONE])) {
690  $forms = [self::CFORM_CLONE => $forms[self::CFORM_CLONE]];
691  }
692  $this->tpl->setContent($this->getCreationFormsHTML($forms));
693  }
694  }
695 
701  protected function initCreationForms(string $new_type): array
702  {
703  $forms = [
704  self::CFORM_NEW => $this->initCreateForm($new_type),
705  self::CFORM_IMPORT => $this->initImportForm($new_type)
706  ];
707 
708  return $forms;
709  }
710 
715  protected function getCreationFormsHTML(array $forms): string
716  {
717  // #13168- sanity check
718  foreach ($forms as $id => $form) {
719  if (!$form instanceof ilPropertyFormGUI) {
720  unset($forms[$id]);
721  }
722  }
723 
724  $acc = new ilAccordionGUI();
725  $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
726  $cnt = 1;
727  foreach ($forms as $form_type => $cf) {
728  $htpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "Services/Object");
729 
730  // using custom form titles (used for repository plugins)
731  $form_title = "";
732  if (method_exists($this, "getCreationFormTitle")) {
733  $form_title = $this->getCreationFormTitle($form_type);
734  }
735  if (!$form_title) {
736  $form_title = $cf->getTitle();
737  }
738 
739  // move title from form to accordion
740  $htpl->setVariable("TITLE", $this->lng->txt("option") . " " . $cnt . ": " . $form_title);
741  $cf->setTitle('');
742  $cf->setTitleIcon('');
743  $cf->setTableWidth("100%");
744 
745  $acc->addItem($htpl->get(), $cf->getHTML());
746 
747  $cnt++;
748  }
749 
750  return "<div class='ilCreationFormSection'>" . $acc->getHTML() . "</div>";
751  }
752 
753  protected function initCreateForm(string $new_type): ilPropertyFormGUI
754  {
755  $form = new ilPropertyFormGUI();
756  $form->setTarget("_top");
757  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
758  $form->setTitle($this->lng->txt($new_type . "_new"));
759 
760  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
761  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
762  $ti->setMaxLength(ilObject::TITLE_LENGTH);
763  $ti->setRequired(true);
764  $form->addItem($ti);
765 
766  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
767  $ta->setCols(40);
768  $ta->setRows(2);
769  $ta->setMaxNumOfChars(ilObject::LONG_DESC_LENGTH);
770  $form->addItem($ta);
771 
772  $form = $this->initDidacticTemplate($form);
773 
774  $form->addCommandButton("save", $this->lng->txt($new_type . "_add"));
775  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
776 
777  return $form;
778  }
779 
781  {
782  $this->lng->loadLanguageModule('didactic');
783  $existing_exclusive = false;
784  $options = [];
785  $options['dtpl_0'] = [
786  $this->lng->txt('didactic_default_type'),
787  sprintf(
788  $this->lng->txt('didactic_default_type_info'),
789  $this->lng->txt('objs_' . $this->type)
790  )
791  ];
792 
793  $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->type)->getTemplates();
794  if ($templates) {
795  foreach ($templates as $template) {
796  if ($template->isEffective((int) $this->requested_ref_id)) {
797  $options["dtpl_" . $template->getId()] = [
798  $template->getPresentationTitle(),
799  $template->getPresentationDescription()
800  ];
801 
802  if ($template->isExclusive()) {
803  $existing_exclusive = true;
804  }
805  }
806  }
807  }
808 
809  $this->addDidacticTemplateOptions($options);
810 
811  if (sizeof($options) > 1) {
812  $type = new ilRadioGroupInputGUI(
813  $this->lng->txt('type'),
814  'didactic_type'
815  );
816  // workaround for containers in edit mode
817  if (!$this->getCreationMode()) {
818  $value = 'dtpl_' . ilDidacticTemplateObjSettings::lookupTemplateId($this->object->getRefId());
819 
820  $type->setValue($value);
821 
822  if (!in_array($value, array_keys($options)) || ($existing_exclusive && $value == "dtpl_0")) {
823  //add or rename actual value to not available
824  $options[$value] = [$this->lng->txt('not_available')];
825  }
826  } else {
827  if ($existing_exclusive) {
828  //if an exclusive template exists use the second template as default value
829  $keys = array_keys($options);
830  $type->setValue($keys[1]);
831  } else {
832  $type->setValue('dtpl_0');
833  }
834  }
835  $form->addItem($type);
836 
837  foreach ($options as $id => $data) {
838  $option = new ilRadioOption($data[0] ?? '', (string) $id, $data[1] ?? '');
839  if ($existing_exclusive && $id == 'dtpl_0') {
840  //set default disabled if an exclusive template exists
841  $option->setDisabled(true);
842  }
843 
844  $type->addOption($option);
845  }
846  }
847 
848  return $form;
849  }
850 
854  protected function addDidacticTemplateOptions(array &$a_options): void
855  {
856  }
857 
858  protected function addAdoptContentLinkToToolbar(): void
859  {
860  $this->toolbar->addComponent(
861  $this->ui_factory->link()->standard(
862  $this->lng->txt('cntr_adopt_content'),
863  $this->ctrl->getLinkTargetByClass(
864  'ilObjectCopyGUI',
865  'adoptContent'
866  )
867  )
868  );
869  }
870 
872  {
873  $toolbar->addSeparator();
874 
875  $toolbar->addComponent(
876  $this->getMultiObjectPropertiesManipulator()->getAvailabilityPeriodButton()
877  );
878  return $toolbar;
879  }
880 
881  public function editAvailabilityPeriodObject(): void
882  {
883  $item_ref_ids = $this->retriever->getSelectedIdsFromObjectList();
884  if (!$this->checkPermissionBool('write')
885  && !$this->checkWritePermissionOnRefIdArray($item_ref_ids)) {
886  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'));
887  return;
888  }
889 
890  $availability_period_modal = $this->getMultiObjectPropertiesManipulator()->getEditAvailabilityPeriodPropertiesModal(
891  $item_ref_ids,
892  $this
893  );
894  if ($availability_period_modal !== null) {
895  $this->tpl->setVariable(
896  'IL_OBJECT_MODALS',
897  $this->ui_renderer->render(
898  $availability_period_modal->withOnLoad(
899  $availability_period_modal->getShowSignal()
900  )
901  )
902  );
903  }
904  $this->renderObject();
905  }
906 
907  public function saveAvailabilityPeriodObject(): void
908  {
909  $availability_period_modal = $this->getMultiObjectPropertiesManipulator()->saveEditAvailabilityPeriodPropertiesModal(
910  $this,
911  fn($ref_ids): bool => $this->checkPermissionBool('write') || $this->checkWritePermissionOnRefIdArray($ref_ids),
912  $this->request
913  );
914  if ($availability_period_modal === true) {
915  $this->tpl->setOnScreenMessage('success', $this->lng->txt('availability_period_changed'));
916  } elseif ($availability_period_modal === false) {
917  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'));
918  } else {
919  $this->tpl->setVariable(
920  'IL_OBJECT_MODALS',
921  $this->ui_renderer->render(
922  $availability_period_modal->withOnLoad(
923  $availability_period_modal->getShowSignal()
924  )
925  )
926  );
927  }
928  $this->renderObject();
929  }
930 
934  public function cancelCreation(): void
935  {
936  $this->ctrl->redirectByClass("ilrepositorygui", "");
937  }
938 
939  public function saveObject(): void
940  {
941  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
942  if (!$this->checkPermissionBool("create", "", $this->requested_new_type)) {
943  $this->error->raiseError($this->lng->txt("no_create_permission"), $this->error->MESSAGE);
944  }
945 
946  $this->lng->loadLanguageModule($this->requested_new_type);
947  $this->ctrl->setParameter($this, "new_type", $this->requested_new_type);
948 
949  $form = $this->initCreateForm($this->requested_new_type);
950  if ($form->checkInput()) {
951  $this->ctrl->setParameter($this, "new_type", "");
952 
953  $class_name = "ilObj" . $this->obj_definition->getClassName($this->requested_new_type);
954  $newObj = new $class_name();
955  $newObj->setType($this->requested_new_type);
956  $newObj->setTitle($form->getInput("title"));
957  $newObj->setDescription($form->getInput("desc"));
958  $newObj->processAutoRating();
959  $newObj->create();
960 
961  $this->putObjectInTree($newObj);
962 
963  $dtpl = $this->getDidacticTemplateVar("dtpl");
964  if ($dtpl) {
965  $newObj->applyDidacticTemplate($dtpl);
966  }
967 
968  $this->afterSave($newObj);
969  }
970 
971  $form->setValuesByPost();
972  $this->tpl->setContent($form->getHTML());
973  }
974 
978  public function getDidacticTemplateVar(string $type): int
979  {
980  if (!$this->post_wrapper->has("didactic_type")) {
981  return 0;
982  }
983 
984  $tpl = $this->post_wrapper->retrieve("didactic_type", $this->refinery->kindlyTo()->string());
985  if (substr($tpl, 0, strlen($type) + 1) != $type . "_") {
986  return 0;
987  }
988 
989  return (int) substr($tpl, strlen($type) + 1);
990  }
991 
995  public function putObjectInTree(ilObject $obj, int $parent_node_id = null): void
996  {
997  if (!$parent_node_id) {
998  $parent_node_id = $this->requested_ref_id;
999  }
1000 
1001  // add new object to custom parent container
1002  if ($this->requested_crtptrefid > 0) {
1003  $parent_node_id = $this->requested_crtptrefid;
1004  }
1005 
1006  $obj->createReference();
1007  $obj->putInTree($parent_node_id);
1008  $obj->setPermissions($parent_node_id);
1009 
1010  $this->obj_id = $obj->getId();
1011  $this->ref_id = $obj->getRefId();
1012 
1013  // BEGIN ChangeEvent: Record save object.
1014  ilChangeEvent::_recordWriteEvent($this->obj_id, $this->user->getId(), 'create');
1015  // END ChangeEvent: Record save object.
1016 
1017  // rbac log
1018  $rbac_log_roles = $this->rbac_review->getParentRoleIds($this->ref_id, false);
1019  $rbac_log = ilRbacLog::gatherFaPa($this->ref_id, array_keys($rbac_log_roles), true);
1020  ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $this->ref_id, $rbac_log);
1021 
1022  // use forced callback after object creation
1023  $this->callCreationCallback($obj, $this->obj_definition, $this->requested_crtcb);
1024  }
1025 
1029  protected function afterSave(ilObject $new_object): void
1030  {
1031  $this->tpl->setOnScreenMessage("success", $this->lng->txt("object_added"), true);
1032  $this->ctrl->returnToParent($this);
1033  }
1034 
1035  public function editObject(): void
1036  {
1037  if (!$this->checkPermissionBool("write")) {
1038  $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
1039  }
1040 
1041  $this->tabs_gui->activateTab("settings");
1042 
1043  $form = $this->initEditForm();
1044  $values = $this->getEditFormValues();
1045  if ($values) {
1046  $form->setValuesByArray($values);
1047  }
1048 
1049  $this->addExternalEditFormCustom($form);
1050 
1051  $this->tpl->setContent($form->getHTML());
1052  }
1053 
1054  public function addExternalEditFormCustom(ilPropertyFormGUI $form): void
1055  {
1056  // has to be done AFTER setValuesByArray() ...
1057  }
1058 
1059  protected function initEditForm(): ilPropertyFormGUI
1060  {
1061  $lng = $this->lng;
1062 
1063  $lng->loadLanguageModule($this->object->getType());
1064 
1065  $form = new ilPropertyFormGUI();
1066  $form->setFormAction($this->ctrl->getFormAction($this, "update"));
1067  $form->setTitle($this->lng->txt($this->object->getType() . "_edit"));
1068 
1069  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
1070  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
1071  $ti->setMaxLength(ilObject::TITLE_LENGTH);
1072  $ti->setRequired(true);
1073  $form->addItem($ti);
1074 
1075  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
1076  $ta->setCols(40);
1077  $ta->setRows(2);
1078  $ta->setMaxNumOfChars(ilObject::LONG_DESC_LENGTH);
1079  $form->addItem($ta);
1080 
1081  $this->initEditCustomForm($form);
1082 
1083  $form->addCommandButton("update", $this->lng->txt("save"));
1084 
1085  return $form;
1086  }
1087 
1091  protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
1092  {
1093  }
1094 
1095  protected function getEditFormValues(): array
1096  {
1097  $values["title"] = $this->object->getTitle();
1098  $values["desc"] = $this->object->getLongDescription();
1099  $this->getEditFormCustomValues($values);
1100  return $values;
1101  }
1102 
1106  protected function getEditFormCustomValues(array &$a_values): void
1107  {
1108  }
1109 
1113  public function updateObject(): void
1114  {
1115  if (!$this->checkPermissionBool("write")) {
1116  $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
1117  }
1118 
1119  $form = $this->initEditForm();
1120  if ($form->checkInput() && $this->validateCustom($form)) {
1121  $this->updateCustom($form);
1122  $this->object->setTitle($form->getInput('title'));
1123  $this->object->setDescription($form->getInput('desc'));
1124  $this->object->update();
1125 
1126  $this->afterUpdate();
1127  return;
1128  }
1129 
1130  // display form again to correct errors
1131  $this->tabs_gui->activateTab("settings");
1132  $form->setValuesByPost();
1133  $this->tpl->setContent($form->getHTML());
1134  }
1135 
1139  protected function validateCustom(ilPropertyFormGUI $form): bool
1140  {
1141  return true;
1142  }
1143 
1147  protected function updateCustom(ilPropertyFormGUI $form): void
1148  {
1149  }
1150 
1154  protected function afterUpdate(): void
1155  {
1156  $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
1157  $this->ctrl->redirect($this, "edit");
1158  }
1159 
1160  protected function initImportForm(string $new_type): ilPropertyFormGUI
1161  {
1162  $import_directory_factory = new ilImportDirectoryFactory();
1163  $export_directory = $import_directory_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_EXPORT);
1164  $upload_files = $export_directory->getFilesFor($this->user->getId(), $new_type);
1165  $has_upload_files = false;
1166  if (count($upload_files)) {
1167  $has_upload_files = true;
1168  }
1169 
1170  $form = new ilPropertyFormGUI();
1171  $form->setTarget("_top");
1172  $form->setFormAction($this->ctrl->getFormAction($this, "importFile"));
1173  $form->setTitle($this->lng->txt($new_type . "_import"));
1174 
1175  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
1176  $fi->setSuffixes(["zip"]);
1177  $fi->setRequired(true);
1178  if ($has_upload_files) {
1179  $this->lng->loadLanguageModule('content');
1180  $option = new ilRadioGroupInputGUI(
1181  $this->lng->txt('cont_choose_file_source'),
1182  'upload_type'
1183  );
1184  $option->setValue((string) self::UPLOAD_TYPE_LOCAL);
1185  $form->addItem($option);
1186 
1187  $direct = new ilRadioOption($this->lng->txt('cont_choose_local'), (string) self::UPLOAD_TYPE_LOCAL);
1188  $option->addOption($direct);
1189 
1190  $direct->addSubItem($fi);
1191  $upload = new ilRadioOption(
1192  $this->lng->txt('cont_choose_upload_dir'),
1193  (string) self::UPLOAD_TYPE_UPLOAD_DIRECTORY
1194  );
1195  $option->addOption($upload);
1196  $files = new ilSelectInputGUI(
1197  $this->lng->txt('cont_choose_upload_dir'),
1198  'uploadFile'
1199  );
1200  $upload_files[''] = $this->lng->txt('cont_select_from_upload_dir');
1201  $files->setOptions($upload_files);
1202  $files->setRequired(true);
1203  $upload->addSubItem($files);
1204  }
1205 
1206  if (!$has_upload_files) {
1207  $form->addItem($fi);
1208  }
1209 
1210  $form->addCommandButton("importFile", $this->lng->txt("import"));
1211  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
1212 
1213  return $form;
1214  }
1215 
1216  protected function importFileObject(int $parent_id = null): void
1217  {
1218  if (!$parent_id) {
1219  $parent_id = $this->requested_ref_id;
1220  }
1221  $new_type = $this->requested_new_type;
1222  $upload_type = self::UPLOAD_TYPE_LOCAL;
1223  if ($this->post_wrapper->has("upload_type")) {
1224  $upload_type = $this->post_wrapper->retrieve("upload_type", $this->refinery->kindlyTo()->int());
1225  }
1226 
1227  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
1228  if (!$this->checkPermissionBool("create", "", $new_type)) {
1229  $this->error->raiseError($this->lng->txt("no_create_permission"));
1230  }
1231 
1232  $this->lng->loadLanguageModule($new_type);
1233  $this->ctrl->setParameter($this, "new_type", $new_type);
1234 
1235  $form = $this->initImportForm($new_type);
1236  if ($form->checkInput()) {
1237  // :todo: make some check on manifest file
1238  if ($this->obj_definition->isContainer($new_type)) {
1239  $imp = new ilImportContainer((int) $parent_id);
1240  } else {
1241  $imp = new ilImport((int) $parent_id);
1242  }
1243 
1244  try {
1245  if ($upload_type == self::UPLOAD_TYPE_LOCAL) {
1246  $new_id = $imp->importObject(
1247  null,
1248  $_FILES["importfile"]["tmp_name"],
1249  $_FILES["importfile"]["name"],
1250  $new_type
1251  );
1252  } else {
1253  $hash = $this->request->getParsedBody()['uploadFile'] ?? '';
1254  $upload_factory = new ilImportDirectoryFactory();
1255  $export_upload = $upload_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_EXPORT);
1256  $file = $export_upload->getAbsolutePathForHash($this->user->getId(), $new_type, $hash);
1257 
1258  $new_id = $imp->importObject(
1259  null,
1260  $file,
1261  basename($file),
1262  $new_type,
1263  '',
1264  true
1265  );
1266  }
1267  } catch (ilException $e) {
1268  $this->tmp_import_dir = $imp->getTemporaryImportDir();
1269  $this->lng->loadLanguageModule('obj');
1270 
1271  $this->tpl->setOnScreenMessage(
1272  "failure",
1273  $this->lng->txt("obj_import_file_error") . " <br />" . $e->getMessage()
1274  );
1275  $form->setValuesByPost();
1276  $this->tpl->setContent($form->getHTML());
1277  return;
1278  }
1279 
1280  if ($new_id > 0) {
1281  $this->ctrl->setParameter($this, "new_type", "");
1282 
1283  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
1284  // put new object id into tree - already done in import for containers
1285  if (!$this->obj_definition->isContainer($new_type)) {
1286  $this->putObjectInTree($newObj);
1287  } else {
1288  $ref_ids = ilObject::_getAllReferences($newObj->getId());
1289  if (count($ref_ids) === 1) {
1290  $newObj->setRefId((int) current($ref_ids));
1291  }
1292  $this->callCreationCallback($newObj, $this->obj_definition, $this->requested_crtcb); // see #24244
1293  }
1294 
1295  $this->afterImport($newObj);
1296  } else {
1297  if ($this->obj_definition->isContainer($new_type)) {
1298  $this->tpl->setOnScreenMessage("failure", $this->lng->txt("container_import_zip_file_invalid"));
1299  } else {
1300  // not enough information here...
1301  return;
1302  }
1303  }
1304  }
1305 
1306  $form->setValuesByPost();
1307  $this->tpl->setContent($form->getHTML());
1308  }
1309 
1313  protected function afterImport(ilObject $new_object): void
1314  {
1315  $this->tpl->setOnScreenMessage("success", $this->lng->txt("object_added"), true);
1316  $this->ctrl->returnToParent($this);
1317  }
1318 
1322  public function getFormAction(string $cmd, string $default_form_action = ""): string
1323  {
1324  if ($this->form_action[$cmd] != "") {
1325  return $this->form_action[$cmd];
1326  }
1327 
1328  return $default_form_action;
1329  }
1330 
1331  protected function setFormAction(string $cmd, string $form_action): void
1332  {
1333  $this->form_action[$cmd] = $form_action;
1334  }
1335 
1339  protected function getReturnLocation(string $cmd, string $default_location = ""): string
1340  {
1341  if (($this->return_location[$cmd] ?? "") !== "") {
1342  return $this->return_location[$cmd];
1343  } else {
1344  return $default_location;
1345  }
1346  }
1347 
1351  protected function setReturnLocation(string $cmd, string $location): void
1352  {
1353  $this->return_location[$cmd] = $location;
1354  }
1355 
1359  protected function getTargetFrame(string $cmd, string $default_target_frame = ""): string
1360  {
1361  if (isset($this->target_frame[$cmd]) && $this->target_frame[$cmd] != "") {
1362  return $this->target_frame[$cmd];
1363  }
1364 
1365  if (!empty($default_target_frame)) {
1366  return "target=\"" . $default_target_frame . "\"";
1367  }
1368 
1369  return "";
1370  }
1371 
1375  protected function setTargetFrame(string $cmd, string $target_frame): void
1376  {
1377  $this->target_frame[$cmd] = "target=\"" . $target_frame . "\"";
1378  }
1379 
1380  public function isVisible(int $ref_id, string $type): bool
1381  {
1382  $visible = $this->checkPermissionBool("visible,read", "", "", $ref_id);
1383 
1384  if ($visible && $type == 'crs') {
1385  $tree = $this->tree;
1386  if ($crs_id = $tree->checkForParentType($ref_id, 'crs')) {
1387  if (!$this->checkPermissionBool("write", "", "", $crs_id)) {
1388  // Show only activated courses
1389  $tmp_obj = ilObjectFactory::getInstanceByRefId($crs_id, false);
1390 
1391  if (!$tmp_obj->isActivated()) {
1392  unset($tmp_obj);
1393  $visible = false;
1394  }
1395  }
1396  }
1397  }
1398 
1399  return $visible;
1400  }
1401 
1405  public function viewObject(): void
1406  {
1407  $this->checkPermission('visible') && $this->checkPermission('read');
1408 
1409  $this->tabs_gui->activateTab('view');
1410 
1412  $this->object->getType(),
1413  $this->object->getRefId(),
1414  $this->object->getId(),
1415  $this->user->getId()
1416  );
1417 
1418  if (!$this->withReferences()) {
1419  $this->ctrl->setParameter($this, 'obj_id', $this->obj_id);
1420  }
1421 
1422  $itab = new ilAdminSubItemsTableGUI(
1423  $this,
1424  "view",
1425  $this->requested_ref_id,
1426  $this->checkPermissionBool('write')
1427  );
1428 
1429  $this->tpl->setContent($itab->getHTML());
1430  }
1431 
1437  public function deleteObject(bool $error = false): void
1438  {
1439  $request_ids = [];
1440  if ($this->post_wrapper->has('id')) {
1441  $request_ids = $this->post_wrapper->retrieve(
1442  'id',
1443  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
1444  );
1445  }
1446 
1447  if (
1448  $this->request_wrapper->has('item_ref_id')
1449  && $this->request_wrapper->retrieve('item_ref_id', $this->refinery->kindlyTo()->string()) !== ""
1450  ) {
1451  $request_ids = [$this->request_wrapper->retrieve('item_ref_id', $this->refinery->kindlyTo()->int())];
1452  }
1453 
1454  if ($request_ids === []) {
1455  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'), true);
1456  $this->ctrl->returnToParent($this);
1457  }
1458 
1459  $modal = $this->buildDeleletionModal(array_unique($request_ids));
1460  $this->tpl->setVariable(
1461  'IL_OBJECT_MODALS',
1462  $this->ui_renderer->render(
1463  $modal->withOnLoad(
1464  $modal->getShowSignal()
1465  )
1466  )
1467  );
1468  $this->renderObject();
1469  }
1470 
1471  private function buildDeleletionModal(array $request_ids): \ILIAS\UI\Component\Modal\RoundTrip
1472  {
1473  [$listing_items, $inputs, $has_additional_references] = $this->buildDeletionModalItems($request_ids);
1474 
1475  $msg = $this->lng->txt('info_delete_sure');
1476  if (!$this->settings->get('enable_trash')) {
1477  $msg .= "<br/>" . $this->lng->txt('info_delete_warning_no_trash');
1478  }
1479 
1480  $content = [
1481  $this->ui_factory->messageBox()->confirmation($msg),
1482  $this->ui_factory->listing()->unordered($listing_items)
1483  ];
1484 
1485  if ($has_additional_references) {
1486  $content[] = $this->ui_factory->messageBox()->confirmation(
1487  $this->lng->txt('multiple_reference_deletion_info') . ' '
1488  . $this->lng->txt('rep_multiple_reference_deletion_instruction')
1489  );
1490  }
1491 
1492  $this->ctrl->setParameterByClass(static::class, 'id', implode(',', $request_ids));
1493  $target_url = $this->ctrl->getFormActionByClass(static::class, 'confirmedDelete');
1494  $this->ctrl->clearParameterByClass(static::class, 'id');
1495 
1496  return $this->ui_factory->modal()->roundtrip(
1497  $this->lng->txt('confirm'),
1498  $content,
1499  $inputs,
1500  $target_url
1501  )->withSubmitLabel($this->lng->txt('delete'));
1502  }
1503 
1504  private function buildDeletionModalItems(array $ref_ids): array
1505  {
1506  $path_gui = new ilPathGUI();
1507  $path_gui->enableTextOnly(true);
1508  $path_gui->enableHideLeaf(false);
1509  return array_reduce(
1510  $ref_ids,
1511  function (array $c, int $v) use ($path_gui): array {
1512  $c[0][] = ilObject::_lookupTitle(
1514  );
1515  $c[1][] = $this->ui_factory->input()->field()->hidden()->withValue($v);
1516 
1517  $other_references = $this->buildInputsForAdditionalDeletionReferences($v, $path_gui);
1518  if ($other_references !== []) {
1519  $c[1][] = $this->ui_factory->input()->field()->multiSelect(
1522  ),
1523  $other_references
1524  );
1525  $c[2] = true;
1526  }
1527  return $c;
1528  },
1529  [[], [], false]
1530  );
1531  }
1532 
1533  private function buildInputsForAdditionalDeletionReferences(int $ref_id, ilPathGUI $path_gui): array
1534  {
1535  return array_reduce(
1537  function (array $c, int $v) use ($ref_id, $path_gui): array {
1538  if ($v !== $ref_id
1539  && !$this->tree->isDeleted($v)
1540  && $this->access->checkAccess('delete', '', $v)) {
1541  $c[$v] = $path_gui->getPath(ROOT_FOLDER_ID, $v);
1542  }
1543  return $c;
1544  },
1545  []
1546  );
1547  }
1548 
1552  protected function showPossibleSubObjects(): void
1553  {
1554  if ($this->sub_objects == "") {
1555  $sub_objects = $this->obj_definition->getCreatableSubObjects(
1556  $this->object->getType(),
1559  );
1560  } else {
1561  $sub_objects = $this->sub_objects;
1562  }
1563 
1564  $subobj = [];
1565  if (count($sub_objects) > 0) {
1566  foreach ($sub_objects as $row) {
1567  $count = 0;
1568  if ($row["max"] > 0) {
1569  //how many elements are present?
1570  for ($i = 0; $i < count($this->data["ctrl"]); $i++) {
1571  if ($this->data["ctrl"][$i]["type"] == $row["name"]) {
1572  $count++;
1573  }
1574  }
1575  }
1576 
1577  if ($row["max"] == "" || $count < $row["max"]) {
1578  $subobj[] = $row["name"];
1579  }
1580  }
1581  }
1582 
1583  if (count($subobj) > 0) {
1584  $opts = ilLegacyFormElementsUtil::formSelect(12, "new_type", $subobj);
1585  $this->tpl->setCurrentBlock("add_object");
1586  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
1587  $this->tpl->setVariable("BTN_NAME", "create");
1588  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
1589  $this->tpl->parseCurrentBlock();
1590  }
1591  }
1592 
1596  protected function getTabs(): void
1597  {
1598  }
1599 
1607  protected function redirectToRefId(int $ref_id, string $cmd = ""): void
1608  {
1609  $obj_type = ilObject::_lookupType($ref_id, true);
1610  $class_name = $this->obj_definition->getClassName($obj_type);
1611  $class = strtolower("ilObj" . $class_name . "GUI");
1612  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
1613  $this->ctrl->redirectByClass(["ilrepositorygui", $class], $cmd);
1614  }
1615 
1619  protected function getCenterColumnHTML(): string
1620  {
1621  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
1622  $obj_type = ilObject::_lookupType($obj_id);
1623 
1624  if ($this->ctrl->getNextClass() != "ilcolumngui") {
1625  // normal command processing
1626  return $this->getContent();
1627  } else {
1628  if (!$this->ctrl->isAsynch()) {
1629  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
1631  // right column wants center
1633  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
1634  $this->setColumnSettings($column_gui);
1635  $this->html = $this->ctrl->forwardCommand($column_gui);
1636  }
1637  // left column wants center
1639  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
1640  $this->setColumnSettings($column_gui);
1641  $this->html = $this->ctrl->forwardCommand($column_gui);
1642  }
1643  } else {
1644  // normal command processing
1645  return $this->getContent();
1646  }
1647  }
1648  }
1649  return "";
1650  }
1651 
1655  protected function getRightColumnHTML(): string
1656  {
1657  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
1658  $obj_type = ilObject::_lookupType($obj_id);
1659 
1660  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
1661 
1662  if ($column_gui->getScreenMode() == IL_SCREEN_FULL) {
1663  return "";
1664  }
1665 
1666  $this->setColumnSettings($column_gui);
1667 
1668  $html = "";
1669  if (
1670  $this->ctrl->getNextClass() == "ilcolumngui" &&
1671  $column_gui->getCmdSide() == IL_COL_RIGHT &&
1672  $column_gui->getScreenMode() == IL_SCREEN_SIDE
1673  ) {
1674  return $this->ctrl->forwardCommand($column_gui);
1675  }
1676 
1677  if (!$this->ctrl->isAsynch()) {
1678  return $this->ctrl->getHTML($column_gui);
1679  }
1680 
1681  return $html;
1682  }
1683 
1684  public function setColumnSettings(ilColumnGUI $column_gui): void
1685  {
1686  $column_gui->setRepositoryMode(true);
1687  $column_gui->setEnableEdit(false);
1688  if ($this->checkPermissionBool("write")) {
1689  $column_gui->setEnableEdit(true);
1690  }
1691  }
1692 
1693  protected function checkPermission(string $perm, string $cmd = "", string $type = "", ?int $ref_id = null): void
1694  {
1695  if (!$this->checkPermissionBool($perm, $cmd, $type, $ref_id)) {
1696  if (!is_int(strpos($_SERVER["PHP_SELF"], "goto.php"))) {
1697  if ($perm != "create" && !is_object($this->object)) {
1698  return;
1699  }
1700 
1701  ilSession::clear("il_rep_ref_id");
1702 
1703  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_read'), true);
1704  $parent_ref_id = $this->tree->getParentNodeData($this->object->getRefId())['ref_id'] ?? null;
1705  $this->ctrl->redirectToURL(ilLink::_getLink($parent_ref_id));
1706  }
1707 
1708  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_read'), true);
1709  self::_gotoRepositoryRoot();
1710  }
1711  }
1712 
1713  protected function checkPermissionBool(string $perm, string $cmd = "", string $type = "", ?int $ref_id = null): bool
1714  {
1715  if ($perm == "create") {
1716  if (!$ref_id) {
1717  $ref_id = $this->requested_ref_id;
1718  }
1719  return $this->access->checkAccess($perm . "_" . $type, $cmd, $ref_id);
1720  }
1721 
1722  if (!is_object($this->object)) {
1723  return false;
1724  }
1725 
1726  if (!$ref_id) {
1727  $ref_id = $this->object->getRefId();
1728  }
1729 
1730  return $this->access->checkAccess($perm, $cmd, $ref_id);
1731  }
1732 
1739  public static function _gotoRepositoryRoot(bool $raise_error = false): void
1740  {
1741  global $DIC;
1742 
1743  $ilAccess = $DIC->access();
1744  $ilErr = $DIC["ilErr"];
1745  $lng = $DIC->language();
1746  $ctrl = $DIC->ctrl();
1747 
1748  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1749  $ctrl->setParameterByClass("ilRepositoryGUI", "ref_id", ROOT_FOLDER_ID);
1750  $ctrl->redirectByClass("ilRepositoryGUI");
1751  }
1752 
1753  if ($raise_error) {
1754  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1755  }
1756  }
1757 
1758  public static function _gotoRepositoryNode(int $ref_id, string $cmd = ""): void
1759  {
1760  global $DIC;
1761 
1762  $ctrl = $DIC->ctrl();
1763  $ctrl->setParameterByClass("ilRepositoryGUI", "ref_id", $ref_id);
1764  $ctrl->redirectByClass("ilRepositoryGUI", $cmd);
1765  }
1766 
1767  public static function _gotoSharedWorkspaceNode(int $wsp_id): void
1768  {
1769  global $DIC;
1770 
1771  $ctrl = $DIC->ctrl();
1772  $ctrl->setParameterByClass(ilSharedResourceGUI::class, "wsp_id", $wsp_id);
1773  $ctrl->redirectByClass(ilSharedResourceGUI::class, "");
1774  }
1775 
1779  protected function enableDragDropFileUpload(): void
1780  {
1781  $this->tpl->setFileUploadRefId($this->ref_id);
1782  }
1783 
1788  public function redirectAfterCreation(): void
1789  {
1790  $link = ilLink::_getLink($this->object->getRefId());
1791  $this->ctrl->redirectToURL($link);
1792  }
1793 
1794  public function addToDeskObject(): void
1795  {
1796  $this->favourites->add(
1797  $this->user->getId(),
1798  $this->request_wrapper->retrieve("item_ref_id", $this->refinery->kindlyTo()->int())
1799  );
1800  $this->lng->loadLanguageModule("rep");
1801  $this->tpl->setOnScreenMessage("success", $this->lng->txt("rep_added_to_favourites"), true);
1802  $this->ctrl->redirectToURL(ilLink::_getLink($this->requested_ref_id));
1803  }
1804 
1805  public function removeFromDeskObject(): void
1806  {
1807  $this->lng->loadLanguageModule("rep");
1808  $item_ref_id = $this->request_wrapper->retrieve("item_ref_id", $this->refinery->kindlyTo()->int());
1809  $this->favourites->remove($this->user->getId(), $item_ref_id);
1810  $this->tpl->setOnScreenMessage("success", $this->lng->txt("rep_removed_from_favourites"), true);
1811  $this->ctrl->redirectToURL(ilLink::_getLink($this->requested_ref_id));
1812  }
1813 
1814  private function checkWritePermissionOnRefIdArray(array $ref_ids): bool
1815  {
1816  foreach ($ref_ids as $ref_id) {
1817  if (!$this->access->checkAccess('write', '', $ref_id)) {
1818  return false;
1819  }
1820  }
1821  return true;
1822  }
1823 }
redrawHeaderActionObject()
Ajax call: redraw action header only.
ilObjectDefinition $obj_definition
Creates a path for a start and endnode.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static gatherFaPa(int $a_ref_id, array $a_role_ids, bool $a_add_action=false)
omitLocator(bool $omit=true)
setAdminMode(string $mode)
const ADMIN_MODE_REPOSITORY
setLocator()
Insert locator.
ilRbacReview $rbac_review
getTargetFrame(string $cmd, string $default_target_frame="")
get target frame for command (command is method name without "Object", e.g.
static getCmdSide()
Get Column Side of Current Command.
exit
Definition: login.php:29
ilRbacSystem $rbac_system
buildRefIdsFromData(array $data)
ilTabsGUI $tabs_gui
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
getTabs()
overwrite in derived GUI class of your object type
initImportForm(string $new_type)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
enableDragDropFileUpload()
Enables the file upload into this object by dropping files.
This class represents a selection list property in a property form.
TableGUI class for sub items listed in repository administration.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
cancelCreation()
cancel create action and go back to repository parent
getFormAction(string $cmd, string $default_form_action="")
Get form action for command (command is method name without "Object", e.g.
cancelObject()
cancel action and go back to previous page
ilObjectRequestRetriever $retriever
const ROOT_FOLDER_ID
Definition: constants.php:32
const TITLE_LENGTH
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
prepareOutput(bool $show_sub_objects=true)
insertHeaderAction(?ilObjectListGUI $list_gui=null)
Insert header action into main template.
This class represents a file property in a property form.
Class ChatMainBarProvider .
static prepareJsLinks(string $redraw_url, string $notes_url, string $tags_url, ilGlobalTemplateInterface $tpl=null)
Insert js/ajax links into template.
buildInputsForAdditionalDeletionReferences(int $ref_id, ilPathGUI $path_gui)
static _getAllReferences(int $id)
get all reference ids for object ID
redirectToRefId(int $ref_id, string $cmd="")
redirects to (repository) view per ref id usually to a container and usually used at the end of a sav...
isVisible(int $ref_id, string $type)
addComponent(\ILIAS\UI\Component\Component $a_comp)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCreationFormsHTML(array $forms)
Get HTML for creation forms (accordion)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
Import class.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
setRepositoryMode(bool $a_repositorymode)
const IL_COL_RIGHT
confirmedDeleteObject()
confirmed deletion of object -> objects are moved to trash or deleted immediately, if trash is disabled
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
viewObject()
viewObject container presentation for "administration -> repository, trash, permissions" ...
createObject()
create new object form
deleteObject(bool $error=false)
Display deletion confirmation screen.
setPermissions(int $parent_ref_id)
Manages favourites, currently the interface for other components, needs discussion.
setEnableEdit(bool $a_enableedit)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
$ilErr
Definition: raiseError.php:17
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
setFormAction(string $cmd, string $form_action)
addExternalEditFormCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCreationMode(bool $mode=true)
If true, a creation screen is displayed the current [ref_id] does belong to the parent class The mode...
importFileObject(int $parent_id=null)
const LONG_DESC_LENGTH
global $DIC
Definition: feed.php:28
getCenterColumnHTML()
Get center column.
createReference()
creates reference for object
ilLanguage $lng
parses the objects.xml it handles the xml-description of all ilias objects
const CREATE_OBJECT
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
string $requested_new_type
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...
const IL_SCREEN_FULL
This class represents a property in a property form.
UIFactory $ui_factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static add(int $a_action, int $a_ref_id, array $a_diff, bool $a_source_ref_id=false)
ilGlobalTemplateInterface $tpl
static _lookupTitle(int $obj_id)
ILIAS Notes Service $notes_service
checkWritePermissionOnRefIdArray(array $ref_ids)
initCreationForms(string $new_type)
Init creation forms.
Column user interface class.
ServerRequestInterface $request
const ADMIN_MODE_SETTINGS
ilRbacAdmin $rbac_admin
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
initDidacticTemplate(ilPropertyFormGUI $form)
Class ilObjectGUI Basic methods of all Output classes.
Interface RequestWrapper.
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
const UPLOAD_TYPE_UPLOAD_DIRECTORY
callCreationCallback(\ilObject $object, \ilObjectDefinition $obj_definition, int $requested_crtcb)
Repository GUI Utilities.
ilToolbarGUI $toolbar
static _recordWriteEvent(int $obj_id, int $usr_id, string $action, ?int $parent_obj_id=null)
Records a write event.
buildDeleletionModal(array $request_ids)
ilObjectService $object_service
header include for all ilias files.
afterSave(ilObject $new_object)
Post (successful) object creation hook.
static _getListGUIByType(string $type, int $context=ilObjectListGUI::CONTEXT_REPOSITORY)
afterImport(ilObject $new_object)
Post (successful) object import hook.
ilFavouritesManager $favourites
Base class for all sub item list gui&#39;s.
MultiObjectPropertiesManipulator $multi_object_manipulator
ArrayBasedRequestWrapper $post_wrapper
getMultiObjectPropertiesManipulator()
ilErrorHandling $error
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
getPath(int $a_startnode, int $a_endnode)
get path
addDidacticTemplateOptions(array &$a_options)
Add custom templates.
putObjectInTree(ilObject $obj, int $parent_node_id=null)
Add object to tree at given position.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
putInTree(int $parent_ref_id)
maybe this method should be in tree object!?
withReferences()
determines whether objects are referenced or not (got ref ids or not)
static getScreenMode()
addAvailabilityPeriodButtonToToolbar(ilToolbarGUI $toolbar)
getRightColumnHTML()
Display right column.
Error Handling & global info handling.
showPossibleSubObjects()
show possible sub objects (pull down menu)
static getInstanceByObjectType(string $a_obj_type)
static _gotoSharedWorkspaceNode(int $wsp_id)
getReturnLocation(string $cmd, string $default_location="")
Get return location for command (command is method name without "Object", e.g.
initCreateForm(string $new_type)
This class represents a text area property in a property form.
setReturnLocation(string $cmd, string $location)
set specific return location for command
ilAccessHandler $access
RequestWrapper $request_wrapper
validateCustom(ilPropertyFormGUI $form)
Validate custom values (if not possible with checkInput())
redirectAfterCreation()
Redirect after creation, see https://docu.ilias.de/goto_docu_wiki_wpage_5035_1357.html Should be overwritten and redirect to settings screen.
setColumnSettings(ilColumnGUI $column_gui)
updateObject()
updates object entry in object_data
setTargetFrame(string $cmd, string $target_frame)
Set specific target frame for command.
setTabs()
set admin tabs
ilObjectCustomIconFactory $custom_icon_factory
Class ilRbacAdmin Core functions for role based access control.
initHeaderAction(?string $sub_type=null, ?int $sub_id=null)
Add header action menu.
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded) ...
static _lookupType(int $id, bool $reference=false)
afterUpdate()
Post (successful) object update hook.
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_SCREEN_SIDE
addHeaderAction()
Add header action menu.
ilLocatorGUI $locator
static clear(string $a_var)
UIRenderer $ui_renderer
ilSetting $settings
getAdminTabs()
administration tabs show only permissions and trash folder
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAdminTabs()
set admin tabs
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded) ...
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
const IL_COL_LEFT
buildDeletionModalItems(array $ref_ids)