ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ComponentEntry.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 
6 
13 {
17  protected $id = "";
18 
22  protected $title = "";
23 
27  protected $is_abstract = false;
28 
32  protected $status_list_entry = array("Accepted","Proposed","To be revised");
33 
37  protected $status_list_implementation = array("Implemented","Partly implemented","To be implemented");
38 
42  protected $status_entry = "";
43 
47  protected $status_implementation = "";
48 
52  protected $description = null;
53 
57  protected $background = "";
58 
62  protected $selector = "";
63 
68 
72  protected $rules = null;
73 
77  protected $parent = false;
78 
82  protected $children = array();
83 
87  protected $less_variables = array();
88 
92  protected $path = "";
93 
94 
98  protected $examples = null;
99 
103  protected $examples_path = "";
104 
110  public function __construct($entry_data)
111  {
112  parent::__construct();
113  $this->assert()->isIndex('id', $entry_data);
114  $this->setId($entry_data['id']);
115  $this->assert()->isIndex('title', $entry_data);
116  $this->setTitle($entry_data['title']);
117  $this->assert()->isIndex('abstract', $entry_data);
118  $this->setIsAbstract($entry_data['abstract']);
119  $this->setStatusEntry("Proposed");
120  $this->setStatusImplementation("Partly implemented");
121  if (array_key_exists('description', $entry_data)) {
122  $this->setDescription(new ComponentEntryDescription($entry_data['description']));
123  }
124  if (array_key_exists('rules', $entry_data)) {
125  $this->setRules(new ComponentEntryRules($entry_data['rules']));
126  }
127 
128  $this->assert()->isIndex('path', $entry_data);
129  $this->setPath($entry_data['path']);
130 
131  if (array_key_exists('background', $entry_data)) {
132  $this->setBackground($entry_data['background']);
133  }
134  if (array_key_exists('featurewiki', $entry_data)) {
135  $this->setFeatureWikiReferences($entry_data['featurewiki']);
136  }
137  if (array_key_exists('parent', $entry_data)) {
138  $this->setParent($entry_data['parent']);
139  }
140  if (array_key_exists('children', $entry_data)) {
141  $this->setChildren($entry_data['children']);
142  }
143 
144  if (!$this->isAbstract()) {
145  $this->readExamples();
146  }
147  }
148 
152  public function getId()
153  {
154  return $this->id;
155  }
156 
160  public function setId($id)
161  {
162  $this->assert()->isString($id, false);
163  $this->id = $id;
164  }
165 
169  public function getTitle()
170  {
171  return $this->title;
172  }
173 
177  public function setTitle($title)
178  {
179  $this->assert()->isString($title, false);
180  $this->title = $title;
181  }
182 
186  public function isAbstract()
187  {
188  return $this->is_abstract;
189  }
190 
194  public function setIsAbstract($is_abstract)
195  {
196  $this->is_abstract = $is_abstract;
197  }
198 
202  public function getStatusEntry()
203  {
204  return $this->status_entry;
205  }
206 
210  public function setStatusEntry($status_entry)
211  {
212  $this->assert()->isString($status_entry);
213  //$this->assert()->isIndex($status_entry,$this->status_list_entry);
214 
215  $this->status_entry = $status_entry;
216  }
217 
221  public function getStatusImplementation()
222  {
224  }
225 
230  {
231  $this->assert()->isString($status_implementation);
232  //$this->assert()->isIndex($status_implementation,$this->status_list_implementation);
233 
234  $this->status_implementation = $status_implementation;
235  }
236 
240  public function getDescription()
241  {
242  return $this->description;
243  }
244 
248  public function getDescriptionAsArray()
249  {
250  return $this->description->getDescription();
251  }
252 
258  {
259  $this->assert()->isTypeOf($description, ComponentEntryDescription::class);
260  $this->description = $description;
261  }
262 
266  public function getBackground()
267  {
268  return $this->background;
269  }
270 
274  public function setBackground($background)
275  {
276  $this->assert()->isString($background);
277  $this->background = $background;
278  }
279 
283  public function getFeatureWikiReferences()
284  {
286  }
287 
292  {
293  $this->assert()->isArray($feature_wiki_references);
294  $this->feature_wiki_references = $feature_wiki_references;
295  }
296 
300  public function getRules()
301  {
302  return $this->rules;
303  }
304 
308  public function getRulesAsArray()
309  {
310  if ($this->rules) {
311  return $this->rules->getRules();
312  } else {
313  return [];
314  }
315  }
316 
320  public function setRules($rules)
321  {
322  $this->assert()->isTypeOf($rules, ComponentEntryRules::class);
323  $this->rules = $rules;
324  }
325 
329  public function getSelector()
330  {
331  return $this->selector;
332  }
333 
337  public function setSelector($selector)
338  {
339  $this->assert()->isString($selector);
340  $this->selector = $selector;
341  }
342 
347  {
348  $this->assert()->isArray($less_variables);
349  $this->less_variables = $less_variables;
350  }
351 
355  public function getLessVariables()
356  {
357  return $this->less_variables;
358  }
359 
363  public function getPath()
364  {
365  return $this->path;
366  }
367 
371  public function setPath($path)
372  {
373  $this->assert()->isString($path);
374  $this->path = $path;
375  }
376 
380  public function getParent()
381  {
382  return $this->parent;
383  }
384 
388  public function setParent($parent)
389  {
390  $this->parent = $parent;
391  }
392 
396  public function getChildren()
397  {
398  return $this->children;
399  }
400 
404  public function setChildren($children)
405  {
406  $this->children = $children;
407  }
408 
412  public function addChild($child)
413  {
414  $this->children[] = $child;
415  }
416 
420  public function addChildren($children)
421  {
422  $this->setChildren(array_merge($this->children, $children));
423  }
424 
428  public function getExamples()
429  {
430  return $this->examples;
431  }
432 
436  protected function readExamples()
437  {
438  $this->examples = array();
439  if (is_dir($this->getExamplesPath())) {
440  foreach (scandir($this->getExamplesPath()) as $file_name) {
441  $example_path = $this->getExamplesPath() . "/" . $file_name;
442  if (is_file($example_path) && pathinfo($example_path)["extension"] =="php") {
443  $example_name = str_replace(".php", "", $file_name);
444  $this->examples[$example_name] = $example_path;
445  }
446  }
447  }
448  }
449 
450  public function getExamplesPath()
451  {
452  if (!$this->examples_path) {
453  $path_componants = str_replace("Component", "examples", $this->getPath())
454  . "/" . str_replace(" ", "", $this->getTitle());
455  $path_array = self::array_iunique(explode("/", $path_componants));
456  $this->examples_path = implode("/", $path_array);
457  }
458  return $this->examples_path;
459  }
460 
461 
466  private static function array_iunique($array)
467  {
468  return array_intersect_key(
469  $array,
470  array_unique(array_map("StrToLower", $array))
471  );
472  }
473 
474 
478  public function jsonSerialize()
479  {
480  return array(
481  'id' => $this->getId(),
482  'title' => $this->getTitle(),
483  'abstract' => $this->isAbstract(),
484  'status_entry' => $this->getStatusEntry(),
485  'status_implementation' => $this->getStatusImplementation(),
486  'description' => $this->getDescription(),
487  'background ' => $this->getBackground(),
488  'selector' => $this->getSelector(),
489  'feature_wiki_references ' => $this->getFeatureWikiReferences(),
490  'rules' => $this->getRules(),
491  'parent' => $this->getParent(),
492  'children' => $this->getChildren(),
493  'less_variables' => $this->getLessVariables(),
494  'path' => $this->getPath()
495  );
496  }
497 }
Abstract Entry Part to share some common entry functionality.
setDescription(ComponentEntryDescription $description)
__construct($entry_data)
ComponentEntry constructor.
Stores Information of UI Components parsed from YAML, examples and less files.
Create styles array
The data for the language used.