ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectContentStyleSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 
32 {
37  protected int $current_style_id;
38  protected int $ref_id;
39  protected int $obj_id;
41 
42  public function __construct(
43  InternalDomainService $domain_service,
44  InternalGUIService $gui_service,
45  ?int $current_style_id,
46  int $ref_id,
47  int $obj_id
48  ) {
49  global $DIC;
50  $this->main_tpl = $DIC->ui()->mainTemplate();
51  $this->domain = $domain_service;
52  $this->gui = $gui_service;
53  $this->ref_id = $ref_id;
54  $this->obj_id = ($obj_id > 0)
55  ? $obj_id
56  : ilObject::_lookupObjId($ref_id);
57  $this->container_manager = $domain_service->repositoryContainer($ref_id);
58  $this->object_manager = $domain_service->object($ref_id, $this->obj_id);
59  $this->current_style_id = $current_style_id ?? $this->object_manager->getStyleId();
60  }
61 
62  public function executeCommand(): void
63  {
64  $ctrl = $this->gui->ctrl();
65 
66  $next_class = $ctrl->getNextClass($this);
67  $cmd = $ctrl->getCmd("settings");
68 
69  switch ($next_class) {
70  case "ilobjstylesheetgui":
71  $this->gui->tabs()->clearTargets();
72  $ctrl->setReturn($this, "settings");
73  $this->forwardToStyleSheet();
74  break;
75 
76  default:
77  if (in_array($cmd, [
78  "settings",
79  "editStyle",
80  "updateStyle",
81  "createStyle",
82  "deleteStyle",
83  "saveStyleSettings",
84  "saveIndividualStyleSettings"
85  ])) {
86  $this->$cmd();
87  }
88  }
89  }
90 
91  protected function settings(): void
92  {
93  $mt = $this->gui->mainTemplate();
94  $form = $this->initStylePropertiesForm();
95  $mt->setContent(
96  $form->getHTML()
97  );
98  }
99 
104  {
105  $ilCtrl = $this->gui->ctrl();
106  $lng = $this->domain->lng();
107  $tabs = $this->gui->tabs();
108  $settings = $this->domain->settings();
109  $mt = $this->gui->mainTemplate();
110 
111  $style_id = $this->current_style_id;
112  /*
113  if (ilObject::_lookupType($style_id) == "sty") {
114  $page_gui->setStyleId($style_id);
115  } else {
116  $style_id = 0;
117  }
118 
119  $page_gui->setTabHook($this, "addPageTabs");
120  $ilCtrl->getHTML($page_gui);
121  $ilTabs->setTabActive("obj_sty");*/
122 
123  $lng->loadLanguageModule("style");
124 
125  $form = new ilPropertyFormGUI();
126  if ($this->object_manager->globalFixed()) {
127  $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
128  $st->setValue($this->object_manager->getGlobalFixedTitle() . " (" .
129  $lng->txt("global_fixed") . ")");
130  $form->addItem($st);
131  } else {
132  $st_styles = $this->object_manager->getSelectableStyles();
133 
134  $st_styles[0] = $lng->txt("default");
135  ksort($st_styles);
136 
137  // individual style
138  if ($this->object_manager->hasEffectiveIndividualStyle($style_id)) {
139  $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
140  $st->setValue(ilObject::_lookupTitle($style_id));
141  $form->addItem($st);
142 
143  if ($this->isContainer()) {
144  $cb = new ilCheckboxInputGUI($lng->txt("style_support_reuse"), "support_reuse");
145  $cb->setInfo($lng->txt("style_support_reuse_info"));
146  $cb->setChecked($this->container_manager->getReuse());
147  $form->addItem($cb);
148  $form->addCommandButton(
149  "saveIndividualStyleSettings",
150  $lng->txt("save")
151  );
152  }
153 
154  $form->addCommandButton(
155  "editStyle",
156  $lng->txt("style_edit_style")
157  );
158  $form->addCommandButton(
159  "deleteStyle",
160  $lng->txt("style_delete_style")
161  );
162  }
163 
164  if ($this->object_manager->canSelectStyle($style_id)) {
165  $style_sel = new ilSelectInputGUI(
166  $lng->txt("style_current_style"),
167  "style_id"
168  );
169  $style_sel->setOptions($st_styles);
170  $style_sel->setValue($style_id);
171  $form->addItem($style_sel);
172  $form->addCommandButton(
173  "saveStyleSettings",
174  $lng->txt("save")
175  );
176  $form->addCommandButton(
177  "createStyle",
178  $lng->txt("sty_create_ind_style")
179  );
180  }
181  }
182  $form->setTitle($lng->txt("obj_sty"));
183  $form->setFormAction($ilCtrl->getFormAction($this));
184 
185  return $form;
186  }
187 
188  protected function isContainer(): bool
189  {
190  if ($this->ref_id > 0) {
191  $type = ilObject::_lookupType($this->ref_id, true);
192  if ($this->domain->objectDefinition()->isContainer($type)) {
193  return true;
194  }
195  }
196  return false;
197  }
198 
199  public function forwardToStyleSheet()
200  {
201  $ctrl = $this->gui->ctrl();
202  $cmd = $ctrl->getCmd();
203 
204  $style_gui = new ilObjStyleSheetGUI(
205  "",
206  $this->current_style_id,
207  false
208  );
209  $style_id = $ctrl->forwardCommand($style_gui);
210  if (in_array($cmd, ["save", "copyStyle", "importStyle", "confirmedDelete"])) {
211  $style_id = $style_gui->getObject()->getId();
212  if ($cmd == "confirmedDelete") {
213  $style_id = 0;
214  } else {
215  $this->setOwnerId($style_id);
216  }
217  $this->updateStyleId($style_id);
218  if (in_array($cmd, ["save", "copyStyle", "importStyle"])) {
219  $ctrl->redirect($this, "editStyle");
220  }
221  $ctrl->redirect($this, "settings");
222  }
223  }
224 
225  protected function updateStyleId(int $style_id): void
226  {
227  $this->object_manager->updateStyleId($style_id);
228  }
229 
230  protected function setOwnerId(int $style_id): void
231  {
232  $this->object_manager->setOwnerOfStyle($style_id);
233  }
234 
235  public function createStyle(): void
236  {
237  $ctrl = $this->gui->ctrl();
238  $ctrl->redirectByClass("ilobjstylesheetgui", "create");
239  }
240 
241  public function editStyle(): void
242  {
243  $ctrl = $this->gui->ctrl();
244  $ctrl->redirectByClass("ilobjstylesheetgui", "edit");
245  }
246 
247  public function deleteStyle(): void
248  {
249  $ctrl = $this->gui->ctrl();
250  $ctrl->redirectByClass("ilobjstylesheetgui", "delete");
251  }
252 
256  protected function saveStyleSettings(): void
257  {
258  $settings = $this->domain->settings();
259  $lng = $this->domain->lng();
260  $ctrl = $this->gui->ctrl();
261 
262  $form = $this->initStylePropertiesForm();
263  $form->checkInput();
264  if ($this->object_manager->canSelectStyle($this->current_style_id)) {
265  $style_id = (int) $form->getInput("style_id");
266  $this->updateStyleId($style_id);
267  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
268  }
269  $ctrl->redirect($this, "settings");
270  }
271 
272  protected function saveIndividualStyleSettings(): void
273  {
274  $lng = $this->domain->lng();
275  $ctrl = $this->gui->ctrl();
276 
277  $form = $this->initStylePropertiesForm();
278  $form->checkInput();
279  if ($this->isContainer()) {
280  $this->container_manager->saveReuse((bool) $form->getInput("support_reuse"));
281  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
282  }
283  $ctrl->redirect($this, "settings");
284  }
285 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This class represents a selection list property in a property form.
Content style internal ui factory.
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service, ?int $current_style_id, int $ref_id, int $obj_id)
Manages repository object related content style behaviour.
setOptions(array $a_options)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
object(int $ref_id, int $obj_id=0)
Objects without ref id (e.g.
static _lookupTitle(int $obj_id)
$lng
static _lookupType(int $id, bool $reference=false)
Manages container related content style behaviour.