ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSystemStylesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  protected bool $with_actions = false;
27  protected bool $management_enabled = false;
28  protected bool $read_documentation = true;
29  protected \ILIAS\DI\UIServices $ui;
30  protected array $modals = [];
31 
32  public function __construct(object $a_parent_obj, string $a_parent_cmd = '')
33  {
34  global $DIC;
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36  $this->ui = $DIC->ui();
37  $this->getStyles();
38 
39  $this->setLimit(9999);
40  $this->setTitle($this->lng->txt('manage_system_styles'));
41  $this->addColumn($this->lng->txt(''));
42  $this->addColumn($this->lng->txt('style_name'), 'style_name');
43  $this->addColumn($this->lng->txt('skin_name'), 'skin_name');
44  $this->addColumn($this->lng->txt('sty_substyle_of'));
45  $this->addColumn($this->lng->txt('scope'));
46  $this->addColumn($this->lng->txt('default'));
47  $this->addColumn($this->lng->txt('active'));
48  $this->addColumn($this->lng->txt('users'), 'users');
49  $this->addColumn($this->lng->txt('version'));
50  $this->setRowTemplate('tpl.sys_styles_row.html', 'Services/Style/System');
51  $this->setEnableHeader(true);
52  }
53 
58  public function addActions($management_enabled, bool $read_documentation = true)
59  {
60  $this->setManagementEnabled($management_enabled);
61  $this->setReadDocumentation($read_documentation);
62 
63  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
64  $this->addCommandButton('saveStyleSettings', $this->lng->txt('save'));
65  $this->setRowTemplate('tpl.sys_styles_row_with_actions.html', 'Services/Style/System');
66 
67  if ($read_documentation || $management_enabled) {
68  $this->setWithActions(true);
69 
70  $this->addColumn($this->lng->txt('actions'));
71  }
72  if ($management_enabled) {
73  $this->addMultiCommand('deleteStyles', $this->lng->txt('delete'));
74  }
75  }
76 
80  public function getStyles()
81  {
82  // get all user assigned styles
83  $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
84 
85  // output 'other' row for all users, that are not assigned to
86  // any existing style
87  $users_missing_styles = 0;
88  foreach ($all_user_styles as $skin_style_id) {
89  $style_arr = explode(':', $skin_style_id);
90  if (!ilStyleDefinition::styleExists($style_arr[1])) {
91  $users_missing_styles += ilObjUser::_getNumberOfUsersForStyle($style_arr[0], $style_arr[1]);
92  }
93  }
95  if ($users_missing_styles > 0) {
96  $all_styles['other'] =
97  [
98  'title' => $this->lng->txt('other'),
99  'id' => 'other',
100  'template_id' => '',
101  'skin_id' => 'other',
102  'style_id' => 'other',
103  'skin_name' => 'other',
104  'style_name' => 'other',
105  'users' => $users_missing_styles,
106  'version' => '-',
107  'substyle_of' => ''
108  ];
109  }
110 
111  $this->setData($all_styles);
112  }
113 
118  protected function fillRow(array $a_set): void
119  {
120  $this->tpl->setVariable('STYLE_NAME', $a_set['style_name']);
121  $this->tpl->setVariable('SKIN_NAME', $a_set['skin_name']);
122  $is_substyle = isset($a_set['substyle_of']) && $a_set['substyle_of'] != '';
123 
124  if (!$is_substyle) {
125  $this->tpl->setVariable('USERS', $a_set['users']);
126  } else {
127  $this->tpl->setVariable('USERS', '-');
128  }
129 
130  if ($a_set['id'] != 'other') {
131  $this->tpl->setCurrentBlock('default_input');
132 
133  if (!$is_substyle) {
134  $this->tpl->setVariable('DEFAULT_ID', $a_set['id']);
135  if (ilSystemStyleSettings::getCurrentDefaultSkin() == $a_set['skin_id'] &&
136  ilSystemStyleSettings::getCurrentDefaultStyle() == $a_set['style_id']
137  ) {
138  $this->tpl->setVariable('CHECKED_DEFAULT', " checked='checked' ");
139  } else {
140  $this->tpl->setVariable('CHECKED_DEFAULT');
141  }
142  $this->tpl->parseCurrentBlock();
143  }
144 
145  $this->tpl->setCurrentBlock('active_input');
146  $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
147 
148  if ($is_substyle) {
149  $this->tpl->setVariable('DISABLED_ACTIVE', 'disabled');
150 
151  if (ilSystemStyleSettings::_lookupActivatedStyle($a_set['skin_id'], $a_set['substyle_of'])) {
152  $this->tpl->setVariable('CHECKED_ACTIVE', " checked='checked' ");
153  } else {
154  $this->tpl->setVariable('CHECKED_ACTIVE');
155  }
156  } elseif (ilSystemStyleSettings::_lookupActivatedStyle($a_set['skin_id'], $a_set['style_id'])) {
157  $this->tpl->setVariable('CHECKED_ACTIVE', " checked='checked' ");
158  } else {
159  $this->tpl->setVariable('CHECKED_ACTIVE');
160  }
161 
162  $this->tpl->parseCurrentBlock();
163  }
164 
165  if ($is_substyle) {
166  $this->tpl->setVariable('SUB_STYLE_OF', $a_set['substyle_of_name']);
167 
169  $a_set['skin_id'],
170  $a_set['substyle_of'],
171  $a_set['style_id']
172  );
173 
174  $categories = [];
175 
176  foreach ($assignments as $assignment) {
177  $category_title = ilObject::_lookupTitle(ilObject::_lookupObjId((int) $assignment['ref_id']));
178  if ($category_title) {
179  $categories[] = $category_title;
180  }
181  }
182 
183  $listing = $this->ui->factory()->listing()->unordered($categories);
184  $this->tpl->setVariable(
185  'CATEGORIES',
186  $this->lng->txt('local') . $this->ui->renderer()->render($listing)
187  );
188  } else {
189  $this->tpl->setVariable('SUB_STYLE_OF');
190  $this->tpl->setVariable('CATEGORIES', $this->lng->txt('global'));
191  }
192 
193  $this->tpl->setVariable('VERSION', $a_set['version']);
194 
195  if ($this->isWithActions()) {
196  $action_items = [];
197 
200  if ($this->isReadDocumentation() && $a_set['skin_id'] != 'other') {
201  $this->ctrl->setParameterByClass(ilSystemStyleDocumentationGUI::class, 'skin_id', $a_set['skin_id']);
202  $this->ctrl->setParameterByClass(ilSystemStyleDocumentationGUI::class, 'style_id', $a_set['style_id']);
203  $action_items[] = $this->ui->factory()->link()->standard(
204  $this->lng->txt('open_documentation'),
205  $this->ctrl->getLinkTargetByClass('ilSystemStyleDocumentationGUI', 'entries')
206  );
207  }
208 
209  if ($this->isManagementEnabled() && $a_set['skin_id'] != 'other') {
210  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'skin_id', $a_set['skin_id']);
211  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'style_id', $a_set['style_id']);
212 
213  $this->ctrl->setParameterByClass(ilSystemStyleOverviewGUI::class, 'skin_id', $a_set['skin_id']);
214  $this->ctrl->setParameterByClass(ilSystemStyleOverviewGUI::class, 'style_id', $a_set['style_id']);
215 
216  $config = new ilSystemStyleConfig();
217  if ($a_set['skin_id'] != $config->getDefaultSkinId()) {
218  $action_items = $this->addManagementActionsToList($action_items);
219  $this->addMultiActions($a_set['id']);
220  }
221 
222  if (!$is_substyle && $a_set['skin_id'] != 'default') {
223  $action_items[] = $this->ui->factory()->link()->standard(
224  $this->lng->txt('export'),
225  $this->ctrl->getLinkTargetByClass(ilSystemStyleOverviewGUI::class, 'export')
226  );
227  }
228  }
229 
230  if (!$is_substyle) {
231  $this->ctrl->setParameterByClass(ilSystemStyleOverviewGUI::class, 'old_skin_id', $a_set['skin_id']);
232  $this->ctrl->setParameterByClass(ilSystemStyleOverviewGUI::class, 'old_style_id', $a_set['style_id']);
233 
234  $assignment_modal = $this->parent_obj->getAssignmentCreationModal($a_set['style_name']);
235 
236  if($assignment_modal) {
237  $this->modals[] = $assignment_modal;
238 
239  $action_items[] = $this->ui->factory()->button()->shy(
240  $this->lng->txt('change_assignment'),
241  "#"
242  )->withOnClick($assignment_modal->getShowSignal());
243  }
244  }
245 
246  $this->tpl->setCurrentBlock('actions');
247  $action_dropdown = $this->ui->factory()->dropdown()->standard($action_items)->withLabel(
248  $this->lng->txt('actions')
249  );
250  $this->tpl->setVariable('ACTIONS', $this->ui->renderer()->render($action_dropdown));
251  $this->tpl->parseCurrentBlock();
252  }
253  }
254 
255  public function getModalsHtml()
256  {
257  return $this->ui->renderer()->render($this->modals);
258  }
259 
260  protected function addManagementActionsToList(array $action_items): array
261  {
262  $action_items[] = $this->ui->factory()->link()->standard(
263  $this->lng->txt('edit'),
264  $this->ctrl->getLinkTargetByClass('ilsystemstyleconfiggui')
265  );
266  $action_items[] = $this->ui->factory()->link()->standard(
267  $this->lng->txt('delete'),
268  $this->ctrl->getLinkTargetByClass('ilSystemStyleOverviewGUI', 'deleteStyle')
269  );
270  return $action_items;
271  }
272 
273  protected function addMultiActions($id)
274  {
275  $this->tpl->setCurrentBlock('multi_actions');
276  $this->tpl->setVariable('MULTI_ACTIONS_ID', $id);
277  $this->tpl->parseCurrentBlock();
278  }
279 
280  public function isWithActions(): bool
281  {
282  return $this->with_actions;
283  }
284 
285  public function setWithActions(bool $with_actions): void
286  {
287  $this->with_actions = $with_actions;
288  }
289 
290  public function isManagementEnabled(): bool
291  {
293  }
294 
295  public function setManagementEnabled(bool $management_enabled)
296  {
297  $this->management_enabled = $management_enabled;
298  }
299 
300  public function isReadDocumentation(): bool
301  {
303  }
304 
305  public function setReadDocumentation(bool $read_documentation)
306  {
307  $this->read_documentation = $read_documentation;
308  }
309 }
setData(array $a_data)
static _lookupActivatedStyle(string $a_skin, string $a_style)
lookup if a style is activated
setFormAction(string $a_form_action, bool $a_multipart=false)
static styleExists(string $style_id)
static getCurrentDefaultSkin()
Gets default Skin of the System.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
static _lookupObjId(int $ref_id)
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
global $DIC
Definition: feed.php:28
addActions($management_enabled, bool $read_documentation=true)
static getAllSkinStyles()
Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this ar...
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
setManagementEnabled(bool $management_enabled)
static getSubStyleCategoryAssignments(string $a_skin_id, string $a_style_id, string $a_sub_style_id)
Get all system category assignments of exactly one substyle.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
setReadDocumentation(bool $read_documentation)
setLimit(int $a_limit=0, int $a_default_limit=0)
__construct(object $a_parent_obj, string $a_parent_cmd='')
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
TableGUI class for system styles.
addManagementActionsToList(array $action_items)
static getCurrentDefaultStyle()
Gets default style of the system.
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)
static _getAllUserAssignedStyles()