ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 = null
 Skins available, used for caching. More...
 

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 58 of file class.ilStyleDefinition.php.

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

59  {
60  global $DIC;
61 
62  if ($skin_id == '') {
63  $skin_id = self::getCurrentSkin();
64  }
65 
66  if (!$system_style_config) {
68  } else {
70  }
71 
72  $this->skin_factory = new ilSkinFactory($DIC->language(), $this->getSystemStylesConf());
73 
74  if ($skin_id != $this->getSystemStylesConf()->getDefaultSkinId()) {
75  $this->setSkin($this->skin_factory->skinFromXML($this->getSystemStylesConf()->getCustomizingSkinPath() . $skin_id . '/template.xml'));
76  } else {
77  $this->setSkin($this->skin_factory->skinFromXML($this->getSystemStylesConf()->getDefaultTemplatePath()));
78  }
79  }
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
global $DIC
Definition: shib_login.php:26
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 320 of file class.ilStyleDefinition.php.

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

Referenced by ilSystemStyleOverviewGUI\checkStyleSettings(), ilSystemStyleOverviewGUI\getAssignmentCreationModal(), ilSystemStylesTableGUI\getStyles(), and ilSystemStyleOverviewGUI\saveStyleSettings().

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

◆ getCachedAllStylesInformation()

static ilStyleDefinition::getCachedAllStylesInformation ( )
staticprotected

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

References null.

