ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjectContentStyleSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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,
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
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
108 $style_id = $this->current_style_id;
109
110 $lng->loadLanguageModule("style");
111
112 $form = new ilPropertyFormGUI();
113 if ($this->object_manager->globalFixed()) {
114 $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
115 $st->setValue($this->object_manager->getGlobalFixedTitle() . " (" .
116 $lng->txt("global_fixed") . ")");
117 $form->addItem($st);
118 } else {
119 $st_styles = $this->object_manager->getSelectableStyles();
120
121 $default_title = "";
122 if ($this->object_manager->getGlobalDefaultTitle() !== "") {
123 $default_title = " (" . $this->object_manager->getGlobalDefaultTitle() . ")";
124 }
125 $st_styles[0] = $lng->txt("default") . $default_title;
126 ksort($st_styles);
127
128 // individual style
129 if ($this->object_manager->hasEffectiveIndividualStyle($style_id)) {
130 $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
131 $st->setValue(ilObject::_lookupTitle($style_id));
132 $form->addItem($st);
133
134 if ($this->isContainer()) {
135 $cb = new ilCheckboxInputGUI($lng->txt("style_support_reuse"), "support_reuse");
136 $cb->setInfo($lng->txt("style_support_reuse_info"));
137 $cb->setChecked($this->container_manager->getReuse());
138 $form->addItem($cb);
139 $form->addCommandButton(
140 "saveIndividualStyleSettings",
141 $lng->txt("save")
142 );
143 }
144
145 $form->addCommandButton(
146 "editStyle",
147 $lng->txt("style_edit_style")
148 );
149 $form->addCommandButton(
150 "deleteStyle",
151 $lng->txt("style_delete_style")
152 );
153 }
154
155 if ($this->object_manager->canSelectStyle($style_id)) {
156 $style_sel = new ilSelectInputGUI(
157 $lng->txt("style_current_style"),
158 "style_id"
159 );
160 $style_sel->setOptions($st_styles);
161 $style_sel->setValue($style_id);
162 $form->addItem($style_sel);
163 $form->addCommandButton(
164 "saveStyleSettings",
165 $lng->txt("save")
166 );
167 $form->addCommandButton(
168 "createStyle",
169 $lng->txt("sty_create_ind_style")
170 );
171 }
172 }
173 $form->setTitle($lng->txt("obj_sty"));
174 $form->setFormAction($ilCtrl->getFormAction($this));
175
176 return $form;
177 }
178
179 protected function isContainer(): bool
180 {
181 if ($this->ref_id > 0) {
182 $type = ilObject::_lookupType($this->ref_id, true);
183 if ($this->domain->objectDefinition()->isContainer($type)) {
184 return true;
185 }
186 }
187 return false;
188 }
189
190 public function forwardToStyleSheet()
191 {
192 $ctrl = $this->gui->ctrl();
193 $cmd = $ctrl->getCmd();
194
195 $style_gui = new ilObjStyleSheetGUI(
196 "",
197 $this->current_style_id,
198 false
199 );
200 $style_id = $ctrl->forwardCommand($style_gui);
201 if (in_array($cmd, ["save", "copyStyle", "importStyle", "confirmedDelete"])) {
202 $style_id = $style_gui->getObject()->getId();
203 if ($cmd == "confirmedDelete") {
204 $style_id = 0;
205 } else {
206 $this->setOwnerId($style_id);
207 }
208 $this->updateStyleId($style_id);
209 if (in_array($cmd, ["save", "copyStyle", "importStyle"])) {
210 $ctrl->redirect($this, "editStyle");
211 }
212 $ctrl->redirect($this, "settings");
213 }
214 }
215
216 protected function updateStyleId(int $style_id): void
217 {
218 $this->object_manager->updateStyleId($style_id);
219 }
220
221 protected function setOwnerId(int $style_id): void
222 {
223 $this->object_manager->setOwnerOfStyle($style_id);
224 }
225
226 public function createStyle(): void
227 {
228 $ctrl = $this->gui->ctrl();
229 $ctrl->redirectByClass("ilobjstylesheetgui", "create");
230 }
231
232 public function editStyle(): void
233 {
234 $ctrl = $this->gui->ctrl();
235 $ctrl->redirectByClass("ilobjstylesheetgui", "edit");
236 }
237
238 public function deleteStyle(): void
239 {
240 $ctrl = $this->gui->ctrl();
241 $ctrl->redirectByClass("ilobjstylesheetgui", "delete");
242 }
243
247 protected function saveStyleSettings(): void
248 {
249 $settings = $this->domain->settings();
250 $lng = $this->domain->lng();
251 $ctrl = $this->gui->ctrl();
252
253 $form = $this->initStylePropertiesForm();
254 $form->checkInput();
255 if ($this->object_manager->canSelectStyle($this->current_style_id)) {
256 $style_id = (int) $form->getInput("style_id");
257 $this->updateStyleId($style_id);
258 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
259 }
260 $ctrl->redirect($this, "settings");
261 }
262
263 protected function saveIndividualStyleSettings(): void
264 {
265 $lng = $this->domain->lng();
266 $ctrl = $this->gui->ctrl();
267
268 $form = $this->initStylePropertiesForm();
269 $form->checkInput();
270 if ($this->isContainer()) {
271 $this->container_manager->saveReuse((bool) $form->getInput("support_reuse"));
272 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
273 }
274 $ctrl->redirect($this, "settings");
275 }
276}
Manages container related content style behaviour.
object(int $ref_id, int $obj_id=0)
Objects without ref id (e.g.
Content style internal ui factory.
Manages repository object related content style behaviour.
This class represents a checkbox property in a property form.
This class represents a non editable value in a property form.
Class ilObjStyleSheetGUI.
Style settings of a repository object.
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service, ?int $current_style_id, int $ref_id, int $obj_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26