ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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;
42
43 public function __construct(
44 InternalDomainService $domain_service,
45 InternalGUIService $gui_service,
47 int $ref_id,
48 int $obj_id
49 ) {
50 global $DIC;
51 $this->main_tpl = $DIC->ui()->mainTemplate();
52 $this->domain = $domain_service;
53 $this->gui = $gui_service;
54 $this->ref_id = $ref_id;
55 $this->obj_id = ($obj_id > 0)
56 ? $obj_id
58 $this->container_manager = $domain_service->repositoryContainer($ref_id);
59 $this->object_manager = $domain_service->object($ref_id, $this->obj_id);
60 $this->current_style_id = $current_style_id ?? $this->object_manager->getStyleId();
61 $this->rbac_system = $DIC->rbac()->system();
62 }
63
64 public function executeCommand(): void
65 {
66 $ctrl = $this->gui->ctrl();
67
68 $next_class = $ctrl->getNextClass($this);
69 $cmd = $ctrl->getCmd("settings");
70
71 switch ($next_class) {
72 case "ilobjstylesheetgui":
73 $this->gui->tabs()->clearTargets();
74 $ctrl->setReturn($this, "settings");
75 $this->forwardToStyleSheet();
76 break;
77
78 default:
79 if (in_array($cmd, [
80 "settings",
81 "editStyle",
82 "updateStyle",
83 "createStyle",
84 "deleteStyle",
85 "saveStyleSettings",
86 "saveIndividualStyleSettings"
87 ])) {
88 $this->$cmd();
89 }
90 }
91 }
92
93 protected function settings(): void
94 {
95 $mt = $this->gui->mainTemplate();
96 $form = $this->initStylePropertiesForm();
97 $mt->setContent(
98 $form->getHTML()
99 );
100 }
101
106 {
107 $ilCtrl = $this->gui->ctrl();
108 $lng = $this->domain->lng();
109
110 $style_id = $this->current_style_id;
111 $access = $this->rbac_system->checkAccess('write', $this->ref_id);
112
113 $lng->loadLanguageModule("style");
114
115 $form = new ilPropertyFormGUI();
116 if ($this->object_manager->globalFixed()) {
117 $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
118 $st->setValue($this->object_manager->getGlobalFixedTitle() . " (" .
119 $lng->txt("global_fixed") . ")");
120 $form->addItem($st);
121 } else {
122 $st_styles = $this->object_manager->getSelectableStyles();
123
124 $default_title = "";
125 if ($this->object_manager->getGlobalDefaultTitle() !== "") {
126 $default_title = " (" . $this->object_manager->getGlobalDefaultTitle() . ")";
127 }
128 $st_styles[0] = $lng->txt("default") . $default_title;
129 ksort($st_styles);
130
131 // individual style
132 if ($this->object_manager->hasEffectiveIndividualStyle($style_id)) {
133 $st = new ilNonEditableValueGUI($lng->txt("style_current_style"));
134 $st->setValue(ilObject::_lookupTitle($style_id));
135 $form->addItem($st);
136
137 if ($this->isContainer()) {
138 $cb = new ilCheckboxInputGUI($lng->txt("style_support_reuse"), "support_reuse");
139 $cb->setInfo($lng->txt("style_support_reuse_info"));
140 $cb->setChecked($this->container_manager->getReuse());
141 $form->addItem($cb);
142 if ($access) {
143 $form->addCommandButton(
144 "saveIndividualStyleSettings",
145 $lng->txt("save")
146 );
147 }
148 }
149
150 if ($access) {
151 $form->addCommandButton(
152 "editStyle",
153 $lng->txt("style_edit_style")
154 );
155
156 $form->addCommandButton(
157 "deleteStyle",
158 $lng->txt("style_delete_style")
159 );
160 }
161 }
162
163 if ($this->object_manager->canSelectStyle($style_id)) {
164 $style_sel = new ilSelectInputGUI(
165 $lng->txt("style_current_style"),
166 "style_id"
167 );
168 $style_sel->setOptions($st_styles);
169 $style_sel->setValue($style_id);
170 $form->addItem($style_sel);
171
172 if ($access) {
173 $form->addCommandButton(
174 "saveStyleSettings",
175 $lng->txt("save")
176 );
177
178 $form->addCommandButton(
179 "createStyle",
180 $lng->txt("sty_create_ind_style")
181 );
182 }
183 }
184 }
185 $form->setTitle($lng->txt("obj_sty"));
186 $form->setFormAction($ilCtrl->getFormAction($this));
187
188 if (!$access) {
189 foreach ($form->getItems() as $item) {
190 if ($item instanceof ilFormSectionHeaderGUI) {
191 continue;
192 }
193
194 $item->setDisabled(true);
195 }
196 }
197
198 return $form;
199 }
200
201 protected function isContainer(): bool
202 {
203 if ($this->ref_id > 0) {
204 $type = ilObject::_lookupType($this->ref_id, true);
205 if ($this->domain->objectDefinition()->isContainer($type)) {
206 return true;
207 }
208 }
209 return false;
210 }
211
212 public function forwardToStyleSheet(): void
213 {
214 $ctrl = $this->gui->ctrl();
215 $cmd = $ctrl->getCmd();
216
217 $style_gui = new ilObjStyleSheetGUI(
218 "",
219 $this->current_style_id,
220 false
221 );
222 $style_id = $ctrl->forwardCommand($style_gui);
223 if (in_array($cmd, ["save", "copyStyle", "importStyle", "confirmedDelete"])) {
224 $style_id = $style_gui->getObject()->getId();
225 if ($cmd == "confirmedDelete") {
226 $style_id = 0;
227 } else {
228 $this->setOwnerId($style_id);
229 }
230 $this->updateStyleId($style_id);
231 if (in_array($cmd, ["save", "copyStyle", "importStyle"])) {
232 $ctrl->redirect($this, "editStyle");
233 }
234 $ctrl->redirect($this, "settings");
235 }
236 }
237
238 protected function updateStyleId(int $style_id): void
239 {
240 $this->object_manager->updateStyleId($style_id);
241 }
242
243 protected function setOwnerId(int $style_id): void
244 {
245 $this->object_manager->setOwnerOfStyle($style_id);
246 }
247
248 public function createStyle(): void
249 {
250 $ctrl = $this->gui->ctrl();
251 $ctrl->redirectByClass("ilobjstylesheetgui", "create");
252 }
253
254 public function editStyle(): void
255 {
256 $ctrl = $this->gui->ctrl();
257 $ctrl->redirectByClass("ilobjstylesheetgui", "edit");
258 }
259
260 public function deleteStyle(): void
261 {
262 $ctrl = $this->gui->ctrl();
263 $ctrl->redirectByClass("ilobjstylesheetgui", "delete");
264 }
265
269 protected function saveStyleSettings(): void
270 {
271 $settings = $this->domain->settings();
272 $lng = $this->domain->lng();
273 $ctrl = $this->gui->ctrl();
274
275 $form = $this->initStylePropertiesForm();
276 $form->checkInput();
277 if ($this->object_manager->canSelectStyle($this->current_style_id)) {
278 $style_id = (int) $form->getInput("style_id");
279 $this->updateStyleId($style_id);
280 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
281 }
282 $ctrl->redirect($this, "settings");
283 }
284
285 protected function saveIndividualStyleSettings(): void
286 {
287 $lng = $this->domain->lng();
288 $ctrl = $this->gui->ctrl();
289
290 $form = $this->initStylePropertiesForm();
291 $form->checkInput();
292 if ($this->isContainer()) {
293 $this->container_manager->saveReuse((bool) $form->getInput("support_reuse"));
294 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
295 }
296 $ctrl->redirect($this, "settings");
297 }
298}
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 section header 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.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a selection list property in a property form.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26