ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
111  global $ilHelp, $DIC, $ilLocator;
112 
113  $DIC->tabs()->clearTargets();
114 
118  $ilHelp->setScreenIdComponent("sty");
119  $ilHelp->setScreenId("system_styles");
120 
121  $skin_id = $_GET["skin_id"];
122  $style_id = $_GET["style_id"];
123 
124  $skin = ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin();
125  $style = $skin->getStyle($style_id);
126 
127  $DIC["tpl"]->setTitle($DIC->language()->txt("documentation"));
128 
129  if ($style->isSubstyle()) {
130  $DIC["tpl"]->setDescription(
131  $this->lng->txt("ks_documentation_of_substyle")
132  . " '"
133  . $style->getName() . "' " .
134  $this->lng->txt("of_parent") . " '" . $skin->getStyle($style->getSubstyleOf())->getName() . "' " .
135  $this->lng->txt("from_skin") . " " . $skin->getName()
136  );
137  } else {
138  $DIC["tpl"]->setDescription(
139  $this->lng->txt("ks_documentation_of_style") . " '" . $style->getName() . "' " .
140  $this->lng->txt("from_skin") . " '" . $skin->getName() . "'"
141  );
142  }
143 
144  $ilLocator->clearItems();
145  $DIC["tpl"]->setLocator();
146  }
147 
148  protected function addGotoLink()
149  {
150  $this->tpl->setPermanentLink("stys", $_GET["ref_id"], "_" . $_GET["node_id"] . "_"
151  . $_GET["skin_id"] . "_" . $_GET["style_id"]);
152  }
153 
158  protected function parseEntries()
159  {
160  $crawler = new Crawler\FactoriesCrawler();
161  $entries = $crawler->crawlFactory(self::ROOT_FACTORY_PATH);
162  file_put_contents(self::$DATA_PATH, json_encode($entries));
163  ilUtil::sendSuccess($this->lng->txt("entries_reloaded"), true);
164  return $entries;
165  }
166 
170  protected function readEntries()
171  {
172  $entries_array = json_decode(file_get_contents(self::$DATA_PATH), true);
173 
174  $entries = new Crawler\Entry\ComponentEntries();
175  foreach ($entries_array as $entry_array) {
176  $entry = new Crawler\Entry\ComponentEntry($entry_array);
177  $entries->addEntry($entry);
178  }
179 
180  return $entries;
181  }
182 
186  public function isReadOnly()
187  {
188  return $this->is_read_only;
189  }
190 
194  public function setIsReadOnly($is_read_only)
195  {
196  $this->is_read_only = $is_read_only;
197  }
198 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$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.