ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  static $current_style = false;
50 
55  static $skins = [];
56 
62  protected $skin;
63 
68  protected static $cached_all_styles_information = null;
69 
77 
83  function __construct($skin_id = "", ilSystemStyleConfig $system_style_config = null)
84  {
85  if($skin_id == ""){
86  $skin_id = self::getCurrentSkin();
87  }
88 
91  }else{
93  }
94 
95  if ($skin_id != $this->getSystemStylesConf()->getDefaultSkinId())
96  {
97  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getCustomizingSkinPath().$skin_id."/template.xml"));
98 
99  }else{
100  $this->setSkin(ilSkinXML::parseFromXML($this->getSystemStylesConf()->getDefaultTemplatePath()));
101  }
102  }
103 
112  public static function getCurrentSkin()
113  {
118  global $DIC,$ilias, $styleDefinition;
119 
120  if(is_object($styleDefinition) && is_object($styleDefinition->getSkin())){
121  return $styleDefinition->getSkin()->getId();
122  }
123  else{
124  $system_style_conf = new ilSystemStyleConfig();
125 
126  if (is_object($ilias) && is_object($ilias->account) && property_exists($ilias->account,"skin")) {
127  $skin_id = $ilias->account->skin;
128  if(!self::skinExists($skin_id)){
129  ilUtil::sendFailure($DIC->language()->txt("set_skin_does_not_exist")." ".$skin_id);
130  $skin_id = $system_style_conf->getDefaultSkinId();
131  }
132  return $skin_id;
133  }else{
134  return null;
135  }
136  }
137  }
138 
142  public function getStyles()
143  {
144  return $this->getSkin()->getStyles();
145  }
146 
147 
151  public function getTemplateName()
152  {
153  return $this->getSkin()->getName();
154  }
155 
156 
161  public function getStyle($a_id)
162  {
163  return $this->getSkin()->getStyle($a_id);
164  }
165 
170  public function getStyleName($a_id)
171  {
172  return $this->getSkin()->getStyle($a_id)->getName();
173  }
174 
180  public function getImageDirectory($style_id)
181  {
182  if(!$style_id){
184  }
185  if(!$this->getSkin()->getStyle($style_id)){
187  }
188  return $this->getSkin()->getStyle($style_id)->getImageDirectory();
189  }
190 
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  if(!self::$skins){
210  }
211 
215  $skins = [];
216  $skins[$system_style_config->getDefaultSkinId()] = ilSkinXML::parseFromXML($system_style_config->getDefaultTemplatePath());
217 
218 
219  if(is_dir($system_style_config->getCustomizingSkinPath())){
220  $cust_skins_directory = new RecursiveDirectoryIterator($system_style_config->getCustomizingSkinPath(),FilesystemIterator::SKIP_DOTS);
221  foreach ($cust_skins_directory as $skin_folder) {
222  if($skin_folder->isDir()){
223  $template_path = $skin_folder->getRealPath()."/template.xml";
224  if (file_exists($template_path))
225  {
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 
243  public static function getAllTemplates(){
244  return self::getAllSkins();
245  }
246 
253  public static function skinExists($skin_id, ilSystemStyleConfig $system_style_config = null)
254  {
257  }
258 
259  if ($skin_id == $system_style_config->getDefaultSkinId())
260  {
261  if (is_file($system_style_config->getDefaultTemplatePath()))
262  {
263  return true;
264  }
265  }
266  else
267  {
268  if (is_file($system_style_config->getCustomizingSkinPath().$skin_id."/template.xml"))
269  {
270  return true;
271  }
272  }
273  return false;
274  }
275 
284  public static function getCurrentStyle()
285  {
286  global $DIC;
287 
291  global $ilias, $styleDefinition, $tree;
292 
293  if (self::$current_style)
294  {
295  return self::$current_style;
296  }
297 
298  if(!is_object($ilias))
299  {
300  return null;
301  }
302 
303  self::setCurrentStyle($ilias->account->prefs['style']);
304 
305  if (is_object($styleDefinition) && self::styleExistsForCurrentSkin(self::$current_style)) {
306 
307  if ($styleDefinition->getSkin()->hasStyleSubstyles(self::$current_style)) {
308  // read assignments, if given
309  $assignments = ilSystemStyleSettings::getSystemStyleCategoryAssignments(self::getCurrentSkin(), self::$current_style);
310  if (count($assignments) > 0) {
311  $ref_ass = [];
312  foreach ($assignments as $a) {
313  if($styleDefinition->getSkin()->hasStyle($a["substyle"]))
314  $ref_ass[$a["ref_id"]] = $a["substyle"];
315  }
316 
317  $ref_id = false;
318  if ($_GET["ref_id"]) {
319  $ref_id = $_GET["ref_id"];
320  } else if ($_GET["target"]) {
321  $target_arr = explode("_", $_GET["target"]);
322  $ref_id = $target_arr[1];
323  }
324 
325  // check whether any ref id assigns a new style
326  if (is_object($tree) && $ref_id && $tree->isInTree($ref_id)) {
327 
328  $path = $tree->getPathId($ref_id);
329  for ($i = count($path) - 1; $i >= 0; $i--) {
330  if (isset($ref_ass[$path[$i]])) {
331  self::$current_style = $ref_ass[$path[$i]];
332  return self::$current_style;
333  }
334  }
335  }
336  }
337  }
338  }
339 
340  if(!self::styleExistsForCurrentSkin(self::$current_style)){
341  ilUtil::sendFailure($DIC->language()->txt("set_style_does_not_exist")." ".self::$current_style);
343  self::setCurrentSkin($system_style_config->getDefaultSkinId());
344  self::setCurrentStyle($system_style_config->getDefaultStyleId());
345  }
346 
347  return self::$current_style;
348  }
349 
356  public static function getAllSkinStyles()
357  {
361  global $styleDefinition;
362 
363 
364 
365  if(!self::getCachedAllStylesInformation()){
366  $all_styles = [];
367 
368  $skins = $styleDefinition->getSkins();
369 
370  foreach ($skins as $skin)
371  {
372  foreach ($skin->getStyles() as $style)
373  {
374  $num_users = ilObjUser::_getNumberOfUsersForStyle($skin->getId(), $style->getId());
375 
376  $parent_name = "";
377  if($style->getSubstyleOf()){
378  $parent_name = $skin->getStyle($style->getSubstyleOf())->getName();
379  }
380 
381  // default selection list
382  $all_styles[$skin->getId().":".$style->getId()] = [
383  "title" => $skin->getName()." / ".$style->getName(),
384  "id" => $skin->getId().":". $style->getId(),
385  "skin_id" => $skin->getId(),
386  "skin_name" => $skin->getName(),
387  "template_id" => $skin->getId(),
388  "template_name" => $skin->getName(),
389  "style_id" => $style->getId(),
390  "style_name" => $style->getName(),
391  "substyle_of" => $style->getSubstyleOf(),
392  "substyle_of_name" => $parent_name,
393  "users" => $num_users
394  ];
395  }
396  }
397  self::setCachedAllStylesInformation($all_styles);
398 
399  }
400 
401  return self::getCachedAllStylesInformation();
402  }
403 
404 
408  public static function setCurrentSkin($a_skin)
409  {
413  global $styleDefinition;
414 
415  if (is_object($styleDefinition) && $styleDefinition->getSkin()->getName() != $a_skin)
416  {
417  $styleDefinition = new ilStyleDefinition($a_skin);
418  if(!self::styleExistsForCurrentSkin(self::$current_style)){
419  $styleDefinition->setCurrentStyle($styleDefinition->getSkin()->getDefaultStyle()->getId());
420  }
421  }
422  }
423 
424 
429  public static function styleExists($style_id){
430  foreach(self::getSkins() as $skin)
431  {
432  if($skin->hasStyle($style_id)){
433  return true;
434  }
435  }
436  return false;
437  }
438 
445  public static function styleExistsForSkinId($skin_id,$style_id){
446  if(!self::skinExists($skin_id)){
447  return false;
448  }
449  $skin = ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin();
450  return $skin->hasStyle($style_id);
451  }
452 
457  public static function styleExistsForCurrentSkin($style_id){
461  global $styleDefinition;
462 
463  return $styleDefinition->getSkin()->hasStyle($style_id);
464  }
465 
469  public static function setCurrentStyle($a_style)
470  {
471  self::$current_style = $a_style;
472  }
473 
477  public static function getSkins()
478  {
479  return self::getAllSkins();
480  }
481 
485  public static function setSkins($skins)
486  {
487  self::$skins = $skins;
488  }
489 
493  public function getSkin()
494  {
495  return $this->skin;
496  }
497 
501  public function setSkin($skin)
502  {
503  $this->skin = $skin;
504  }
505 
509  protected static function getCachedAllStylesInformation()
510  {
511  return self::$cached_all_styles_information;
512  }
513 
518  {
519  self::$cached_all_styles_information = $cached_all_styles_information;
520  }
521 
525  public function getSystemStylesConf()
526  {
528  }
529 
534  {
535  $this->system_style_config = $system_style_config;
536  }
537 }
$target_arr
Definition: goto.php:49
$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.
$_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.
$ref_id
Definition: sahs_server.php:39
static setCachedAllStylesInformation($cached_all_styles_information)
ilStyleDefinition acts as a wrapper of style related actions.
global $DIC
static setCurrentStyle($a_style)