ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStyleDefinition Class Reference

ilStyleDefinition acts as a wrapper of style related actions. More...

+ Collaboration diagram for ilStyleDefinition:

Public Member Functions

 __construct (string $skin_id='', ilSystemStyleConfig $system_style_config=null)
 ilStyleDefinition constructor. More...
 
 getStyles ()
 
 getTemplateName ()
 
 getStyle (string $a_id)
 
 getStyleName (string $a_id)
 
 getImageDirectory (string $style_id)
 
 getSoundDirectory (string $style_id)
 
 getSkin ()
 
 setSkin (ilSkin $skin)
 
 getSystemStylesConf ()
 
 setSystemStylesConf (ilSystemStyleConfig $system_style_config)
 

Static Public Member Functions

static getCurrentSkin ()
 get the current skin use always this function instead of getting the account's skin the current skin may be changed on the fly by setCurrentSkin() More...
 
static skinExists (string $skin_id, ?ilSystemStyleConfig $system_style_config=null)
 Check whether a skin exists. More...
 
static getCurrentStyle ()
 get the current style or sub style use always this function instead of getting the account's style the current style may be changed on the fly by setCurrentStyle() More...
 
static getAllSkinStyles ()
 Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this array is only used for legacy reasons an might be removed in future. More...
 
static setCurrentSkin (string $a_skin)
 
static styleExists (string $style_id)
 
static styleExistsForSkinId (string $skin_id, string $style_id)
 
static styleExistsForCurrentSkin (string $style_id)
 
static setCurrentStyle (string $a_style)
 
static getSkins ()
 
static setSkins (array $skins)
 

Static Public Attributes

static string $current_style
 currently selected style, used for caching More...
 
static array $skins = []
 

Static Protected Member Functions

static getCachedAllStylesInformation ()
 
static setCachedAllStylesInformation (array $cached_all_styles_information)
 

Protected Attributes

ilSkin $skin
 Sets the current skin. More...
 
ilSystemStyleConfig $system_style_config
 Used to wire this component up with the correct paths into the customizing directory. More...
 
ilSkinFactory $skin_factory
 

Static Protected Attributes

static array $cached_all_styles_information
 Used for caching. More...
 

Detailed Description

ilStyleDefinition acts as a wrapper of style related actions.

See Readme for Details.

Definition at line 24 of file class.ilStyleDefinition.php.

Constructor & Destructor Documentation

◆ __construct()

ilStyleDefinition::__construct ( string  $skin_id = '',
ilSystemStyleConfig  $system_style_config = null 
)

ilStyleDefinition constructor.

Exceptions
ilSystemStyleException

Definition at line 59 of file class.ilStyleDefinition.php.

References $DIC, getSystemStylesConf(), setSkin(), and setSystemStylesConf().

60  {
61  global $DIC;
62 
63  if ($skin_id == '') {
64  $skin_id = self::getCurrentSkin();
65  }
66 
67  if (!$system_style_config) {
69  } else {
70  $this->setSystemStylesConf($system_style_config);
71  }
72 
73  $this->skin_factory = new ilSkinFactory($DIC->language(), $this->getSystemStylesConf());
74 
75  if ($skin_id != $this->getSystemStylesConf()->getDefaultSkinId()) {
76  $this->setSkin($this->skin_factory->skinFromXML($this->getSystemStylesConf()->getCustomizingSkinPath() . $skin_id . '/template.xml'));
77  } else {
78  $this->setSkin($this->skin_factory->skinFromXML($this->getSystemStylesConf()->getDefaultTemplatePath()));
79  }
80  }
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
global $DIC
Definition: feed.php:28
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
setSystemStylesConf(ilSystemStyleConfig $system_style_config)
+ Here is the call graph for this function:

Member Function Documentation

◆ getAllSkinStyles()

static ilStyleDefinition::getAllSkinStyles ( )
static

Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this array is only used for legacy reasons an might be removed in future.

Exceptions
ilSystemStyleException

Definition at line 321 of file class.ilStyleDefinition.php.

References $DIC, $version, and ilObjUser\_getNumberOfUsersForStyle().

Referenced by ilSystemStyleOverviewGUI\addSubStyleForms(), ilSystemStyleOverviewGUI\checkStyleSettings(), ilSystemStyleOverviewGUI\cloneSystemStyleForm(), ilSystemStyleOverviewGUI\edit(), ilSystemStylesTableGUI\getStyles(), and ilSystemStyleOverviewGUI\saveStyleSettings().

