ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilContentStyleSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
18 protected $settings;
19
23 protected $tree;
24
28 protected $ctrl;
29
33 protected $rbacsystem;
34
38 protected $toolbar;
39
43 protected $lng;
44
48 protected $tpl;
49
53 protected $DIC;
54
58 protected $ref_id;
59
63 public function __construct(ilObjStyleSettingsGUI $a_parent_gui)
64 {
65 global $DIC;
66
67 $this->tree = $DIC->repositoryTree();
68 $this->settings = $DIC->settings();
69
70 $this->parent_gui = $a_parent_gui;
71 $this->dic = $DIC;
72 $this->ctrl = $DIC->ctrl();
73 $this->rbacsystem = $DIC->rbac()->system();
74 $this->toolbar = $DIC->toolbar();
75 $this->lng = $DIC->language();
76 $this->tpl = $DIC["tpl"];
77 $this->ref_id = (int) $_GET["ref_id"];
78 $this->obj_id = (int) $_GET["obj_id"]; // note that reference ID is the id of the style settings node and object ID may be a style sheet object ID
79
80
81 include_once("./Services/Style/Content/classes/class.ilContentStyleSettings.php");
82 $this->cs_settings = new ilContentStyleSettings();
83 }
84
88 public function executeCommand()
89 {
90 $next_class = $this->ctrl->getNextClass($this);
91 $cmd = $this->ctrl->getCmd("edit");
92
93 switch ($next_class) {
94 case "ilobjstylesheetgui":
95 $this->ctrl->setReturn($this, "edit");
96 include_once("./Services/Style/Content/classes/class.ilObjStyleSheetGUI.php");
97 $style_gui = new ilObjStyleSheetGUI("", $this->obj_id, false, false);
98 $this->ctrl->forwardCommand($style_gui);
99 break;
100
101 default:
102 $this->parent_gui->prepareOutput();
103 if (in_array($cmd, array("edit", "delete", "toggleGlobalDefault", "toggleGlobalFixed", "setScope", "saveScope", "saveActiveStyles",
104 "createStyle", "moveLMStyles", "moveIndividualStyles", "deleteStyle", "cancelDelete", "confirmedDelete"))) {
105 $this->$cmd();
106 } else {
107 die("Unknown command " . $cmd);
108 }
109 }
110 }
111
119 public function checkPermission($a_perm, $a_throw_exc = true)
120 {
121 if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id)) {
122 if ($a_throw_exc) {
123 include_once "Services/Object/exceptions/class.ilObjectException.php";
124 throw new ilObjectException($this->lng->txt("permission_denied"));
125 }
126 return false;
127 }
128 return true;
129 }
130
134 public function createStyle()
135 {
137
138 // $ilCtrl->setParameterByClass("ilobjstylesheetgui", "new_type", "sty");
139 $ilCtrl->redirectByClass("ilobjstylesheetgui", "create");
140 }
141
145 public function edit()
146 {
147 $this->checkPermission("visible,read");
148
149 // this may not be cool, if styles are organised as (independent) Service
150 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
151 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
152
153 $from_styles = $to_styles = $data = array();
154 $styles = $this->cs_settings->getStyles();
155 foreach ($styles as $style) {
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" => ilObjContentObject::_getNrLMsIndividualStyles());
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" => ilObjContentObject::_getNrLMsNoStyle());
181 $from_styles[0] = $this->lng->txt("sty_default_style");
182 $to_styles[0] = $this->lng->txt("sty_default_style");
183 }
184
185 if ($this->checkPermission("sty_write_content", false)) {
186 $this->toolbar->addButton(
187 $this->lng->txt("sty_add_content_style"),
188 $this->ctrl->getLinkTarget($this, "createStyle")
189 );
190 $this->toolbar->addSeparator();
191 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
192
193 // from styles selector
194 $si = new ilSelectInputGUI($this->lng->txt("sty_move_lm_styles") . ": " . $this->lng->txt("sty_from"), "from_style");
195 $si->setOptions($from_styles);
196 $this->toolbar->addInputItem($si, true);
197
198 // from styles selector
199 $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
200 $si->setOptions($to_styles);
201 $this->toolbar->addInputItem($si, true);
202 $this->toolbar->addFormButton($this->lng->txt("sty_move_style"), "moveLMStyles");
203
204 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
205 }
206
207 include_once("./Services/Style/Content/classes/class.ilContentStylesTableGUI.php");
208 $table = new ilContentStylesTableGUI($this, "edit", $data, $this->cs_settings);
209 $this->tpl->setContent($table->getHTML());
210 }
211
215 public function moveLMStyles()
216 {
217 $this->checkPermission("sty_write_content");
218
219 if ($_POST["from_style"] == -1) {
221 return;
222 }
223
224 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
225 ilObjContentObject::_moveLMStyles($_POST["from_style"], $_POST["to_style"]);
226 $this->ctrl->redirect($this, "edit");
227 }
228
229
233 public function moveIndividualStyles()
234 {
235 $this->checkPermission("sty_write_content");
236
237 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
239 $this->ctrl->redirect($this, "edit");
240 }
241
246 {
247 $this->checkPermission("sty_write_content");
248
249 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
250
251 $this->ctrl->setParameter($this, "to_style", $_POST["to_style"]);
252
253 $cgui = new ilConfirmationGUI();
254 $cgui->setFormAction($this->ctrl->getFormAction($this));
255 $cgui->setHeaderText($this->lng->txt("sty_confirm_del_ind_styles") . ": " .
256 sprintf(
257 $this->lng->txt("sty_confirm_del_ind_styles_desc"),
258 ilObject::_lookupTitle($_POST["to_style"])
259 ));
260 $cgui->setCancel($this->lng->txt("cancel"), "edit");
261 $cgui->setConfirm($this->lng->txt("ok"), "moveIndividualStyles");
262 $this->tpl->setContent($cgui->getHTML());
263 }
264
265
266
270 public function deleteStyle()
271 {
272 $this->checkPermission("sty_write_content");
273
274 if (!isset($_POST["id"])) {
275 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
276 $this->ctrl->redirect($this, "edit");
277 }
278
279 // display confirmation message
280 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
281 $cgui = new ilConfirmationGUI();
282 $cgui->setFormAction($this->ctrl->getFormAction($this));
283 $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
284 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
285 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
286
287 foreach ($_POST["id"] as $id) {
288 $caption = ilUtil::getImageTagByType("sty", $this->tpl->tplPath) .
290
291 $cgui->addItem("id[]", $id, $caption);
292 }
293
294 $this->tpl->setContent($cgui->getHTML());
295 }
296
297
301 public function confirmedDelete()
302 {
303 $this->checkPermission("sty_write_content");
304
305 foreach ($_POST["id"] as $id) {
306 include_once("./Services/Style/Content/classes/class.ilContentStyleSettings.php");
307 $set = new ilContentStyleSettings();
308 $set->removeStyle($id);
309 $set->update();
310
312 $style_obj->delete();
313 }
314
315 $this->ctrl->redirect($this, "edit");
316 }
317
318
322 public function toggleGlobalDefault()
323 {
326
327 $this->checkPermission("sty_write_content");
328
329 if ($_GET["id"] > 0) {
330 $ilSetting->delete("fixed_content_style_id");
331 $def_style = $ilSetting->get("default_content_style_id");
332
333 if ($def_style != $_GET["id"]) {
334 $ilSetting->set("default_content_style_id", (int) $_GET["id"]);
335 } else {
336 $ilSetting->delete("default_content_style_id");
337 }
338 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
339 }
340 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
341 }
342
346 public function toggleGlobalFixed()
347 {
350
351 $this->checkPermission("sty_write_content");
352
353 if ($_GET["id"] > 0) {
354 $ilSetting->delete("default_content_style_id");
355 $fixed_style = $ilSetting->get("fixed_content_style_id");
356 if ($fixed_style == (int) $_GET["id"]) {
357 $ilSetting->delete("fixed_content_style_id");
358 } else {
359 $ilSetting->set("fixed_content_style_id", (int) $_GET["id"]);
360 }
361 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
362 }
363 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
364 }
365
366
370 public function saveActiveStyles()
371 {
372 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
373 $styles = $this->cs_settings->getStyles();
374 foreach ($styles as $style) {
375 if ($_POST["std_" . $style["id"]] == 1) {
377 } else {
379 }
380 }
381 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
382 }
383
390 public function showActions($with_subobjects = false)
391 {
392
393 // delete
394 $this->tpl->setCurrentBlock("tbl_action_btn");
395 $this->tpl->setVariable("BTN_NAME", "deleteStyle");
396 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
397 $this->tpl->parseCurrentBlock();
398
399 // set global default
400 $this->tpl->setCurrentBlock("tbl_action_btn");
401 $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
402 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
403 $this->tpl->parseCurrentBlock();
404
405 // set global default
406 $this->tpl->setCurrentBlock("tbl_action_btn");
407 $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
408 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
409 $this->tpl->parseCurrentBlock();
410
411 // set global default
412 $this->tpl->setCurrentBlock("tbl_action_btn");
413 $this->tpl->setVariable("BTN_NAME", "setScope");
414 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
415 $this->tpl->parseCurrentBlock();
416
417 // save active styles
418 $this->tpl->setCurrentBlock("tbl_action_btn");
419 $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
420 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
421 $this->tpl->parseCurrentBlock();
422
423 if ($with_subobjects === true) {
424 $this->showPossibleSubObjects();
425 }
426
427 $this->tpl->setCurrentBlock("tbl_action_row");
428 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
429 $this->tpl->parseCurrentBlock();
430 }
431
437 public function cancelDelete()
438 {
439 ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
440 $this->ctrl->redirect($this, "edit");
441 }
442
446 public function setScope()
447 {
450
451 $this->checkPermission("sty_write_content");
452
453 $ilCtrl->saveParameter($this, "id");
454 include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
456 $this,
457 "setScope",
458 $this,
459 "saveScope",
460 "cat"
461 );
462 $exp->setTypeWhiteList(array("root", "cat"));
463 if (!$exp->handleCommand()) {
464 $tpl->setContent($exp->getHTML());
465 }
466 }
467
471 public function saveScope()
472 {
474
475 $this->checkPermission("sty_write_content");
476
477 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
478 if ($_GET["cat"] == $tree->readRootId()) {
479 $_GET["cat"] = "";
480 }
482
483 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
484
485 ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
486 }
487}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
Settings UI class for system styles.
moveIndividualStyles()
move all learning modules with individual styles to new style
showActions($with_subobjects=false)
show possible action (form buttons)
deleteStyle()
display deletion confirmation screen
toggleGlobalFixed()
Toggle global fixed style.
moveLMStyles()
move learning modules from one style to another
checkPermission($a_perm, $a_throw_exc=true)
Check permission.
toggleGlobalDefault()
Toggle global default style.
__construct(ilObjStyleSettingsGUI $a_parent_gui)
Constructor.
confirmedDelete()
delete selected style objects
static _getNrLMsIndividualStyles()
get number of learning modules with individual styles
static _getNrLMsNoStyle()
get number of learning modules assigned no style
static _getNrOfAssignedLMs($a_style_id)
gets the number of learning modules assigned to a content style
static _moveLMStyles($a_from_style, $a_to_style)
move learning modules from one style to another
Style settings GUI class.
Class ilObjStyleSheetGUI.
static _lookupActive($a_id)
Lookup active flag.
static _writeActive($a_id, $a_active)
Write active flag.
static _writeScope($a_id, $a_scope)
Write scope.
Base exception class for object service.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupTitle($a_id)
lookup object title
Explorer for selecting repository items.
This class represents a selection list property in a property form.
static getImageTagByType($a_type, $a_path, $a_big=false)
Builds an html image tag TODO: function still in use, but in future use getImagePath and move HTML-Co...
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$style
Definition: example_012.php:70
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
if(empty($password)) $table
Definition: pwgen.php:24
settings()
Definition: settings.php:2
$data
Definition: bench.php:6