ILIAS  release_8 Revision v8.24
class.ilContainerStartObjectsGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
36 protected ilObject $object;
39 protected \ILIAS\Style\Content\GUIService $content_style_gui;
40 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
41
42 public function __construct(ilObject $a_parent_obj)
43 {
44 global $DIC;
45
46 $this->access = $DIC->access();
47 $this->settings = $DIC->settings();
48 $this->toolbar = $DIC->toolbar();
49 $ilCtrl = $DIC->ctrl();
50 $ilTabs = $DIC->tabs();
51 $lng = $DIC->language();
52 $tpl = $DIC["tpl"];
53
54 $this->ctrl = $ilCtrl;
55 $this->tabs_gui = $ilTabs;
56 $this->lng = $lng;
57 $this->tpl = $tpl;
58 $this->object = $a_parent_obj;
59
60 $this->start_object = new ilContainerStartObjects(
61 $this->object->getRefId(),
62 $this->object->getId()
63 );
64
65 $this->request = $DIC->container()
66 ->internal()
67 ->gui()
68 ->standardRequest();
69
70 $this->lng->loadLanguageModule("crs");
71 $cs = $DIC->contentStyle();
72 $this->content_style_domain = $cs->domain()->styleForRefId($a_parent_obj->getRefId());
73 $this->content_style_gui = $cs->gui();
74 }
75
76 public function executeCommand(): void
77 {
78 switch ($this->ctrl->getNextClass($this)) {
79 case "ilcontainerstartobjectspagegui":
80 $this->checkPermission("write");
81 $this->tabs_gui->clearTargets();
82 $this->tabs_gui->setBackTarget(
83 $this->lng->txt("back"),
84 $this->ctrl->getLinkTarget($this, "listStructure")
85 );
86
87 if (!ilContainerStartObjectsPage::_exists("cstr", $this->object->getId())) {
88 // doesn't exist -> create new one
89 $new_page_object = new ilContainerStartObjectsPage();
90 $new_page_object->setParentId($this->object->getId());
91 $new_page_object->setId($this->object->getId());
92 $new_page_object->createFromXML();
93 unset($new_page_object);
94 }
95
96 $this->content_style_gui->addCss(
97 $this->tpl,
98 $this->object->getRefId()
99 );
100
101 $this->ctrl->setReturnByClass("ilcontainerstartobjectspagegui", "edit");
102 $pgui = new ilContainerStartObjectsPageGUI($this->object->getId());
103 $pgui->setStyleId(
104 $this->content_style_domain->getEffectiveStyleId()
105 );
106
107 $ret = $this->ctrl->forwardCommand($pgui);
108 if ($ret) {
109 $this->tpl->setContent($ret);
110 }
111 break;
112
113 default:
114 $cmd = $this->ctrl->getCmd("listStructure");
115 $cmd .= "Object";
116 $this->$cmd();
117 break;
118 }
119 }
120
121 protected function checkPermission(string $a_cmd): void
122 {
123 $ilAccess = $this->access;
124
125 $ref_id = $this->object->getRefId();
126 if (!$ilAccess->checkAccess($a_cmd, "", $ref_id)) {
127 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
128 ilUtil::redirect("goto.php?target=" . $this->object->getType() . "_" . $ref_id);
129 }
130 }
131
132 public function setTabs(string $a_active = "manage"): void
133 {
135
136 $this->tabs_gui->addSubTab(
137 "manage",
138 $this->lng->txt("cntr_manage"),
139 $this->ctrl->getLinkTarget($this, "listStructure")
140 );
141
142 $this->tabs_gui->activateSubTab($a_active);
143 }
144
145 protected function listStructureObject(): void
146 {
147 $ilToolbar = $this->toolbar;
149
150 $this->checkPermission('write');
151 $this->setTabs();
152
153 $ilToolbar->addButton(
154 $this->lng->txt('crs_add_starter'),
155 $this->ctrl->getLinkTarget($this, 'selectStarter')
156 );
157
158 // :TODO: depending on this setting?
159 if ($ilSetting->get("enable_cat_page_edit")) {
160 $ilToolbar->addButton(
161 $this->lng->txt("cntr_text_media_editor"),
162 $this->ctrl->getLinkTargetByClass("ilContainerStartObjectsPageGUI", "edit")
163 );
164 }
165
166 $table = new ilContainerStartObjectsTableGUI($this, 'listStructure', $this->start_object);
167 $this->tpl->setContent($table->getHTML());
168 }
169
170 protected function saveSortingObject(): void
171 {
172 $pos = $this->request->getStartObjPositions();
173 if (is_array($pos)) {
174 asort($pos);
175 $counter = 0;
176 foreach (array_keys($pos) as $start_id) {
177 $counter += 10;
178 $this->start_object->setObjectPos($start_id, $counter);
179 }
180
181 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cntr_saved_sorting'), true);
182 }
183
184 $this->ctrl->redirect($this, "listStructure");
185 }
186
187 protected function askDeleteStarterObject(): void
188 {
189 if (count($this->request->getStartObjIds()) === 0) {
190 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
191 $this->ctrl->redirect($this, "listStructure");
192 }
193
194 $this->checkPermission('write');
195 $this->setTabs();
196
197 // display confirmation message
198 $cgui = new ilConfirmationGUI();
199 $cgui->setFormAction($this->ctrl->getFormAction($this, "listStructure"));
200 $cgui->setHeaderText($this->lng->txt("crs_starter_delete_sure"));
201 $cgui->setCancel($this->lng->txt("cancel"), "listStructure");
202 $cgui->setConfirm($this->lng->txt("remove"), "deleteStarter");
203
204 // list objects that should be deleted
205 $all = $this->start_object->getStartObjects();
206 foreach ($this->request->getStartObjIds() as $starter_id) {
207 $obj_id = ilObject::_lookupObjId($all[$starter_id]["item_ref_id"]);
208 $title = ilObject::_lookupTitle($obj_id);
209 $icon = ilObject::_getIcon($obj_id, "tiny");
210 $alt = $this->lng->txt('obj_' . ilObject::_lookupType($obj_id));
211 $cgui->addItem("starter[]", (string) $starter_id, $title, $icon, $alt);
212 }
213
214 $this->tpl->setContent($cgui->getHTML());
215 }
216
217 protected function deleteStarterObject(): void
218 {
219 $this->checkPermission('write');
220
221 if (count($this->request->getStartObjIds()) === 0) {
222 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
223 } else {
224 foreach ($this->request->getStartObjIds() as $starter_id) {
225 $this->start_object->delete((int) $starter_id);
226 }
227
228 $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_starter_deleted'), true);
229 }
230
231 $this->ctrl->redirect($this, "listStructure");
232 }
233
234 protected function selectStarterObject(): void
235 {
236 $this->checkPermission('write');
237 $this->setTabs();
238
239 $table = new ilContainerStartObjectsTableGUI($this, 'selectStarter', $this->start_object);
240 $this->tpl->setContent($table->getHTML());
241 }
242
243 protected function addStarterObject(): void
244 {
245 $this->checkPermission('write');
246
247 if (count($this->request->getStartObjIds()) === 0) {
248 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
249 $this->ctrl->redirect($this, "selectStarter");
250 }
251
252 $added = 0;
253 foreach ($this->request->getStartObjIds() as $item_ref_id) {
254 if (!$this->start_object->exists($item_ref_id)) {
255 ++$added;
256 $this->start_object->add($item_ref_id);
257 }
258 }
259 if ($added) {
260 $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_added_starters'), true);
261 $this->ctrl->redirect($this, "listStructure");
262 } else {
263 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_starters_already_assigned'), true);
264 $this->ctrl->redirect($this, "selectStarter");
265 }
266 }
267}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilContainerStartObjectsGUI.
ILIAS Style Content GUIService $content_style_gui
ILIAS Style Content Object ObjectFacade $content_style_domain
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static redirect(string $a_script)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
global $ilSetting
Definition: privfeed.php:17