1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once("Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php"); 5 6use ILIAS\UI\Implementation\Crawler\Entry as Entry; 7use ILIAS\UI\Implementation\Crawler as Crawler; 8 9/** 10 * Explorer example 11 */ 12class ilKSDocumentationExplorerGUI extends ilExplorerBaseGUI 13{ 14 /** 15 * @var ilCtrl $ctrl 16 */ 17 protected $ctrl; 18 19 /** 20 * 21 */ 22 protected $id = "ksDocumentationExplorer"; 23 24 /** 25 * @var string 26 */ 27 protected $parentLink = ""; 28 29 /** 30 * @var Entry\ComponentEntries 31 */ 32 protected $entries = null; 33 34 /** 35 * @var string 36 */ 37 protected $current_opened_node_id = ""; 38 39 /** 40 * ilKSDocumentationExplorerGUI constructor. 41 * @param ilSystemStyleDocumentationGUI $a_parent_obj 42 * @param Entry\ComponentEntries $entries 43 * @param $current_opened_node_id 44 */ 45 public function __construct() 46 { 47 global $DIC; 48 $this->ctrl = $DIC->ctrl(); 49 50 parent::__construct($this->id, null, ""); 51 52 $this->setParentLink($this->ctrl->getLinkTargetByClass(["ilAdministrationGUI","ilObjStyleSettingsGUI","ilSystemStyleMainGUI","ilSystemStyleDocumentationGUI"], "entries")); 53 54 $entries = Crawler\Entry\ComponentEntries::createFromArray(include ilSystemStyleDocumentationGUI::$DATA_PATH); 55 56 $this->setEntries($entries); 57 $this->setOfflineMode(true); 58 $current_opened_node_id = $_GET["node_id"]; 59 60 if ($current_opened_node_id) { 61 $this->setCurrentOpenedNodeId($current_opened_node_id); 62 } else { 63 $this->setCurrentOpenedNodeId($this->getEntries()->getRootEntryId()); 64 } 65 66 $this->openNodesRecursively($this->getCurrentOpenedNodeId()); 67 } 68 69 /** 70 * @param $id 71 * @throws \ILIAS\UI\Implementation\Crawler\Exception\CrawlerException 72 */ 73 protected function openNodesRecursively($id) 74 { 75 $this->setNodeOpen($id); 76 $parent_id = $this->getEntries()->getEntryById($id)->getParent(); 77 78 if ($parent_id) { 79 $this->openNodesRecursively($parent_id); 80 } 81 } 82 /** 83 * Get root node. 84 * 85 * @return mixed root node object/array 86 */ 87 public function getRootNode() 88 { 89 return $this->getEntries()->getRootEntry(); 90 } 91 92 /** 93 * @param $a_parent_node_id 94 * @return Entry\ComponentEntry[] 95 */ 96 public function getChildsOfNode($a_parent_node_id) 97 { 98 $entry = $this->getEntries()->getEntryById($a_parent_node_id); 99 100 /** 101 * @var Entry\ComponentEntry[] 102 */ 103 $children = array(); 104 foreach ($entry->getChildren() as $child_id) { 105 $children[$child_id] = $this->getEntries()->getEntryById($child_id); 106 } 107 return $children; 108 } 109 110 /** 111 * @param $a_entry_id 112 * @return Entry\ComponentEntry 113 * @throws \ILIAS\UI\Implementation\Crawler\Exception\CrawlerException 114 */ 115 public function getNodeById($a_entry_id) 116 { 117 return $this->getEntries()->getEntryById($a_entry_id); 118 } 119 120 /** 121 * @param mixed $entry 122 * @return Entry\ComponentEntry 123 */ 124 public function getNodeContent($entry) 125 { 126 return $entry->getTitle(); 127 } 128 129 /** 130 * @param Entry\ComponentEntry $entry 131 * @return string 132 */ 133 public function getNodeHref($entry) 134 { 135 return $this->getParentLink() . "&node_id=" . $entry->getId(); 136 } 137 138 /** 139 * @param Entry\ComponentEntry $entry 140 * @return bool 141 */ 142 public function isNodeHighlighted($entry) 143 { 144 return $entry->getId() == $this->getCurrentOpenedNode()->getId(); 145 } 146 /** 147 * @param Entry\ComponentEntry $entry 148 * @return mixed 149 */ 150 public function getNodeId($entry) 151 { 152 return $entry->getId(); 153 } 154 155 /** 156 * @return string 157 */ 158 public function getParentLink() 159 { 160 return $this->parentLink; 161 } 162 163 /** 164 * @param string $parentLink 165 */ 166 public function setParentLink($parentLink) 167 { 168 $this->parentLink = $parentLink; 169 } 170 171 /** 172 * @return Entry\ComponentEntries 173 */ 174 public function getEntries() 175 { 176 return $this->entries; 177 } 178 179 /** 180 * @param Entry\ComponentEntries $entries 181 */ 182 public function setEntries($entries) 183 { 184 $this->entries = $entries; 185 } 186 187 /** 188 * @return string 189 */ 190 public function getCurrentOpenedNodeId() 191 { 192 return $this->current_opened_node_id; 193 } 194 195 /** 196 * @param string $current_opened_node_id 197 */ 198 public function setCurrentOpenedNodeId($current_opened_node_id) 199 { 200 $this->current_opened_node_id = $current_opened_node_id; 201 } 202 203 /** 204 * @return Entry\ComponentEntry 205 * @throws ilSystemStyleException 206 */ 207 public function getCurrentOpenedNode() 208 { 209 return $this->getEntries()->getEntryById($this->getCurrentOpenedNodeId()); 210 } 211} 212