ILIAS  release_8 Revision v8.23
ComponentEntry.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 
31 {
35  protected array $children = array();
36 
37  protected string $id = "";
38  protected string $title = "";
39  protected bool $is_abstract = false;
40  protected array $status_list_entry = array("Accepted", "Proposed", "To be revised");
41  protected array $status_list_implementation = array("Implemented", "Partly implemented", "To be implemented");
42  protected string $status_entry = "";
43  protected string $status_implementation = "";
45  protected string $background = "";
46  protected array $context = [];
47  protected string $selector = "";
48  protected array $feature_wiki_references = array();
49  protected ?ComponentEntryRules $rules = null;
50  protected ?string $parent = null;
51  protected array $less_variables = array();
52  protected string $path = "";
53  protected ?array $examples = null;
54  protected string $examples_path = "";
55  protected string $examples_namespace = "";
56  protected string $namesapce = "";
57 
58  public function __construct($entry_data)
59  {
61  $this->assert()->isIndex('id', $entry_data);
62  $this->setId($entry_data['id']);
63  $this->assert()->isIndex('title', $entry_data);
64  $this->setTitle($entry_data['title']);
65  $this->assert()->isIndex('namespace', $entry_data);
66  $this->setNamespace($entry_data['namespace']);
67  $this->setIsAbstract((bool) $entry_data['abstract']);
68  $this->setStatusEntry("Proposed");
69  $this->setStatusImplementation("Partly implemented");
70  if (array_key_exists('description', $entry_data)) {
71  $this->setDescription(new ComponentEntryDescription($entry_data['description']));
72  }
73  if (array_key_exists('rules', $entry_data) && is_array($entry_data['rules'])) {
74  $this->setRules(new ComponentEntryRules($entry_data['rules']));
75  }
76 
77  $this->assert()->isIndex('path', $entry_data);
78  $this->setPath($entry_data['path']);
79 
80  if (array_key_exists('background', $entry_data)) {
81  $this->setBackground($entry_data['background']);
82  }
83  if (array_key_exists('context', $entry_data)) {
84  $this->setContext($entry_data['context']);
85  }
86  if (array_key_exists('featurewiki', $entry_data)) {
87  $this->setFeatureWikiReferences($entry_data['featurewiki']);
88  }
89  if (array_key_exists('parent', $entry_data)) {
90  $this->setParent((string) $entry_data['parent']);
91  }
92  if (array_key_exists('children', $entry_data)) {
93  $this->setChildren($entry_data['children']);
94  }
95 
96  $this->readExamples();
97  }
98 
99  public function getId(): string
100  {
101  return $this->id;
102  }
103 
104  public function setId(string $id): void
105  {
106  $this->assert()->isString($id, false);
107  $this->id = $id;
108  }
109 
110  public function getTitle(): string
111  {
112  return $this->title;
113  }
114 
115  public function setTitle(string $title): void
116  {
117  $this->assert()->isString($title, false);
118  $this->title = $title;
119  }
120 
121  public function isAbstract(): bool
122  {
123  return $this->is_abstract;
124  }
125 
126  public function setIsAbstract(bool $is_abstract): void
127  {
128  $this->is_abstract = $is_abstract;
129  }
130 
131  public function getStatusEntry(): string
132  {
133  return $this->status_entry;
134  }
135 
136  public function setStatusEntry(string $status_entry): void
137  {
138  $this->assert()->isString($status_entry);
139  $this->status_entry = $status_entry;
140  }
141 
142  public function getStatusImplementation(): string
143  {
145  }
146 
147  public function setStatusImplementation(string $status_implementation): void
148  {
149  $this->assert()->isString($status_implementation);
150 
151  $this->status_implementation = $status_implementation;
152  }
153 
155  {
156  return $this->description;
157  }
158 
159  public function getDescriptionAsArray(): array
160  {
161  return $this->description->getDescription();
162  }
163 
167  public function setDescription(ComponentEntryDescription $description): void
168  {
169  $this->assert()->isTypeOf($description, ComponentEntryDescription::class);
170  $this->description = $description;
171  }
172 
173  public function getBackground(): string
174  {
175  return $this->background;
176  }
177 
178  public function setBackground(string $background): void
179  {
180  $this->assert()->isString($background);
181  $this->background = $background;
182  }
183 
184  public function getContext(): array
185  {
186  return $this->context;
187  }
188 
189  public function setContext(array $context): void
190  {
191  $this->assert()->isArray($context);
192  $this->context = $context;
193  }
194 
195  public function getFeatureWikiReferences(): array
196  {
198  }
199 
200  public function setFeatureWikiReferences(array $feature_wiki_references): void
201  {
202  $this->assert()->isArray($feature_wiki_references);
203  $this->feature_wiki_references = $feature_wiki_references;
204  }
205 
206  public function getRules(): ?ComponentEntryRules
207  {
208  return $this->rules;
209  }
210 
211  public function getRulesAsArray(): array
212  {
213  if ($this->rules) {
214  return $this->rules->getRules();
215  } else {
216  return [];
217  }
218  }
219 
220  public function setRules(ComponentEntryRules $rules): void
221  {
222  $this->assert()->isTypeOf($rules, ComponentEntryRules::class);
223  $this->rules = $rules;
224  }
225 
226  public function getSelector(): string
227  {
228  return $this->selector;
229  }
230 
231  public function setSelector(string $selector): void
232  {
233  $this->assert()->isString($selector);
234  $this->selector = $selector;
235  }
236 
237  public function setLessVariables(array $less_variables): void
238  {
239  $this->assert()->isArray($less_variables);
240  $this->less_variables = $less_variables;
241  }
242 
243  public function getLessVariables(): array
244  {
245  return $this->less_variables;
246  }
247 
248  public function getPath(): string
249  {
250  return $this->path;
251  }
252 
253  public function setPath(string $path): void
254  {
255  $this->assert()->isString($path);
256  $this->path = $path;
257  }
258 
259  public function getParent(): ?string
260  {
261  return $this->parent;
262  }
263 
264  public function setParent(string $parent): void
265  {
266  $this->parent = $parent;
267  }
268 
272  public function getChildren(): array
273  {
274  return $this->children;
275  }
276 
280  public function setChildren(array $children): void
281  {
282  $this->children = $children;
283  }
284 
285  public function addChild(string $child): void
286  {
287  $this->children[] = $child;
288  }
289 
293  public function addChildren(array $children): void
294  {
295  $this->setChildren(array_merge($this->children, $children));
296  }
297 
298  public function getExamples(): ?array
299  {
300  return $this->examples;
301  }
302 
303  protected function readExamples(): void
304  {
305  $this->examples = array();
306  $case_insensitive_path = $this->getCaseInsensitiveExampleFolder();
307  if (is_dir($case_insensitive_path)) {
308  foreach (scandir($case_insensitive_path) as $file_name) {
309  $example_path = $this->getExamplesPath() . "/" . $file_name;
310  if (is_file($example_path) && pathinfo($example_path)["extension"] == "php") {
311  $example_name = str_replace(".php", "", $file_name);
312  $this->examples[$example_name] = $example_path;
313  }
314  }
315  }
316  }
317 
323  protected function getCaseInsensitiveExampleFolder(): string
324  {
325  $parent_folder = dirname($this->getExamplesPath());
326 
327  if (is_dir($parent_folder)) {
328  foreach (scandir($parent_folder) as $folder_name) {
329  if (strtolower($folder_name) == strtolower(basename($this->getExamplesPath()))) {
330  return $parent_folder . "/" . $folder_name;
331  }
332  }
333  }
334 
335  return "";
336  }
337 
338  public function getExamplesPath(): string
339  {
340  if (!$this->examples_path) {
341  $path_components = str_replace(
342  "/Factory",
343  "",
344  str_replace("Component", "examples", $this->getPath())
345  )
346  . "/" . str_replace(" ", "", $this->getTitle());
347  $path_array = self::array_iunique(explode("/", $path_components));
348  $this->examples_path = implode("/", $path_array);
349  }
350  return $this->examples_path;
351  }
352 
353  public function getExamplesNamespace(): string
354  {
355  if (!$this->examples_namespace) {
356  $this->examples_namespace = str_replace(
357  "/",
358  "\\",
359  str_replace("src/UI", "\ILIAS\UI", $this->getExamplesPath())
360  );
361  }
363  }
364 
365  public function getNamespace(): string
366  {
367  return $this->namesapce;
368  }
369 
370  public function setNamespace(string $namespace): void
371  {
372  $this->namesapce = $namespace;
373  }
374 
375  private static function array_iunique(array $array): array
376  {
377  return array_intersect_key(
378  $array,
379  array_unique(array_map("StrToLower", $array))
380  );
381  }
382 
383  public function jsonSerialize(): array
384  {
385  $description = $this->getDescription();
386  if ($description) {
387  $description_serialized = $description->jsonSerialize();
388  } else {
389  $description_serialized = "";
390  }
391 
392  $rules = $this->getRules();
393  if ($rules) {
394  $rules_serialized = $rules->jsonSerialize();
395  } else {
396  $rules_serialized = "";
397  }
398  return array(
399  'id' => $this->getId(),
400  'title' => $this->getTitle(),
401  'abstract' => $this->isAbstract(),
402  'status_entry' => $this->getStatusEntry(),
403  'status_implementation' => $this->getStatusImplementation(),
404  'description' => $description_serialized,
405  'background' => $this->getBackground(),
406  'context' => $this->getContext(),
407  'selector' => $this->getSelector(),
408  'feature_wiki_references' => $this->getFeatureWikiReferences(),
409  'rules' => $rules_serialized,
410  'parent' => $this->getParent(),
411  'children' => $this->getChildren(),
412  'less_variables' => $this->getLessVariables(),
413  'path' => $this->getPath(),
414  'namespace' => $this->getNamespace()
415  );
416  }
417 }
if($err=$client->getError()) $namespace
Abstract Entry Part to share some common entry functionality.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Stores Information of UI Components parsed from YAML, examples and less files.
__construct(Container $dic, ilPlugin $plugin)
setFeatureWikiReferences(array $feature_wiki_references)