ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjMDSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 use ILIAS\Data\URI;
27 
35 {
36  protected ?ilPropertyFormGUI $form = null;
37  protected ?ilMDSettings $md_settings = null;
40  protected Factory $refinery;
43 
44  public function __construct($a_data, $a_id, bool $a_call_by_reference = true, bool $a_prepare_output = true)
45  {
46  global $DIC;
47  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
48 
49  $this->type = 'mds';
50  $this->lng->loadLanguageModule("meta");
51  $this->http = $DIC->http();
52  $this->refinery = $DIC->refinery();
53  $this->ui_factory = $DIC->ui()->factory();
54  $this->ui_renderer = $DIC->ui()->renderer();
55  }
56 
57  protected function initEntryIdFromQuery(): int
58  {
59  $entry_id = 0;
60  if ($this->http->wrapper()->query()->has('entry_id')) {
61  $entry_id = $this->http->wrapper()->query()->retrieve(
62  'entry_id',
63  $this->refinery->kindlyTo()->int()
64  );
65  }
66  return $entry_id;
67  }
68 
69  protected function initEntryIdFromPost(): array
70  {
71  $entries = [];
72  if ($this->http->wrapper()->post()->has('entry_id')) {
73  return $this->http->wrapper()->post()->retrieve(
74  'entry_id',
75  $this->refinery->kindlyTo()->listOf(
76  $this->refinery->kindlyTo()->int()
77  )
78  );
79  }
80  return [];
81  }
82 
83  public function executeCommand(): void
84  {
85  $next_class = $this->ctrl->getNextClass($this);
86  $cmd = $this->ctrl->getCmd();
87 
88  $this->prepareOutput();
89 
90  if (!$this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
91  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
92  }
93 
94  switch ($next_class) {
95  case 'iladvancedmdsettingsgui':
96  $this->tabs_gui->setTabActive('md_advanced');
97  $adv_md = new ilAdvancedMDSettingsGUI(
99  $this->ref_id
100  );
101  $ret = $this->ctrl->forwardCommand($adv_md);
102  break;
103 
104  case 'ilpermissiongui':
105  $this->tabs_gui->setTabActive('perm_settings');
106 
107  $perm_gui = new ilPermissionGUI($this);
108  $ret = $this->ctrl->forwardCommand($perm_gui);
109  break;
110 
111  case 'ilmdcopyrightusagegui':
112  // this command is used if copyrightUsageGUI calls getParentReturn (see ...UsageGUI->setTabs)
113  $this->ctrl->setReturn($this, 'showCopyrightSettings');
114  $copyright_id = $this->initEntryIdFromQuery();
115  $gui = new ilMDCopyrightUsageGUI($copyright_id);
116  $this->ctrl->forwardCommand($gui);
117  break;
118 
119  default:
120  $this->initMDSettings();
121  if (!$cmd || $cmd === 'view') {
122  $cmd = "showGeneralSettings";
123  }
124 
125  $this->$cmd();
126  break;
127  }
128  }
129 
130  protected function getType(): string
131  {
132  return $this->type;
133  }
134 
135  protected function getParentObjType(): string
136  {
137  return 'meta';
138  }
139 
140  protected function getAdministrationFormId(): int
141  {
143  }
144 
145  public function getAdminTabs(): void
146  {
147  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
148  $this->tabs_gui->addTarget(
149  "md_general_settings",
150  $this->ctrl->getLinkTarget($this, "showGeneralSettings"),
151  array("showGeneralSettings", "view")
152  );
153 
154  $this->tabs_gui->addTarget(
155  "md_copyright",
156  $this->ctrl->getLinkTarget($this, "showCopyrightSettings"),
157  array("showCopyrightSettings")
158  );
159 
160  $this->tabs_gui->addTarget(
161  "md_advanced",
162  $this->ctrl->getLinkTargetByClass('iladvancedmdsettingsgui', ""),
163  '',
164  'iladvancedmdsettingsgui'
165  );
166  }
167 
168  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
169  $this->tabs_gui->addTarget(
170  "perm_settings",
171  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
172  array(),
173  'ilpermissiongui'
174  );
175  }
176  }
177 
178  public function showGeneralSettings(?ilPropertyFormGUI $form = null): void
179  {
180  if (!$form instanceof ilPropertyFormGUI) {
181  $form = $this->initGeneralSettingsForm();
182  }
183  $this->tpl->setContent($form->getHTML());
184  }
185 
186  public function initGeneralSettingsForm(string $a_mode = "edit"): ilPropertyFormGUI
187  {
188  $this->tabs_gui->setTabActive('md_general_settings');
189  $form = new ilPropertyFormGUI();
190  $ti = new ilTextInputGUI($this->lng->txt("md_delimiter"), "delimiter");
191  $ti->setInfo($this->lng->txt("md_delimiter_info"));
192  $ti->setMaxLength(1);
193  $ti->setSize(1);
194  $ti->setValue($this->md_settings->getDelimiter());
195  $form->addItem($ti);
196 
197  if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
198  $form->addCommandButton("saveGeneralSettings", $this->lng->txt("save"));
199  $form->addCommandButton("showGeneralSettings", $this->lng->txt("cancel"));
200  }
201  $form->setTitle($this->lng->txt("md_general_settings"));
202  $form->setFormAction($this->ctrl->getFormAction($this));
203  return $form;
204  }
205 
206  public function saveGeneralSettings(): void
207  {
208  if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
209  $this->ctrl->redirect($this, "showGeneralSettings");
210  }
211  $form = $this->initGeneralSettingsForm();
212  if ($form->checkInput()) {
213  $delim = $form->getInput('delimiter');
214  $delim = (
215  trim($delim) === '' ?
216  ',' :
217  trim($delim)
218  );
219  $this->md_settings->setDelimiter($delim);
220  $this->md_settings->save();
221  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
222  $this->ctrl->redirect($this, "showGeneralSettings");
223  }
224  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
225  $form->setValuesByPost();
226  $this->showGeneralSettings($form);
227  }
228 
229  public function showCopyrightSettings(?ilPropertyFormGUI $form = null): void
230  {
231  $this->tabs_gui->setTabActive('md_copyright');
232  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.settings.html', 'Services/MetaData');
233 
234  if (!$form instanceof ilPropertyFormGUI) {
235  $form = $this->initSettingsForm();
236  }
237  $this->tpl->setVariable('SETTINGS_TABLE', $form->getHTML());
238 
239  $has_write = $this->access->checkAccess('write', '', $this->object->getRefId());
240  $table_gui = new ilMDCopyrightTableGUI($this, 'showCopyrightSettings', $has_write);
241  $table_gui->setTitle($this->lng->txt("md_copyright_selection"));
242  $table_gui->parseSelections();
243 
244  if ($has_write) {
245  $table_gui->addCommandButton('addEntry', $this->lng->txt('add'));
246  $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
247  $table_gui->setSelectAllCheckbox("entry_id");
248  }
249  $this->tpl->setVariable('COPYRIGHT_TABLE', $table_gui->getHTML());
250  }
251 
252  public function saveCopyrightSettings(): void
253  {
254  if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
255  $this->ctrl->redirect($this, "showCopyrightSettings");
256  }
257  $form = $this->initSettingsForm();
258  if ($form->checkInput()) {
259  $this->md_settings->activateCopyrightSelection((bool) $form->getInput('active'));
260  $this->md_settings->save();
261  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
262  $this->ctrl->redirect($this, 'showCopyrightSettings');
263  }
264  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
265  $this->showCopyrightSettings($form);
266  }
267 
268  public function showCopyrightUsages(): void
269  {
270  $this->ctrl->setParameterByClass('ilmdcopyrightusagegui', 'entry_id', $this->initEntryIdFromQuery());
271  $this->ctrl->redirectByClass('ilmdcopyrightusagegui', "showUsageTable");
272  }
273 
274  public function editEntry(?StandardForm $form = null): void
275  {
276  $this->ctrl->saveParameter($this, 'entry_id');
277  if (!$form instanceof StandardForm) {
278  $form = $this->initCopyrightEditForm();
279  }
280  $this->tabs_gui->clearTargets();
281  $this->tabs_gui->setBackTarget(
282  $this->lng->txt('back'),
283  $post_url = $this->ctrl->getLinkTarget($this, 'showCopyrightSettings')
284  );
285  $this->tpl->setContent($this->ui_renderer->render($form));
286  }
287 
288  public function addEntry(?StandardForm $form = null): void
289  {
290  if (!$form instanceof StandardForm) {
291  $form = $this->initCopyrightEditForm('add');
292  }
293  $this->tabs_gui->clearTargets();
294  $this->tabs_gui->setBackTarget(
295  $this->lng->txt('back'),
296  $post_url = $this->ctrl->getLinkTarget($this, 'showCopyrightSettings')
297  );
298  $this->tpl->setContent($this->ui_renderer->render($form));
299  }
300 
301  public function saveEntry(): bool
302  {
303  $form = $this->initCopyrightEditForm('add')->withRequest($this->request);
304  if ($data = $form->getData()) {
305  $data = $data[0];
306  $this->entry = new ilMDCopyrightSelectionEntry(0);
307  $this->entry->setTitle($data['title']);
308  $this->entry->setDescription($data['description']);
309  $this->entry->setCopyrightData(
310  $data['copyright']['full_name'],
311  $data['copyright']['link'],
312  $data['copyright']['image_link'],
313  $data['copyright']['alt_text']
314  );
315  $this->entry->setOutdated((bool) $data['outdated']);
316  $this->entry->setLanguage('en');
317  $this->entry->setCopyrightAndOtherRestrictions(true);
318  $this->entry->setCosts(false);
319 
320  if (!$this->entry->validate()) {
321  $this->tpl->setOnScreenMessage('info', $this->lng->txt('fill_out_all_required_fields'));
322  $this->addEntry($form);
323  return false;
324  }
325  $this->entry->add();
326  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
327  $this->ctrl->redirect($this, 'showCopyrightSettings');
328  return true;
329  }
330  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
331  $this->addEntry($form);
332  return false;
333  }
334 
335  public function confirmDeleteEntries(): void
336  {
337  $entry_ids = $this->initEntryIdFromPost();
338  if (!count($entry_ids)) {
339  $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
340  $this->showCopyrightSettings();
341  return;
342  }
343 
344  $c_gui = new ilConfirmationGUI();
345  // set confirm/cancel commands
346  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
347  $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
348  $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSettings");
349  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
350 
351  // add items to delete
352  foreach ($entry_ids as $entry_id) {
353  $entry = new ilMDCopyrightSelectionEntry($entry_id);
354  $c_gui->addItem('entry_id[]', (string) $entry_id, $entry->getTitle());
355  }
356  $this->tpl->setContent($c_gui->getHTML());
357  }
358 
359  public function deleteEntries(): bool
360  {
361  $entry_ids = $this->initEntryIdFromPost();
362  if (!count($entry_ids)) {
363  $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
364  $this->showCopyrightSettings();
365  return true;
366  }
367 
368  foreach ($entry_ids as $entry_id) {
369  $entry = new ilMDCopyrightSelectionEntry($entry_id);
370  $entry->delete();
371  }
372  $this->tpl->setOnScreenMessage('success', $this->lng->txt('md_copyrights_deleted'));
373  $this->showCopyrightSettings();
374  return true;
375  }
376 
377  public function updateEntry(): bool
378  {
379  $this->entry = new ilMDCopyrightSelectionEntry($this->initEntryIdFromQuery());
380  $form = $this->initCopyrightEditForm()->withRequest($this->request);
381  if ($data = $form->getData()) {
382  $data = $data[0];
383  $this->entry->setTitle($data['title']);
384  $this->entry->setDescription($data['description']);
385  $this->entry->setCopyrightData(
386  $data['copyright']['full_name'],
387  $data['copyright']['link'],
388  $data['copyright']['image_link'],
389  $data['copyright']['alt_text']
390  );
391  $this->entry->setOutdated((bool) $data['outdated']);
392  if (!$this->entry->validate()) {
393  $this->tpl->setOnScreenMessage('info', $this->lng->txt('fill_out_all_required_fields'));
394  $this->editEntry($form);
395  return false;
396  }
397  $this->entry->update();
398  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
399  $this->ctrl->redirect($this, 'showCopyrightSettings');
400  return true;
401  }
402  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
403  $this->editEntry($form);
404  return false;
405  }
406 
407  protected function initSettingsForm(): ilPropertyFormGUI
408  {
409  $form = new ilPropertyFormGUI();
410  $form->setFormAction($this->ctrl->getFormAction($this));
411  $form->setTitle($this->lng->txt('md_copyright_settings'));
412 
413  if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
414  $form->addCommandButton('saveCopyrightSettings', $this->lng->txt('save'));
415  $form->addCommandButton('showCopyrightSettings', $this->lng->txt('cancel'));
416  }
417 
418  $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'), 'active');
419  $check->setChecked($this->md_settings->isCopyrightSelectionActive());
420  $check->setValue('1');
421  $check->setInfo($this->lng->txt('md_copyright_enable_info'));
422  $form->addItem($check);
423 
425  $this->getAdministrationFormId(),
426  $form,
427  $this
428  );
429  return $form;
430  }
431 
432  public function initCopyrightEditForm(string $a_mode = 'edit'): StandardForm
433  {
434  if (!is_object($this->entry)) {
435  $this->entry = new ilMDCopyrightSelectionEntry($this->initEntryIdFromQuery());
436  }
437 
438  $inputs = [];
439  $ff = $this->ui_factory->input()->field();
440 
441  $title = $ff
442  ->text($this->lng->txt('title'))
443  ->withValue($this->entry->getTitle())
444  ->withRequired(true)
445  ->withMaxLength(255);
446  $inputs['title'] = $title;
447 
448  $des = $ff
449  ->textarea($this->lng->txt('description'))
450  ->withValue($this->entry->getDescription());
451  $inputs['description'] = $des;
452 
453  $usage = $ff
454  ->radio($this->lng->txt('meta_copyright_usage'))
455  ->withOption('0', $this->lng->txt('meta_copyright_in_use'))
456  ->withOption('1', $this->lng->txt('meta_copyright_outdated'))
457  ->withValue((int) $this->entry->getOutdated());
458  $inputs['outdated'] = $usage;
459 
460  $cp_data = $this->entry->getCopyrightData();
461 
462  $full_name = $ff
463  ->text($this->lng->txt('md_copyright_full_name'))
464  ->withValue($cp_data->fullName());
465 
466  $link = $ff
467  ->url(
468  $this->lng->txt('md_copyright_link'),
469  $this->lng->txt('md_copyright_link_info')
470  )
471  ->withValue((string) $cp_data->link())
473  $this->refinery->custom()->transformation(fn ($v) => $v instanceof URI ? $v : null)
474  );
475 
476  $image_link = $ff
477  ->url($this->lng->txt('md_copyright_image_link'))
478  ->withValue((string) $cp_data->imageLink())
479  ->withAdditionalTransformation($this->refinery->custom()->transformation(
480  fn ($v) => $v instanceof URI ? $v : null
481  ));
482 
483  $alt_text = $ff
484  ->text(
485  $this->lng->txt('md_copyright_alt_text'),
486  $this->lng->txt('md_copyright_alt_text_info')
487  )
488  ->withValue($cp_data->altText());
489 
490  $cop = $ff
491  ->section(
492  [
493  'full_name' => $full_name,
494  'link' => $link,
495  'image_link' => $image_link,
496  'alt_text' => $alt_text
497  ],
498  $this->lng->txt('md_copyright_value')
499  );
500  $inputs['copyright'] = $cop;
501 
502  $form_title = '';
503  $post_url = '';
504  switch ($a_mode) {
505  case 'edit':
506  $form_title = $this->lng->txt('md_copyright_edit');
507  $post_url = $this->ctrl->getLinkTarget($this, 'updateEntry');
508  break;
509 
510  case 'add':
511  $form_title = $this->lng->txt('md_copyright_add');
512  $post_url = $this->ctrl->getLinkTarget($this, 'saveEntry');
513  break;
514  }
515  return $this->ui_factory->input()->container()->form()->standard(
516  $post_url,
517  [$ff->section($inputs, $form_title)]
518  );
519  }
520 
521  protected function initMDSettings(): void
522  {
523  $this->md_settings = ilMDSettings::_getInstance();
524  }
525 
526  public function saveCopyrightPosition(): bool
527  {
528  if (!$this->http->wrapper()->post()->has('order')) {
529  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_select_one'), true);
530  $this->ctrl->redirect($this, 'showCopyrightSettings');
531  return false;
532  }
533  $positions = $this->http->wrapper()->post()->retrieve(
534  'order',
535  $this->refinery->kindlyTo()->dictOf(
536  $this->refinery->kindlyTo()->string()
537  )
538  );
539  asort($positions);
540  $position = 0;
541  foreach ($positions as $entry_id => $position_ignored) {
542  $copyright = new ilMDCopyrightSelectionEntry($entry_id);
543  $copyright->setOrderPosition($position++);
544  $copyright->update();
545  }
546  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
547  $this->ctrl->redirect($this, 'showCopyrightSettings');
548  return false;
549  }
550 }
Interface GlobalHttpState.
prepareOutput(bool $show_sub_objects=true)
This class represents a checkbox property in a property form.
showGeneralSettings(?ilPropertyFormGUI $form=null)
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-...
addEntry(?StandardForm $form=null)
global $DIC
Definition: feed.php:28
initGeneralSettingsForm(string $a_mode="edit")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
setFormAction(string $a_formaction)
Class ilObjectGUI Basic methods of all Output classes.
__construct($a_data, $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
ilMDCopyrightSelectionEntry $entry
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
initCopyrightEditForm(string $a_mode='edit')
editEntry(?StandardForm $form=null)
showCopyrightSettings(?ilPropertyFormGUI $form=null)
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
$check
Definition: buildRTE.php:81
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...