ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
12class ComponentEntry extends AbstractEntryPart implements \JsonSerializable
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 {
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
203 {
204 $this->is_abstract = $is_abstract;
205 }
206
210 public function getStatusEntry()
211 {
212 return $this->status_entry;
213 }
214
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 {
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 $case_insensitive_path = $this->getCaseInsensitiveExampleFolder();
466 if (is_dir($case_insensitive_path)) {
467 foreach (scandir($case_insensitive_path) as $file_name) {
468 $example_path = $this->getExamplesPath() . "/" . $file_name;
469 if (is_file($example_path) && pathinfo($example_path)["extension"] == "php") {
470 $example_name = str_replace(".php", "", $file_name);
471 $this->examples[$example_name] = $example_path;
472 }
473 }
474 }
475 }
476
482 protected function getCaseInsensitiveExampleFolder() : string
483 {
484 $parent_folder = dirname($this->getExamplesPath());
485
486 if (is_dir($parent_folder)) {
487 foreach (scandir($parent_folder) as $folder_name) {
488 if (strtolower($folder_name) == strtolower(basename($this->getExamplesPath()))) {
489 return $parent_folder . "/" . $folder_name;
490 }
491 }
492 }
493
494 return "";
495 }
496
497 public function getExamplesPath()
498 {
499 if (!$this->examples_path) {
500 $path_componants = str_replace("Component", "examples", $this->getPath())
501 . "/" . str_replace(" ", "", $this->getTitle());
502 $path_array = self::array_iunique(explode("/", $path_componants));
503 $this->examples_path = implode("/", $path_array);
504 }
506 }
507
508
513 private static function array_iunique($array)
514 {
515 return array_intersect_key(
516 $array,
517 array_unique(array_map("StrToLower", $array))
518 );
519 }
520
521
525 public function jsonSerialize()
526 {
527 $description = $this->getDescription();
528 if ($description) {
529 $description_serialized = $description->jsonSerialize();
530 } else {
531 $description_serialized = "";
532 }
533
534 $rules = $this->getRules();
535 if ($rules) {
536 $rules_serialized = $rules->jsonSerialize();
537 } else {
538 $rules_serialized = "";
539 }
540 return array(
541 'id' => $this->getId(),
542 'title' => $this->getTitle(),
543 'abstract' => $this->isAbstract(),
544 'status_entry' => $this->getStatusEntry(),
545 'status_implementation' => $this->getStatusImplementation(),
546 'description' => $description_serialized,
547 'background' => $this->getBackground(),
548 'context' => $this->getContext(),
549 'selector' => $this->getSelector(),
550 'feature_wiki_references' => $this->getFeatureWikiReferences(),
551 'rules' => $rules_serialized,
552 'parent' => $this->getParent(),
553 'children' => $this->getChildren(),
554 'less_variables' => $this->getLessVariables(),
555 'path' => $this->getPath()
556 );
557 }
558}
An exception for terminatinating execution or to throw for unit testing.
Abstract Entry Part to share some common entry functionality.
Stores Information of UI Components parsed from YAML, examples and less files.
setDescription(ComponentEntryDescription $description)
getCaseInsensitiveExampleFolder()
Note case handling of is dir is different from OS to OS, therefore while reading the examples from th...
__construct($entry_data)
ComponentEntry constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc