ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StructureElement.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
30 public function __construct(
31 bool $is_root,
34 ) {
36 $is_root ? NoID::ROOT : NoID::STRUCTURE,
39 );
40 }
41
42 public function getMDID(): NoID
43 {
44 $mdid = parent::getMDID();
45 if ($mdid !== NoID::STRUCTURE && $mdid !== NoID::ROOT) {
46 throw new \ilMDElementsException(
47 'Structure metadata elements can not have IDs.'
48 );
49 }
50 return $mdid;
51 }
52
54 {
55 $super = parent::getSuperElement();
56 if (!isset($super) || ($super instanceof StructureElement)) {
57 return $super;
58 }
59 throw new \ilMDElementsException(
60 'Metadata element has invalid super-element.'
61 );
62 }
63
67 public function getSubElements(): \Generator
68 {
69 foreach (parent::getSubElements() as $sub_element) {
70 $this->checkSubElement($sub_element);
71 yield $sub_element;
72 }
73 }
74
75 public function getSubElement(string $name): ?StructureElementInterface
76 {
77 foreach ($this->getSubElements() as $sub_element) {
78 $sub_name = $sub_element->getDefinition()->name();
79 if (strtolower($sub_name) === strtolower($name)) {
80 $this->checkSubElement($sub_element);
81 return $sub_element;
82 }
83 }
84 return null;
85 }
86
90 protected function checkSubElement(BaseElement $element): void
91 {
92 if (!($element instanceof StructureElement)) {
93 throw new \ilMDElementsException(
94 'Metadata element has invalid sub-element.'
95 );
96 }
97 }
98}
__construct(bool $is_root, DefinitionInterface $definition, StructureElement ... $sub_elements)
getSubElement(string $name)
Return the first sub-element with the given name, if one exists.
getDefinition()
Defining properties of the metadata element.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc