ILIAS  release_8 Revision v8.23
class.ilObjBibliographicGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
38 {
39  use \ILIAS\Modules\OrgUnit\ARHelper\DIC;
40 
41  public const P_ENTRY_ID = 'entry_id';
42  public const CMD_SHOW_CONTENT = 'showContent';
43  public const CMD_SEND_FILE = "sendFile";
44  public const TAB_CONTENT = "content";
45  public const SUB_TAB_FILTER = "filter";
46  public const CMD_VIEW = "view";
47  public const TAB_EXPORT = "export";
48  public const TAB_SETTINGS = self::SUBTAB_SETTINGS;
49  public const TAB_ID_RECORDS = "id_records";
50  public const TAB_ID_PERMISSIONS = "id_permissions";
51  public const TAB_ID_INFO = "id_info";
52  public const CMD_SHOW_DETAILS = "showDetails";
53  public const CMD_EDIT = "edit";
54  public const SUBTAB_SETTINGS = "settings";
55  public const CMD_EDIT_OBJECT = 'editObject';
56  public const CMD_UPDATE_OBJECT = 'updateObject';
57 
58  public ?ilObject $object = null;
59  protected ?\ilBiblFactoryFacade $facade = null;
60  protected \ilBiblTranslationFactory $translation_factory;
61  protected \ilBiblFieldFactory $field_factory;
62  protected \ilBiblFieldFilterFactory $filter_factory;
63  protected \ilBiblTypeFactory $type_factory;
67  protected $storage;
68  protected \ilObjBibliographicStakeholder $stakeholder;
69  protected ?string $cmd = self::CMD_SHOW_CONTENT;
70 
71  public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
72  {
73  global $DIC;
74 
75  $this->storage = $DIC['resource_storage'];
76  $this->stakeholder = new ilObjBibliographicStakeholder();
77 
78  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
79  $DIC->language()->loadLanguageModule('bibl');
80  $DIC->language()->loadLanguageModule('content');
81  $DIC->language()->loadLanguageModule('obj');
82  $DIC->language()->loadLanguageModule('cntr');
83 
84  if (is_object($this->object)) {
86  $obj = $this->object;
87  $this->facade = new ilBiblFactoryFacade($obj);
88  }
89  }
90 
94  public function getStandardCmd(): string
95  {
96  return self::CMD_VIEW;
97  }
98 
103  public function getType(): string
104  {
105  return "bibl";
106  }
107 
111  public function executeCommand(): void
112  {
113  global $DIC;
114  $ilNavigationHistory = $DIC['ilNavigationHistory'];
115 
116  // Navigation History
117  $link = $this->dic()->ctrl()->getLinkTarget($this, $this->getStandardCmd());
118  if ($this->object != null) {
119  $ilNavigationHistory->addItem($this->object->getRefId(), $link, "bibl");
120  $this->addHeaderAction();
121  }
122 
123  // general Access Check, especially for single entries not matching the object
124  if ($this->object instanceof ilObjBibliographic && !$DIC->access()->checkAccess(
125  'read',
126  "",
127  $this->object->getRefId()
128  )) {
129  $this->handleNonAccess();
130  }
131 
132  $next_class = $this->dic()->ctrl()->getNextClass($this);
133  $this->cmd = $this->dic()->ctrl()->getCmd();
134  switch ($next_class) {
135  case strtolower(ilInfoScreenGUI::class):
136  $this->prepareOutput();
137  $this->dic()->tabs()->activateTab(self::TAB_ID_INFO);
138  $this->infoScreenForward();
139  break;
140  case strtolower(ilCommonActionDispatcherGUI::class):
141  $this->prepareOutput();
143  $this->ctrl->forwardCommand($gui);
144  break;
145  case strtolower(ilPermissionGUI::class):
146  $this->prepareOutput();
147  $this->dic()->tabs()->activateTab(self::TAB_ID_PERMISSIONS);
148  $this->ctrl->forwardCommand(new ilPermissionGUI($this));
149  break;
150  case strtolower(ilObjectCopyGUI::class):
151  $cp = new ilObjectCopyGUI($this);
152  $cp->setType('bibl');
153  $this->dic()['tpl']->loadStandardTemplate();
154  $this->ctrl->forwardCommand($cp);
155  break;
156  case strtolower(ilExportGUI::class):
157  $this->prepareOutput();
158  $this->dic()->tabs()->setTabActive(self::TAB_EXPORT);
159  $exp_gui = new ilExportGUI($this);
160  $exp_gui->addFormat("xml");
161  $this->ctrl->forwardCommand($exp_gui);
162  break;
163  case strtolower(ilBiblFieldFilterGUI::class):
164  $this->prepareOutput();
165  $this->dic()->tabs()->setTabActive(self::TAB_SETTINGS);
166  $this->initSubTabs();
167  $this->tabs_gui->activateSubTab(self::SUB_TAB_FILTER);
168  $this->ctrl->forwardCommand(new ilBiblFieldFilterGUI($this->facade));
169  break;
170  default:
171  $this->prepareOutput();
172  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_CONTENT);
173  switch ($cmd) {
174  case 'edit':
175  case 'update':
176  case self::CMD_EDIT_OBJECT:
177  case self::CMD_UPDATE_OBJECT:
178  $this->initSubTabs();
179  $this->tabs_gui->activateSubTab(self::SUBTAB_SETTINGS);
180  $this->{$cmd}();
181  break;
182  default:
183  $this->{$cmd}();
184  break;
185  }
186  break;
187  }
188  }
189 
195  public function infoScreen(): void
196  {
197  $this->ctrl->setCmd("showSummary");
198  $this->ctrl->setCmdClass(ilInfoScreenGUI::class);
199  $this->infoScreenForward();
200  }
201 
205  public function infoScreenForward(): void
206  {
207  global $DIC;
212  if (!$this->checkPermissionBoolAndReturn("visible") && !$this->checkPermissionBoolAndReturn('read')) {
213  $this->tpl->setOnScreenMessage('failure', $DIC['lng']->txt("msg_no_perm_read"), true);
214  $this->ctrl->redirectByClass('ilDashboardGUI', '');
215  }
216  $DIC->tabs()->activateTab(self::TAB_ID_INFO);
217  $info = new ilInfoScreenGUI($this);
218 
219  $info->enablePrivateNotes();
220  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
221 
222  // Storage Info
223  $irss = new ilResourceStorageInfoGUI($this->object->getResourceId());
224  $irss->append($info);
225 
226  $this->ctrl->forwardCommand($info);
227  }
228 
229  /*
230  * addLocatorItems
231  */
232  public function addLocatorItems(): void
233  {
234  global $DIC;
235  $ilLocator = $DIC['ilLocator'];
236  if (is_object($this->object)) {
237  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
238  }
239  }
240 
245  public static function _goto(string $a_target): void
246  {
247  global $DIC;
248 
249  $id = explode("_", $a_target);
250  $DIC->ctrl()->setTargetScript('ilias.php');
251  $DIC->ctrl()->setParameterByClass(ilObjBibliographicGUI::class, "ref_id", (int) ($id[0] ?? 1));
252  // Detail-View
253  if (isset($id[1]) && $id[1] !== '') {
254  $DIC->ctrl()
255  ->setParameterByClass(ilObjBibliographicGUI::class, ilObjBibliographicGUI::P_ENTRY_ID, $id[1]);
256  $DIC->ctrl()->redirectByClass(
257  array(
258  ilRepositoryGUI::class,
259  ilObjBibliographicGUI::class,
260  ),
261  self::CMD_SHOW_DETAILS
262  );
263  } else {
264  $DIC->ctrl()->redirectByClass(
265  array(
266  ilRepositoryGUI::class,
267  ilObjBibliographicGUI::class,
268  ),
269  self::CMD_VIEW
270  );
271  }
272  }
273 
277  protected function initCreationForms(string $a_new_type): array
278  {
279  global $DIC;
280 
281  $forms = parent::initCreationForms($a_new_type);
282  // Add File-Upload
283  $in_file = new ilFileInputGUI($DIC->language()->txt("bibliography_file"), "bibliographic_file");
284  $in_file->setSuffixes(array("ris", "bib", "bibtex"));
285  $in_file->setRequired(true);
286  $forms[self::CFORM_NEW]->addItem($in_file);
287  $this->ctrl->saveParameterByClass('ilobjrootfoldergui', 'new_type');
288  $forms[self::CFORM_NEW]->setFormAction($this->ctrl->getFormActionByClass('ilobjrootfoldergui', "save"));
289 
290  return $forms;
291  }
292 
293  public function save(): void
294  {
295  global $DIC;
296 
297  $form = $this->initCreationForms($this->getType());
298  if ($form[self::CFORM_NEW]->checkInput()) {
299  parent::save();
300  } else {
301  $form = $form[self::CFORM_NEW];
302  $form->setValuesByPost();
303  $DIC->ui()->mainTemplate()->setContent($form->getHtml());
304  }
305  }
306 
307  protected function afterSave(ilObject $a_new_object): void
308  {
309  $this->addNews($a_new_object->getId(), 'created');
310  $this->ctrl->redirect($this, self::CMD_EDIT);
311  }
312 
318  public function setTabs(): void
319  {
320  global $DIC;
321 
322  $ilHelp = $DIC['ilHelp'];
326  $ilHelp->setScreenIdComponent('bibl');
327  // info screen
328  if ($DIC->access()->checkAccess('read', "", $this->object->getRefId())) {
329  $DIC->tabs()->addTab(
330  self::TAB_CONTENT,
331  $DIC->language()
332  ->txt(self::TAB_CONTENT),
333  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_CONTENT)
334  );
335  }
336  // info screen
337  if ($DIC->access()->checkAccess('visible', "", $this->object->getRefId())
338  || $DIC->access()->checkAccess('read', "", $this->object->getRefId())
339  ) {
340  $DIC->tabs()->addTab(
341  self::TAB_ID_INFO,
342  $DIC->language()
343  ->txt("info_short"),
344  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary")
345  );
346  }
347  // settings
348  if ($DIC->access()->checkAccess('write', "", $this->object->getRefId())) {
349  $DIC->tabs()->addTab(
350  self::SUBTAB_SETTINGS,
351  $DIC->language()
352  ->txt(self::SUBTAB_SETTINGS),
353  $this->ctrl->getLinkTarget($this, self::CMD_EDIT_OBJECT)
354  );
355  }
356  // export
357  if ($DIC->access()->checkAccess("write", "", $this->object->getRefId())) {
358  $DIC->tabs()->addTab(
359  self::TAB_EXPORT,
360  $DIC->language()
361  ->txt(self::TAB_EXPORT),
362  $this->ctrl->getLinkTargetByClass("ilexportgui", "")
363  );
364  }
365  // edit permissions
366  if ($DIC->access()->checkAccess('edit_permission', "", $this->object->getRefId())) {
367  $DIC->tabs()->addTab(
368  self::TAB_ID_PERMISSIONS,
369  $DIC->language()
370  ->txt("perm_settings"),
371  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm")
372  );
373  }
374  }
375 
376  protected function initSubTabs(): void
377  {
378  global $DIC;
379  $DIC->tabs()->addSubTab(
380  self::SUBTAB_SETTINGS,
381  $DIC->language()
382  ->txt(self::SUBTAB_SETTINGS),
383  $this->ctrl->getLinkTarget($this, self::CMD_EDIT_OBJECT)
384  );
385  $DIC->tabs()->addSubTab(
386  self::SUB_TAB_FILTER,
387  $DIC->language()
388  ->txt("bibl_filter"),
389  $this->ctrl->getLinkTargetByClass(ilBiblFieldFilterGUI::class, ilBiblFieldFilterGUI::CMD_STANDARD)
390  );
391  }
392 
397  public function editObject(): void
398  {
399  $tpl = $this->tpl;
400  $ilTabs = $this->tabs_gui;
402 
403  if (!$this->checkPermissionBool("write")) {
404  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
405  }
406 
407  $ilTabs->activateTab("settings");
408 
409  $form = $this->initEditForm();
410  $values = $this->getEditFormValues();
411  if ($values !== []) {
412  $form->setValuesByArray($values, true);
413  }
414 
415  $this->addExternalEditFormCustom($form);
416 
417  $tpl->setContent($form->getHTML());
418  }
419 
420  public function initEditForm(): \ilPropertyFormGUI
421  {
422  global $DIC;
423 
424  $form = parent::initEditForm();
425  // Add File-Upload
426  $in_file = new ilFileInputGUI(
427  $DIC->language()
428  ->txt("bibliography_file"),
429  "bibliographic_file"
430  );
431  $in_file->setSuffixes(array("ris", "bib", "bibtex"));
432  $in_file->setRequired(false);
433  $cb_override = new ilCheckboxInputGUI(
434  $DIC->language()
435  ->txt("override_entries"),
436  "override_entries"
437  );
438  $cb_override->addSubItem($in_file);
439 
440  $form->addItem($cb_override);
441 
442  $section_appearance = new ilFormSectionHeaderGUI();
443  $section_appearance->setTitle($this->lng->txt('cont_presentation'));
444  $form->addItem($section_appearance);
445  $DIC->object()->commonSettings()->legacyForm($form, $this->object)->addTileImage();
446 
447  $form->setFormAction($DIC->ctrl()->getFormAction($this, "save"));
448 
449  return $form;
450  }
451 
452  protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
453  {
454  global $DIC;
455 
456  $DIC->tabs()->activateTab(self::SUBTAB_SETTINGS);
457  // is_online
458  $cb = new ilCheckboxInputGUI($DIC->language()->txt("online"), "is_online");
459  $a_form->addItem($cb);
460  }
461 
462  public function getEditFormCustomValues(array &$values): void
463  {
464  $values["is_online"] = $this->object->getOnline();
465  }
466 
467  public function render(): void
468  {
469  $this->showContent();
470  }
471 
475  public function showContent(): void
476  {
477  global $DIC;
478 
479  // if user has read permission and object is online OR user has write permissions
480  $read_access = $DIC->access()->checkAccess('read', "", $this->object->getRefId());
481  $online = $this->object->getOnline();
482  $write_access = $DIC->access()->checkAccess('write', "", $this->object->getRefId());
483  if (($read_access && $online) || $write_access) {
484  $DIC->tabs()->activateTab(self::TAB_CONTENT);
485 
487  $b->setCaption('download_original_file');
488  $b->setUrl($DIC->ctrl()->getLinkTargetByClass(self::class, self::CMD_SEND_FILE));
489  $b->setPrimary(true);
490  $DIC->toolbar()->addButtonInstance($b);
491 
492  $table = new ilBiblEntryTableGUI($this, $this->facade);
493  $html = $table->getHTML();
494  $DIC->ui()->mainTemplate()->setContent($html);
495 
496  //Permanent Link
497  $DIC->ui()->mainTemplate()->setPermanentLink("bibl", $this->object->getRefId());
498  } else {
499  $object_title = ilObject::_lookupTitle(ilObject::_lookupObjId($this->ref_id));
500  $this->tpl->setOnScreenMessage('failure', sprintf(
501  $DIC->language()
502  ->txt("msg_no_perm_read_item"),
503  $object_title
504  ), true);
505  //redirect to repository without any parameters
506  $this->handleNonAccess();
507  }
508  }
509 
510  protected function applyFilter(): void
511  {
512  $table = new ilBiblEntryTableGUI($this, $this->facade);
513  $table->writeFilterToSession();
514  $table->resetOffset();
515  $this->ctrl->redirect($this, self::CMD_SHOW_CONTENT);
516  }
517 
518  protected function resetFilter(): void
519  {
520  $table = new ilBiblEntryTableGUI($this, $this->facade);
521  $table->resetFilter();
522  $table->resetOffset();
523  $this->ctrl->redirect($this, self::CMD_SHOW_CONTENT);
524  }
525 
529  public function sendFile(): void
530  {
531  global $DIC;
532 
533  if ($DIC['ilAccess']->checkAccess('read', "", $this->object->getRefId())) {
534  if (!$this->object->isMigrated()) {
535  $file_path = $this->object->getLegacyAbsolutePath();
536  if ($file_path) {
537  if (is_file($file_path)) {
539  $file_path,
540  $this->object->getFilename(),
541  'application/octet-stream'
542  );
543  } else {
544  $this->tpl->setOnScreenMessage('failure', $DIC['lng']->txt("file_not_found"));
545  $this->showContent();
546  }
547  }
548  } else {
549  $this->storage->consume()->download($this->object->getResourceId())->run();
550  }
551  } else {
552  $this->handleNonAccess();
553  }
554  }
555 
556  public function showDetails(): void
557  {
558  global $DIC;
559 
560  if ($DIC->access()->checkAccess('read', "", $this->object->getRefId())) {
561  $id = $DIC->http()->request()->getQueryParams()[self::P_ENTRY_ID];
562  $entry = $this->facade->entryFactory()
563  ->findByIdAndTypeString($id, $this->object->getFileTypeAsString());
564  $bibGUI = new ilBiblEntryDetailPresentationGUI($entry, $this->facade);
565 
566  $DIC->ui()->mainTemplate()->setContent($bibGUI->getHTML());
567  } else {
568  $this->handleNonAccess();
569  }
570  }
571 
572  public function view(): void
573  {
574  $this->showContent();
575  }
576 
580  public function updateCustom(ilPropertyFormGUI $a_form): void
581  {
582  global $DIC;
583 
584  if ($DIC->access()->checkAccess('write', "", $this->object->getRefId())) {
585  if ($this->object->getOnline() != $a_form->getInput("is_online")) {
586  $this->object->setOnline($a_form->getInput("is_online"));
587  }
588 
589  if (!empty($_FILES['bibliographic_file']['name'])) {
590  $this->addNews($this->object->getId(), 'updated');
591  }
592 
593  $DIC->object()->commonSettings()->legacyForm($a_form, $this->object)->saveTileImage();
594  } else {
595  $this->handleNonAccess();
596  }
597  }
598 
599  public function toggleNotification(): void
600  {
601  global $DIC;
602  $ntf = $DIC->http()->wrapper()->query()->retrieve(
603  "ntf",
604  $DIC->refinery()->to()->int()
605  );
606 
607  switch ($ntf) {
608  case 1:
611  $DIC->user()
612  ->getId(),
614  false
615  );
616  break;
617  case 2:
620  $DIC->user()
621  ->getId(),
623  true
624  );
625  break;
626  }
627  $DIC->ctrl()->redirect($this, "");
628  }
629 
630  public function addNews(int $obj_id, string $change = 'created'): void
631  {
632  global $DIC;
633 
634  $ilNewsItem = new ilNewsItem();
635  $ilNewsItem->setTitle($DIC->language()->txt('news_title_' . $change));
636  $ilNewsItem->setPriority(NEWS_NOTICE);
637  $ilNewsItem->setContext($obj_id, $this->getType());
638  $ilNewsItem->setUserId($DIC->user()->getId());
639  $ilNewsItem->setVisibility(NEWS_USERS);
640  $ilNewsItem->setContentTextIsLangVar(false);
641  $ilNewsItem->create();
642  }
643 
648  public function addToDesk(): void
649  {
650  $this->addToDeskObject();
651  }
652 
657  public function removeFromDesk(): void
658  {
659  $this->removeFromDeskObject();
660  }
661 
662  protected function afterImport(ilObject $a_new_object): void
663  {
667  $a_new_object->parseFileToDatabase();
668 
669  parent::afterImport($a_new_object);
670  }
671 
672  private function handleNonAccess(): void
673  {
674  global $DIC;
675 
676  $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt("no_permission"), true);
678  }
679 }
afterSave(ilObject $a_new_object)
Class ilObjBibliographicGUI.
Class ilInfoScreenGUI.
ilErrorHandling $error
removeFromDesk()
Remove from desktop.
New implementation of ilObjectGUI.
GUI class for the workflow of copying objects.
ilBiblFieldFilterFactory $filter_factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
updateCustom(ilPropertyFormGUI $a_form)
updateSettings
This class represents a checkbox property in a property form.
prepareOutput(bool $show_sub_objects=true)
setSuffixes(array $a_suffixes)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilObjBibliographicStakeholder $stakeholder
sendFile()
provide file as a download
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
$ilErr
Definition: raiseError.php:17
Class ilResourceStorageInfoGUI.
addExternalEditFormCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
static setNotification(int $type, int $user_id, int $id, bool $status=true)
Set notification status for object and user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
Class ilObjBibliographicStakeholder.
const NEWS_NOTICE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
ilGlobalTemplateInterface $tpl
afterImport(ilObject $new_object)
Post (successful) object import hook.
ilBiblTranslationFactory $translation_factory
removeFromDeskObject()
Remove from desktop public.
setTabs()
create tabs (repository/workspace switch)
A news item can be created by different sources.
addNews(int $obj_id, string $change='created')
initEditCustomForm(ilPropertyFormGUI $a_form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
showContent()
shows the overview page with all entries in a table
addToDeskObject()
Add desktop item public.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
const NEWS_USERS
static _goto(string $a_target)
_goto Deep link
Class ilObjBibliographic.
Class ilBiblEntryDetailPresentationGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHeaderAction()
Add header action menu.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
infoScreen()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually...