ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilObjObjectGroupGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Data\Factory as DataFactory;
25
35{
36 protected \ILIAS\ObjectGroup\InternalGUIService $gui;
38 protected ilTabsGUI $tabs;
39 protected ilHelpGUI $help;
40 private readonly DataFactory $data_factory;
41
42 public function __construct(
43 int $a_id = 0,
44 int $a_id_type = self::REPOSITORY_NODE_ID,
45 int $a_parent_node_id = 0
46 ) {
47 global $DIC;
48 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
49
50 $this->lng = $DIC->language();
51 $this->tabs = $DIC->tabs();
52 $this->access = $DIC->access();
53 $this->tpl = $DIC["tpl"];
54 $this->ctrl = $DIC->ctrl();
55 $this->locator = $DIC["ilLocator"];
56 $this->tree = $DIC->repositoryTree();
57 $this->help = $DIC["ilHelp"];
58 $this->gui = $DIC->objectGroup()->internal()->gui();
59 $this->og_request = $this->gui
60 ->standardRequest();
61 $this->data_factory = new DataFactory();
62 }
63
64 protected function afterConstructor(): void
65 {
67
68 $lng->loadLanguageModule("obgr");
69 $this->ctrl->saveParameter($this, array("ref_id"));
70 }
71
72 final public function getType(): string
73 {
74 return "obgr";
75 }
76
77 public function executeCommand(): void
78 {
79 $ilTabs = $this->tabs;
80 $next_class = $this->ctrl->getNextClass($this);
81
82 switch ($next_class) {
83 case 'ilpermissiongui':
84 $this->prepareOutput();
85 $ilTabs->activateTab("perm_settings");
86 $this->addHeaderAction();
87 $perm_gui = new ilPermissionGUI($this);
88 $this->ctrl->forwardCommand($perm_gui);
89 break;
90
91 case "ilcommonactiondispatchergui":
93 $this->ctrl->forwardCommand($gui);
94 break;
95
96 case strtolower(TranslationGUI::class):
97 $this->checkPermissionBool("write");
98 $this->prepareOutput();
99 $this->setSettingsSubTabs("settings_trans");
100 $transgui = new TranslationGUI(
101 $this->getObject(),
102 $this->lng,
103 $this->access,
104 $this->user,
105 $this->ctrl,
106 $this->tpl,
107 $this->ui_factory,
108 $this->ui_renderer,
109 $this->http,
110 $this->refinery,
111 $this->toolbar
112 );
113 $transgui->supportContentTranslation(false);
114 $this->ctrl->forwardCommand($transgui);
115 break;
116
117 case 'ildidactictemplategui':
118 $this->checkPermissionBool("write");
119 $this->prepareOutput();
120 $this->ctrl->setReturn($this, 'edit');
121 $did = new ilDidacticTemplateGUI($this, $this->og_request->getDidactivTemplateId());
122 $this->ctrl->forwardCommand($did);
123 break;
124
125 default:
126 $cmd = $this->ctrl->getCmd("listMaterials");
127 $this->prepareOutput();
128 $this->addHeaderAction();
129 $this->$cmd();
130 break;
131 }
132 }
133
134 public function addLocatorItems(): void
135 {
136 $ilLocator = $this->locator;
137 $ilAccess = $this->access;
138
139 if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId())) {
140 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $this->requested_ref_id);
141 }
142 }
143
144 protected function initEditCustomForm(ilPropertyFormGUI $form): void
145 {
146 $form->removeItemByPostVar("desc");
147
148 // Show didactic template type
149 $this->initDidacticTemplate($form);
150
151 // presentation
152 $pres = new ilFormSectionHeaderGUI();
153 $pres->setTitle($this->lng->txt('obj_presentation'));
154 $form->addItem($pres);
155
156 // display
157 $display_radio_group = new ilRadioGroupInputGUI($this->lng->txt('obgr_display'), ilObjectGroupAR::DISPLAY);
158 $display_radio_group->setRequired(true);
159 $form->addItem($display_radio_group);
160
161 $no_title_option = new ilRadioOption(
162 $this->lng->txt('obgr_display_without_title'),
164 );
165 $display_radio_group->addOption($no_title_option);
166
167 $with_title_option = new ilRadioOption(
168 $this->lng->txt('obgr_display_with_title'),
170 );
171 $display_radio_group->addOption($with_title_option);
172
173 $with_title_and_toggleable_option = new ilRadioOption(
174 $this->lng->txt('obgr_display_with_title_and_toggleable'),
176 );
177 $with_title_and_toggleable_option_radio_group = new ilRadioGroupInputGUI(
178 $this->lng->txt('obgr_display_with_title_and_toggleable'),
180 );
181 $with_title_and_toggleable_option_radio_group->setRequired(true);
182 $with_title_and_toggleable_option_radio_group->addOption(
183 new ilRadioOption(
184 $this->lng->txt('obgr_display_with_title_and_toggleable_initially_closed'),
186 )
187 );
188 $with_title_and_toggleable_option_radio_group->addOption(
189 new ilRadioOption(
190 $this->lng->txt('obgr_display_with_title_and_toggleable_initially_open'),
192 )
193 );
194 $with_title_and_toggleable_option->addSubItem($with_title_and_toggleable_option_radio_group);
195 $display_radio_group->addOption($with_title_and_toggleable_option);
196
197 // tile/list
198 $lpres = new ilRadioGroupInputGUI($this->lng->txt('obgr_list_presentation'), "list_presentation");
199
200 $std_list = new ilRadioOption($this->lng->txt('obgr_list_default'), "");
201 $std_list->setInfo($this->lng->txt('obgr_list_default_info'));
202 $lpres->addOption($std_list);
203
204 $item_list = new ilRadioOption($this->lng->txt('obgr_list'), "list");
205 $lpres->addOption($item_list);
206
207 $tile_view = new ilRadioOption($this->lng->txt('obgr_tile'), "tile");
208 $lpres->addOption($tile_view);
209
210 // tile size
211 $si = new ilRadioGroupInputGUI($this->lng->txt("obgr_tile_size"), "tile_size");
212 $dummy_container = new ilContainer();
213 $this->lng->loadLanguageModule("cont");
214 foreach ($dummy_container->getTileSizes() as $key => $txt) {
215 $op = new ilRadioOption($txt, $key);
216 $si->addOption($op);
217 }
218 $tile_view->addSubItem($si);
219 $si->setValue($this->object->getTileSize());
220
221 $lpres->setValue($this->object->getListPresentation());
222 $form->addItem($lpres);
223 }
224
225 public function edit(): void
226 {
227 if (!$this->checkPermissionBool("write")) {
228 $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
229 }
230
231 $this->tabs_gui->activateTab("settings");
232
233 $form = $this->initEditForm();
234 $values = $this->getEditFormValues();
235 if ($values) {
236 $form->setValuesByArray($values, true);
237 }
238
239 $this->addExternalEditFormCustom($form);
240
241 $this->tpl->setContent($form->getHTML());
242 $this->setSettingsSubTabs("general");
243 }
244
245 protected function afterUpdate(): void
246 {
247 // check if template is changed
249 $this->object->getRefId()
250 );
251 $new_tpl_id = $this->getDidacticTemplateVar('dtpl');
252
253 if ($new_tpl_id !== $current_tpl_id) {
254 $this->ctrl->setParameterByClass(ilDidacticTemplateGUI::class, "didactic_type", $new_tpl_id);
255 $this->ctrl->redirectByClass(ilDidacticTemplateGUI::class, "confirmTemplateSwitch");
256 return;
257 }
258 parent::afterUpdate();
259 }
260
261 public function listMaterials(): void
262 {
263 $this->checkPermission("write");
264
265 $this->tabs->activateTab("materials");
266
267 $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
268 $parent_type = ilObject::_lookupType($parent_ref_id, true);
269 $parent_gui_class = "ilObj{$this->obj_definition->getClassName($parent_type)}GUI";
270 $this->ctrl->setParameterByClass($parent_gui_class, 'ref_id', $parent_ref_id);
271 $add_new_item_gui = $this->resolveAddNewItemGUI();
272 $add_new_item_gui->renderToolbarAction();
273 $this->ctrl->clearParameterByClass($parent_gui_class, 'ref_id');
274
275
276 $this->tpl->setContent(
277 $this->ui_renderer->render(
278 $this->configureObjectsTable()->getComponents($this->getTableActionUrlBuilder())
279 )
280 );
281 }
282
284 {
285 $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
286 $parent_type = ilObject::_lookupType($parent_ref_id, true);
287 $parent_gui_class = "ilObj{$this->obj_definition->getClassName($parent_type)}GUI";
288
289 return new AddNewItemGUI(
292 $parent_gui_class,
293 $this->object->getRefId()
294 )
295 );
296 }
297
298 public function executeTableAction(): void
299 {
300 $this->checkPermission('write');
301 $this->configureObjectsTable()->execute($this->getTableActionUrlBuilder());
302 }
303
305 {
306 return new ObjectsTable(
307 $this->ctrl,
308 $this->lng,
309 $this->tpl,
310 $this->ui_factory,
311 $this->ui_renderer,
312 $this->http,
313 $this->refinery,
314 $this->object->getRefId(),
315 $this->object->getId()
316 );
317 }
318
320 {
321 return new URLBuilder($this->data_factory->uri(
322 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'executeTableAction')
323 ));
324 }
325
326 public function getCreatableObjectTypes(): array
327 {
328 $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
329 $parent_type = ilObject::_lookupType($parent_ref_id, true);
330 $parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
331 $parent_gui = new $parent_gui_class('', $parent_ref_id, true, false);
332 $types = $parent_gui->getCreatableObjectTypes();
333 foreach (array_merge(['obgr', 'sess' ], $this->obj_definition->getSideBlockTypes()) as $type_to_remove) {
334 unset($types[$type_to_remove]);
335 }
336 return $types;
337 }
338
339 public function getTemplate(): void
340 {
341 $this->tpl->loadStandardTemplate();
342 }
343
344 protected function setTabs(): void
345 {
346 $ilAccess = $this->access;
347 $ilTabs = $this->tabs;
348 $ilHelp = $this->help;
351
352 $ilHelp->setScreenIdComponent("obgr");
353
354 $parent_ref_id = $tree->getParentId($this->object->getRefId());
355 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
356 $parent_type = ilObject::_lookupType($parent_obj_id);
357
358 $ilTabs->setBackTarget(
359 $lng->txt('obj_' . $parent_type),
360 ilLink::_getLink($parent_ref_id),
361 "_top"
362 );
363
364 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
365 $ilTabs->addTab(
366 'materials',
367 $lng->txt('obgr_materials'),
368 $this->ctrl->getLinkTarget($this, 'listMaterials')
369 );
370
371 $ilTabs->addTab(
372 'settings',
373 $lng->txt('settings'),
374 $this->ctrl->getLinkTarget($this, 'edit')
375 );
376 }
377
378 if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
379 $ilTabs->addTab(
380 "perm_settings",
381 $lng->txt('perm_settings'),
382 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
383 );
384 }
385 }
386
387 protected function setSettingsSubTabs(string $active_tab = "general"): void
388 {
389 $this->tabs_gui->addSubTab(
390 "general",
391 $this->lng->txt("settings"),
392 $this->ctrl->getLinkTarget($this, "edit")
393 );
394
395 $this->tabs_gui->addSubTab(
396 "settings_trans",
397 $this->lng->txt("obj_multilinguality"),
398 $this->ctrl->getLinkTargetByClass(TranslationGUI::class, "")
399 );
400 $this->tabs_gui->activateTab("settings");
401 $this->tabs_gui->activateSubTab($active_tab);
402 }
403
404 public static function _goto(string $a_target): void
405 {
406 global $DIC;
407 $main_tpl = $DIC->ui()->mainTemplate();
408
409 $ilAccess = $DIC->access();
410 $lng = $DIC->language();
411 $tree = $DIC->repositoryTree();
412
413 $targets = explode('_', $a_target);
414 $ref_id = $targets[0];
415 $par_id = $tree->getParentId($ref_id);
416
417 if ($ilAccess->checkAccess("read", "", $par_id)) {
418 ilUtil::redirect(ilLink::_getLink($par_id));
419 exit;
420 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
421 $main_tpl->setOnScreenMessage('failure', sprintf(
422 $lng->txt("msg_no_perm_read_item"),
424 ), true);
426 }
427
428 throw new ilPermissionException($lng->txt("msg_no_perm_read"));
429 }
430
431 public function gotoParent(): void
432 {
433 $ilAccess = $this->access;
435
436 $ref_id = $this->object->getRefId();
437 $par_id = $tree->getParentId($ref_id);
438
439 if ($ilAccess->checkAccess("read", "", $par_id)) {
440 ilUtil::redirect(ilLink::_getLink($par_id));
441 exit;
442 }
443 }
444
448 public function afterSaveCallback(ilObject $a_obj): void
449 {
450 // add new object to materials
451 $items = new ilObjectGroupItems($this->object->getRefId());
452 $items->addItem($a_obj->getRefId());
453 $items->update();
454 }
455
459 protected function getEditFormCustomValues(array &$a_values): void
460 {
462 $object = $this->getObject();
463 $a_values[ilObjectGroupAR::DISPLAY] = $object->getDisplay();
464 $a_values[ilObjectGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY] = $object->getDisplayWithTitleAndToggleableInitially();
465 $a_values['list_presentation'] = $object->getListPresentation();
466 $a_values['tile_size'] = $object->getTileSize();
467 }
468
469 protected function updateCustom(ilPropertyFormGUI $form): void
470 {
472 $object = $this->getObject();
473 $object->setDisplay($form->getInput(ilObjectGroupAR::DISPLAY));
474 $object->setDisplayWithTitleAndToggleableInitially($form->getInput(ilObjectGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY));
475 $object->setListPresentation($form->getInput('list_presentation'));
476 $object->setTileSize($form->getInput('tile_size'));
477 }
478
479 protected function initCreateForm(string $new_type): \ILIAS\UI\Component\Input\Container\Form\Standard
480 {
481 $object = $this->getObject();
482 if ($object === null) {
483 $object = new ilObject();
484 }
485 $form_fields['title'] = $this->ui_factory->input()->field()->text($this->lng->txt('title'))
486 ->withMaxLength(ilObject::TITLE_LENGTH)
487 ->withRequired(true);
488
489 $didactic_templates = $this->didacticTemplatesToForm();
490
491 if ($didactic_templates !== null) {
492 $form_fields['didactic_templates'] = $didactic_templates;
493 }
494
495 return $this->ui_factory->input()->container()->form()->standard(
496 $this->ctrl->getFormAction($this, 'save'),
497 $form_fields
498 )->withSubmitLabel($this->lng->txt($new_type . '_add'));
499 }
500
501 public function save(): void
502 {
503 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
504 if (!$this->checkPermissionBool("create", "", $this->requested_new_type)) {
505 $this->error->raiseError($this->lng->txt("no_create_permission"), $this->error->MESSAGE);
506 }
507
508 $this->lng->loadLanguageModule($this->requested_new_type);
509 $this->ctrl->setParameter($this, "new_type", $this->requested_new_type);
510
511 $form = $this->initCreateForm($this->requested_new_type);
512 $data = $form->withRequest($this->request)->getData();
513 if ($data === null) {
514 $this->tpl->setContent($this->getCreationFormsHTML($form));
515 return;
516 }
517
518 $this->ctrl->setParameter($this, 'new_type', '');
519
520 $new_obj = new ilObjObjectGroup();
521 $new_obj->setType($this->requested_new_type);
522 $new_obj->processAutoRating();
523 $new_obj->setTitle($data['title']);
524 $new_obj->create();
525
526 $this->putObjectInTree($new_obj);
527
528 $dtpl = $data['didactic_templates'] ?? null;
529 if ($dtpl !== null) {
530 $dtpl_id = $this->parseDidacticTemplateVar($dtpl, 'dtpl');
531 $new_obj->applyDidacticTemplate($dtpl_id);
532 }
533
534 $this->ctrl->setParameterByClass(self::class, 'ref_id', $new_obj->getRefId());
535 $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
536 $this->ctrl->redirectByClass(self::class, "listMaterials");
537 }
538}
Builds data types.
Definition: Factory.php:36
Render add new item selector.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Class ilContainer.
GUI class for didactic template settings inside repository objects.
This class represents a section header in a property form.
Help GUI class.
loadLanguageModule(string $a_module)
Load language module.
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
User Interface class for object groups.
getType()
Functions that must be overwritten.
static _goto(string $a_target)
readonly DataFactory $data_factory
afterUpdate()
Post (successful) object update hook.
StandardGUIRequest $og_request
afterSaveCallback(ilObject $a_obj)
Custom callback after object is created (in parent container)
addLocatorItems()
Functions to be overwritten.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
initEditCustomForm(ilPropertyFormGUI $form)
Add custom fields to update form.
afterConstructor()
Do anything that should be done after constructor in here.
setSettingsSubTabs(string $active_tab="general")
ILIAS ObjectGroup InternalGUIService $gui
setTabs()
create tabs (repository/workspace switch)
Class ilObjObjectGroup.
New implementation of ilObjectGUI.
ilAccessHandler $access
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
ilLocatorGUI $locator
prepareOutput(bool $show_sub_objects=true)
buildAddNewItemElements(array $subtypes, string $create_target_class=ilRepositoryGUI::class, ?int $redirect_target_ref_id=null,)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
addExternalEditFormCustom(ilPropertyFormGUI $form)
getCreationFormsHTML(StandardForm|ilPropertyFormGUI|array $form)
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
initDidacticTemplate(ilPropertyFormGUI $form)
addHeaderAction()
Add header action menu.
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
parseDidacticTemplateVar(string $var, string $type)
const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED
const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY
const DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
const TITLE_LENGTH
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
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-...
removeItemByPostVar(string $a_post_var, bool $a_remove_unused_headers=false)
This class represents a property in a property form.
This class represents an option in a radio group.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getParentId(int $a_node_id)
get parent id of given node
static redirect(string $a_script)
const ROOT_FOLDER_ID
Definition: constants.php:32
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...