ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\Elements\Element Class Reference
+ Inheritance diagram for ILIAS\MetaData\Elements\Element:
+ Collaboration diagram for ILIAS\MetaData\Elements\Element:

Public Member Functions

 __construct (NoID|int $md_id, DefinitionInterface $definition, DataInterface $data, Element ... $sub_elements)
 
 getData ()
 
 isScaffold ()
 
 getSuperElement ()
 
 getSubElements ()
 
 isMarked ()
 Elements can be marked to be created, updated or deleted. More...
 
 getMarker ()
 
 mark (MarkerFactoryInterface $factory, Action $action, string $data_value='')
 
 unmark ()
 Removes markers from this element, and recursively from all sub-elements. More...
 
 addScaffoldsToSubElements (ScaffoldProviderInterface $scaffold_provider)
 Scaffolds are used to mark where elements could potentially be created. More...
 
 addScaffoldToSubElements (ScaffoldProviderInterface $scaffold_provider, string $name)
 If possible, adds a scaffold with the given name to this element's sub-elements, and returns it. More...
 
 getMDID ()
 
 getDefinition ()
 Defining properties of the metadata element. More...
 
 getSubElements ()
 
 getSuperElement ()
 
 isRoot ()
 
 getSubElements ()
 
 getSuperElement ()
 
 isScaffold ()
 
 getData ()
 
 addScaffoldsToSubElements (ScaffoldProviderInterface $scaffold_provider)
 Scaffolds are used to mark where elements could potentially be created. More...
 
 addScaffoldToSubElements (ScaffoldProviderInterface $scaffold_provider, string $name)
 If possible, adds a scaffold with the given name to this element's sub-elements, and returns it. More...
 

Protected Member Functions

 setMarker (?MarkerInterface $marker)
 

Private Attributes

MarkerInterface $marker = null
 
DataInterface $data
 

Detailed Description

Definition at line 34 of file Element.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\Elements\Element::__construct ( NoID|int  $md_id,
DefinitionInterface  $definition,
DataInterface  $data,
Element ...  $sub_elements 
)

Member Function Documentation

◆ addScaffoldsToSubElements()

ILIAS\MetaData\Elements\Element::addScaffoldsToSubElements ( ScaffoldProviderInterface  $scaffold_provider)

Scaffolds are used to mark where elements could potentially be created.

Adds all possible scaffolds to this element's sub-elements. Scaffolds are added such that the order of elements as suggested by the structure is preserved.

Implements ILIAS\MetaData\Elements\Scaffolds\ScaffoldableInterface.

Definition at line 128 of file Element.php.

130 : void {
131 foreach ($scaffold_provider->getScaffoldsForElement($this) as $scaffold) {
132 if ($scaffold->getSubElements()->current() !== null) {
133 throw new \ilMDElementsException('Can only add scaffolds with no sub-elements.');
134 }
135 $this->addSubElement($scaffold);
136 $this->orderSubElements(...$scaffold_provider->getPossibleSubElementNamesForElementInOrder($this));
137 }
138 }
addSubElement(BaseElement $sub_element)
Definition: BaseElement.php:78
orderSubElements(string ... $names_in_order)
Definition: BaseElement.php:84
getPossibleSubElementNamesForElementInOrder(ElementInterface $element)
Returns the names of all possible sub-elements for the given element in the order defined by the stru...
getScaffoldsForElement(ElementInterface $element)
Returns all elements that could be added as sub-elements to the given element as scaffolds.

References ILIAS\MetaData\Manipulator\ScaffoldProvider\ScaffoldProviderInterface\getPossibleSubElementNamesForElementInOrder().

+ Here is the call graph for this function:

◆ addScaffoldToSubElements()

ILIAS\MetaData\Elements\Element::addScaffoldToSubElements ( ScaffoldProviderInterface  $scaffold_provider,
string  $name 
)

If possible, adds a scaffold with the given name to this element's sub-elements, and returns it.

Scaffolds are added such that the order of elements as suggested by the structure is preserved.

Returns
ElementInterface[]

Implements ILIAS\MetaData\Elements\Scaffolds\ScaffoldableInterface.

Definition at line 140 of file Element.php.