321  : ?array
322  {
323  global $DIC;
324 
325  if (!self::getCachedAllStylesInformation()) {
326  $all_styles = [];
327 
328  $skins = $DIC->systemStyle()->getSkins();
329 
330  foreach ($skins as $skin) {
331  foreach ($skin->getStyles() as $style) {
332  $num_users = ilObjUser::_getNumberOfUsersForStyle($skin->getId(), $style->getId());
333 
334  $parent_name = '';
335  if ($style->getSubstyleOf()) {
336  $parent_name = $skin->getStyle($style->getSubstyleOf())->getName();
337  }
338 
339  $version = $skin->getVersion();
340  if ($version == '$Id$') {
341  $version = '-';
342  }
343  // default selection list
344  $all_styles[$skin->getId() . ':' . $style->getId()] = [
345  'title' => $skin->getName() . ' / ' . $style->getName(),
346  'id' => $skin->getId() . ':' . $style->getId(),
347  'skin_id' => $skin->getId(),
348  'skin_name' => $skin->getName(),
349  'template_id' => $skin->getId(),
350  'template_name' => $skin->getName(),
351  'style_id' => $style->getId(),
352  'style_name' => $style->getName(),
353  'substyle_of' => $style->getSubstyleOf(),
354  'substyle_of_name' => $parent_name,
355  'users' => $num_users,
356  'version' => $version,
357  ];
358  }
359  }
360  self::setCachedAllStylesInformation($all_styles);
361  }
362 
363  return self::getCachedAllStylesInformation();
364  }
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
global $DIC
Definition: feed.php:28
ilSkin $skin
Sets the current skin.
$version
Definition: plugin.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCachedAllStylesInformation()

static ilStyleDefinition::getCachedAllStylesInformation ( )
staticprotected

Definition at line 448 of file class.ilStyleDefinition.php.

448  : ?array
449  {
450  if (!isset(self::$cached_all_styles_information)) {
451  return null;
452  }
453  return self::$cached_all_styles_information;
454  }

◆ getCurrentSkin()

static ilStyleDefinition::getCurrentSkin ( )
static

get the current skin use always this function instead of getting the account's skin the current skin may be changed on the fly by setCurrentSkin()

Definition at line 87 of file class.ilStyleDefinition.php.

References $DIC, $messages, and ilSystemStyleMessage\TYPE_ERROR.

Referenced by ilUtil\getImagePath(), ilUtil\getNewContentStyleSheetLocation(), ilUtil\getStyleSheetLocation(), ilTestPDFGenerator\getTemplatePath(), and ilTemplate\getTemplatePath().

87  : ?string
88  {
89  global $DIC;
90 
91  if (!$DIC || is_array($DIC)) {
92  return null;
93  }
94  if ($DIC->isDependencyAvailable('systemStyle') && is_object($DIC->systemStyle()->getSkin())) {
95  return $DIC->systemStyle()->getSkin()->getId();
96  } else {
97  $system_style_conf = new ilSystemStyleConfig();
98 
99  if ($DIC->isDependencyAvailable('user') && is_object($DIC->user()) && property_exists(
100  $DIC->user(),
101  'skin'
102  )) {
103  $skin_id = $DIC->user()->skin;
104  if ($skin_id && !self::skinExists($skin_id)) {
105  if($DIC->isDependencyAvailable('systemStyle')) {
106  $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
107  $message_text = $DIC->language()->txt('set_skin_does_not_exist') . ' ' . $skin_id;
108  $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
109  $messages->sendMessages();
110  }
111  $skin_id = $system_style_conf->getDefaultSkinId();
112  }
113  return $skin_id;
114  } else {
115  return null;
116  }
117  }
118  }
global $DIC
Definition: feed.php:28
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Used to stack messages to be shown to the user.
+ Here is the caller graph for this function:

◆ getCurrentStyle()

static ilStyleDefinition::getCurrentStyle ( )
static

get the current style or sub style use always this function instead of getting the account's style the current style may be changed on the fly by setCurrentStyle()

Exceptions
ilSystemStyleException

Definition at line 239 of file class.ilStyleDefinition.php.

