ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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(
203 $this->lng->txt("sty_move_obj_styles") . ": " . $this->lng->txt("sty_from"),
204 "from_style"
205 );
206 $si->setOptions($from_styles);
207 $this->toolbar->addInputItem($si, true);
208
209 // from styles selector
210 $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
211 $si->setOptions($to_styles);
212 $this->toolbar->addInputItem($si, true);
213 $this->toolbar->addFormButton($this->lng->txt("sty_move_style"), "moveLMStyles");
214
215 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
216 }
217
218 $table = new ilContentStylesTableGUI($this, "edit", $data);
219 $this->tpl->setContent($table->getHTML() . $rendered_modal);
220 }
221
222 protected function getImportForm(): FormAdapterGUI
223 {
224 $gui = new ilObjStyleSheetGUI("", 0, false);
225 return $this->gui->form([self::class], "import")
226 ->file(
227 "import_file",
228 $this->lng->txt("import"),
229 $gui->handleImport(...), // Placeholder for upload handler
230 "obj_id",
231 "",
232 1,
233 ["application/zip"]
234 );
235 }
236
237 public function import(): void
238 {
239 $form = $this->getImportForm();
240 if ($form->isValid()) {
241 if ($this->request->getRefId() > 0) {
242 $fold = ilObjectFactory::getInstanceByRefId($this->request->getRefId());
243 if ($fold->getType() == "stys") {
244 $obj_id = (int) $form->getData("import_file");
245 $cont_style_settings = new ilContentStyleSettings();
246 $cont_style_settings->addStyle($obj_id);
247 $cont_style_settings->update();
249 $this->ctrl->redirectByClass(self::class, "");
250 }
251 }
252 }
253 }
254
255
259 public function moveLMStyles(): void
260 {
261 $this->checkPermission("sty_write_content");
262
263 if ($this->request->getFromStyleId() == -1) {
265 return;
266 }
267
269 $this->request->getFromStyleId(),
270 $this->request->getToStyleId()
271 );
272 $this->ctrl->redirect($this, "edit");
273 }
274
278 public function moveIndividualStyles(): void
279 {
280 $this->checkPermission("sty_write_content");
281
282 ilObjContentObject::_moveLMStyles(-1, $this->request->getToStyleId());
283 $this->ctrl->redirect($this, "edit");
284 }
285
286 public function confirmDeleteIndividualStyles(): void
287 {
288 $this->checkPermission("sty_write_content");
289
290 $this->ctrl->setParameter($this, "to_style", $this->request->getToStyleId());
291
292 $cgui = new ilConfirmationGUI();
293 $cgui->setFormAction($this->ctrl->getFormAction($this));
294 $cgui->setHeaderText($this->lng->txt("sty_confirm_del_ind_styles") . ": " .
295 sprintf(
296 $this->lng->txt("sty_confirm_del_ind_styles_desc"),
297 ilObject::_lookupTitle($this->request->getToStyleId())
298 ));
299 $cgui->setCancel($this->lng->txt("cancel"), "edit");
300 $cgui->setConfirm($this->lng->txt("ok"), "moveIndividualStyles");
301 $this->tpl->setContent($cgui->getHTML());
302 }
303
307 public function deleteStyle(): void
308 {
309 $this->checkPermission("sty_write_content");
310
311 $ids = $this->request->getIds();
312 if (count($ids) == 0) {
313 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
314 $this->ctrl->redirect($this, "edit");
315 }
316
317 // display confirmation message
318 $cgui = new ilConfirmationGUI();
319 $cgui->setFormAction($this->ctrl->getFormAction($this));
320 $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
321 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
322 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
323
324 foreach ($ids as $id) {
325 $caption = ilObject::_lookupTitle($id);
326
327 $cgui->addItem("id[]", (string) $id, $caption);
328 }
329
330 $this->tpl->setContent($cgui->getHTML());
331 }
332
336 public function confirmedDelete(): void
337 {
338 $this->checkPermission("sty_write_content");
339
340 $ids = $this->request->getIds();
341 foreach ($ids as $id) {
342 $set = new ilContentStyleSettings();
343 $set->removeStyle($id);
344 $set->update();
345
347 $style_obj->delete();
348 }
349
350 $this->ctrl->redirect($this, "edit");
351 }
352
356 public function toggleGlobalDefault(): void
357 {
360
361 $this->checkPermission("sty_write_content");
362
363 if ($this->request->getId() > 0) {
364 $ilSetting->delete("fixed_content_style_id");
365 $def_style = $ilSetting->get("default_content_style_id");
366
367 if ($def_style != $this->request->getId()) {
368 $ilSetting->set("default_content_style_id", (string) $this->request->getId());
369 } else {
370 $ilSetting->delete("default_content_style_id");
371 }
372 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
373 }
374 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
375 }
376
380 public function toggleGlobalFixed(): void
381 {
384
385 $this->checkPermission("sty_write_content");
386
387 if ($this->request->getId() > 0) {
388 $ilSetting->delete("default_content_style_id");
389 $fixed_style = $ilSetting->get("fixed_content_style_id");
390 if ($fixed_style == $this->request->getId()) {
391 $ilSetting->delete("fixed_content_style_id");
392 } else {
393 $ilSetting->set("fixed_content_style_id", (string) $this->request->getId());
394 }
395 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
396 }
397 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
398 }
399
400 public function saveActiveStyles(): void
401 {
402 $styles = $this->cs_settings->getStyles();
403 foreach ($styles as $style) {
404 if ($this->request->getSelectedStandard($style["id"]) == 1) {
405 ilObjStyleSheet::_writeActive((int) $style["id"], true);
406 } else {
407 ilObjStyleSheet::_writeActive((int) $style["id"], false);
408 }
409 }
410 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
411 }
412
416 public function showActions(bool $with_subobjects = false): void
417 {
418 // delete
419 $this->tpl->setCurrentBlock("tbl_action_btn");
420 $this->tpl->setVariable("BTN_NAME", "deleteStyle");
421 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
422 $this->tpl->parseCurrentBlock();
423
424 // set global default
425 $this->tpl->setCurrentBlock("tbl_action_btn");
426 $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
427 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
428 $this->tpl->parseCurrentBlock();
429
430 // set global default
431 $this->tpl->setCurrentBlock("tbl_action_btn");
432 $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
433 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
434 $this->tpl->parseCurrentBlock();
435
436 // set global default
437 $this->tpl->setCurrentBlock("tbl_action_btn");
438 $this->tpl->setVariable("BTN_NAME", "setScope");
439 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
440 $this->tpl->parseCurrentBlock();
441
442 // save active styles
443 $this->tpl->setCurrentBlock("tbl_action_btn");
444 $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
445 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
446 $this->tpl->parseCurrentBlock();
447
448 $this->tpl->setCurrentBlock("tbl_action_row");
449 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("nav/arrow_downright.svg"));
450 $this->tpl->parseCurrentBlock();
451 }
452
453 public function cancelDelete(): void
454 {
455 $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_cancel"), true);
456 $this->ctrl->redirect($this, "edit");
457 }
458
459 public function setScope(): void
460 {
462 $ilCtrl = $this->ctrl;
463
464 $this->checkPermission("sty_write_content");
465
466 $ilCtrl->saveParameter($this, "id");
468 $this,
469 "setScope",
470 $this,
471 "saveScope",
472 "cat"
473 );
474 $exp->setTypeWhiteList(array("root", "cat"));
475 if (!$exp->handleCommand()) {
476 $tpl->setContent($exp->getHTML());
477 }
478 }
479
480 public function saveScope(): void
481 {
483
484 $this->checkPermission("sty_write_content");
485
486 $cat_id = $this->request->getCatId();
487 if ($cat_id == $tree->readRootId()) {
488 $cat_id = 0;
489 }
490
491 ilObjStyleSheet::_writeScope($this->request->getId(), $cat_id);
492
493 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
494
495 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
496 }
497}
$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