ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $context = [];
63 
67  protected $selector = "";
68 
72  protected $feature_wiki_references = array();
73 
77  protected $rules = null;
78 
82  protected $parent = false;
83 
87  protected $children = array();
88 
92  protected $less_variables = array();
93 
97  protected $path = "";
98 
99 
103  protected $examples = null;
104 
108  protected $examples_path = "";
109 
115  public function __construct($entry_data)
116  {
117  parent::__construct();
118  $this->assert()->isIndex('id', $entry_data);
119  $this->setId($entry_data['id']);
120  $this->assert()->isIndex('title', $entry_data);
121  $this->setTitle($entry_data['title']);
122  $this->assert()->isIndex('abstract', $entry_data);
123  $this->setIsAbstract($entry_data['abstract']);
124  $this->setStatusEntry("Proposed");
125  $this->setStatusImplementation("Partly implemented");
126  if (array_key_exists('description', $entry_data)) {
127  $this->setDescription(new ComponentEntryDescription($entry_data['description']));
128  }
129  if (array_key_exists('rules', $entry_data)) {
130  $this->setRules(new ComponentEntryRules($entry_data['rules']));
131  }
132 
133  $this->assert()->isIndex('path', $entry_data);
134  $this->setPath($entry_data['path']);
135 
136  if (array_key_exists('background', $entry_data)) {
137  $this->setBackground($entry_data['background']);
138  }
139  if (array_key_exists('context', $entry_data)) {
140  $this->setContext($entry_data['context']);
141  }
142  if (array_key_exists('featurewiki', $entry_data)) {
143  $this->setFeatureWikiReferences($entry_data['featurewiki']);
144  }
145  if (array_key_exists('parent', $entry_data)) {
146  $this->setParent($entry_data['parent']);
147  }
148  if (array_key_exists('children', $entry_data)) {
149  $this->setChildren($entry_data['children']);
150  }
151 
152  if (!$this->isAbstract()) {
153  $this->readExamples();
154  }
155  }
156 
160  public function getId()
161  {
162  return $this->id;
163  }
164 
168  public function setId($id)
169  {
170  $this->assert()->isString($id, false);
171  $this->id = $id;
172  }
173 
177  public function getTitle()
178  {
179  return $this->title;
180  }
181 
185  public function setTitle($title)
186  {
187  $this->assert()->isString($title, false);
188  $this->title = $title;
189  }
190 
194  public function isAbstract()
195  {
196  return $this->is_abstract;
197  }
198 
202  public function setIsAbstract($is_abstract)
203  {
204  $this->is_abstract = $is_abstract;
205  }
206 
210  public function getStatusEntry()
211  {
212  return $this->status_entry;
213  }
214 
218  public function setStatusEntry($status_entry)
219  {
220  $this->assert()->isString($status_entry);
221  //$this->assert()->isIndex($status_entry,$this->status_list_entry);
222 
223  $this->status_entry = $status_entry;
224  }
225 
229  public function getStatusImplementation()
230  {
232  }
233 
238  {
239  $this->assert()->isString($status_implementation);
240  //$this->assert()->isIndex($status_implementation,$this->status_list_implementation);
241 
242  $this->status_implementation = $status_implementation;
243  }
244 
248  public function getDescription()
249  {
250  return $this->description;
251  }
252 
256  public function getDescriptionAsArray()
257  {
258  return $this->description->getDescription();
259  }
260 
266  {
267  $this->assert()->isTypeOf($description, ComponentEntryDescription::class);
268  $this->description = $description;
269  }
270 
274  public function getBackground()
275  {
276  return $this->background;
277  }
278 
282  public function setBackground($background)
283  {
284  $this->assert()->isString($background);
285  $this->background = $background;
286  }
287 
291  public function getContext()
292  {
293  return $this->context;
294  }
295 
299  public function setContext($context)
300  {
301  $this->assert()->isArray($context);
302  $this->context = $context;
303  }
304 
305 
309  public function getFeatureWikiReferences()
310  {
312  }
313 
318  {
319  $this->assert()->isArray($feature_wiki_references);
320  $this->feature_wiki_references = $feature_wiki_references;
321  }
322 
326  public function getRules()
327  {
328  return $this->rules;
329  }
330 
334  public function getRulesAsArray()
335  {
336  if ($this->rules) {
337  return $this->rules->getRules();
338  } else {
339  return [];
340  }
341  }
342 
346  public function setRules($rules)
347  {
348  $this->assert()->isTypeOf($rules, ComponentEntryRules::class);
349  $this->rules = $rules;
350  }
351 
355  public function getSelector()
356  {
357  return $this->selector;
358  }
359 
363  public function setSelector($selector)
364  {
365  $this->assert()->isString($selector);
366  $this->selector = $selector;
367  }
368 
373  {
374  $this->assert()->isArray($less_variables);
375  $this->less_variables = $less_variables;
376  }
377 
381  public function getLessVariables()
382  {
383  return $this->less_variables;
384  }
385 
389  public function getPath()
390  {
391  return $this->path;
392  }
393 
397  public function setPath($path)
398  {
399  $this->assert()->isString($path);
400  $this->path = $path;
401  }
402 
406  public function getParent()
407  {
408  return $this->parent;
409  }
410 
414  public function setParent($parent)
415  {
416  $this->parent = $parent;
417  }
418 
422  public function getChildren()
423  {
424  return $this->children;
425  }
426 
430  public function setChildren($children)
431  {
432  $this->children = $children;
433  }
434 
438  public function addChild($child)
439  {
440  $this->children[] = $child;
441  }
442 
446  public function addChildren($children)
447  {
448  $this->setChildren(array_merge($this->children, $children));
449  }
450 
454  public function getExamples()
455  {
456  return $this->examples;
457  }
458 
462  protected function readExamples()
463  {
464  $this->examples = array();
465  if (is_dir($this->getExamplesPath())) {
466  foreach (scandir($this->getExamplesPath()) as $file_name) {
467  $example_path = $this->getExamplesPath() . "/" . $file_name;
468  if (is_file($example_path) && pathinfo($example_path)["extension"] == "php") {
469  $example_name = str_replace(".php", "", $file_name);
470  $this->examples[$example_name] = $example_path;
471  }
472  }
473  }
474  }
475 
476  public function getExamplesPath()
477  {
478  if (!$this->examples_path) {
479  $path_componants = str_replace("Component", "examples", $this->getPath())
480  . "/" . str_replace(" ", "", $this->getTitle());
481  $path_array = self::array_iunique(explode("/", $path_componants));
482  $this->examples_path = implode("/", $path_array);
483  }
484  return $this->examples_path;
485  }
486 
487 
492  private static function array_iunique($array)
493  {
494  return array_intersect_key(
495  $array,
496  array_unique(array_map("StrToLower", $array))
497  );
498  }
499 
500 
504  public function jsonSerialize()
505  {
506  return array(
507  'id' => $this->getId(),
508  'title' => $this->getTitle(),
509  'abstract' => $this->isAbstract(),
510  'status_entry' => $this->getStatusEntry(),
511  'status_implementation' => $this->getStatusImplementation(),
512  'description' => $this->getDescription(),
513  'background' => $this->getBackground(),
514  'context' => $this->getContext(),
515  'selector' => $this->getSelector(),
516  'feature_wiki_references ' => $this->getFeatureWikiReferences(),
517  'rules' => $this->getRules(),
518  'parent' => $this->getParent(),
519  'children' => $this->getChildren(),
520  'less_variables' => $this->getLessVariables(),
521  'path' => $this->getPath()
522  );
523  }
524 }
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.