ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilSystemStyleOverviewGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
29 {
30  protected ilCtrl $ctrl;
32  protected Language $lng;
37  protected Factory $ui_factory;
38  protected Renderer $renderer;
40  protected Refinery $refinery;
42  protected ilTabsGUI $tabs;
43  protected ilHelpGUI $help;
44  protected FileUpload $upload;
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(
52  ilCtrl $ctrl,
53  Language $lng,
55  Factory $ui_factory,
56  Renderer $renderer,
57  WrapperFactory $request_wrapper,
58  ilToolbarGUI $toolbar,
59  Refinery $refinery,
60  ilSkinFactory $skin_factory,
61  FileUpload $upload,
62  ilTabsGUI $tabs,
63  ilHelpGUI $help,
64  string $skin_id,
65  string $style_id,
66  string $ref_id,
67  bool $read_only,
68  bool $management_enabled
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)) {
191  $all_styles = ilStyleDefinition::getAllSkinStyles();
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  );
206  ilSystemStyleSettings::setCurrentDefaultStyle($sknst[0], $sknst[1]);
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;
259  $message_stack->addMessage(new ilSystemStyleMessage(
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;
278  $message_stack->addMessage(new ilSystemStyleMessage(
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
286  $all_styles = ilStyleDefinition::getAllSkinStyles();
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;
292  $message_stack->addMessage(new ilSystemStyleMessage(
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static styleExists(string $style_id)
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
Interface Observer Contains several chained tasks and infos about them.
static _moveUsersToStyle(string $a_from_skin, string $a_from_style, string $a_to_skin, string $a_to_style)
__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)
Help GUI class.
Base exception class for object service.
renderer()
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
getAssignmentCreationModal(string $style_name="")
static _deactivateStyle(string $a_skin, string $a_style)
deactivate system style
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
static _activateStyle(string $a_skin, string $a_style)
activate system style
This class is responsible for all file system related actions related actions of a skin such as copyi...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getAllSkinStyles()
Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this ar...
This is how the factory for UI elements looks.
Definition: Factory.php:37
skinStyleContainerFromId(string $skin_id, ilSystemStyleMessageStack $message_stack)
Get container class is responsible for all file system related actions related actions of a skin such...
global $DIC
Definition: shib_login.php:26
checkStyleSettings(ilSystemStyleMessageStack $message_stack, ?array $active_styles)
static setCurrentDefaultStyle(string $skin_id, string $style_id)
Sets the default style of the system.
Class FileUpload.
Definition: FileUpload.php:37
$txt
Definition: error.php:31
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
ilSystemStyleMessageStack $message_stack
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Used to stack messages to be shown to the user.
$message
Definition: xapiexit.php:31
TableGUI class for system styles.
setManagementEnabled(bool $management_enabled)
static _getAllUserAssignedStyles()