ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ctrl;
19 
23  protected $rbacsystem;
24 
28  protected $toolbar;
29 
33  protected $lng;
34 
38  protected $tpl;
39 
43  protected $DIC;
44 
48  protected $ref_id;
49 
53  function __construct(ilObjStyleSettingsGUI $a_parent_gui)
54  {
55  global $DIC;
56 
57  $this->parent_gui = $a_parent_gui;
58  $this->dic = $DIC;
59  $this->ctrl = $DIC->ctrl();
60  $this->rbacsystem = $DIC->rbac()->system();
61  $this->toolbar = $DIC->toolbar();
62  $this->lng = $DIC->language();
63  $this->tpl = $DIC["tpl"];
64  $this->ref_id = (int) $_GET["ref_id"];
65  $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
66 
67 
68  include_once("./Services/Style/Content/classes/class.ilContentStyleSettings.php");
69  $this->settings = new ilContentStyleSettings();
70  }
71 
75  function executeCommand()
76  {
77  $next_class = $this->ctrl->getNextClass($this);
78  $cmd = $this->ctrl->getCmd("edit");
79 
80  switch ($next_class)
81  {
82  case "ilobjstylesheetgui":
83  $this->ctrl->setReturn($this, "edit");
84  include_once("./Services/Style/Content/classes/class.ilObjStyleSheetGUI.php");
85  $style_gui = new ilObjStyleSheetGUI("", $this->obj_id, false, false);
86  $this->ctrl->forwardCommand($style_gui);
87  break;
88 
89  default:
90  $this->parent_gui->prepareOutput();
91  if (in_array($cmd, array("edit", "delete", "toggleGlobalDefault", "toggleGlobalFixed", "setScope", "saveScope", "saveActiveStyles",
92  "createStyle", "moveLMStyles", "moveIndividualStyles", "deleteStyle", "cancelDelete", "confirmedDelete")))
93  {
94  $this->$cmd();
95  }
96  else
97  {
98  die("Unknown command ".$cmd);
99  }
100  }
101  }
102 
110  function checkPermission($a_perm, $a_throw_exc = true)
111  {
112  if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id))
113  {
114  if ($a_throw_exc)
115  {
116  include_once "Services/Object/exceptions/class.ilObjectException.php";
117  throw new ilObjectException($this->lng->txt("permission_denied"));
118  }
119  return false;
120  }
121  return true;
122  }
123 
127  function createStyle()
128  {
129  global $ilCtrl;
130 
131  // $ilCtrl->setParameterByClass("ilobjstylesheetgui", "new_type", "sty");
132  $ilCtrl->redirectByClass("ilobjstylesheetgui", "create");
133  }
134 
138  function edit()
139  {
140  $this->checkPermission("visible,read");
141 
142  // this may not be cool, if styles are organised as (independent) Service
143  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
144  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
145 
146  $from_styles = $to_styles = $data = array();
147  $styles = $this->settings->getStyles();
148  foreach($styles as $style)
149  {
150  $style["active"] = ilObjStyleSheet::_lookupActive($style["id"]);
151  $style["lm_nr"] = ilObjContentObject::_getNrOfAssignedLMs($style["id"]);
152  $data[$style["title"].":".$style["id"]]
153  = $style;
154  if ($style["lm_nr"] > 0)
155  {
156  $from_styles[$style["id"]] = $style["title"];
157  }
158  if ($style["active"] > 0)
159  {
160  $to_styles[$style["id"]] = $style["title"];
161  }
162  }
163 
164  // number of individual styles
165  if ($fixed_style <= 0)
166  {
167  $data[-1] =
168  array("title" => $this->lng->txt("sty_individual_styles"),
169  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsIndividualStyles());
170  $from_styles[-1] = $this->lng->txt("sty_individual_styles");
171  }
172 
173  // number of default style (fallback default style)
174  if ($default_style <= 0 && $fixed_style <= 0)
175  {
176  $data[0] =
177  array("title" => $this->lng->txt("sty_default_style"),
178  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsNoStyle());
179  $from_styles[0] = $this->lng->txt("sty_default_style");
180  $to_styles[0] = $this->lng->txt("sty_default_style");
181  }
182 
183  if ($this->checkPermission("sty_write_content", false))
184  {
185  $this->toolbar->addButton($this->lng->txt("sty_add_content_style"),
186  $this->ctrl->getLinkTarget($this, "createStyle"));
187  $this->toolbar->addSeparator();
188  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
189 
190  // from styles selector
191  $si = new ilSelectInputGUI($this->lng->txt("sty_move_lm_styles").": ".$this->lng->txt("sty_from"), "from_style");
192  $si->setOptions($from_styles);
193  $this->toolbar->addInputItem($si, true);
194 
195  // from styles selector
196  $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
197  $si->setOptions($to_styles);
198  $this->toolbar->addInputItem($si, true);
199  $this->toolbar->addFormButton($this->lng->txt("sty_move_style"), "moveLMStyles");
200 
201  $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
202  }
203 
204  include_once("./Services/Style/Content/classes/class.ilContentStylesTableGUI.php");
205  $table = new ilContentStylesTableGUI($this, "edit", $data, $this->settings);
206  $this->tpl->setContent($table->getHTML());
207 
208  }
209 
213  function moveLMStyles()
214  {
215  $this->checkPermission("sty_write_content");
216 
217  if ($_POST["from_style"] == -1)
218  {
220  return;
221  }
222 
223  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
224  ilObjContentObject::_moveLMStyles($_POST["from_style"], $_POST["to_style"]);
225  $this->ctrl->redirect($this, "edit");
226  }
227 
228 
233  {
234  $this->checkPermission("sty_write_content");
235 
236  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
237  ilObjContentObject::_moveLMStyles(-1, $_GET["to_style"]);
238  $this->ctrl->redirect($this, "edit");
239  }
240 
245  {
246  $this->checkPermission("sty_write_content");
247 
248  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
249 
250  $this->ctrl->setParameter($this, "to_style", $_POST["to_style"]);
251 
252  $cgui = new ilConfirmationGUI();
253  $cgui->setFormAction($this->ctrl->getFormAction($this));
254  $cgui->setHeaderText($this->lng->txt("sty_confirm_del_ind_styles").": ".
255  sprintf($this->lng->txt("sty_confirm_del_ind_styles_desc"),
256  ilObject::_lookupTitle($_POST["to_style"])));
257  $cgui->setCancel($this->lng->txt("cancel"), "edit");
258  $cgui->setConfirm($this->lng->txt("ok"), "moveIndividualStyles");
259  $this->tpl->setContent($cgui->getHTML());
260  }
261 
262 
263 
267  function deleteStyle()
268  {
269  $this->checkPermission("sty_write_content");
270 
271  if (!isset($_POST["id"]))
272  {
273  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
274  $this->ctrl->redirect($this, "edit");
275  }
276 
277  // display confirmation message
278  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
279  $cgui = new ilConfirmationGUI();
280  $cgui->setFormAction($this->ctrl->getFormAction($this));
281  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
282  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
283  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
284 
285  foreach ($_POST["id"] as $id)
286  {
287  $caption = ilUtil::getImageTagByType("sty", $this->tpl->tplPath).
288  " ".ilObject::_lookupTitle($id);
289 
290  $cgui->addItem("id[]", $id, $caption);
291  }
292 
293  $this->tpl->setContent($cgui->getHTML());
294  }
295 
296 
300  function confirmedDelete()
301  {
302  global $ilias;
303 
304  $this->checkPermission("sty_write_content");
305 
306  foreach($_POST["id"] as $id)
307  {
308  include_once("./Services/Style/Content/classes/class.ilContentStyleSettings.php");
309  $set = new ilContentStyleSettings();
310  $set->removeStyle($id);
311  $set->update();
312  $style_obj = $ilias->obj_factory->getInstanceByObjId($id);
313  $style_obj->delete();
314  }
315 
316  $this->ctrl->redirect($this, "edit");
317  }
318 
319 
324  {
325  global $ilSetting, $lng;
326 
327  $this->checkPermission("sty_write_content");
328 
329  if ($_GET["id"] > 0)
330  {
331  $ilSetting->delete("fixed_content_style_id");
332  $def_style = $ilSetting->get("default_content_style_id");
333 
334  if ($def_style != $_GET["id"])
335  {
336  $ilSetting->set("default_content_style_id", (int) $_GET["id"]);
337  }
338  else
339  {
340  $ilSetting->delete("default_content_style_id");
341  }
342  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
343  }
344  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
345  }
346 
350  function toggleGlobalFixed()
351  {
352  global $ilSetting, $lng;
353 
354  $this->checkPermission("sty_write_content");
355 
356  if ($_GET["id"] > 0)
357  {
358  $ilSetting->delete("default_content_style_id");
359  $fixed_style = $ilSetting->get("fixed_content_style_id");
360  if ($fixed_style == (int) $_GET["id"])
361  {
362  $ilSetting->delete("fixed_content_style_id");
363  }
364  else
365  {
366  $ilSetting->set("fixed_content_style_id", (int) $_GET["id"]);
367  }
368  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
369  }
370  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
371  }
372 
373 
377  function saveActiveStyles()
378  {
379  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
380  $styles = $this->settings->getStyles();
381  foreach($styles as $style)
382  {
383  if ($_POST["std_".$style["id"]] == 1)
384  {
385  ilObjStyleSheet::_writeActive((int) $style["id"], 1);
386  }
387  else
388  {
389  ilObjStyleSheet::_writeActive((int) $style["id"], 0);
390  }
391  }
392  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
393  }
394 
401  function showActions($with_subobjects = false)
402  {
403 
404  // delete
405  $this->tpl->setCurrentBlock("tbl_action_btn");
406  $this->tpl->setVariable("BTN_NAME", "deleteStyle");
407  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
408  $this->tpl->parseCurrentBlock();
409 
410  // set global default
411  $this->tpl->setCurrentBlock("tbl_action_btn");
412  $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
413  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
414  $this->tpl->parseCurrentBlock();
415 
416  // set global default
417  $this->tpl->setCurrentBlock("tbl_action_btn");
418  $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
419  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
420  $this->tpl->parseCurrentBlock();
421 
422  // set global default
423  $this->tpl->setCurrentBlock("tbl_action_btn");
424  $this->tpl->setVariable("BTN_NAME", "setScope");
425  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
426  $this->tpl->parseCurrentBlock();
427 
428  // save active styles
429  $this->tpl->setCurrentBlock("tbl_action_btn");
430  $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
431  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
432  $this->tpl->parseCurrentBlock();
433 
434  if ($with_subobjects === true)
435  {
436  $this->showPossibleSubObjects();
437  }
438 
439  $this->tpl->setCurrentBlock("tbl_action_row");
440  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
441  $this->tpl->parseCurrentBlock();
442  }
443 
449  function cancelDelete()
450  {
451  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
452  $this->ctrl->redirect($this, "edit");
453 
454  }
455 
459  function setScope()
460  {
461  global $tpl, $ilCtrl;
462 
463  $this->checkPermission("sty_write_content");
464 
465  $ilCtrl->saveParameter($this, "id");
466  include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
467  $exp = new ilRepositorySelectorExplorerGUI($this, "setScope",
468  $this, "saveScope", "cat");
469  $exp->setTypeWhiteList(array("root", "cat"));
470  if (!$exp->handleCommand())
471  {
472  $tpl->setContent($exp->getHTML());
473  }
474  }
475 
479  function saveScope()
480  {
481  global $tree;
482 
483  $this->checkPermission("sty_write_content");
484 
485  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
486  if ($_GET["cat"] == $tree->readRootId())
487  {
488  $_GET["cat"] = "";
489  }
491 
492  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
493 
494  ilUtil::redirect($this->ctrl->getLinkTarget($this, "edit", "", false, false));
495  }
496 
497 
498 }
499 
500 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _writeScope($a_id, $a_scope)
Write scope.
$style
Definition: example_012.php:70
static _getNrLMsNoStyle()
get number of learning modules assigned no style
Explorer for selecting repository items.
This class represents a selection list property in a property form.
toggleGlobalFixed()
Toggle global fixed style.
$_GET["client_id"]
static _getNrOfAssignedLMs($a_style_id)
gets the number of learning modules assigned to a content style
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...
confirmedDelete()
delete selected style objects
$cmd
Definition: sahs_server.php:35
Base exception class for object service.
checkPermission($a_perm, $a_throw_exc=true)
Check permission.
moveLMStyles()
move learning modules from one style to another
static _lookupTitle($a_id)
lookup object title
toggleGlobalDefault()
Toggle global default style.
cancelDelete()
cancel deletion of object
deleteStyle()
display deletion confirmation screen
global $ilCtrl
Definition: ilias.php:18
static _moveLMStyles($a_from_style, $a_to_style)
move learning modules from one style to another
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static _writeActive($a_id, $a_active)
Write active flag.
Style settings GUI class.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct(ilObjStyleSettingsGUI $a_parent_gui)
Constructor.
settings()
Definition: settings.php:2
Class ilObjStyleSheetGUI.
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
static _lookupActive($a_id)
Lookup active flag.
static redirect($a_script)
http redirect to other script
showActions($with_subobjects=false)
show possible action (form buttons)
$_POST["username"]
Confirmation screen class.
Settings UI class for system styles.