ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LOMDictionaryInitiator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class LOMDictionaryInitiator extends BaseDictionaryInitiator
30 {
32 
33  public function __construct(
34  TagFactory $tag_factory,
38  ) {
39  $this->tag_factory = $tag_factory;
40  parent::__construct($path_factory, $navigator_factory, $structure);
41  }
42 
43  public function get(): DictionaryInterface
44  {
45  $this->initDictionary();
46  return new LOMDictionary($this->path_factory, $this->navigator_factory, ...$this->getTagAssignments());
47  }
48 
49  protected function initDictionary(): void
50  {
51  $structure = $this->getStructure();
52 
62  }
63 
64  protected function setTagsForGeneral(
66  ): void {
67  $general = $structure->getRoot()->getSubElement('general');
69  $this->setLastTagForLangString($general->getSubElement('title'));
71  $general->getSubElement('language'),
72  true,
73  true
74  );
76  $general->getSubElement('description'),
77  true
78  );
80  $general->getSubElement('keyword'),
81  true
82  );
84  $general->getSubElement('coverage'),
85  true
86  );
87  $this->setLastTagForVocab($general->getSubElement('structure'));
88  $this->setLastTagForVocab($general->getSubElement('aggregationLevel'));
89  }
90 
91  protected function setTagsForLifecycle(
93  ): void {
94  $life_cycle = $structure->getRoot()->getSubElement('lifeCycle');
95  $this->setLastTagForLangString($life_cycle->getSubElement('version'));
96  $this->setLastTagForVocab($life_cycle->getSubElement('status'));
97  $this->setTagsForSubContribute($life_cycle);
98  }
99 
100  protected function setTagsForMetaMetadata(
102  ): void {
103  $meta = $structure->getRoot()->getSubElement('metaMetadata');
104  $this->setTagsForSubIdentifier($meta);
105  $this->setTagsForSubContribute($meta);
107  $meta->getSubElement('metadataSchema'),
108  true,
109  true
110  );
112  $meta->getSubElement('language'),
113  false,
114  true
115  );
116  }
117 
118  protected function setTagsForTechnical(
120  ): void {
121  $technical = $structure->getRoot()->getSubElement('technical');
123  $technical->getSubElement('format'),
124  true,
125  true
126  );
128  $technical->getSubElement('size'),
129  false,
130  true
131  );
133  $technical->getSubElement('location'),
134  true,
135  true
136  );
137  $this->addTagToElement(
138  $this->tag($requirement = $technical->getSubElement('requirement'))
139  ->withCreatedWith($or = $requirement->getSubElement('orComposite'))
140  ->withPreview($or->getSubElement('name')->getSubElement('value'))
141  ->get(),
142  $requirement
143  );
144  $this->addTagToElement(
145  $this->tag($or)
146  ->withPreview($or->getSubElement('name')->getSubElement('value'))
147  ->withRepresentation($or->getSubElement('type')->getSubElement('value'))
148  ->withLastInTree(true)
149  ->get(),
150  $or
151  );
152  $this->setImportantLabelTag($or->getSubElement('minimumVersion'));
153  $this->setImportantLabelTag($or->getSubElement('maximumVersion'));
154  $this->setLastTagForLangString($technical->getSubElement('installationRemarks'));
155  $this->setLastTagForLangString($technical->getSubElement('otherPlatformRequirements'));
156  $this->setLastTag(
157  $technical->getSubElement('duration'),
158  false,
159  'duration'
160  );
161  }
162 
163  protected function setTagsForEducational(
165  ): void {
166  $educational = $structure->getRoot()->getSubElement('educational');
167  $this->addTagToElement(
168  $this->tag($educational)
169  ->withPreview($educational->getSubElement('typicalLearningTime')->getSubElement('duration'))
170  ->withRepresentation($educational->getSubElement('interactivityType')->getSubElement('value'))
171  ->withIsCollected(true)
172  ->get(),
174  );
175  $this->setLastTagForVocab($educational->getSubElement('interactivityType'));
176  $this->setLastTagForVocab(
177  $educational->getSubElement('learningResourceType'),
178  true
179  );
180  $this->setLastTagForVocab($educational->getSubElement('interactivityLevel'));
181  $this->setLastTagForVocab($educational->getSubElement('semanticDensity'));
182  $this->setLastTagForVocab(
183  $educational->getSubElement('intendedEndUserRole'),
184  true
185  );
186  $this->setLastTagForVocab(
187  $educational->getSubElement('context'),
188  true
189  );
191  $educational->getSubElement('typicalAgeRange'),
192  true
193  );
194  $this->setLastTagForVocab($educational->getSubElement('difficulty'));
195  $this->setLastTag(
196  $educational->getSubElement('typicalLearningTime'),
197  false,
198  'duration'
199  );
201  $educational->getSubElement('description'),
202  true
203  );
205  $educational->getSubElement('language'),
206  true,
207  true
208  );
209  }
210 
211  protected function setTagsForRights(
213  ): void {
214  $rights = $structure->getRoot()->getSubElement('rights');
215  $this->addTagToElement(
216  $this->tag($rights)
217  ->withLastInTree(true)
218  ->get(),
219  $rights
220  );
221  $this->addTagToElement(
222  $this->tag($cost = $rights->getSubElement('cost'))
223  ->withPreview($cost->getSubElement('value'))
224  ->get(),
225  $cost
226  );
227  $this->addTagToElement(
228  $this->tag($cor = $rights->getSubElement('copyrightAndOtherRestrictions'))
229  ->withPreview($cor->getSubElement('value'))
230  ->get(),
231  $cor
232  );
233  $this->addTagToElement(
234  $this->tag($description = $rights->getSubElement('description'))
235  ->withPreview($description->getSubElement('string'))
236  ->get(),
237  $description
238  );
239  }
240 
241  protected function setTagsForRelation(
243  ): void {
244  $relation = $structure->getRoot()->getSubElement('relation');
245  $this->addTagToElement(
246  $this->tag($relation)
247  ->withPreview($relation->getSubElement('resource')->getSubElement('identifier')->getSubElement('entry'))
248  ->withCreatedWith($kind = $relation->getSubElement('kind'))
249  ->withRepresentation($kind->getSubElement('value'))
250  ->withIsCollected(true)
251  ->get(),
252  $relation
253  );
254  $this->setLastTagForVocab($kind);
255  $this->addTagToElement(
256  $this->tag($resource = $relation->getSubElement('resource'))
257  ->withCreatedWith($identifier = $resource->getSubElement('identifier'))
258  ->withPreview($identifier->getSubElement('entry'))
259  ->get(),
260  $resource
261  );
262  $this->setTagsForSubIdentifier($resource);
264  $resource->getSubElement('description'),
265  true
266  );
267  }
268 
269  protected function setTagsForAnnotation(
271  ): void {
272  $annotation = $structure->getRoot()->getSubElement('annotation');
273  $this->addTagToElement(
274  $this->tag($annotation)
275  ->withPreview($annotation->getSubElement('description')->getSubElement('string'))
276  ->withRepresentation($annotation->getSubElement('entity'))
277  ->withIsCollected(true)
278  ->withLastInTree(true)
279  ->get(),
281  );
282  $this->addTagToElement(
283  $this->tag($entity = $annotation->getSubElement('entity'))
284  ->withPreview($entity)
285  ->withImportantLabel(true)
286  ->get(),
287  $entity
288  );
289  $this->addTagToElement(
290  $this->tag($date = $annotation->getSubElement('date'))
291  ->withPreview($date->getSubElement('dateTime'))
292  ->get(),
293  $date
294  );
295  $this->addTagToElement(
296  $this->tag($description = $annotation->getSubElement('description'))
297  ->withPreview($description->getSubElement('string'))
298  ->get(),
299  $description
300  );
301  }
302 
303  protected function setTagsForClassification(
305  ): void {
306  $class = $structure->getRoot()->getSubElement('classification');
307  $taxon_path = $class->getSubElement('taxonPath');
308  $taxon = $taxon_path->getSubElement('taxon');
309  $taxon_entry_string = $taxon->getSubElement('entry')->getSubElement('string');
310  $this->addTagToElement(
311  $this->tag($class)
312  ->withPreview($taxon_entry_string)
313  ->withCreatedWith($purpose = $class->getSubElement('purpose'))
314  ->withRepresentation($purpose->getSubElement('value'))
315  ->withIsCollected(true)
316  ->get(),
317  $class
318  );
319  $this->setLastTagForVocab($purpose);
320  $this->addTagToElement(
321  $this->tag($taxon_path)
322  ->withPreview($taxon_entry_string)
323  ->withCreatedWith($source = $taxon_path->getSubElement('source'))
324  ->withRepresentation($source->getSubElement('string'))
325  ->get(),
326  $taxon_path
327  );
328  $this->setLastTagForLangString($source);
329  $this->setLastTag(
330  $taxon,
331  true,
332  'entry',
333  'string'
334  );
335  $this->setLastTagForLangString($class->getSubElement('description'));
337  $class->getSubElement('keyword'),
338  true
339  );
340  }
341 
342  protected function setTagsForSubIdentifier(
343  StructureElementInterface $super_element
344  ): void {
345  $this->setLastTag(
346  $identifier = $super_element->getSubElement('identifier'),
347  true,
348  'entry'
349  );
350  $this->setImportantLabelTag($identifier->getSubElement('catalog'));
351  $this->setImportantLabelTag($identifier->getSubElement('entry'));
352  }
353 
354  protected function setImportantLabelTag(
356  ) {
357  $this->addTagToElement(
358  $this->tag($element)
359  ->withImportantLabel(true)
360  ->get(),
361  $element
362  );
363  }
364 
365  protected function setTagsForSubContribute(
366  StructureElementInterface $super_element
367  ): void {
368  $this->addTagToElement(
369  $this->tag($contribute = $super_element->getSubElement('contribute'))
370  ->withPreview($contribute->getSubElement('entity'))
371  ->withCreatedWith($role = $contribute->getSubElement('role'))
372  ->withRepresentation($role->getSubElement('value'))
373  ->get(),
374  $contribute
375  );
376  $this->setLastTagForVocab($contribute->getSubElement('role'));
378  $contribute->getSubElement('entity'),
379  true,
380  true
381  );
382  $this->setLastTag(
383  $contribute->getSubElement('date'),
384  false,
385  'dateTime'
386  );
387  }
388 
389  protected function setLastTagForLangString(
390  StructureElementInterface $element,
391  bool $is_collected = false
392  ): void {
393  $this->setLastTag(
394  $element,
395  $is_collected,
396  'string'
397  );
398  }
399 
400  protected function setLastTagForVocab(
401  StructureElementInterface $element,
402  bool $is_collected = false
403  ): void {
404  $this->setLastTag(
405  $element,
406  $is_collected,
407  'value'
408  );
409  }
410 
411  protected function setLastTagForNonContainer(
412  StructureElementInterface $element,
413  bool $is_collected,
414  bool $important_label
415  ): void {
416  $this->addTagToElement(
417  $this->tag($element)
418  ->withPreview($element)
419  ->withIsCollected($is_collected)
420  ->withLastInTree(true)
421  ->withImportantLabel($important_label)
422  ->get(),
423  $element
424  );
425  }
426 
427  protected function setLastTag(
428  StructureElementInterface $element,
429  bool $is_collected,
430  string ...$steps_to_preview
431  ): void {
432  $preview = $element;
433  foreach ($steps_to_preview as $step) {
434  $preview = $preview->getSubElement($step);
435  }
436  $this->addTagToElement(
437  $this->tag($element)
438  ->withPreview($preview)
439  ->withLastInTree(true)
440  ->withIsCollected($is_collected)
441  ->get(),
442  $element
443  );
444  }
445 
446  protected function tag(StructureElementInterface $element): TagBuilder
447  {
448  return $this->tag_factory->forElement($element);
449  }
450 }
getSubElement(string $name)
Return the first sub-element with the given name, if one exists.
$relation
$technical
setLastTagForNonContainer(StructureElementInterface $element, bool $is_collected, bool $important_label)
__construct(TagFactory $tag_factory, PathFactoryInterface $path_factory, NavigatorFactoryInterface $navigator_factory, StructureSetInterface $structure)
setLastTag(StructureElementInterface $element, bool $is_collected, string ... $steps_to_preview)
setTagsForSubIdentifier(StructureElementInterface $super_element)
getRoot()
Returns the root element of the metadata set.
$educational
$general
SECTIONS.
$annotation
setLastTagForVocab(StructureElementInterface $element, bool $is_collected=false)
addTagToElement(TagInterface $tag, StructureElementInterface $element)
When indices are added, the tag applies only to copies of the element with those indices (beginning w...
NavigatorFactoryInterface $navigator_factory
only needed to instantiate dictionaries, which is done in inheritors
$rights
setLastTagForLangString(StructureElementInterface $element, bool $is_collected=false)
__construct(Container $dic, ilPlugin $plugin)
setTagsForSubContribute(StructureElementInterface $super_element)