References Vendor\Package\$a, $DIC, $i, $messages, $path, $ref_id, $target_arr, ilSystemStyleConfig\getDefaultSkinId(), ilSystemStyleConfig\getDefaultStyleId(), ilSystemStyleSettings\getSystemStyleCategoryAssignments(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by ilUtil\getImagePath(), ilUtil\getNewContentStyleSheetLocation(), ilUtil\getStyleSheetLocation(), and ilTemplate\getTemplatePath().

239  : ?string
240  {
241  global $DIC;
242 
243  if (isset(self::$current_style)) {
244  return self::$current_style;
245  }
246 
247  if (!$DIC || is_array($DIC) || !$DIC->isDependencyAvailable('user')) {
248  return null;
249  }
250 
251  if (array_key_exists('style', $DIC->user()->prefs) && $DIC->user()->prefs['style']) {
252  self::setCurrentStyle($DIC->user()->prefs['style']);
253  } else {
255  self::setCurrentStyle($system_style_config->getDefaultStyleId());
256  }
257 
258  if ($DIC->isDependencyAvailable('systemStyle') && self::styleExistsForCurrentSkin(self::$current_style)) {
259  if ($DIC->systemStyle()->getSkin()->hasStyleSubstyles(self::$current_style)) {
260  // read assignments, if given
262  self::getCurrentSkin(),
263  self::$current_style
264  );
265  if (count($assignments) > 0) {
266  $ref_ass = [];
267  foreach ($assignments as $a) {
268  if ($DIC->systemStyle()->getSkin()->hasStyle($a['substyle'])) {
269  $ref_ass[$a['ref_id']] = $a['substyle'];
270  }
271  }
272 
273  $ref_id = '';
274 
275  if ($DIC->http()->wrapper()->query()->has('ref_id')) {
276  $ref_id = $DIC->http()->wrapper()->query()->retrieve(
277  'ref_id',
278  $DIC->refinery()->kindlyTo()->string()
279  );
280  } elseif ($DIC->http()->wrapper()->query()->has('target')) {
281  $target = $DIC->http()->wrapper()->query()->retrieve(
282  'target',
283  $DIC->refinery()->kindlyTo()->string()
284  );
285  $target_arr = explode('_', $target);
286  $ref_id = $target_arr[1] ?? '';
287  }
288 
289  // check whether any ref id assigns a new style
290  if ($DIC->isDependencyAvailable('repositoryTree') && $ref_id && $DIC->repositoryTree()->isInTree((int) $ref_id)) {
291  $path = $DIC->repositoryTree()->getPathId((int) $ref_id);
292  for ($i = count($path) - 1; $i >= 0; $i--) {
293  if (isset($ref_ass[$path[$i]])) {
294  self::$current_style = $ref_ass[$path[$i]];
295  return self::$current_style;
296  }
297  }
298  }
299  }
300  }
301  }
302 
303  if ($DIC->isDependencyAvailable('systemStyle') && !self::styleExistsForCurrentSkin(self::$current_style)) {
304  $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
305  $message_text = $DIC->language()->txt('set_style_does_not_exist') . ' ' . self::$current_style;
306  $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
307  $messages->sendMessages();
309  self::setCurrentSkin($system_style_config->getDefaultSkinId());
310  self::setCurrentStyle($system_style_config->getDefaultStyleId());
311  }
312 
313  return self::$current_style;
314  }
$target_arr
Definition: goto.php:50
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
static getSystemStyleCategoryAssignments(string $a_skin_id, string $a_style_id)
Get all system sub styles category assignments.
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
$ref_id
Definition: ltiauth.php:67
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Used to stack messages to be shown to the user.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageDirectory()

ilStyleDefinition::getImageDirectory ( string  $style_id)
Exceptions
ilSystemStyleException

Definition at line 152 of file class.ilStyleDefinition.php.

References Vendor\Package\$e, getSkin(), ilSystemStyleException\NO_STYLE_ID, and ilSystemStyleException\NOT_EXISTING_STYLE.

152  : string
153  {
154  if (!$style_id) {
156  }
157  try {
158  return $this->getSkin()->getStyle($style_id)->getImageDirectory();
159  } catch (ilSystemStyleException $e) {
161  }
162  }
+ Here is the call graph for this function:

◆ getSkin()

ilStyleDefinition::getSkin ( )

Definition at line 438 of file class.ilStyleDefinition.php.

References $skin.

Referenced by getImageDirectory(), getSoundDirectory(), getStyle(), getStyleName(), getStyles(), and getTemplateName().

438  : ilSkin
439  {
440  return $this->skin;
441  }
ilSkin $skin
Sets the current skin.
ilSkin holds an manages the basic data of a skin as provide by the template of the skin...
+ Here is the caller graph for this function:

◆ getSkins()

static ilStyleDefinition::getSkins ( )
static
Returns
ilSkin[]
Exceptions
ilSystemStyleException

Definition at line 425 of file class.ilStyleDefinition.php.

Referenced by ilUtil\getStyleSheetLocation().

425  : array
426  {
427  return self::getAllSkins();
428  }
+ Here is the caller graph for this function:

◆ getSoundDirectory()

