ILIAS  release_7 Revision v7.30-3-g800a261c036
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
11class ComponentEntry extends AbstractEntryPart implements \JsonSerializable
12{
16 protected $id = "";
17
21 protected $title = "";
22
26 protected $is_abstract = false;
27
31 protected $status_list_entry = array("Accepted", "Proposed", "To be revised");
32
36 protected $status_list_implementation = array("Implemented", "Partly implemented", "To be implemented");
37
41 protected $status_entry = "";
42
46 protected $status_implementation = "";
47
51 protected $description = null;
52
56 protected $background = "";
57
61 protected $context = [];
62
66 protected $selector = "";
67
71 protected $feature_wiki_references = array();
72
76 protected $rules = null;
77
81 protected $parent = false;
82
86 protected $children = array();
87
91 protected $less_variables = array();
92
96 protected $path = "";
97
101 protected $examples = null;
102
106 protected $examples_path = "";
107
112 public function __construct($entry_data)
113 {
115 $this->assert()->isIndex('id', $entry_data);
116 $this->setId($entry_data['id']);
117 $this->assert()->isIndex('title', $entry_data);
118 $this->setTitle($entry_data['title']);
119 $this->assert()->isIndex('abstract', $entry_data);
120 $this->setIsAbstract($entry_data['abstract']);
121 $this->setStatusEntry("Proposed");
122 $this->setStatusImplementation("Partly implemented");
123 if (array_key_exists('description', $entry_data)) {
124 $this->setDescription(new ComponentEntryDescription($entry_data['description']));
125 }
126 if (array_key_exists('rules', $entry_data)) {
127 $this->setRules(new ComponentEntryRules($entry_data['rules']));
128 }
129
130 $this->assert()->isIndex('path', $entry_data);
131 $this->setPath($entry_data['path']);
132
133 if (array_key_exists('background', $entry_data)) {
134 $this->setBackground($entry_data['background']);
135 }
136 if (array_key_exists('context', $entry_data)) {
137 $this->setContext($entry_data['context']);
138 }
139 if (array_key_exists('featurewiki', $entry_data)) {
140 $this->setFeatureWikiReferences($entry_data['featurewiki']);
141 }
142 if (array_key_exists('parent', $entry_data)) {
143 $this->setParent($entry_data['parent']);
144 }
145 if (array_key_exists('children', $entry_data)) {
146 $this->setChildren($entry_data['children']);
147 }
148
149 if (!$this->isAbstract()) {
150 $this->readExamples();
151 }
152 }
153
154 public function getId() : string
155 {
156 return $this->id;
157 }
158
159 public function setId(string $id)
160 {
161 $this->assert()->isString($id, false);
162 $this->id = $id;
163 }
164
165 public function getTitle() : string
166 {
167 return $this->title;
168 }
169
170 public function setTitle(string $title)
171 {
172 $this->assert()->isString($title, false);
173 $this->title = $title;
174 }
175
176 public function isAbstract() : bool
177 {
178 return $this->is_abstract;
179 }
180
181 public function setIsAbstract(bool $is_abstract)
182 {
183 $this->is_abstract = $is_abstract;
184 }
185
186 public function getStatusEntry() : string
187 {
188 return $this->status_entry;
189 }
190
191 public function setStatusEntry(string $status_entry)
192 {
193 $this->assert()->isString($status_entry);
194 $this->status_entry = $status_entry;
195 }
196
197 public function getStatusImplementation() : string
198 {
200 }
201
203 {
204 $this->assert()->isString($status_implementation);
205
206 $this->status_implementation = $status_implementation;
207 }
208
210 {
211 return $this->description;
212 }
213
217 public function getDescriptionAsArray()
218 {
219 return $this->description->getDescription();
220 }
221
227 {
228 $this->assert()->isTypeOf($description, ComponentEntryDescription::class);
229 $this->description = $description;
230 }
231
232 public function getBackground() : string
233 {
234 return $this->background;
235 }
236
237 public function setBackground(string $background)
238 {
239 $this->assert()->isString($background);
240 $this->background = $background;
241 }
242
243 public function getContext() : array
244 {
245 return $this->context;
246 }
247
248 public function setContext(array $context)
249 {
250 $this->assert()->isArray($context);
251 $this->context = $context;
252 }
253
254 public function getFeatureWikiReferences() : array
255 {
257 }
258
260 {
261 $this->assert()->isArray($feature_wiki_references);
262 $this->feature_wiki_references = $feature_wiki_references;
263 }
264
265 public function getRules() : ?ComponentEntryRules
266 {
267 return $this->rules;
268 }
269
270 public function getRulesAsArray() : array
271 {
272 if ($this->rules) {
273 return $this->rules->getRules();
274 } else {
275 return [];
276 }
277 }
278
280 {
281 $this->assert()->isTypeOf($rules, ComponentEntryRules::class);
282 $this->rules = $rules;
283 }
284
285 public function getSelector() : string
286 {
287 return $this->selector;
288 }
289
290 public function setSelector(string $selector)
291 {
292 $this->assert()->isString($selector);
293 $this->selector = $selector;
294 }
295
296 public function setLessVariables(array $less_variables)
297 {
298 $this->assert()->isArray($less_variables);
299 $this->less_variables = $less_variables;
300 }
301
302 public function getLessVariables() : array
303 {
305 }
306
307 public function getPath() : string
308 {
309 return $this->path;
310 }
311
312 public function setPath(string $path)
313 {
314 $this->assert()->isString($path);
315 $this->path = $path;
316 }
317
318 public function getParent() : string
319 {
320 return $this->parent;
321 }
322
323 public function setParent(string $parent)
324 {
325 $this->parent = $parent;
326 }
327
331 public function getChildren()
332 {
333 return $this->children;
334 }
335
339 public function setChildren($children)
340 {
341 $this->children = $children;
342 }
343
344 public function addChild(string $child)
345 {
346 $this->children[] = $child;
347 }
348
352 public function addChildren($children)
353 {
354 $this->setChildren(array_merge($this->children, $children));
355 }
356
357 public function getExamples() : ?array
358 {
359 return $this->examples;
360 }
361
362 protected function readExamples()
363 {
364 $this->examples = array();
365 $case_insensitive_path = $this->getCaseInsensitiveExampleFolder();
366 if (is_dir($case_insensitive_path)) {
367 foreach (scandir($case_insensitive_path) as $file_name) {
368 $example_path = $this->getExamplesPath() . "/" . $file_name;
369 if (is_file($example_path) && pathinfo($example_path)["extension"] == "php") {
370 $example_name = str_replace(".php", "", $file_name);
371 $this->examples[$example_name] = $example_path;
372 }
373 }
374 }
375 }
376
382 protected function getCaseInsensitiveExampleFolder() : string
383 {
384 $parent_folder = dirname($this->getExamplesPath());
385
386 if (is_dir($parent_folder)) {
387 foreach (scandir($parent_folder) as $folder_name) {
388 if (strtolower($folder_name) == strtolower(basename($this->getExamplesPath()))) {
389 return $parent_folder . "/" . $folder_name;
390 }
391 }
392 }
393
394 return "";
395 }
396
397 public function getExamplesPath()
398 {
399 if (!$this->examples_path) {
400 $path_components =
401 str_replace("Component", "examples", $this->getPath())
402 . "/" . str_replace(" ", "", $this->getTitle());
403 $path_array = self::array_iunique(explode("/", $path_components));
404 $this->examples_path = implode("/", $path_array);
405 }
407 }
408
409
410 public function getExamplesNamespace()
411 {
412 if (!$this->examples_namespace) {
413 $this->examples_namespace = str_replace(
414 "/",
415 "\\",
416 str_replace("src/UI", "\ILIAS\UI", $this->getExamplesPath())
417 );
418 }
419 return $this->examples_namespace;
420 }
421
422 public function getNamespace() : string
423 {
424 return $this->namesapce;
425 }
426
427 public function setNamespace(string $namespace) : void
428 {
429 $this->namesapce = $namespace;
430 }
431
432 private static function array_iunique(array $array) : array
433 {
434 return array_intersect_key(
435 $array,
436 array_unique(array_map("StrToLower", $array))
437 );
438 }
439
440 public function jsonSerialize() : array
441 {
442 $description = $this->getDescription();
443 if ($description) {
444 $description_serialized = $description->jsonSerialize();
445 } else {
446 $description_serialized = "";
447 }
448
449 $rules = $this->getRules();
450 if ($rules) {
451 $rules_serialized = $rules->jsonSerialize();
452 } else {
453 $rules_serialized = "";
454 }
455 return array(
456 'id' => $this->getId(),
457 'title' => $this->getTitle(),
458 'abstract' => $this->isAbstract(),
459 'status_entry' => $this->getStatusEntry(),
460 'status_implementation' => $this->getStatusImplementation(),
461 'description' => $description_serialized,
462 'background' => $this->getBackground(),
463 'context' => $this->getContext(),
464 'selector' => $this->getSelector(),
465 'feature_wiki_references' => $this->getFeatureWikiReferences(),
466 'rules' => $rules_serialized,
467 'parent' => $this->getParent(),
468 'children' => $this->getChildren(),
469 'less_variables' => $this->getLessVariables(),
470 'path' => $this->getPath()
471 );
472 }
473}
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.
setFeatureWikiReferences(array $feature_wiki_references)
setStatusImplementation(string $status_implementation)
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.
if($err=$client->getError()) $namespace
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc