ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
83  public function __construct($skin_id = "", ilSystemStyleConfig $system_style_config = null)
84  {
85  if ($skin_id == "") {
86  $skin_id = self::getCurrentSkin();
87  }
88 
89  if (!$system_style_config) {
91  } else {
93  }
94 
95  if ($skin_id != $this->getSystemStylesConf()->getDefaultSkinId()) {
96  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getCustomizingSkinPath() . $skin_id . "/template.xml"));
97  } else {
98  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getDefaultTemplatePath()));
99  }
100  }
101 
110  public static function getCurrentSkin()
111  {
116  global $DIC,$ilias, $styleDefinition;
117 
118  if (is_object($styleDefinition) && is_object($styleDefinition->getSkin())) {
119  return $styleDefinition->getSkin()->getId();
120  } else {
121  $system_style_conf = new ilSystemStyleConfig();
122 
123  if (is_object($ilias) && is_object($ilias->account) && property_exists($ilias->account, "skin")) {
124  $skin_id = $ilias->account->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 
158  public function getStyle($a_id)
159  {
160  return $this->getSkin()->getStyle($a_id);
161  }
162 
167  public function getStyleName($a_id)
168  {
169  return $this->getSkin()->getStyle($a_id)->getName();
170  }
171 
177  public function getImageDirectory($style_id)
178  {
179  if (!$style_id) {
181  }
182  if (!$this->getSkin()->getStyle($style_id)) {
184  }
185  return $this->getSkin()->getStyle($style_id)->getImageDirectory();
186  }
187 
192  public function getSoundDirectory($style_id)
193  {
194  return $this->getSkin()->getStyle($style_id)->getSoundDirectory();
195  }
196 
197 
203  public static function getAllSkins(ilSystemStyleConfig $system_style_config = null)
204  {
205  if (!self::$skins) {
206  if (!$system_style_config) {
208  }
209 
213  $skins = [];
214  $skins[$system_style_config->getDefaultSkinId()] = ilSkinXML::parseFromXML($system_style_config->getDefaultTemplatePath());
215 
216 
217  if (is_dir($system_style_config->getCustomizingSkinPath())) {
218  $cust_skins_directory = new RecursiveDirectoryIterator($system_style_config->getCustomizingSkinPath(), FilesystemIterator::SKIP_DOTS);
219  foreach ($cust_skins_directory as $skin_folder) {
220  if ($skin_folder->isDir()) {
221  $template_path = $skin_folder->getRealPath() . "/template.xml";
222  if (file_exists($template_path)) {
223  $skin = ilSkinXML::parseFromXML($template_path);
224  $skins[$skin->getId()] = $skin;
225  }
226  }
227  }
228  }
229 
230  self::setSkins($skins);
231  }
232 
233  return self::$skins;
234  }
235 
240  public static function getAllTemplates()
241  {
242  return self::getAllSkins();
243  }
244 
251  public static function skinExists($skin_id, ilSystemStyleConfig $system_style_config = null)
252  {
253  if (!$system_style_config) {
255  }
256 
257  if ($skin_id == $system_style_config->getDefaultSkinId()) {
258  if (is_file($system_style_config->getDefaultTemplatePath())) {
259  return true;
260  }
261  } else {
262  if (is_file($system_style_config->getCustomizingSkinPath() . $skin_id . "/template.xml")) {
263  return true;
264  }
265  }
266  return false;
267  }
268 
277  public static function getCurrentStyle()
278  {
279  global $DIC;
280 
284  global $ilias, $styleDefinition, $tree;
285 
286  if (self::$current_style) {
287  return self::$current_style;
288  }
289 
290  if (!is_object($ilias)) {
291  return null;
292  }
293 
294  self::setCurrentStyle($ilias->account->prefs['style']);
295 
296  if (is_object($styleDefinition) && self::styleExistsForCurrentSkin(self::$current_style)) {
297  if ($styleDefinition->getSkin()->hasStyleSubstyles(self::$current_style)) {
298  // read assignments, if given
299  $assignments = ilSystemStyleSettings::getSystemStyleCategoryAssignments(self::getCurrentSkin(), self::$current_style);
300  if (count($assignments) > 0) {
301  $ref_ass = [];
302  foreach ($assignments as $a) {
303  if ($styleDefinition->getSkin()->hasStyle($a["substyle"])) {
304  $ref_ass[$a["ref_id"]] = $a["substyle"];
305  }
306  }
307 
308  $ref_id = false;
309  if ($_GET["ref_id"]) {
310  $ref_id = $_GET["ref_id"];
311  } elseif ($_GET["target"]) {
312  $target_arr = explode("_", $_GET["target"]);
313  $ref_id = $target_arr[1];
314  }
315 
316  // check whether any ref id assigns a new style
317  if (is_object($tree) && $ref_id && $tree->isInTree($ref_id)) {
318  $path = $tree->getPathId($ref_id);
319  for ($i = count($path) - 1; $i >= 0; $i--) {
320  if (isset($ref_ass[$path[$i]])) {
321  self::$current_style = $ref_ass[$path[$i]];
322  return self::$current_style;
323  }
324  }
325  }
326  }
327  }
328  }
329 
330  if (!self::styleExistsForCurrentSkin(self::$current_style)) {
331  ilUtil::sendFailure($DIC->language()->txt("set_style_does_not_exist") . " " . self::$current_style);
333  self::setCurrentSkin($system_style_config->getDefaultSkinId());
334  self::setCurrentStyle($system_style_config->getDefaultStyleId());
335  }
336 
337  return self::$current_style;
338  }
339 
346  public static function getAllSkinStyles()
347  {
351  global $styleDefinition;
352 
353 
354 
355  if (!self::getCachedAllStylesInformation()) {
356  $all_styles = [];
357 
358  $skins = $styleDefinition->getSkins();
359 
360  foreach ($skins as $skin) {
361  foreach ($skin->getStyles() as $style) {
362  $num_users = ilObjUser::_getNumberOfUsersForStyle($skin->getId(), $style->getId());
363 
364  $parent_name = "";
365  if ($style->getSubstyleOf()) {
366  $parent_name = $skin->getStyle($style->getSubstyleOf())->getName();
367  }
368 
369  // default selection list
370  $all_styles[$skin->getId() . ":" . $style->getId()] = [
371  "title" => $skin->getName() . " / " . $style->getName(),
372  "id" => $skin->getId() . ":" . $style->getId(),
373  "skin_id" => $skin->getId(),
374  "skin_name" => $skin->getName(),
375  "template_id" => $skin->getId(),
376  "template_name" => $skin->getName(),
377  "style_id" => $style->getId(),
378  "style_name" => $style->getName(),
379  "substyle_of" => $style->getSubstyleOf(),
380  "substyle_of_name" => $parent_name,
381  "users" => $num_users
382  ];
383  }
384  }
385  self::setCachedAllStylesInformation($all_styles);
386  }
387 
388  return self::getCachedAllStylesInformation();
389  }
390 
391 
395  public static function setCurrentSkin($a_skin)
396  {
400  global $styleDefinition;
401 
402  if (is_object($styleDefinition) && $styleDefinition->getSkin()->getName() != $a_skin) {
403  $styleDefinition = new ilStyleDefinition($a_skin);
404  if (!self::styleExistsForCurrentSkin(self::$current_style)) {
405  $styleDefinition->setCurrentStyle($styleDefinition->getSkin()->getDefaultStyle()->getId());
406  }
407  }
408  }
409 
410 
415  public static function styleExists($style_id)
416  {
417  foreach (self::getSkins() as $skin) {
418  if ($skin->hasStyle($style_id)) {
419  return true;
420  }
421  }
422  return false;
423  }
424 
431  public static function styleExistsForSkinId($skin_id, $style_id)
432  {
433  if (!self::skinExists($skin_id)) {
434  return false;
435  }
436  $skin = ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin();
437  return $skin->hasStyle($style_id);
438  }
439 
444  public static function styleExistsForCurrentSkin($style_id)
445  {
449  global $styleDefinition;
450 
451  return $styleDefinition->getSkin()->hasStyle($style_id);
452  }
453 
457  public static function setCurrentStyle($a_style)
458  {
459  self::$current_style = $a_style;
460  }
461 
465  public static function getSkins()
466  {
467  return self::getAllSkins();
468  }
469 
473  public static function setSkins($skins)
474  {
475  self::$skins = $skins;
476  }
477 
481  public function getSkin()
482  {
483  return $this->skin;
484  }
485 
489  public function setSkin($skin)
490  {
491  $this->skin = $skin;
492  }
493 
497  protected static function getCachedAllStylesInformation()
498  {
499  return self::$cached_all_styles_information;
500  }
501 
506  {
507  self::$cached_all_styles_information = $cached_all_styles_information;
508  }
509 
513  public function getSystemStylesConf()
514  {
516  }
517 
522  {
523  $this->system_style_config = $system_style_config;
524  }
525 }
$target_arr
Definition: goto.php:47
$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)
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 setCurrentStyle($a_style)