ilStyleDefinition::getSoundDirectory ( string  $style_id)
Exceptions
ilSystemStyleException

Definition at line 167 of file class.ilStyleDefinition.php.

References $DIC, $skin, $system_style_config, ilSystemStyleConfig\getCustomizingSkinPath(), ilSystemStyleConfig\getDefaultSkinId(), ilSystemStyleConfig\getDefaultTemplatePath(), ilSkin\getId(), and getSkin().

167  : string
168  {
169  return $this->getSkin()->getStyle($style_id)->getSoundDirectory();
170  }
+ Here is the call graph for this function:

◆ getStyle()

ilStyleDefinition::getStyle ( string  $a_id)
Exceptions
ilSystemStyleException

Definition at line 136 of file class.ilStyleDefinition.php.

References getSkin().

136  : ilSkinStyle
137  {
138  return $this->getSkin()->getStyle($a_id);
139  }
+ Here is the call graph for this function:

◆ getStyleName()

ilStyleDefinition::getStyleName ( string  $a_id)
Exceptions
ilSystemStyleException

Definition at line 144 of file class.ilStyleDefinition.php.

References getSkin().

144  : string
145  {
146  return $this->getSkin()->getStyle($a_id)->getName();
147  }
+ Here is the call graph for this function:

◆ getStyles()

ilStyleDefinition::getStyles ( )
Returns
ilSkinStyle[]

Definition at line 123 of file class.ilStyleDefinition.php.

References getSkin().

123  : array
124  {
125  return $this->getSkin()->getStyles();
126  }
+ Here is the call graph for this function:

◆ getSystemStylesConf()

ilStyleDefinition::getSystemStylesConf ( )

Definition at line 461 of file class.ilStyleDefinition.php.

References $system_style_config.

Referenced by __construct().

462  {
464  }
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
+ Here is the caller graph for this function:

◆ getTemplateName()

ilStyleDefinition::getTemplateName ( )

Definition at line 128 of file class.ilStyleDefinition.php.

References getSkin().

128  : string
129  {
130  return $this->getSkin()->getName();
131  }
+ Here is the call graph for this function:

◆ setCachedAllStylesInformation()

static ilStyleDefinition::setCachedAllStylesInformation ( array  $cached_all_styles_information)
staticprotected

Definition at line 456 of file class.ilStyleDefinition.php.

References $cached_all_styles_information.

456  : void
457  {
458  self::$cached_all_styles_information = $cached_all_styles_information;
459  }
static array $cached_all_styles_information
Used for caching.

◆ setCurrentSkin()

static ilStyleDefinition::setCurrentSkin ( string  $a_skin)
static
Exceptions
ilSystemStyleException

Definition at line 369 of file class.ilStyleDefinition.php.

References $DIC.

369  : void
370  {
371  global $DIC;
372 
373  if ($DIC->isDependencyAvailable('systemStyle') && $DIC->systemStyle()->getSkin()->getName() != $a_skin) {
374  $styleDefinition = new ilStyleDefinition($a_skin);
375  if (!self::styleExistsForCurrentSkin(self::$current_style)) {
376  $styleDefinition->setCurrentStyle($DIC->systemStyle()->getSkin()->getDefaultStyle()->getId());
377  }
378  }
379  }
global $DIC
Definition: feed.php:28
ilStyleDefinition acts as a wrapper of style related actions.

◆ setCurrentStyle()

static ilStyleDefinition::setCurrentStyle ( string  $a_style)
static

Definition at line 416 of file class.ilStyleDefinition.php.

416  : void
417  {
418  self::$current_style = $a_style;
419  }

◆ setSkin()

ilStyleDefinition::setSkin ( ilSkin  $skin)

Definition at line 443 of file class.ilStyleDefinition.php.

References $skin.

Referenced by __construct().

443  : void
444  {
445  $this->skin = $skin;
446  }
ilSkin $skin
Sets the current skin.
+ Here is the caller graph for this function:

◆ setSkins()

static ilStyleDefinition::setSkins ( array  $skins)
static
Parameters
ilSkin[]$skins

Definition at line 433 of file class.ilStyleDefinition.php.

References $skins.

433  : void
434  {
435  self::$skins = $skins;
436  }

◆ setSystemStylesConf()

ilStyleDefinition::setSystemStylesConf ( ilSystemStyleConfig  $system_style_config)

Definition at line 466 of file class.ilStyleDefinition.php.

References $system_style_config.

Referenced by __construct().

467  {
468  $this->system_style_config = $system_style_config;
469  }
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
+ Here is the caller graph for this function:

