ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSystemStyleDocumentationGUI.php
Go to the documentation of this file.
1 <?php
2 require_once("Services/Style/System/classes/Documentation/class.ilKSDocumentationExplorerGUI.php");
3 require_once("Services/Style/System/classes/Documentation/class.ilKSDocumentationEntryGUI.php");
4 require_once("libs/composer/vendor/geshi/geshi/src/geshi.php");
5 
6 
8 
15 {
19  protected $tpl;
23  protected $ctrl;
24 
28  protected $lng;
29 
33  protected $is_read_only = false;
34 
35  const ROOT_FACTORY_PATH = "./Services/Style/System/data/abstractDataFactory.php";
36  const DATA_DIRECTORY = "./Services/Style/System/data";
37  const DATA_FILE = "data.json";
38  public static $DATA_PATH;
39 
44  public function __construct($read_only = false)
45  {
46  global $DIC;
47 
48  $this->ctrl = $DIC->ctrl();
49  $this->lng = $DIC->language();
50  $this->tpl = $DIC["tpl"];
51 
52  $this->setIsReadOnly($read_only);
53 
54  self::$DATA_PATH = self::DATA_DIRECTORY . "/" . self::DATA_FILE;
55  }
56 
60  public function executeCommand()
61  {
62  $cmd = $this->ctrl->getCmd();
63 
64  switch ($cmd) {
65  case 'parseEntries':
66  $this->$cmd();
67  $this->show();
68  break;
69  default:
70  if ($this->is_read_only) {
71  $this->resetForReadOnly();
72  }
73  $this->addGotoLink();
74  $this->show();
75  break;
76  }
77  }
78 
79  public function show()
80  {
81  $entries = $this->readEntries();
82  $content = "";
83 
84  //The button to parse the entries from code should only be shown in DEVMODE. Other users do not need that.
85  if (DEVMODE == 1 && !$this->isReadOnly()) {
86  $toolbar = new ilToolbarGUI();
87  $reload_btn = ilLinkButton::getInstance();
88  $reload_btn->setCaption($this->lng->txt('refresh_entries'), false);
89  if ($_GET["node_id"]) {
90  $this->ctrl->saveParameter($this, "node_id");
91  }
92  $reload_btn->setUrl($this->ctrl->getLinkTarget($this, 'parseEntries'));
93  $toolbar->addButtonInstance($reload_btn);
94  $content .= $toolbar->getHTML();
95  }
96 
97  $explorer = new ilKSDocumentationExplorerGUI($this, "entries", $entries, $_GET["node_id"]);
98  $this->tpl->setLeftNavContent($explorer->getHTML());
99  $entry_gui = new ilKSDocumentationEntryGUI($this, $explorer->getCurrentOpenedNode(), $entries);
100  $content .= $entry_gui->renderEntry();
101 
102  $this->tpl->setContent($content);
103  }
104 
105  protected function resetForReadOnly()
106  {
110  global $DIC;
111 
112  $DIC->tabs()->clearTargets();
113 
117  $DIC->help()->setScreenIdComponent("sty");
118  $DIC->help()->setScreenId("system_styles");
119 
120  $skin_id = $_GET["skin_id"];
121  $style_id = $_GET["style_id"];
122 
123  $skin = ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin();
124  $style = $skin->getStyle($style_id);
125 
126  $DIC["tpl"]->setTitle($DIC->language()->txt("documentation"));
127 
128  if ($style->isSubstyle()) {
129  $DIC["tpl"]->setDescription(
130  $this->lng->txt("ks_documentation_of_substyle")
131  . " '"
132  . $style->getName() . "' " .
133  $this->lng->txt("of_parent") . " '" . $skin->getStyle($style->getSubstyleOf())->getName() . "' " .
134  $this->lng->txt("from_skin") . " " . $skin->getName()
135  );
136  } else {
137  $DIC["tpl"]->setDescription(
138  $this->lng->txt("ks_documentation_of_style") . " '" . $style->getName() . "' " .
139  $this->lng->txt("from_skin") . " '" . $skin->getName() . "'"
140  );
141  }
142 
143  $DIC["ilLocator"]->clearItems();
144  $DIC["tpl"]->setLocator();
145  }
146 
147  protected function addGotoLink()
148  {
149  $this->tpl->setPermanentLink("stys", $_GET["ref_id"], "_" . $_GET["node_id"] . "_"
150  . $_GET["skin_id"] . "_" . $_GET["style_id"]);
151  }
152 
157  protected function parseEntries()
158  {
159  $crawler = new Crawler\FactoriesCrawler();
160  $entries = $crawler->crawlFactory(self::ROOT_FACTORY_PATH);
161  file_put_contents(self::$DATA_PATH, json_encode($entries));
162  ilUtil::sendSuccess($this->lng->txt("entries_reloaded"), true);
163  return $entries;
164  }
165 
169  protected function readEntries()
170  {
171  $entries_array = json_decode(file_get_contents(self::$DATA_PATH), true);
172 
173  $entries = new Crawler\Entry\ComponentEntries();
174  foreach ($entries_array as $entry_array) {
175  $entry = new Crawler\Entry\ComponentEntry($entry_array);
176  $entries->addEntry($entry);
177  }
178 
179  return $entries;
180  }
181 
185  public function isReadOnly()
186  {
187  return $this->is_read_only;
188  }
189 
193  public function setIsReadOnly($is_read_only)
194  {
195  $this->is_read_only = $is_read_only;
196  }
197 }
$style
Definition: example_012.php:70
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
__construct($read_only=false)
ilSystemStyleDocumentationGUI constructor.