ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Elements.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\MetaData\Presentation\ElementsInterface as ElementsPresentation;
30
32{
33 protected const string SEPARATOR = ': ';
34 protected const string DELIMITER = ', ';
35
39 protected ElementsPresentation $elements;
40
41 public function __construct(
45 ElementsPresentation $elements
46 ) {
47 $this->data = $data;
48 $this->dictionary = $dictionary;
49 $this->navigator_factory = $navigator_factory;
50 $this->elements = $elements;
51 }
52
53 public function nameWithRepresentation(
54 bool $plural,
56 ): string {
57 if (empty($elements)) {
58 return '';
59 }
60 $name = $this->name(
61 $elements[0],
62 $plural
63 );
64 $tag = $this->dictionary->tagForElement($elements[0]);
65 if ($tag?->hasRepresentation()) {
66 $values = $this->getDataValueStringByPath(
67 $tag->representation(),
68 ...$elements
69 );
70 if ($values !== '') {
71 $name = implode(self::SEPARATOR, [$name, $values]);
72 }
73 }
74 return $name;
75 }
76
77 public function preview(ElementInterface ...$elements): string
78 {
79 if (empty($elements)) {
80 return '';
81 }
82 $tag = $this->dictionary->tagForElement($elements[0]);
83 if (!$tag?->hasPreview()) {
84 return '';
85 }
86 return $this->getDataValueStringByPath($tag->preview(), ...$elements);
87 }
88
89 public function name(
90 BaseElementInterface $element,
91 bool $plural = false
92 ): string {
93 return $this->elements->name($element, $plural);
94 }
95
96 public function nameWithParents(
97 BaseElementInterface $element,
98 ?BaseElementInterface $cut_off = null,
99 bool $plural = false,
100 bool $never_skip_initial = false
101 ): string {
102 //skip the name of the element if it does not add any information
103 $skip_arr = [Type::VOCAB_VALUE, Type::DURATION, Type::DATETIME, Type::STRING];
104 $skip_initial =
105 !$never_skip_initial &&
106 !$this->dictionary->tagForElement($element)?->isLabelImportant() &&
107 in_array($element->getDefinition()->dataType(), $skip_arr);
108
109 return $this->elements->nameWithParents(
110 $element,
111 $cut_off,
112 $plural,
113 $skip_initial
114 );
115 }
116
117 protected function getDataValueStringByPath(
119 ElementInterface ...$elements
120 ): string {
121 $values = [];
122 foreach ($elements as $element) {
123 $navigator = $this->navigator_factory->navigator(
124 $path,
125 $element
126 );
127 foreach ($navigator->elementsAtFinalStep() as $el) {
128 if (
129 ($data = $el->getData())->type() !== Type::NULL &&
130 $data->value() !== ''
131 ) {
132 $values[] = $this->data->dataValue($data);
133 }
134 }
135 }
136 return implode(self::DELIMITER, $values);
137 }
138}
nameWithParents(BaseElementInterface $element, ?BaseElementInterface $cut_off=null, bool $plural=false, bool $never_skip_initial=false)
Definition: Elements.php:96
getDataValueStringByPath(PathInterface $path, ElementInterface ... $elements)
Definition: Elements.php:117
nameWithRepresentation(bool $plural, ElementInterface ... $elements)
Definition: Elements.php:53
NavigatorFactoryInterface $navigator_factory
Definition: Elements.php:38
__construct(DataInterface $data, DictionaryInterface $dictionary, NavigatorFactoryInterface $navigator_factory, ElementsPresentation $elements)
Definition: Elements.php:41
name(BaseElementInterface $element, bool $plural=false)
Definition: Elements.php:89
preview(ElementInterface ... $elements)
Definition: Elements.php:77
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDefinition()
Defining properties of the metadata element.
$path
Definition: ltiservices.php:30
if(!file_exists('../ilias.ini.php'))