ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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.

59 {
60 global $DIC;
61
62 if ($skin_id == '') {
63 $skin_id = self::getCurrentSkin();
64 }
65
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 }
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: shib_login.php:26

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

317 : ?array
318 {
319 global $DIC;
320
321 if (!self::getCachedAllStylesInformation()) {
322 $all_styles = [];
323
324 $skins = $DIC->systemStyle()->getSkins();
325
326 foreach ($skins as $skin) {
327 foreach ($skin->getStyles() as $style) {
328 $num_users = ilObjUser::_getNumberOfUsersForStyle($skin->getId(), $style->getId());
329
330 $parent_name = '';
331 if ($style->getSubstyleOf()) {
332 $parent_name = $skin->getStyle($style->getSubstyleOf())->getName();
333 }
334
336 if ($version == '$Id$') {
337 $version = '-';
338 }
339 // default selection list
340 $all_styles[$skin->getId() . ':' . $style->getId()] = [
341 'title' => $skin->getName() . ' / ' . $style->getName(),
342 'id' => $skin->getId() . ':' . $style->getId(),
343 'skin_id' => $skin->getId(),
344 'skin_name' => $skin->getName(),
345 'template_id' => $skin->getId(),
346 'template_name' => $skin->getName(),
347 'style_id' => $style->getId(),
348 'style_name' => $style->getName(),
349 'substyle_of' => $style->getSubstyleOf(),
350 'substyle_of_name' => $parent_name,
351 'users' => $num_users,
352 'version' => $version,
353 ];
354 }
355 }
357 }
358
360 }
$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.
static array $skins
Skins available, used for caching.

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

Referenced by ilSystemStyleOverviewGUI\checkStyleSettings(), ilSystemStyleOverviewGUI\getAssignmentCreationModal(), 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 444 of file class.ilStyleDefinition.php.

444 : ?array
445 {
446 if (!isset(self::$cached_all_styles_information)) {
447 return null;
448 }
450 }
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 86 of file class.ilStyleDefinition.php.

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())) {
99 $skin_id = $DIC->user()->getSkin();
100 if ($skin_id && !self::skinExists($skin_id)) {
101 if ($DIC->isDependencyAvailable('systemStyle')) {
102 $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
103 $message_text = $DIC->language()->txt('set_skin_does_not_exist') . ' ' . $skin_id;
104 $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
105 $messages->sendMessages();
106 }
107 $skin_id = $system_style_conf->getDefaultSkinId();
108 }
109 return $skin_id === '' ? $system_style_conf->getDefaultSkinId() : $skin_id;
110 } else {
111 return null;
112 }
113 }
114 }
Used to stack messages to be shown to the user.
$messages
Definition: xapiexit.php:21

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

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

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

235 : ?string
236 {
237 global $DIC;
238
239 if (isset(self::$current_style)) {
241 }
242
243 if (!$DIC || is_array($DIC) || !$DIC->isDependencyAvailable('user')) {
244 return null;
245 }
246
247 if ($DIC->user()->getPref('style')) {
248 self::setCurrentStyle($DIC->user()->getPref('style'));
249 } else {
252 }
253
254 if ($DIC->isDependencyAvailable('systemStyle') && self::styleExistsForCurrentSkin(self::$current_style)) {
255 if ($DIC->systemStyle()->getSkin()->hasStyleSubstyles(self::$current_style)) {
256 // read assignments, if given
258 self::getCurrentSkin(),
259 self::$current_style
260 );
261 if (count($assignments) > 0) {
262 $ref_ass = [];
263 foreach ($assignments as $a) {
264 if ($DIC->systemStyle()->getSkin()->hasStyle($a['substyle'])) {
265 $ref_ass[$a['ref_id']] = $a['substyle'];
266 }
267 }
268
269 $ref_id = '';
270
271 if ($DIC->http()->wrapper()->query()->has('ref_id')) {
272 $ref_id = $DIC->http()->wrapper()->query()->retrieve(
273 'ref_id',
274 $DIC->refinery()->kindlyTo()->string()
275 );
276 } elseif ($DIC->http()->wrapper()->query()->has('target')) {
277 $target = $DIC->http()->wrapper()->query()->retrieve(
278 'target',
279 $DIC->refinery()->kindlyTo()->string()
280 );
281 $target_arr = explode('_', $target);
282 $ref_id = $target_arr[1] ?? '';
283 }
284
285 // check whether any ref id assigns a new style
286 if ($DIC->isDependencyAvailable('repositoryTree') && $ref_id && $DIC->repositoryTree()->isInTree((int) $ref_id)) {
287 $path = $DIC->repositoryTree()->getPathId((int) $ref_id);
288 for ($i = count($path) - 1; $i >= 0; $i--) {
289 if (isset($ref_ass[$path[$i]])) {
290 self::$current_style = $ref_ass[$path[$i]];
292 }
293 }
294 }
295 }
296 }
297 }
298
299 if ($DIC->isDependencyAvailable('systemStyle') && !self::styleExistsForCurrentSkin(self::$current_style)) {
300 $messages = new ilSystemStyleMessageStack($DIC->ui()->mainTemplate());
301 $message_text = $DIC->language()->txt('set_style_does_not_exist') . ' ' . self::$current_style;
302 $messages->addMessage(new ilSystemStyleMessage($message_text, ilSystemStyleMessage::TYPE_ERROR));
303 $messages->sendMessages();
307 }
308
310 }
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.
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

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

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

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

148 : string
149 {
150 if (!$style_id) {
152 }
153 try {
154 return $this->getSkin()->getStyle($style_id)->getImageDirectory();
155 } catch (ilSystemStyleException $e) {
157 }
158 }
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 434 of file class.ilStyleDefinition.php.

434 : ilSkin
435 {
436 return $this->skin;
437 }
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 421 of file class.ilStyleDefinition.php.

421 : array
422 {
423 return self::getAllSkins();
424 }

◆ getSoundDirectory()

ilStyleDefinition::getSoundDirectory ( string  $style_id)
Exceptions
ilSystemStyleException

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

163 : string
164 {
165 return $this->getSkin()->getStyle($style_id)->getSoundDirectory();
166 }

References getSkin().

+ Here is the call graph for this function:

◆ getStyle()

ilStyleDefinition::getStyle ( string  $a_id)
Exceptions
ilSystemStyleException

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

133 {
134 return $this->getSkin()->getStyle($a_id);
135 }

References getSkin().

+ Here is the call graph for this function:

◆ getStyleName()

ilStyleDefinition::getStyleName ( string  $a_id)
Exceptions
ilSystemStyleException

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

140 : string
141 {
142 return $this->getSkin()->getStyle($a_id)->getName();
143 }

References getSkin().

+ Here is the call graph for this function:

◆ getStyles()

ilStyleDefinition::getStyles ( )
Returns
ilSkinStyle[]

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

119 : array
120 {
121 return $this->getSkin()->getStyles();
122 }

References getSkin().

+ Here is the call graph for this function:

◆ getSystemStylesConf()

ilStyleDefinition::getSystemStylesConf ( )

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

458 {
460 }

References $system_style_config.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getTemplateName()

ilStyleDefinition::getTemplateName ( )

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

124 : string
125 {
126 return $this->getSkin()->getName();
127 }

References getSkin().

+ Here is the call graph for this function:

◆ setCachedAllStylesInformation()

static ilStyleDefinition::setCachedAllStylesInformation ( array  $cached_all_styles_information)
staticprotected

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

452 : void
453 {
454 self::$cached_all_styles_information = $cached_all_styles_information;
455 }

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

365 : void
366 {
367 global $DIC;
368
369 if ($DIC->isDependencyAvailable('systemStyle') && $DIC->systemStyle()->getSkin()->getName() != $a_skin) {
370 $styleDefinition = new ilStyleDefinition($a_skin);
371 if (!self::styleExistsForCurrentSkin(self::$current_style)) {
372 $styleDefinition->setCurrentStyle($DIC->systemStyle()->getSkin()->getDefaultStyle()->getId());
373 }
374 }
375 }
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 412 of file class.ilStyleDefinition.php.

412 : void
413 {
414 self::$current_style = $a_style;
415 }

Referenced by getCurrentStyle().

+ Here is the caller graph for this function:

◆ setSkin()

ilStyleDefinition::setSkin ( ilSkin  $skin)

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

439 : void
440 {
441 $this->skin = $skin;
442 }

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

429 : void
430 {
431 self::$skins = $skins;
432 }

References $skins.

◆ setSystemStylesConf()

ilStyleDefinition::setSystemStylesConf ( ilSystemStyleConfig  $system_style_config)

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

463 {
464 $this->system_style_config = $system_style_config;
465 }

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

213 : bool
214 {
217 }
218
219 if ($skin_id == $system_style_config->getDefaultSkinId()) {
221 return true;
222 }
223 } elseif (is_file($system_style_config->getCustomizingSkinPath() . $skin_id . '/template.xml')) {
224 return true;
225 }
226 return false;
227 }

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

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

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

380 : bool
381 {
382 foreach (self::getSkins() as $skin) {
383 if ($skin->hasStyle($style_id)) {
384 return true;
385 }
386 }
387 return false;
388 }
hasStyle(string $id)

References $skin, and ilSkin\hasStyle().

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

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

405 : bool
406 {
407 global $DIC;
408
409 return $DIC->systemStyle()->getSkin()->hasStyle($style_id);
410 }

References $DIC.

◆ styleExistsForSkinId()

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

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

393 : bool
394 {
395 global $DIC;
396
397 if (!self::skinExists($skin_id)) {
398 return false;
399 }
400 $factory = new ilSkinFactory($DIC->language());
401 $skin = $factory->skinStyleContainerFromId($skin_id, new ilSystemStyleMessageStack($DIC->ui()->mainTemplate()))->getSkin();
402 return $skin->hasStyle($style_id);
403 }

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

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

+ 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 44 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 39 of file class.ilStyleDefinition.php.

Referenced by getAllSkinStyles(), getSkin(), setSkin(), styleExists(), and styleExistsForSkinId().

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

Referenced by __construct(), getCurrentStyle(), getSystemStylesConf(), setSystemStylesConf(), and skinExists().


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