447  : ?array
448  {
449  if (!isset(self::$cached_all_styles_information)) {
450  return null;
451  }
452  return self::$cached_all_styles_information;
453  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ 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 86 of file class.ilStyleDefinition.php.

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

Referenced by ilTemplate\getCurrentSkin(), ilUtil\getImagePath(), ilUtil\getNewContentStyleSheetLocation(), ilUtil\getStyleSheetLocation(), ilTestHTMLGenerator\getTemplatePath(), and ilImagePathResolver\resolveImagePath().

86  : ?string
87  {
88  global $DIC;
89 
90  if (!$DIC || is_array($DIC)) {
91  return null;
92  }
93  if ($DIC->isDependencyAvailable('systemStyle') && is_object($DIC->systemStyle()->getSkin())) {
94  return $DIC->systemStyle()->getSkin()->getId();
95  } else {
96  $system_style_conf = new ilSystemStyleConfig();
97 
98  if ($DIC->isDependencyAvailable('user') && is_object($DIC->user()) && property_exists(
99  $DIC->user(),
100  'skin'
101  )) {
102  $skin_id = $DIC->user()->skin;
103  if ($skin_id && !self::skinExists($skin_id)) {
104  if($DIC->isDependencyAvailable('systemStyle')) {
105  $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
106  $message_text = $DIC->language()->txt('set_skin_does_not_exist') . ' ' . $skin_id;
107  $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
108  $messages->sendMessages();
109  }
110  $skin_id = $system_style_conf->getDefaultSkinId();
111  }
112  return $skin_id === '' ? $system_style_conf->getDefaultSkinId() : $skin_id;
113  } else {
114  return null;
115  }
116  }
117  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$messages
Definition: xapiexit.php:21
global $DIC
Definition: shib_login.php:26
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 238 of file class.ilStyleDefinition.php.

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

Referenced by ilTemplate\getCurrentStyle(), ilUtil\getImagePath(), ilUtil\getNewContentStyleSheetLocation(), ilUtil\getStyleSheetLocation(), and ilImagePathResolver\resolveImagePath().

238  : ?string
239  {
240  global $DIC;
241 
242  if (isset(self::$current_style)) {
243  return self::$current_style;
244  }
245 
246  if (!$DIC || is_array($DIC) || !$DIC->isDependencyAvailable('user')) {
247  return null;
248  }
249 
250  if (array_key_exists('style', $DIC->user()->prefs) && $DIC->user()->prefs['style']) {
251  self::setCurrentStyle($DIC->user()->prefs['style']);
252  } else {
254  self::setCurrentStyle($system_style_config->getDefaultStyleId());
255  }
256 
257  if ($DIC->isDependencyAvailable('systemStyle') && self::styleExistsForCurrentSkin(self::$current_style)) {
258  if ($DIC->systemStyle()->getSkin()->hasStyleSubstyles(self::$current_style)) {
259  // read assignments, if given
261  self::getCurrentSkin(),
262  self::$current_style
263  );
264  if (count($assignments) > 0) {
265  $ref_ass = [];
266  foreach ($assignments as $a) {
267  if ($DIC->systemStyle()->getSkin()->hasStyle($a['substyle'])) {
268  $ref_ass[$a['ref_id']] = $a['substyle'];
269  }
270  }
271 
272  $ref_id = '';
273 
274  if ($DIC->http()->wrapper()->query()->has('ref_id')) {
275  $ref_id = $DIC->http()->wrapper()->query()->retrieve(
276  'ref_id',
277  $DIC->refinery()->kindlyTo()->string()
278  );
279  } elseif ($DIC->http()->wrapper()->query()->has('target')) {
280  $target = $DIC->http()->wrapper()->query()->retrieve(
281  'target',
282  $DIC->refinery()->kindlyTo()->string()
283  );
284  $target_arr = explode('_', $target);
285  $ref_id = $target_arr[1] ?? '';
286  }
287 
288  // check whether any ref id assigns a new style
289  if ($DIC->isDependencyAvailable('repositoryTree') && $ref_id && $DIC->repositoryTree()->isInTree((int) $ref_id)) {
290  $path = $DIC->repositoryTree()->getPathId((int) $ref_id);
291  for ($i = count($path) - 1; $i >= 0; $i--) {
292  if (isset($ref_ass[$path[$i]])) {
293  self::$current_style = $ref_ass[$path[$i]];
294  return self::$current_style;
295  }
296  }
297  }
298  }
299  }
300  }
301 
302  if ($DIC->isDependencyAvailable('systemStyle') && !self::styleExistsForCurrentSkin(self::$current_style)) {
303  $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
304  $message_text = $DIC->language()->txt('set_style_does_not_exist') . ' ' . self::$current_style;
305  $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
306  $messages->sendMessages();
308  self::setCurrentSkin($system_style_config->getDefaultSkinId());
309  self::setCurrentStyle($system_style_config->getDefaultStyleId());
310  }
311 
312  return self::$current_style;
313  }
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:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$messages
Definition: xapiexit.php:21
$ref_id
Definition: ltiauth.php:65
global $DIC
Definition: shib_login.php:26
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
+ 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 151 of file class.ilStyleDefinition.php.

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

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

◆ getSkin()

ilStyleDefinition::getSkin ( )

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

References $skin.

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

437  : ilSkin
438  {
439  return $this->skin;
440  }
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 424 of file class.ilStyleDefinition.php.

Referenced by ilUtil\getStyleSheetLocation().

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

◆ getSoundDirectory()

ilStyleDefinition::getSoundDirectory ( string  $style_id)
Exceptions
ilSystemStyleException

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

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

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

◆ getStyle()

ilStyleDefinition::getStyle ( string  $a_id)
Exceptions
ilSystemStyleException

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

References getSkin().

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

◆ getStyleName()

ilStyleDefinition::getStyleName ( string  $a_id)
Exceptions
ilSystemStyleException

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

References getSkin().

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

◆ getStyles()

ilStyleDefinition::getStyles ( )
Returns
ilSkinStyle[]

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

References getSkin().

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

◆ getSystemStylesConf()

ilStyleDefinition::getSystemStylesConf ( )

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

References $system_style_config.

Referenced by __construct().

461  {
463  }
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 127 of file class.ilStyleDefinition.php.

References getSkin().

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

◆ setCachedAllStylesInformation()

static ilStyleDefinition::setCachedAllStylesInformation ( array  $cached_all_styles_information)
staticprotected

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

References $cached_all_styles_information.

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

◆ setCurrentSkin()

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

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

References $DIC.

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

◆ setCurrentStyle()

static ilStyleDefinition::setCurrentStyle ( string  $a_style)
static

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

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

◆ setSkin()

ilStyleDefinition::setSkin ( ilSkin  $skin)

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

References $skin.

Referenced by __construct().

442  : void
443  {
444  $this->skin = $skin;
445  }
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 432 of file class.ilStyleDefinition.php.

References $skins.

432  : void
433  {
434  self::$skins = $skins;
435  }
static array $skins
Skins available, used for caching.

◆ setSystemStylesConf()

ilStyleDefinition::setSystemStylesConf ( ilSystemStyleConfig  $system_style_config)

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

References $system_style_config.

Referenced by __construct().

466  {
467  $this->system_style_config = $system_style_config;
468  }
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 216 of file class.ilStyleDefinition.php.

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

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

216  : bool
217  {
218  if (!$system_style_config) {
220  }
221 
222  if ($skin_id == $system_style_config->getDefaultSkinId()) {
224  return true;
225  }
226  } elseif (is_file($system_style_config->getCustomizingSkinPath() . $skin_id . '/template.xml')) {
227  return true;
228  }
229  return false;
230  }
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 383 of file class.ilStyleDefinition.php.

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

383  : bool
384  {
385  foreach (self::getSkins() as $skin) {
386  if ($skin->hasStyle($style_id)) {
387  return true;
388  }
389  }
390  return false;
391  }
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 408 of file class.ilStyleDefinition.php.

References $DIC.

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

◆ styleExistsForSkinId()

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

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

References $DIC.

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

396  : bool
397  {
398  global $DIC;
399 
400  if (!self::skinExists($skin_id)) {
401  return false;
402  }
403  $factory = new ilSkinFactory($DIC->language());
404  $skin = $factory->skinStyleContainerFromId($skin_id, new ilSystemStyleMessageStack($DIC->ui()->mainTemplate()))->getSkin();
405  return $skin->hasStyle($style_id);
406  }
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
global $DIC
Definition: shib_login.php:26
ilSkin $skin
Sets the current skin.
Used to stack messages to be shown to the user.
+ 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 44 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 39 of file class.ilStyleDefinition.php.

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

◆ $skin_factory

ilSkinFactory ilStyleDefinition::$skin_factory
protected

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

◆ $skins

array ilStyleDefinition::$skins = null
static

Skins available, used for caching.

Definition at line 34 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 50 of file class.ilStyleDefinition.php.

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


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