ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilContentStyleSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
32{
34 protected \ILIAS\Style\Content\InternalDomainService $domain;
37 protected int $obj_id;
40 protected ilTree $tree;
41 protected ilCtrl $ctrl;
44 protected ilLanguage $lng;
47 protected int $ref_id;
48
49 public function __construct(ilObjStyleSettingsGUI $a_parent_gui)
50 {
51 global $DIC;
52
53 $this->tree = $DIC->repositoryTree();
54 $this->settings = $DIC->settings();
55
56 $this->parent_gui = $a_parent_gui;
57 $this->ctrl = $DIC->ctrl();
58 $this->rbacsystem = $DIC->rbac()->system();
59 $this->toolbar = $DIC->toolbar();
60 $this->lng = $DIC->language();
61 $this->tpl = $DIC->ui()->mainTemplate();
62 $this->request = $DIC->contentStyle()
63 ->internal()
64 ->gui()
65 ->standardRequest();
66
67 $this->ref_id = $this->request->getRefId();
68 $this->obj_id = $this->request->getObjId(); // note that reference ID is the id of the style settings node and object ID may be a style sheet object ID
69
70 $this->cs_settings = new ilContentStyleSettings();
71 $this->gui = $DIC->contentStyle()->internal()->gui();
72 $this->domain = $DIC->contentStyle()->internal()->domain();
73 }
74
75 public function executeCommand(): void
76 {
77 $next_class = $this->ctrl->getNextClass($this);
78 $cmd = $this->ctrl->getCmd("edit");
79
80 switch ($next_class) {
81 case "ilobjstylesheetgui":
82 $this->ctrl->setReturn($this, "edit");
83 $style_gui = new ilObjStyleSheetGUI("", $this->obj_id, false);
84 $this->ctrl->forwardCommand($style_gui);
85 break;
86
87 case strtolower(ilRepoStandardUploadHandlerGUI::class):
88 $form = $this->getImportForm();
89 $gui = $form->getRepoStandardUploadHandlerGUI("import_file");
90 $this->ctrl->forwardCommand($gui);
91 break;
92
93
94 default:
95 $this->parent_gui->prepareOutput();
96 if (in_array($cmd, array("edit",
97 "delete",
98 "toggleGlobalDefault",
99 "toggleGlobalFixed",
100 "setScope",
101 "saveScope",
102 "saveActiveStyles",
103 "createStyle",
104 "moveLMStyles",
105 "moveIndividualStyles",
106 "deleteStyle",
107 "cancelDelete",
108 "confirmedDelete",
109 "import"
110 ))) {
111 $this->$cmd();
112 } else {
113 die("Unknown command " . $cmd);
114 }
115 }
116 }
117
122 public function checkPermission(string $a_perm, bool $a_throw_exc = true): bool
123 {
124 if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id)) {
125 if ($a_throw_exc) {
126 throw new ilObjectException($this->lng->txt("permission_denied"));
127 }
128 return false;
129 }
130 return true;
131 }
132
133 public function createStyle(): void
134 {
135 $ilCtrl = $this->ctrl;
136
137 // $ilCtrl->setParameterByClass("ilobjstylesheetgui", "new_type", "sty");
138 $ilCtrl->redirectByClass("ilobjstylesheetgui", "create");
139 }
140
144 public function edit(): void
145 {
146 $this->checkPermission("visible,read");
147
148 // @todo: check these, they are checked later, but never (ILIAS 6) set
149 $fixed_style = 0;
150 $default_style = 0;
151
152 // this may not be cool, if styles are organised as (independent) Service
153 $from_styles = $to_styles = $data = array();
154 $styles = $this->cs_settings->getStyles();
155 foreach ($styles as $style) {
156 $style["active"] = ilObjStyleSheet::_lookupActive((int) $style["id"]);
157 $style["lm_nr"] = $this->domain->object(0)->countObjSelected((int) $style["id"]);
158 $data[$style["title"] . ":" . $style["id"]]
159 = $style;
160 if ($style["lm_nr"] > 0) {
161 $from_styles[$style["id"]] = $style["title"];
162 }
163 if ($style["active"] > 0) {
164 $to_styles[$style["id"]] = $style["title"];
165 }
166 }
167
168 // number of individual styles
169 if ($fixed_style <= 0) {
170 $data[-1] =
171 array("title" => $this->lng->txt("sty_individual_styles"),
172 "id" => 0, "lm_nr" => $this->domain->object(0)->countOverallOwned());
173 //$from_styles[-1] = $this->lng->txt("sty_individual_styles");
174 }
175
176 // number of default style (fallback default style)
177 if ($default_style <= 0 && $fixed_style <= 0) {
178 $data[0] =
179 array("title" => $this->lng->txt("sty_default_style"),
180 "id" => 0, "lm_nr" => $this->domain->object(0)->countObjSelected(0));
181 $from_styles[0] = $this->lng->txt("sty_default_style");
182 $to_styles[0] = $this->lng->txt("sty_default_style");
183 }
184
185 $rendered_modal = "";
186 if ($this->checkPermission("sty_write_content", false)) {
187 $this->toolbar->addButton(
188 $this->lng->txt("sty_add_content_style"),
189 $this->ctrl->getLinkTarget($this, "createStyle")
190 );
191
192 /*
193 $modal = $this->gui->modal($this->lng->txt("import"))
194 ->form($this->getImportForm());
195 $modal_c = $modal->getTriggerButtonComponents($this->lng->txt("import"), false);
196 $this->toolbar->addComponent($modal_c["button"]);
197 $rendered_modal = $this->gui->ui()->renderer()->render($modal_c["modal"]);*/
198
199 $this->toolbar->addSeparator();
200
201 // from styles selector
202 $si = new ilSelectInputGUI($this->lng->txt("sty_move_obj_styles") . ": " . $this->lng->txt("sty_from"), "from_style");
203 $si->setOptions($from_styles);
204 $this->toolbar->addInputItem($si, true);
205
206 // from styles selector
207 $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
208 $si->setOptions($to_styles);
209 $this->toolbar->addInputItem($si, true);
210 $this->toolbar->addFormButton($this->lng->txt("sty_move_style"), "moveLMStyles");
211
212 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
213 }
214
215 $table = new ilContentStylesTableGUI($this, "edit", $data);
216 $this->tpl->setContent($table->getHTML() . $rendered_modal);
217 }
218
219 protected function getImportForm(): FormAdapterGUI
220 {
221 $gui = new ilObjStyleSheetGUI("", 0, false);
222 return $this->gui->form([self::class], "import")
223 ->file(
224 "import_file",
225 $this->lng->txt("import"),
226 $gui->handleImport(...), // Placeholder for upload handler
227 "obj_id",
228 "",
229 1,
230 ["application/zip"]
231 );
232 }
233
234 public function import(): void
235 {
236 $form = $this->getImportForm();
237 if ($form->isValid()) {
238 if ($this->request->getRefId() > 0) {
239 $fold = ilObjectFactory::getInstanceByRefId($this->request->getRefId());
240 if ($fold->getType() == "stys") {
241 $obj_id = (int) $form->getData("import_file");
242 $cont_style_settings = new ilContentStyleSettings();
243 $cont_style_settings->addStyle($obj_id);
244 $cont_style_settings->update();
246 $this->ctrl->redirectByClass(self::class, "");
247 }
248 }
249 }
250 }
251
252
256 public function moveLMStyles(): void
257 {
258 $this->checkPermission("sty_write_content");
259
260 if ($this->request->getFromStyleId() == -1) {
262 return;
263 }
264
265 $this->domain->object(0)->move($this->request->getFromStyleId(), $this->request->getToStyleId());
266 $this->ctrl->redirect($this, "edit");
267 }
268
272 public function moveIndividualStyles(): void
273 {
274 $this->checkPermission("sty_write_content");
275
276 ilObjContentObject::_moveLMStyles(-1, $this->request->getToStyleId());
277 $this->ctrl->redirect($this, "edit");
278 }
279
280 public function confirmDeleteIndividualStyles(): void
281 {
282 $this->checkPermission("sty_write_content");
283
284 $this->ctrl->setParameter($this, "to_style", $this->request->getToStyleId());
285
286 $cgui = new ilConfirmationGUI();
287 $cgui->setFormAction($this->ctrl->getFormAction($this));
288 $cgui->setHeaderText($this->lng->txt("sty_confirm_del_ind_styles") . ": " .
289 sprintf(
290 $this->lng->txt("sty_confirm_del_ind_styles_desc"),
291 ilObject::_lookupTitle($this->request->getToStyleId())
292 ));
293 $cgui->setCancel($this->lng->txt("cancel"), "edit");
294 $cgui->setConfirm($this->lng->txt("ok"), "moveIndividualStyles");
295 $this->tpl->setContent($cgui->getHTML());
296 }
297
301 public function deleteStyle(): void
302 {
303 $this->checkPermission("sty_write_content");
304
305 $ids = $this->request->getIds();
306 if (count($ids) == 0) {
307 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
308 $this->ctrl->redirect($this, "edit");
309 }
310
311 // display confirmation message
312 $cgui = new ilConfirmationGUI();
313 $cgui->setFormAction($this->ctrl->getFormAction($this));
314 $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
315 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
316 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
317
318 foreach ($ids as $id) {
319 $caption = ilObject::_lookupTitle($id);
320
321 $cgui->addItem("id[]", (string) $id, $caption);
322 }
323
324 $this->tpl->setContent($cgui->getHTML());
325 }
326
330 public function confirmedDelete(): void
331 {
332 $this->checkPermission("sty_write_content");
333
334 $ids = $this->request->getIds();
335 foreach ($ids as $id) {
336 $set = new ilContentStyleSettings();
337 $set->removeStyle($id);
338 $set->update();
339
341 $style_obj->delete();
342 }
343
344 $this->ctrl->redirect($this, "edit");
345 }
346
350 public function toggleGlobalDefault(): void
351 {
354
355 $this->checkPermission("sty_write_content");
356
357 if ($this->request->getId() > 0) {
358 $ilSetting->delete("fixed_content_style_id");
359 $def_style = $ilSetting->get("default_content_style_id");
360
361 if ($def_style != $this->request->getId()) {
362 $ilSetting->set("default_content_style_id", (string) $this->request->getId());
363 } else {
364 $ilSetting->delete("default_content_style_id");
365 }
366 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
367 }
368 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
369 }
370
374 public function toggleGlobalFixed(): void
375 {
378
379 $this->checkPermission("sty_write_content");
380
381 if ($this->request->getId() > 0) {
382 $ilSetting->delete("default_content_style_id");
383 $fixed_style = $ilSetting->get("fixed_content_style_id");
384 if ($fixed_style == $this->request->getId()) {
385 $ilSetting->delete("fixed_content_style_id");
386 } else {
387 $ilSetting->set("fixed_content_style_id", (string) $this->request->getId());
388 }
389 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
390 }
391 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
392 }
393
394 public function saveActiveStyles(): void
395 {
396 $styles = $this->cs_settings->getStyles();
397 foreach ($styles as $style) {
398 if ($this->request->getSelectedStandard($style["id"]) == 1) {
399 ilObjStyleSheet::_writeActive((int) $style["id"], true);
400 } else {
401 ilObjStyleSheet::_writeActive((int) $style["id"], false);
402 }
403 }
404 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
405 }
406
410 public function showActions(bool $with_subobjects = false): void
411 {
412 // delete
413 $this->tpl->setCurrentBlock("tbl_action_btn");
414 $this->tpl->setVariable("BTN_NAME", "deleteStyle");
415 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
416 $this->tpl->parseCurrentBlock();
417
418 // set global default
419 $this->tpl->setCurrentBlock("tbl_action_btn");
420 $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
421 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
422 $this->tpl->parseCurrentBlock();
423
424 // set global default
425 $this->tpl->setCurrentBlock("tbl_action_btn");
426 $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
427 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
428 $this->tpl->parseCurrentBlock();
429
430 // set global default
431 $this->tpl->setCurrentBlock("tbl_action_btn");
432 $this->tpl->setVariable("BTN_NAME", "setScope");
433 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
434 $this->tpl->parseCurrentBlock();
435
436 // save active styles
437 $this->tpl->setCurrentBlock("tbl_action_btn");
438 $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
439 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
440 $this->tpl->parseCurrentBlock();
441
442 $this->tpl->setCurrentBlock("tbl_action_row");
443 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("nav/arrow_downright.svg"));
444 $this->tpl->parseCurrentBlock();
445 }
446
447 public function cancelDelete(): void
448 {
449 $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_cancel"), true);
450 $this->ctrl->redirect($this, "edit");
451 }
452
453 public function setScope(): void
454 {
456 $ilCtrl = $this->ctrl;
457
458 $this->checkPermission("sty_write_content");
459
460 $ilCtrl->saveParameter($this, "id");
462 $this,
463 "setScope",
464 $this,
465 "saveScope",
466 "cat"
467 );
468 $exp->setTypeWhiteList(array("root", "cat"));
469 if (!$exp->handleCommand()) {
470 $tpl->setContent($exp->getHTML());
471 }
472 }
473
474 public function saveScope(): void
475 {
477
478 $this->checkPermission("sty_write_content");
479
480 $cat_id = $this->request->getCatId();
481 if ($cat_id == $tree->readRootId()) {
482 $cat_id = 0;
483 }
484
485 ilObjStyleSheet::_writeScope($this->request->getId(), $cat_id);
486
487 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
488
489 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
490 }
491}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Content style internal ui factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Settings UI class for system styles.
moveIndividualStyles()
move all learning modules with individual styles to new style
deleteStyle()
display deletion confirmation screen
showActions(bool $with_subobjects=false)
show possible action (form buttons)
checkPermission(string $a_perm, bool $a_throw_exc=true)
Check permission.
toggleGlobalFixed()
Toggle global fixed style.
ILIAS Style Content InternalDomainService $domain
moveLMStyles()
move learning modules from one style to another
toggleGlobalDefault()
Toggle global default style.
__construct(ilObjStyleSettingsGUI $a_parent_gui)
confirmedDelete()
delete selected style objects
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _moveLMStyles(int $a_from_style, int $a_to_style)
move learning modules from one style to another
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjStyleSheetGUI.
static _writeActive(int $a_id, bool $a_active)
static _lookupActive(int $a_id)
Lookup active flag.
static _writeScope(int $a_id, int $a_scope)
static _writeStandard(int $a_id, bool $a_std)
Write standard flag.
Base exception class for object service.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupTitle(int $obj_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
Explorer for selecting repository items.
This class represents a selection list property in a property form.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static redirect(string $a_script)
setContent(string $a_html)
Sets content for standard template.
global $ilSetting
Definition: privfeed.php:31