ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSystemStyleOverviewGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as Refinery;
27
29{
30 protected ilCtrl $ctrl;
32 protected Language $lng;
40 protected Refinery $refinery;
42 protected ilTabsGUI $tabs;
43 protected ilHelpGUI $help;
45 protected string $ref_id;
46 protected bool $read_only = true;
47 protected bool $management_enabled = false;
48
49 protected string $style_id;
50
51 public function __construct(
59 Refinery $refinery,
64 string $skin_id,
65 string $style_id,
66 string $ref_id,
67 bool $read_only,
69 ) {
70 $this->ctrl = $ctrl;
71 $this->lng = $lng;
72 $this->tpl = $tpl;
73 $this->ui_factory = $ui_factory;
74 $this->renderer = $renderer;
75 $this->request_wrapper = $request_wrapper;
76 $this->toolbar = $toolbar;
77 $this->refinery = $refinery;
78 $this->tabs = $tabs;
79 $this->style_id = $style_id;
80 $this->message_stack = new ilSystemStyleMessageStack($this->tpl);
81 $this->skin_factory = $skin_factory;
82 $this->style_container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
83 $this->help = $help;
84 $this->ref_id = $ref_id;
85 $this->upload = $upload;
86 $this->config = new ilSystemStyleConfig();
87 $this->setReadOnly($read_only);
88 $this->setManagementEnabled($management_enabled);
89 }
90
91 public function executeCommand(): void
92 {
93 $cmd = $this->ctrl->getCmd();
94
95 if ($cmd == '') {
96 $cmd = $this->isReadOnly() ? 'view' : 'edit';
97 }
98
99 switch ($cmd) {
100 case 'addSystemStyle':
101 case 'addSubStyle':
102 case 'saveNewSystemStyle':
103 case 'saveNewSubStyle':
104 case 'copyStyle':
105 case 'importStyle':
106 case 'deleteStyles':
107 case 'deleteStyle':
108 case 'confirmDelete':
109 if (!$this->isManagementEnabled()) {
110 throw new ilObjectException($this->lng->txt('permission_denied'));
111 }
112 $this->$cmd();
113 break;
114 case 'cancel':
115 case 'edit':
116 case 'export':
117 case 'moveUserStyles':
118 case 'saveStyleSettings':
119 if ($this->isReadOnly()) {
120 throw new ilObjectException($this->lng->txt('permission_denied'));
121 }
122 $this->$cmd();
123 break;
124 case 'view':
125 $this->$cmd();
126 break;
127 }
128 $this->message_stack->sendMessages();
129 }
130
131 protected function view(): void
132 {
133 $table = new ilSystemStylesTableGUI($this, 'edit');
134 $this->tpl->setContent($table->getHTML().$table->getModalsHtml());
135 }
136
137 public function getAssignmentCreationModal(string $style_name = ""): ?\ILIAS\UI\Component\Modal\RoundTrip
138 {
139 $options = [];
140 foreach (ilStyleDefinition::getAllSkinStyles() as $id => $skin_style) {
141 if (!$skin_style['substyle_of'] && $style_name != $skin_style['style_name']) {
142 $options[$id] = $skin_style['title'];
143 }
144 }
145
146 $default = "default:delos";
147 if ($style_name == "Delos") {
148 $default = key($options);
149 }
150
151 if (count($options) == 0) {
152 return null;
153 }
154
155 $txt = $this->lng->txt('sty_move_user_styles').' '.$this->lng->txt('sty_to');
156
157 $byline = $this->lng->txt('sty_move_user_styles') . ' ' .
158 $this->lng->txt('sty_from') . ' ' . $style_name;
159
160 $select = $this->ui_factory->input()->field()
161 ->select($txt, $options, $byline)
162 ->withValue($default)
163 ->withAdditionalTransformation($this->refinery->string()->splitString(':'))
164 ->withRequired(true);
165
166 return $this->ui_factory->modal()->roundtrip(
167 $this->lng->txt('change_assignment'),
168 [],
169 ["new_style" => $select],
170 $this->ctrl->getLinkTargetByClass(ilSystemStyleOverviewGUI::class, 'moveUserStyles')
171 );
172 }
173
174 protected function cancel(): void
175 {
176 $this->edit();
177 }
178
179 public function edit(): void
180 {
181 $table = new ilSystemStylesTableGUI($this, 'edit');
182 $table->addActions($this->isManagementEnabled());
183 $this->tpl->setContent($table->getHTML().$table->getModalsHtml());
184 }
185
186 public function saveStyleSettings(): void
187 {
188 $active_styles = $this->request_wrapper->post()->retrieve('st_act', $this->refinery->identity());
189
190 if ($this->checkStyleSettings($this->message_stack, $active_styles)) {
192 foreach ($all_styles as $style) {
193 if (!isset($active_styles[$style['id']])) {
194 ilSystemStyleSettings::_deactivateStyle($style['template_id'], $style['style_id']);
195 } else {
196 ilSystemStyleSettings::_activateStyle($style['template_id'], $style['style_id']);
197 }
198 }
199
200 //set default skin and style
201 if ($this->request_wrapper->post()->has('default_skin_style')) {
202 $sknst = $this->request_wrapper->post()->retrieve(
203 'default_skin_style',
204 $this->refinery->string()->splitString(':')
205 );
207 }
208 $this->message_stack->addMessage(new ilSystemStyleMessage(
209 $this->lng->txt('msg_obj_modified'),
211 ));
212 }
213 $this->message_stack->sendMessages();
214 $this->ctrl->redirect($this, 'edit');
215 }
216
217 public function moveUserStyles(): void
218 {
219 global $DIC;
220
221 $request = $DIC->http()->request();
222
223 $modal = $this->getAssignmentCreationModal()->withRequest($request);
224 [$new_skin, $new_style] = $modal->getData()["new_style"];
225
226 $old_skin = $this->request_wrapper->query()->retrieve('old_skin_id', $this->refinery->kindlyTo()->string());
227 $old_style = $this->request_wrapper->query()->retrieve('old_style_id', $this->refinery->kindlyTo()->string());
228
229
230
231 if ($old_style == 'other') {
232 // get all user assigned styles
233 $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
234
235 // move users that are not assigned to
236 // currently existing style
237 foreach ($all_user_styles as $style) {
238 if (!ilStyleDefinition::styleExists($style)) {
239 [$old_skin, $old_style] = explode(':', $style);
240 ilObjUser::_moveUsersToStyle($old_skin, $old_style, $new_skin, $new_style);
241 }
242 }
243 } else {
244 ilObjUser::_moveUsersToStyle($old_skin, $old_style, $new_skin, $new_style);
245 }
246 $message = sprintf($this->lng->txt('sty_move_user_styles_saved'), $old_skin, $new_skin);
247
248 $this->message_stack->addMessage(new ilSystemStyleMessage($message, ilSystemStyleMessage::TYPE_SUCCESS));
249 $this->message_stack->sendMessages();
250 $this->ctrl->redirect($this, 'edit');
251 }
252
253 protected function checkStyleSettings(ilSystemStyleMessageStack $message_stack, ?array $active_styles): bool
254 {
255 $passed = true;
256
257 if (!$active_styles || count($active_styles) < 1) {
258 $passed = false;
260 $this->lng->txt('at_least_one_style'),
262 ));
263 }
264
265 if ($this->request_wrapper->post()->has('default_skin_style')) {
266 $default_style = $this->request_wrapper->post()->retrieve(
267 'default_skin_style',
268 $this->refinery->kindlyTo()->string()
269 );
270 } else {
271 $default_style = $this->config->getDefaultStyleId();
272 }
273
274
275
276 if (!isset($active_styles[$default_style])) {
277 $passed = false;
279 $this->lng->txt('cant_deactivate_default_style'),
281 ));
282 }
283
284 // check if a style should be deactivated, that still has
285 // a user assigned to
287
288 foreach ($all_styles as $style) {
289 if (!isset($active_styles[$style['id']])) {
290 if (ilObjUser::_getNumberOfUsersForStyle($style['template_id'], $style['style_id']) > 0) {
291 $passed = false;
293 $style['style_name'] . ': ' . $this->lng->txt('cant_deactivate_if_users_assigned'),
295 ));
296 }
297 }
298 }
299 return $passed;
300 }
301
302
303 protected function export(): void
304 {
305 try {
306 $this->style_container->export();
307 } catch (Exception $e) {
308 $this->message_stack->addMessage(new ilSystemStyleMessage(
309 $this->lng->txt('zip_export_failed') . ' ' . $e->getMessage(),
311 ));
312 }
313 }
314
315
316 public function isReadOnly(): bool
317 {
318 return $this->read_only;
319 }
320
321 public function setReadOnly(bool $read_only): void
322 {
323 $this->read_only = $read_only;
324 }
325
326 public function isManagementEnabled(): bool
327 {
329 }
330
331 public function setManagementEnabled(bool $management_enabled): void
332 {
333 $this->management_enabled = $management_enabled;
334 }
335}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class ilCtrl provides processing control methods.
Help GUI class.
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
static _getAllUserAssignedStyles()
static _moveUsersToStyle(string $a_from_skin, string $a_from_style, string $a_to_skin, string $a_to_style)
Base exception class for object service.
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
skinStyleContainerFromId(string $skin_id, ilSystemStyleMessageStack $message_stack)
Get container class is responsible for all file system related actions related actions of a skin such...
This class is responsible for all file system related actions related actions of a skin such as copyi...
static getAllSkinStyles()
Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this ar...
static styleExists(string $style_id)
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Used to stack messages to be shown to the user.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
checkStyleSettings(ilSystemStyleMessageStack $message_stack, ?array $active_styles)
setManagementEnabled(bool $management_enabled)
__construct(ilCtrl $ctrl, Language $lng, ilGlobalTemplateInterface $tpl, Factory $ui_factory, Renderer $renderer, WrapperFactory $request_wrapper, ilToolbarGUI $toolbar, Refinery $refinery, ilSkinFactory $skin_factory, FileUpload $upload, ilTabsGUI $tabs, ilHelpGUI $help, string $skin_id, string $style_id, string $ref_id, bool $read_only, bool $management_enabled)
ilSystemStyleMessageStack $message_stack
getAssignmentCreationModal(string $style_name="")
static _activateStyle(string $a_skin, string $a_style)
activate system style
static _deactivateStyle(string $a_skin, string $a_style)
deactivate system style
static setCurrentDefaultStyle(string $skin_id, string $style_id)
Sets the default style of the system.
TableGUI class for system styles.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:31
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31