ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContainerStartObjectsGUI.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\UI\Factory as UIFactory;
24
32{
33 protected ilCtrl $ctrl;
35 protected ilLanguage $lng;
40 protected UIFactory $ui_factory;
41 protected ilObject $object;
44 protected \ILIAS\Style\Content\GUIService $content_style_gui;
45 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
46
47 public function __construct(ilObject $a_parent_obj)
48 {
49 global $DIC;
50
51 $this->access = $DIC->access();
52 $this->settings = $DIC->settings();
53 $this->toolbar = $DIC->toolbar();
54 $this->ui_factory = $DIC->ui()->factory();
55 $ilCtrl = $DIC->ctrl();
56 $ilTabs = $DIC->tabs();
57 $lng = $DIC->language();
58 $tpl = $DIC["tpl"];
59
60 $this->ctrl = $ilCtrl;
61 $this->tabs_gui = $ilTabs;
62 $this->lng = $lng;
63 $this->tpl = $tpl;
64 $this->object = $a_parent_obj;
65
66 $this->start_object = new ilContainerStartObjects(
67 $this->object->getRefId(),
68 $this->object->getId()
69 );
70
71 $this->request = $DIC->container()
72 ->internal()
73 ->gui()
74 ->standardRequest();
75
76 $this->lng->loadLanguageModule("crs");
77 $cs = $DIC->contentStyle();
78 $this->content_style_domain = $cs->domain()->styleForRefId($a_parent_obj->getRefId());
79 $this->content_style_gui = $cs->gui();
80 }
81
82 public function executeCommand(): void
83 {
84 switch ($this->ctrl->getNextClass($this)) {
85 case "ilcontainerstartobjectspagegui":
86 $this->checkPermission("write");
87 $this->tabs_gui->clearTargets();
88 $this->tabs_gui->setBackTarget(
89 $this->lng->txt("back"),
90 $this->ctrl->getLinkTarget($this, "listStructure")
91 );
92
93 if (!ilContainerStartObjectsPage::_exists("cstr", $this->object->getId())) {
94 // doesn't exist -> create new one
95 $new_page_object = new ilContainerStartObjectsPage();
96 $new_page_object->setParentId($this->object->getId());
97 $new_page_object->setId($this->object->getId());
98 $new_page_object->createFromXML();
99 unset($new_page_object);
100 }
101
102 $this->content_style_gui->addCss(
103 $this->tpl,
104 $this->object->getRefId()
105 );
106
107 $this->ctrl->setReturnByClass("ilcontainerstartobjectspagegui", "edit");
108 $pgui = new ilContainerStartObjectsPageGUI($this->object->getId());
109 $pgui->setStyleId(
110 $this->content_style_domain->getEffectiveStyleId()
111 );
112
113 $ret = $this->ctrl->forwardCommand($pgui);
114 if ($ret) {
115 $this->tpl->setContent($ret);
116 }
117 break;
118
119 default:
120 $cmd = $this->ctrl->getCmd("listStructure");
121 $cmd .= "Object";
122 $this->$cmd();
123 break;
124 }
125 }
126
127 protected function checkPermission(string $a_cmd): void
128 {
129 $ilAccess = $this->access;
130
131 $ref_id = $this->object->getRefId();
132 if (!$ilAccess->checkAccess($a_cmd, "", $ref_id)) {
133 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
134 ilUtil::redirect("goto.php?target=" . $this->object->getType() . "_" . $ref_id);
135 }
136 }
137
138 public function setTabs(string $a_active = "manage"): void
139 {
141
142 $this->tabs_gui->addSubTab(
143 "manage",
144 $this->lng->txt("cntr_manage"),
145 $this->ctrl->getLinkTarget($this, "listStructure")
146 );
147
148 $this->tabs_gui->activateSubTab($a_active);
149 }
150
151 protected function listStructureObject(): void
152 {
153 $ilToolbar = $this->toolbar;
155
156 $this->checkPermission('write');
157 $this->setTabs();
158
159 $ilToolbar->addButton(
160 $this->lng->txt('crs_add_starter'),
161 $this->ctrl->getLinkTarget($this, 'selectStarter')
162 );
163
164 // :TODO: depending on this setting?
165 if ($ilSetting->get("enable_cat_page_edit")) {
166 $ilToolbar->addButton(
167 $this->lng->txt("cntr_text_media_editor"),
168 $this->ctrl->getLinkTargetByClass("ilContainerStartObjectsPageGUI", "edit")
169 );
170 }
171
172 $table = $this->buildObjectsTable();
173 if ($table->handleCommand()) {
174 return;
175 }
176
177 $this->tpl->setContent($table->render());
178 }
179
180 protected function buildObjectsTable(): TableAdapterGUI
181 {
182 $builder = new ObjectsTableBuilder(
183 $this,
184 'listStructure',
185 $this->start_object,
186 $this->lng,
187 $this->ui_factory
188 );
189 return $builder->getTable();
190 }
191
192 protected function saveSortingObject(): void
193 {
194 $table = $this->buildObjectsTable();
195 $pos = $table->getData();
196 if (is_array($pos)) {
197 $counter = 0;
198 foreach ($pos as $start_id) {
199 $counter += 10;
200 $this->start_object->setObjectPos($start_id, $counter);
201 }
202
203 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cntr_saved_sorting'), true);
204 }
205
206 $this->ctrl->redirect($this, "listStructure");
207 }
208
212 public function askDeleteStarter(array $start_obj_ids): void
213 {
214 if (count($start_obj_ids) === 0) {
215 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
216 $this->ctrl->redirect($this, "listStructure");
217 }
218
219 $this->checkPermission('write');
220 $this->setTabs();
221
222 // display confirmation message
223 $cgui = new ilConfirmationGUI();
224 $cgui->setFormAction($this->ctrl->getFormAction($this, "listStructure"));
225 $cgui->setHeaderText($this->lng->txt("crs_starter_delete_sure"));
226 $cgui->setCancel($this->lng->txt("cancel"), "listStructure");
227 $cgui->setConfirm($this->lng->txt("remove"), "deleteStarter");
228
229 // list objects that should be deleted
230 $all = $this->start_object->getStartObjects();
231 foreach ($start_obj_ids as $starter_id) {
232 $obj_id = ilObject::_lookupObjId($all[$starter_id]["item_ref_id"]);
233 $title = ilObject::_lookupTitle($obj_id);
234 $icon = ilObject::_getIcon($obj_id, "tiny");
235 $alt = $this->lng->txt('obj_' . ilObject::_lookupType($obj_id));
236 $cgui->addItem("starter[]", (string) $starter_id, $title, $icon, $alt);
237 }
238
239 $this->tpl->setContent($cgui->getHTML());
240 }
241
242 protected function deleteStarterObject(): void
243 {
244 $this->checkPermission('write');
245
246 if (count($this->request->getStartObjIds()) === 0) {
247 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
248 } else {
249 foreach ($this->request->getStartObjIds() as $starter_id) {
250 $this->start_object->delete((int) $starter_id);
251 }
252
253 $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_starter_deleted'), true);
254 }
255
256 $this->ctrl->redirect($this, "listStructure");
257 }
258
259 protected function selectStarterObject(): void
260 {
261 $this->checkPermission('write');
262 $this->setTabs();
263
264 $table = $this->buildPossibleObjectsTable();
265 if ($table->handleCommand()) {
266 return;
267 }
268
269 $this->tpl->setContent($table->render());
270 }
271
273 {
274 $builder = new PossibleObjectsTableBuilder(
275 $this,
276 'selectStarter',
277 $this->start_object,
278 $this->lng,
279 $this->ui_factory
280 );
281 return $builder->getTable();
282 }
283
287 public function addStarter(array $selected_ref_ids): void
288 {
289 $this->checkPermission('write');
290
291 if (count($selected_ref_ids) === 0) {
292 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
293 $this->ctrl->redirect($this, "selectStarter");
294 }
295
296 $added = 0;
297 foreach ($selected_ref_ids as $item_ref_id) {
298 if (!$this->start_object->exists($item_ref_id)) {
299 ++$added;
300 $this->start_object->add($item_ref_id);
301 }
302 }
303 if ($added) {
304 $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_added_starters'), true);
305 $this->ctrl->redirect($this, "listStructure");
306 } else {
307 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_starters_already_assigned'), true);
308 $this->ctrl->redirect($this, "selectStarter");
309 }
310 }
311}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
Container start objects page GUI class.
Container start objects page object.
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
Class ilObject Basic functions for all objects.
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.
ILIAS Setting Class.
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)
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$counter