143 : ?ElementInterface {
144 foreach ($scaffold_provider->getScaffoldsForElement($this) as $scaffold) {
145 if (strtolower($scaffold->getDefinition()->name()) === strtolower($name)) {
146 if ($scaffold->getSubElements()->current() !== null) {
147 throw new \ilMDElementsException('Can only add scaffolds with no sub-elements.');
148 }
149 $this->addSubElement($scaffold);
150 $this->orderSubElements(...$scaffold_provider->getPossibleSubElementNamesForElementInOrder($this));
151 return $scaffold;
152 }
153 }
154 return null;
155 }

References ILIAS\MetaData\Manipulator\ScaffoldProvider\ScaffoldProviderInterface\getPossibleSubElementNamesForElementInOrder().

+ Here is the call graph for this function:

◆ getData()

ILIAS\MetaData\Elements\Element::getData ( )

◆ getMarker()

ILIAS\MetaData\Elements\Element::getMarker ( )

◆ getSubElements()

ILIAS\MetaData\Elements\Element::getSubElements ( )
Returns
Element[]

Reimplemented from ILIAS\MetaData\Elements\Base\BaseElement.

Definition at line 73 of file Element.php.

73 : \Generator
74 {
75 foreach (parent::getSubElements() as $sub_element) {
76 if (!($sub_element instanceof Element)) {
77 throw new \ilMDElementsException(
78 'Metadata element has invalid sub-element.'
79 );
80 }
81 yield $sub_element;
82 }
83 }

◆ getSuperElement()

ILIAS\MetaData\Elements\Element::getSuperElement ( )

Reimplemented from ILIAS\MetaData\Elements\Base\BaseElement.

Definition at line 59 of file Element.php.

59 : ?Element
60 {
61 $super = parent::getSuperElement();
62 if (!isset($super) || ($super instanceof Element)) {
63 return $super;
64 }
65 throw new \ilMDElementsException(
66 'Metadata element has invalid super-element.'
67 );
68 }

◆ isMarked()

ILIAS\MetaData\Elements\Element::isMarked ( )

Elements can be marked to be created, updated or deleted.

Implements ILIAS\MetaData\Elements\Markers\MarkableInterface.

Definition at line 85 of file Element.php.

85 : bool
86 {
87 return isset($this->marker);
88 }

◆ isScaffold()

ILIAS\MetaData\Elements\Element::isScaffold ( )

Implements ILIAS\MetaData\Elements\ElementInterface.

Definition at line 54 of file Element.php.

54 : bool
55 {
56 return $this->getMDID() === NoID::SCAFFOLD;
57 }

References ILIAS\MetaData\Elements\Base\BaseElement\getMDID().

+ Here is the call graph for this function:

◆ mark()

ILIAS\MetaData\Elements\Element::mark ( MarkerFactoryInterface  $factory,
Action  $action,
string  $data_value = '' 
)

Definition at line 95 of file Element.php.

99 : void {
100 $this->setMarker($factory->marker($action, $data_value));
101 $curr_element = $this->getSuperElement();
102 while ($curr_element) {
103 if ($curr_element->isMarked()) {
104 return;
105 }
106 $trail_action = Action::NEUTRAL;
107 if ($curr_element->isScaffold() && $action === Action::CREATE_OR_UPDATE) {
108 $trail_action = Action::CREATE_OR_UPDATE;
109 }
110 $curr_element->setMarker($factory->marker($trail_action));
111 $curr_element = $curr_element->getSuperElement();
112 }
113 }
setMarker(?MarkerInterface $marker)
Definition: Element.php:123
marker(Action $action, string $data_value='')

◆ setMarker()

ILIAS\MetaData\Elements\Element::setMarker ( ?MarkerInterface  $marker)
protected

Definition at line 123 of file Element.php.

123 : void
124 {
125 $this->marker = $marker;
126 }

◆ unmark()

ILIAS\MetaData\Elements\Element::unmark ( )

Removes markers from this element, and recursively from all sub-elements.

Implements ILIAS\MetaData\Elements\Markers\MarkableInterface.

Definition at line 115 of file Element.php.

115 : void
116 {
117 $this->setMarker(null);
118 foreach ($this->getSubElements() as $sub_element) {
119 $sub_element->unmark();
120 }
121 }

Field Documentation

◆ $data

DataInterface ILIAS\MetaData\Elements\Element::$data
private

◆ $marker

MarkerInterface ILIAS\MetaData\Elements\Element::$marker = null
private

Definition at line 36 of file Element.php.

Referenced by ILIAS\MetaData\Elements\Element\getMarker().


The documentation for this class was generated from the following file: