ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilContentStyleSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
29 {
32  protected int $obj_id;
34  protected ilSetting $settings;
35  protected ilTree $tree;
36  protected ilCtrl $ctrl;
39  protected ilLanguage $lng;
42  protected int $ref_id;
43 
44  public function __construct(ilObjStyleSettingsGUI $a_parent_gui)
45  {
46  global $DIC;
47 
48  $this->tree = $DIC->repositoryTree();
49  $this->settings = $DIC->settings();
50 
51  $this->parent_gui = $a_parent_gui;
52  $this->ctrl = $DIC->ctrl();
53  $this->rbacsystem = $DIC->rbac()->system();
54  $this->toolbar = $DIC->toolbar();
55  $this->lng = $DIC->language();
56  $this->tpl = $DIC->ui()->mainTemplate();
57  $this->request = $DIC->contentStyle()
58  ->internal()
59  ->gui()
60  ->standardRequest();
61 
62 
63  $this->ref_id = $this->request->getRefId();
64  $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
65 
66  $this->cs_settings = new ilContentStyleSettings();
67  }
68 
69  public function executeCommand(): void
70  {
71  $next_class = $this->ctrl->getNextClass($this);
72  $cmd = $this->ctrl->getCmd("edit");
73 
74  switch ($next_class) {
75  case "ilobjstylesheetgui":
76  $this->ctrl->setReturn($this, "edit");
77  $style_gui = new ilObjStyleSheetGUI("", $this->obj_id, false);
78  $this->ctrl->forwardCommand($style_gui);
79  break;
80 
81  default:
82  $this->parent_gui->prepareOutput();
83  if (in_array($cmd, array("edit", "delete", "toggleGlobalDefault", "toggleGlobalFixed", "setScope", "saveScope", "saveActiveStyles",
84  "createStyle", "moveLMStyles", "moveIndividualStyles", "deleteStyle", "cancelDelete", "confirmedDelete"))) {
85  $this->$cmd();
86  } else {
87  die("Unknown command " . $cmd);
88  }
89  }
90  }
91 
96  public function checkPermission(string $a_perm, bool $a_throw_exc = true): bool
97  {
98  if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id)) {
99  if ($a_throw_exc) {
100  throw new ilObjectException($this->lng->txt("permission_denied"));
101  }
102  return false;
103  }
104  return true;
105  }
106 
107  public function createStyle(): void
108  {
109  $ilCtrl = $this->ctrl;
110 
111  // $ilCtrl->setParameterByClass("ilobjstylesheetgui", "new_type", "sty");
112  $ilCtrl->redirectByClass("ilobjstylesheetgui", "create");
113  }
114 
118  public function edit(): void
119  {
120  $this->checkPermission("visible,read");
121 
122  // @todo: check these, they are checked later, but never (ILIAS 6) set
123  $fixed_style = 0;
124  $default_style = 0;
125 
126  // this may not be cool, if styles are organised as (independent) Service
127  $from_styles = $to_styles = $data = array();
128  $styles = $this->cs_settings->getStyles();
129  foreach ($styles as $style) {
130  $style["active"] = ilObjStyleSheet::_lookupActive((int) $style["id"]);
131  $style["lm_nr"] = ilObjContentObject::_getNrOfAssignedLMs((int) $style["id"]);
132  $data[$style["title"] . ":" . $style["id"]]
133  = $style;
134  if ($style["lm_nr"] > 0) {
135  $from_styles[$style["id"]] = $style["title"];
136  }
137  if ($style["active"] > 0) {
138  $to_styles[$style["id"]] = $style["title"];
139  }
140  }
141 
142  // number of individual styles
143  if ($fixed_style <= 0) {
144  $data[-1] =
145  array("title" => $this->lng->txt("sty_individual_styles"),
146  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsIndividualStyles());
147  $from_styles[-1] = $this->lng->txt("sty_individual_styles");
148  }
149 
150  // number of default style (fallback default style)
151  if ($default_style <= 0 && $fixed_style <= 0) {
152  $data[0] =
153  array("title" => $this->lng->txt("sty_default_style"),
154  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsNoStyle());
155  $from_styles[0] = $this->lng->txt("sty_default_style");
156  $to_styles[0] = $this->lng->txt("sty_default_style");
157  }
158 
159  if ($this->checkPermission("sty_write_content", false)) {
160  $this->toolbar->addButton(
161  $this->lng->txt("sty_add_content_style"),
162  $this->ctrl->getLinkTarget($this, "createStyle")
163  );
164  $this->toolbar->addSeparator();
165 
166  // from styles selector
167  $si = new ilSelectInputGUI($this->lng->txt("sty_move_lm_styles") . ": " . $this->lng->txt("sty_from"), "from_style");
168  $si->setOptions($from_styles);
169  $this->toolbar->addInputItem($si, true);
170 
171  // from styles selector
172  $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
173  $si->setOptions($to_styles);
174  $this->toolbar->addInputItem($si, true);
175  $this->toolbar->addFormButton($this->lng->txt("sty_move_style"), "moveLMStyles");
176 
177  $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
178  }
179 
180  $table = new ilContentStylesTableGUI($this, "edit", $data);
181  $this->tpl->setContent($table->getHTML());
182  }
183 
187  public function moveLMStyles(): void
188  {
189  $this->checkPermission("sty_write_content");
190 
191  if ($this->request->getFromStyleId() == -1) {
193  return;
194  }
195 
197  $this->request->getFromStyleId(),
198  $this->request->getToStyleId()
199  );
200  $this->ctrl->redirect($this, "edit");
201  }
202 
203 
207  public function moveIndividualStyles(): void
208  {
209  $this->checkPermission("sty_write_content");
210 
211  ilObjContentObject::_moveLMStyles(-1, $this->request->getToStyleId());
212  $this->ctrl->redirect($this, "edit");
213  }
214 
215  public function confirmDeleteIndividualStyles(): void
216  {
217  $this->checkPermission("sty_write_content");
218 
219 
220  $this->ctrl->setParameter($this, "to_style", $this->request->getToStyleId());
221 
222  $cgui = new ilConfirmationGUI();
223  $cgui->setFormAction($this->ctrl->getFormAction($this));
224  $cgui->setHeaderText($this->lng->txt("sty_confirm_del_ind_styles") . ": " .
225  sprintf(
226  $this->lng->txt("sty_confirm_del_ind_styles_desc"),
227  ilObject::_lookupTitle($this->request->getToStyleId())
228  ));
229  $cgui->setCancel($this->lng->txt("cancel"), "edit");
230  $cgui->setConfirm($this->lng->txt("ok"), "moveIndividualStyles");
231  $this->tpl->setContent($cgui->getHTML());
232  }
233 
237  public function deleteStyle(): void
238  {
239  $this->checkPermission("sty_write_content");
240 
241  $ids = $this->request->getIds();
242  if (count($ids) == 0) {
243  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
244  $this->ctrl->redirect($this, "edit");
245  }
246 
247  // display confirmation message
248  $cgui = new ilConfirmationGUI();
249  $cgui->setFormAction($this->ctrl->getFormAction($this));
250  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
251  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
252  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
253 
254  foreach ($ids as $id) {
255  $caption = ilObject::_lookupTitle($id);
256 
257  $cgui->addItem("id[]", (string) $id, $caption);
258  }
259 
260  $this->tpl->setContent($cgui->getHTML());
261  }
262 
263 
267  public function confirmedDelete(): void
268  {
269  $this->checkPermission("sty_write_content");
270 
271  $ids = $this->request->getIds();
272  foreach ($ids as $id) {
273  $set = new ilContentStyleSettings();
274  $set->removeStyle($id);
275  $set->update();
276 
277  $style_obj = ilObjectFactory::getInstanceByObjId($id);
278  $style_obj->delete();
279  }
280 
281  $this->ctrl->redirect($this, "edit");
282  }
283 
284 
288  public function toggleGlobalDefault(): void
289  {
291  $lng = $this->lng;
292 
293  $this->checkPermission("sty_write_content");
294 
295  if ($this->request->getId() > 0) {
296  $ilSetting->delete("fixed_content_style_id");
297  $def_style = $ilSetting->get("default_content_style_id");
298 
299  if ($def_style != $this->request->getId()) {
300  $ilSetting->set("default_content_style_id", (string) $this->request->getId());
301  } else {
302  $ilSetting->delete("default_content_style_id");
303  }
304  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
305  }
306  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
307  }
308 
312  public function toggleGlobalFixed(): void
313  {
315  $lng = $this->lng;
316 
317  $this->checkPermission("sty_write_content");
318 
319  if ($this->request->getId() > 0) {
320  $ilSetting->delete("default_content_style_id");
321  $fixed_style = $ilSetting->get("fixed_content_style_id");
322  if ($fixed_style == $this->request->getId()) {
323  $ilSetting->delete("fixed_content_style_id");
324  } else {
325  $ilSetting->set("fixed_content_style_id", (string) $this->request->getId());
326  }
327  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
328  }
329  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
330  }
331 
332  public function saveActiveStyles(): void
333  {
334  $styles = $this->cs_settings->getStyles();
335  foreach ($styles as $style) {
336  if ($this->request->getSelectedStandard($style["id"]) == 1) {
337  ilObjStyleSheet::_writeActive((int) $style["id"], true);
338  } else {
339  ilObjStyleSheet::_writeActive((int) $style["id"], false);
340  }
341  }
342  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
343  }
344 
348  public function showActions(bool $with_subobjects = false): void
349  {
350  // delete
351  $this->tpl->setCurrentBlock("tbl_action_btn");
352  $this->tpl->setVariable("BTN_NAME", "deleteStyle");
353  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
354  $this->tpl->parseCurrentBlock();
355 
356  // set global default
357  $this->tpl->setCurrentBlock("tbl_action_btn");
358  $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
359  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
360  $this->tpl->parseCurrentBlock();
361 
362  // set global default
363  $this->tpl->setCurrentBlock("tbl_action_btn");
364  $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
365  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
366  $this->tpl->parseCurrentBlock();
367 
368  // set global default
369  $this->tpl->setCurrentBlock("tbl_action_btn");
370  $this->tpl->setVariable("BTN_NAME", "setScope");
371  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
372  $this->tpl->parseCurrentBlock();
373 
374  // save active styles
375  $this->tpl->setCurrentBlock("tbl_action_btn");
376  $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
377  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
378  $this->tpl->parseCurrentBlock();
379 
380  $this->tpl->setCurrentBlock("tbl_action_row");
381  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
382  $this->tpl->parseCurrentBlock();
383  }
384 
385  public function cancelDelete(): void
386  {
387  $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_cancel"), true);
388  $this->ctrl->redirect($this, "edit");
389  }
390 
391  public function setScope(): void
392  {
393  $tpl = $this->tpl;
394  $ilCtrl = $this->ctrl;
395 
396  $this->checkPermission("sty_write_content");
397 
398  $ilCtrl->saveParameter($this, "id");
400  $this,
401  "setScope",
402  $this,
403  "saveScope",
404  "cat"
405  );
406  $exp->setTypeWhiteList(array("root", "cat"));
407  if (!$exp->handleCommand()) {
408  $tpl->setContent($exp->getHTML());
409  }
410  }
411 
412  public function saveScope(): void
413  {
414  $tree = $this->tree;
415 
416  $this->checkPermission("sty_write_content");
417 
418  $cat_id = $this->request->getCatId();
419  if ($cat_id == $tree->readRootId()) {
420  $cat_id = 0;
421  }
422 
423  ilObjStyleSheet::_writeScope($this->request->getId(), $cat_id);
424 
425  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
426 
427  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", ""));
428  }
429 }
static _getNrOfAssignedLMs(int $a_style_id)
gets the number of learning modules assigned to a content style
static _getNrLMsNoStyle()
get number of learning modules assigned no style
static _writeActive(int $a_id, bool $a_active)
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
Explorer for selecting repository items.
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...
toggleGlobalFixed()
Toggle global fixed style.
static _writeScope(int $a_id, int $a_scope)
confirmedDelete()
delete selected style objects
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
moveLMStyles()
move learning modules from one style to another
toggleGlobalDefault()
Toggle global default style.
deleteStyle()
display deletion confirmation screen
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _moveLMStyles(int $a_from_style, int $a_to_style)
move learning modules from one style to another
static _lookupActive(int $a_id)
Lookup active flag.
static redirect(string $a_script)
__construct(ilObjStyleSettingsGUI $a_parent_gui)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
global $ilSetting
Definition: privfeed.php:17
static _getNrLMsIndividualStyles()
get number of learning modules with individual styles
moveIndividualStyles()
move all learning modules with individual styles to new style
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermission(string $a_perm, bool $a_throw_exc=true)
Check permission.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showActions(bool $with_subobjects=false)
show possible action (form buttons)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Settings UI class for system styles.