ILIAS  release_8 Revision v8.24
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.

60 {
61 global $DIC;
62
63 if ($skin_id == '') {
64 $skin_id = self::getCurrentSkin();
65 }
66
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...
static getCurrentSkin()
get the current skin use always this function instead of getting the account's skin the current skin ...
ilSystemStyleConfig $system_style_config
Used to wire this component up with the correct paths into the customizing directory.
setSystemStylesConf(ilSystemStyleConfig $system_style_config)
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
global $DIC
Definition: feed.php:28

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

+ 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.

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
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 }
361 }
362
364 }
$version
Definition: plugin.php:24
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
getStyle(string $id)
static setCachedAllStylesInformation(array $cached_all_styles_information)
ilSkin $skin
Sets the current skin.

References $DIC, $skin, $skins, $version, ilObjUser\_getNumberOfUsersForStyle(), getCachedAllStylesInformation(), ilSkin\getId(), ilSkin\getName(), ilSkin\getStyle(), ilSkin\getStyles(), ilSkin\getVersion(), and setCachedAllStylesInformation().

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

+ 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 }
454 }
static array $cached_all_styles_information
Used for caching.

References $cached_all_styles_information.

Referenced by getAllSkinStyles().

+ Here is the caller graph for this function:

◆ 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.

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 }
Used to stack messages to be shown to the user.
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22

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

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

+ 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.

239 : ?string
240 {
241 global $DIC;
242
243 if (isset(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 {
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]];
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();
311 }
312
314 }
static string $current_style
currently selected style, used for caching
static setCurrentSkin(string $a_skin)
static setCurrentStyle(string $a_style)
static getSystemStyleCategoryAssignments(string $a_skin_id, string $a_style_id)
Get all system sub styles category assignments.
$target_arr
Definition: goto.php:50
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
$i
Definition: metadata.php:41
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

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

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

+ 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.

152 : string
153 {
154 if (!$style_id) {
156 }
157 try {
158 return $this->getSkin()->getStyle($style_id)->getImageDirectory();
159 } catch (ilSystemStyleException $e) {
161 }
162 }
Class for advanced editing exception handling in ILIAS.

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

+ Here is the call graph for this function:

◆ getSkin()

ilStyleDefinition::getSkin ( )

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

438 : ilSkin
439 {
440 return $this->skin;
441 }
ilSkin holds an manages the basic data of a skin as provide by the template of the skin.

References $skin.

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

+ 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.

425 : array
426 {
427 return self::getAllSkins();
428 }

◆ getSoundDirectory()

ilStyleDefinition::getSoundDirectory ( string  $style_id)
Exceptions
ilSystemStyleException

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

167 : string
168 {
169 return $this->getSkin()->getStyle($style_id)->getSoundDirectory();
170 }

References getSkin().

+ 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.

137 {
138 return $this->getSkin()->getStyle($a_id);
139 }

References getSkin().

+ 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.

144 : string
145 {
146 return $this->getSkin()->getStyle($a_id)->getName();
147 }

References getSkin().

+ Here is the call graph for this function:

◆ getStyles()

ilStyleDefinition::getStyles ( )
Returns
ilSkinStyle[]

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

123 : array
124 {
125 return $this->getSkin()->getStyles();
126 }

References getSkin().

+ Here is the call graph for this function:

◆ getSystemStylesConf()

ilStyleDefinition::getSystemStylesConf ( )

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

462 {
464 }

References $system_style_config.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getTemplateName()

ilStyleDefinition::getTemplateName ( )

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

128 : string
129 {
130 return $this->getSkin()->getName();
131 }

References getSkin().

+ 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.

456 : void
457 {
458 self::$cached_all_styles_information = $cached_all_styles_information;
459 }

References $cached_all_styles_information.

Referenced by getAllSkinStyles().

+ Here is the caller graph for this function:

◆ setCurrentSkin()

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

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

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 }
ilStyleDefinition acts as a wrapper of style related actions.

References $DIC.

Referenced by getCurrentStyle().

+ Here is the caller graph for this function:

◆ 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 }

Referenced by getCurrentStyle().

+ Here is the caller graph for this function:

◆ setSkin()

ilStyleDefinition::setSkin ( ilSkin  $skin)

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

443 : void
444 {
445 $this->skin = $skin;
446 }

References $skin.

Referenced by __construct().

+ 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.

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

References $skins.

◆ setSystemStylesConf()

ilStyleDefinition::setSystemStylesConf ( ilSystemStyleConfig  $system_style_config)

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

467 {
468 $this->system_style_config = $system_style_config;
469 }

References $system_style_config.

Referenced by __construct().

+ 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.

217 : bool
218 {
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 }

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

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

+ 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.

384 : bool
385 {
386 foreach (self::getSkins() as $skin) {
387 if ($skin->hasStyle($style_id)) {
388 return true;
389 }
390 }
391 return false;
392 }
hasStyle(string $id)

References $skin, and ilSkin\hasStyle().

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

+ Here is the call graph for this function:
+ 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.

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

References $DIC.

◆ styleExistsForSkinId()

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

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

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
Definition: metadata.php:75

References $DIC, $factory, $skin, and ilSkin\hasStyle().

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

+ Here is the call graph for this function:
+ 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 getCachedAllStylesInformation(), and setCachedAllStylesInformation().

◆ $current_style

string ilStyleDefinition::$current_style
static

currently selected style, used for caching

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

Referenced by getCurrentStyle().

◆ $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 getAllSkinStyles(), getSkin(), setSkin(), styleExists(), and styleExistsForSkinId().

◆ $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 getAllSkinStyles(), and 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 __construct(), getCurrentStyle(), getSystemStylesConf(), setSystemStylesConf(), and skinExists().


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