◆ skinExists()

static ilStyleDefinition::skinExists ( string  $skin_id,
?ilSystemStyleConfig  $system_style_config = null 
)
static

Check whether a skin exists.

Not using array_key_exists($skin_id,self::getAllSkins()); for performance reasons

Definition at line 217 of file class.ilStyleDefinition.php.

References ilSystemStyleConfig\getCustomizingSkinPath(), ilSystemStyleConfig\getDefaultSkinId(), and ilSystemStyleConfig\getDefaultTemplatePath().

Referenced by ilSkinFactory\copyFromSkinStyleContainer(), ilSystemStyleSettings\getCurrentDefaultSkin(), ilObjUser\read(), ilSystemStyleOverviewGUI\saveNewSystemStyle(), and ilSkinFactory\skinStyleContainerFromZip().

217  : bool
218  {
219  if (!$system_style_config) {
221  }
222 
223  if ($skin_id == $system_style_config->getDefaultSkinId()) {
225  return true;
226  }
227  } elseif (is_file($system_style_config->getCustomizingSkinPath() . $skin_id . '/template.xml')) {
228  return true;
229  }
230  return false;
231  }
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ styleExists()

static ilStyleDefinition::styleExists ( string  $style_id)
static
Exceptions
ilSystemStyleException

Definition at line 384 of file class.ilStyleDefinition.php.

Referenced by ilSystemStylesTableGUI\getStyles(), ilSystemStyleOverviewGUI\moveUserStyles(), and ilObjUser\read().

384  : bool
385  {
386  foreach (self::getSkins() as $skin) {
387  if ($skin->hasStyle($style_id)) {
388  return true;
389  }
390  }
391  return false;
392  }
ilSkin $skin
Sets the current skin.
+ Here is the caller graph for this function:

◆ styleExistsForCurrentSkin()

static ilStyleDefinition::styleExistsForCurrentSkin ( string  $style_id)
static

Definition at line 409 of file class.ilStyleDefinition.php.

References $DIC.

409  : bool
410  {
411  global $DIC;
412 
413  return $DIC->systemStyle()->getSkin()->hasStyle($style_id);
414  }
global $DIC
Definition: feed.php:28

◆ styleExistsForSkinId()

static ilStyleDefinition::styleExistsForSkinId ( string  $skin_id,
string  $style_id 
)
static
Exceptions
ilSystemStyleException

Definition at line 397 of file class.ilStyleDefinition.php.

References $DIC, and $factory.

Referenced by ilSystemStyleSettings\getCurrentDefaultStyle(), and ilObjUser\read().

397  : bool
398  {
399  global $DIC;
400 
401  if (!self::skinExists($skin_id)) {
402  return false;
403  }
404  $factory = new ilSkinFactory($DIC->language());
405  $skin = $factory->skinStyleContainerFromId($skin_id, new ilSystemStyleMessageStack($DIC->ui()->mainTemplate()))->getSkin();
406  return $skin->hasStyle($style_id);
407  }
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
global $DIC
Definition: feed.php:28
ilSkin $skin
Sets the current skin.
Used to stack messages to be shown to the user.
$factory
Definition: metadata.php:75
+ Here is the caller graph for this function:

Field Documentation

◆ $cached_all_styles_information

array ilStyleDefinition::$cached_all_styles_information
staticprotected

Used for caching.

Definition at line 45 of file class.ilStyleDefinition.php.

Referenced by setCachedAllStylesInformation().

◆ $current_style

string ilStyleDefinition::$current_style
static

currently selected style, used for caching

Definition at line 29 of file class.ilStyleDefinition.php.

◆ $skin

ilSkin ilStyleDefinition::$skin
protected

Sets the current skin.

This is used by the global instance of this class.

Definition at line 40 of file class.ilStyleDefinition.php.

Referenced by getSkin(), getSoundDirectory(), and setSkin().

◆ $skin_factory

ilSkinFactory ilStyleDefinition::$skin_factory
protected

Definition at line 53 of file class.ilStyleDefinition.php.

◆ $skins

array ilStyleDefinition::$skins = []
static

Definition at line 35 of file class.ilStyleDefinition.php.

Referenced by setSkins().

◆ $system_style_config

ilSystemStyleConfig ilStyleDefinition::$system_style_config
protected

Used to wire this component up with the correct paths into the customizing directory.

This is dynamic and not constant for this class to remain testable

Definition at line 51 of file class.ilStyleDefinition.php.

Referenced by getSoundDirectory(), getSystemStylesConf(), and setSystemStylesConf().


The documentation for this class was generated from the following file: