ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilStyleDefinition.php
Go to the documentation of this file.
1 <?php
2 include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
3 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
4 include_once("Services/Style/System/classes/class.ilSystemStyleSettings.php");
5 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleConfig.php");
6 
7 
8 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
9 
10 
43 {
49  public static $current_style = false;
50 
55  public static $skins = [];
56 
62  protected $skin;
63 
68  protected static $cached_all_styles_information = null;
69 
77 
84  public function __construct($skin_id = "", ilSystemStyleConfig $system_style_config = null)
85  {
86  if ($skin_id == "") {
87  $skin_id = self::getCurrentSkin();
88  }
89 
90  if (!$system_style_config) {
92  } else {
94  }
95 
96  if ($skin_id != $this->getSystemStylesConf()->getDefaultSkinId()) {
97  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getCustomizingSkinPath() . $skin_id . "/template.xml"));
98  } else {
99  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getDefaultTemplatePath()));
100  }
101  }
102 
111  public static function getCurrentSkin()
112  {
113  global $DIC;
114 
115  if (!$DIC) {
116  return null;
117  }
118  if ($DIC->isDependencyAvailable("systemStyle") && is_object($DIC->systemStyle()->getSkin())) {
119  return $DIC->systemStyle()->getSkin()->getId();
120  } else {
121  $system_style_conf = new ilSystemStyleConfig();
122 
123  if ($DIC->isDependencyAvailable("user") && is_object($DIC->user()) && property_exists($DIC->user(), "skin")) {
124  $skin_id = $DIC->user()->skin;
125  if (!self::skinExists($skin_id)) {
126  ilUtil::sendFailure($DIC->language()->txt("set_skin_does_not_exist") . " " . $skin_id);
127  $skin_id = $system_style_conf->getDefaultSkinId();
128  }
129  return $skin_id;
130  } else {
131  return null;
132  }
133  }
134  }
135 
139  public function getStyles()
140  {
141  return $this->getSkin()->getStyles();
142  }
143 
144 
148  public function getTemplateName()
149  {
150  return $this->getSkin()->getName();
151  }
152 
153 
159  public function getStyle($a_id)
160  {
161  return $this->getSkin()->getStyle($a_id);
162  }
163 
169  public function getStyleName($a_id)
170  {
171  return $this->getSkin()->getStyle($a_id)->getName();
172  }
173 
179  public function getImageDirectory($style_id)
180  {
181  if (!$style_id) {
183  }
184  if (!$this->getSkin()->getStyle($style_id)) {
186  }
187  return $this->getSkin()->getStyle($style_id)->getImageDirectory();
188  }
189 
195  public function getSoundDirectory($style_id)
196  {
197  return $this->getSkin()->getStyle($style_id)->getSoundDirectory();
198  }
199 
200 
206  public static function getAllSkins(ilSystemStyleConfig $system_style_config = null)
207  {
208  if (!self::$skins) {
209  if (!$system_style_config) {
211  }
212 
216  $skins = [];
217  $skins[$system_style_config->getDefaultSkinId()] = ilSkinXML::parseFromXML($system_style_config->getDefaultTemplatePath());
218 
219 
220  if (is_dir($system_style_config->getCustomizingSkinPath())) {
221  $cust_skins_directory = new RecursiveDirectoryIterator($system_style_config->getCustomizingSkinPath(), FilesystemIterator::SKIP_DOTS);
222  foreach ($cust_skins_directory as $skin_folder) {
223  if ($skin_folder->isDir()) {
224  $template_path = $skin_folder->getRealPath() . "/template.xml";
225  if (file_exists($template_path)) {
226  $skin = ilSkinXML::parseFromXML($template_path);
227  $skins[$skin->getId()] = $skin;
228  }
229  }
230  }
231  }
232 
233  self::setSkins($skins);
234  }
235 
236  return self::$skins;
237  }
238 
245  public static function getAllTemplates()
246  {
247  return self::getAllSkins();
248  }
249 
256  public static function skinExists($skin_id, ilSystemStyleConfig $system_style_config = null)
257  {
258  if (!$system_style_config) {
260  }
261 
262  if ($skin_id == $system_style_config->getDefaultSkinId()) {
263  if (is_file($system_style_config->getDefaultTemplatePath())) {
264  return true;
265  }
266  } else {
267  if (is_file($system_style_config->getCustomizingSkinPath() . $skin_id . "/template.xml")) {
268  return true;
269  }
270  }
271  return false;
272  }
273 
283  public static function getCurrentStyle()
284  {
285  global $DIC;
286 
287  if (self::$current_style) {
288  return self::$current_style;
289  }
290 
291  if (!$DIC || !$DIC->isDependencyAvailable("user")) {
292  return null;
293  }
294 
295  self::setCurrentStyle($DIC->user()->prefs['style']);
296 
297  if ($DIC->isDependencyAvailable("systemStyle") && self::styleExistsForCurrentSkin(self::$current_style)) {
298  if ($DIC->systemStyle()->getSkin()->hasStyleSubstyles(self::$current_style)) {
299  // read assignments, if given
300  $assignments = ilSystemStyleSettings::getSystemStyleCategoryAssignments(self::getCurrentSkin(), self::$current_style);
301  if (count($assignments) > 0) {
302  $ref_ass = [];
303  foreach ($assignments as $a) {
304  if ($DIC->systemStyle()->getSkin()->hasStyle($a["substyle"])) {
305  $ref_ass[$a["ref_id"]] = $a["substyle"];
306  }
307  }
308 
309  $ref_id = false;
310  if ($_GET["ref_id"]) {
311  $ref_id = $_GET["ref_id"];
312  } elseif ($_GET["target"]) {
313  $target_arr = explode("_", $_GET["target"]);
314  $ref_id = $target_arr[1];
315  }
316 
317  // check whether any ref id assigns a new style
318  if ($DIC->isDependencyAvailable("repositoryTree") && $ref_id && $DIC->repositoryTree()->isInTree($ref_id)) {
319  $path = $DIC->repositoryTree()->getPathId($ref_id);
320  for ($i = count($path) - 1; $i >= 0; $i--) {
321  if (isset($ref_ass[$path[$i]])) {
322  self::$current_style = $ref_ass[$path[$i]];
323  return self::$current_style;
324  }
325  }
326  }
327  }
328  }
329  }
330 
331  if (!self::styleExistsForCurrentSkin(self::$current_style)) {
332  ilUtil::sendFailure($DIC->language()->txt("set_style_does_not_exist") . " " . self::$current_style);
334  self::setCurrentSkin($system_style_config->getDefaultSkinId());
335  self::setCurrentStyle($system_style_config->getDefaultStyleId());
336  }
337 
338  return self::$current_style;
339  }
340 
348  public static function getAllSkinStyles()
349  {
350  global $DIC;
351 
352  if (!self::getCachedAllStylesInformation()) {
353  $all_styles = [];
354 
355  $skins = $DIC->systemStyle()->getSkins();
356 
357  foreach ($skins as $skin) {
358  foreach ($skin->getStyles() as $style) {
359  $num_users = ilObjUser::_getNumberOfUsersForStyle($skin->getId(), $style->getId());
360 
361  $parent_name = "";
362  if ($style->getSubstyleOf()) {
363  $parent_name = $skin->getStyle($style->getSubstyleOf())->getName();
364  }
365 
366  // default selection list
367  $all_styles[$skin->getId() . ":" . $style->getId()] = [
368  "title" => $skin->getName() . " / " . $style->getName(),
369  "id" => $skin->getId() . ":" . $style->getId(),
370  "skin_id" => $skin->getId(),
371  "skin_name" => $skin->getName(),
372  "template_id" => $skin->getId(),
373  "template_name" => $skin->getName(),
374  "style_id" => $style->getId(),
375  "style_name" => $style->getName(),
376  "substyle_of" => $style->getSubstyleOf(),
377  "substyle_of_name" => $parent_name,
378  "users" => $num_users
379  ];
380  }
381  }
382  self::setCachedAllStylesInformation($all_styles);
383  }
384 
385  return self::getCachedAllStylesInformation();
386  }
387 
388 
393  public static function setCurrentSkin($a_skin)
394  {
395  global $DIC;
396 
397  if ($DIC->isDependencyAvailable("systemStyle") && $DIC->systemStyle()->getSkin()->getName() != $a_skin) {
398  $styleDefinition = new ilStyleDefinition($a_skin);
399  if (!self::styleExistsForCurrentSkin(self::$current_style)) {
400  $styleDefinition->setCurrentStyle($DIC->systemStyle()->getSkin()->getDefaultStyle()->getId());
401  }
402  }
403  }
404 
405 
411  public static function styleExists($style_id)
412  {
413  foreach (self::getSkins() as $skin) {
414  if ($skin->hasStyle($style_id)) {
415  return true;
416  }
417  }
418  return false;
419  }
420 
427  public static function styleExistsForSkinId($skin_id, $style_id)
428  {
429  if (!self::skinExists($skin_id)) {
430  return false;
431  }
432  $skin = ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin();
433  return $skin->hasStyle($style_id);
434  }
435 
440  public static function styleExistsForCurrentSkin($style_id)
441  {
442  global $DIC;
443 
444  return $DIC->systemStyle()->getSkin()->hasStyle($style_id);
445  }
446 
450  public static function setCurrentStyle($a_style)
451  {
452  self::$current_style = $a_style;
453  }
454 
459  public static function getSkins()
460  {
461  return self::getAllSkins();
462  }
463 
467  public static function setSkins($skins)
468  {
469  self::$skins = $skins;
470  }
471 
475  public function getSkin()
476  {
477  return $this->skin;
478  }
479 
483  public function setSkin($skin)
484  {
485  $this->skin = $skin;
486  }
487 
491  protected static function getCachedAllStylesInformation()
492  {
493  return self::$cached_all_styles_information;
494  }
495 
500  {
501  self::$cached_all_styles_information = $cached_all_styles_information;
502  }
503 
507  public function getSystemStylesConf()
508  {
510  }
511 
516  {
517  $this->system_style_config = $system_style_config;
518  }
519 }
$target_arr
Definition: goto.php:47
$path
Definition: aliased.php:25
$style
Definition: example_012.php:70
static _getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
static styleExists($style_id)
static getSystemStyleCategoryAssignments($a_skin_id, $a_style_id)
Get all system sub styles category assignments.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static styleExistsForSkinId($skin_id, $style_id)
setSystemStylesConf($system_style_config)
static getAllSkinStyles()
Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this ar...
static getCurrentSkin()
get the current skin
static setCurrentSkin($a_skin)
Class for advanced editing exception handling in ILIAS.
static skinExists($skin_id, ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
__construct($skin_id="", ilSystemStyleConfig $system_style_config=null)
ilStyleDefinition constructor.
static setCachedAllStylesInformation($cached_all_styles_information)
ilStyleDefinition acts as a wrapper of style related actions.
$i
Definition: disco.tpl.php:19
static getCurrentStyle()
get the current style or sub style
static styleExistsForCurrentSkin($style_id)
static setCurrentStyle($a_style)