ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ComponentEntries.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4
7
14{
18 protected $root_entry_id = 'root';
19
23 protected $id_to_entry_map = array();
24
28 public function __construct(){
29 parent::__construct();
30 $this->rewind();
31 }
32
39 public function addEntry(ComponentEntry $entry){
40 $this->assert()->isNotIndex($entry->getId(),$this->id_to_entry_map);
41 if(count($this)==0){
42 $this->setRootEntryId($entry->getId());
43 }
44 $this->id_to_entry_map[$entry->getId()] = $entry;
45
46 }
47
52 public function addEntries(ComponentEntries $entries){
53 foreach($entries as $entry){
54 $this->addEntry($entry);
55 }
56 }
57
62 {
63 $this->root_entry_id = $root_entry_id;
64 }
65
69 public function getRootEntryId(){
71 }
72
76 public function getRootEntry(){
77 return $this->getEntryById($this->getRootEntryId());
78 }
79
85 public function getEntryById($id = "")
86 {
87 if(array_key_exists ( $id, $this->id_to_entry_map )){
88 return $this->id_to_entry_map[$id];
89 }
90 throw $this->f->exception(Crawler\Exception\CrawlerException::INVALID_ID,$id);
91
92 }
93
98 public function getParentsOfEntry($id){
99 $parent_id = $this->getEntryById($id)->getParent();
100
101 if(!$parent_id){
102 return array();
103 }
104 else{
105 $parents = $this->getParentsOfEntry($parent_id);
106 array_push($parents,$parent_id);
107 return $parents;
108 }
109 }
110
115 public function getParentsOfEntryTitles($id){
116 $titles = array();
117 foreach ($this->getParentsOfEntry($id) as $parent_id) {
118 $titles[$parent_id] = $this->getEntryById($parent_id)->getTitle();
119 }
120 return $titles;
121 }
122
127 public function getDescendantsOfEntry($id){
128 $children = $this->getEntryById($id)->getChildren();
129 foreach($this->getEntryById($id)->getChildren() as $child){
130 $children = array_merge($children,$this->getDescendantsOfEntry($child));
131 }
132 return $children;
133 }
134
139 public function getDescendantsOfEntryTitles($id){
140 $titles = array();
141 foreach ($this->getDescendantsOfEntry($id) as $parent_id) {
142 $titles[$parent_id] = $this->getEntryById($parent_id)->getTitle();
143 }
144 return $titles;
145 }
146
147 public function expose() {
148 return get_object_vars($this);
149 }
150
156 public function valid() {
157 return current($this->id_to_entry_map) !== false;
158 }
159
163 public function key() {
164 return key($this->id_to_entry_map);
165 }
166
170 public function current() {
171 return current($this->id_to_entry_map);
172 }
173
174 public function next() {
175 next($this->id_to_entry_map);
176 }
177 public function rewind() {
178 reset($this->id_to_entry_map);
179 }
180
184 public function count(){
185 return count($this->id_to_entry_map);
186 }
187
193 public function jsonSerialize() {
195 }
196}
An exception for terminatinating execution or to throw for unit testing.
Abstract Entry Part to share some common entry functionality.
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable.
addEntry(ComponentEntry $entry)
Add and entry, first is always root.
Stores Information of UI Components parsed from YAML, examples and less files.