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

Public Member Functions

 __construct (ScaffoldProviderInterface $scaffold_provider, MarkerFactoryInterface $marker_factory, NavigatorFactoryInterface $navigator_factory, PathFactoryInterface $path_factory, PathUtilitiesFactoryInterface $path_utilities_factory)
 
 prepareCreateOrUpdate (SetInterface $set, PathInterface $path, string ... $values)
 
 prepareForceCreate (SetInterface $set, PathInterface $path, string ... $values)
 

Protected Member Functions

 moveNavigatorBackwardsToFirstNonUnique (NavigatorInterface $navigator)
 
 remainingPathOfNavigator (NavigatorInterface $navigator)
 
 getLastNavigatorWithElements (PathInterface $path, ElementInterface $root)
 
 insertPathElementsAsScaffolds (PathInterface $path, ElementInterface $root, PathConditionsCollectionInterface $path_conditions_collection)
 
 createTargetElements (array $roots, array $paths, PathConditionsCollectionInterface $path_conditions)
 
 insertConditionPathElementsAsScaffolds (PathInterface $condition_path, ElementInterface $root)
 
 addAndMarkScaffoldByStep (ElementInterface $element, StepInterface $step)
 also returns the added scaffold, if valid More...
 
 markElementsCreateOrUpdate (array $target_elements, array $values)
 
 markElementsDelete (array $target_elements)
 

Protected Attributes

ScaffoldProviderInterface $scaffold_provider
 
MarkerFactoryInterface $marker_factory
 
NavigatorFactoryInterface $navigator_factory
 
PathFactoryInterface $path_factory
 
PathUtilitiesFactoryInterface $path_utilities_factory
 

Detailed Description

Definition at line 41 of file Manipulator.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\Manipulator\Manipulator::__construct ( ScaffoldProviderInterface  $scaffold_provider,
MarkerFactoryInterface  $marker_factory,
NavigatorFactoryInterface  $navigator_factory,
PathFactoryInterface  $path_factory,
PathUtilitiesFactoryInterface  $path_utilities_factory 
)

Member Function Documentation

◆ addAndMarkScaffoldByStep()

ILIAS\MetaData\Manipulator\Manipulator::addAndMarkScaffoldByStep ( ElementInterface  $element,
StepInterface  $step 
)
protected

also returns the added scaffold, if valid

Definition at line 397 of file Manipulator.php.

401 if ($step->name() === StepToken::SUPER) {
402 return $element->getSuperElement();
403 }
404 $scaffold = $element->addScaffoldToSubElements(
405 $this->scaffold_provider,
406 $step->name()
407 );
408 if (!isset($scaffold)) {
409 return null;
410 }
411 $data = '';
412 foreach ($step->filters() as $filter) {
413 if ($filter->type() === FilterType::DATA) {
414 $data = $filter->values()->current();
415 break;
416 }
417 }
418 $scaffold->mark(
419 $this->marker_factory,
420 Action::CREATE_OR_UPDATE,
421 $data
422 );
423 return $scaffold;
424 }
addScaffoldToSubElements(ScaffoldProviderInterface $scaffold_provider, string $name)
If possible, adds a scaffold with the given name to this element's sub-elements, and returns it.
name()
Steps are identified by the names of LOM elements, or a token to specify a step to the super-element.
filters()
Filters restrict the elements a step leads to.

References ILIAS\MetaData\Elements\ElementInterface\getSuperElement().

+ Here is the call graph for this function:

◆ createTargetElements()

ILIAS\MetaData\Manipulator\Manipulator::createTargetElements ( array  $roots,
array  $paths,
PathConditionsCollectionInterface  $path_conditions 
)
protected
Parameters
ElementInterface[]$roots
PathInterface[]$paths
Returns
ElementInterface[]
Exceptions
ilMDPathException

Definition at line 359 of file Manipulator.php.

363 : array {
364 $target_elements = [];
365 while (0 < count($paths)) {
366 $target_elements[] = $this->insertPathElementsAsScaffolds(
367 array_shift($paths),
368 array_shift($roots),
369 $path_conditions
370 );
371 }
372 return $target_elements;
373 }
insertPathElementsAsScaffolds(PathInterface $path, ElementInterface $root, PathConditionsCollectionInterface $path_conditions_collection)

◆ getLastNavigatorWithElements()

ILIAS\MetaData\Manipulator\Manipulator::getLastNavigatorWithElements ( PathInterface  $path,
ElementInterface  $root 
)
protected

Definition at line 315 of file Manipulator.php.

319 $navigator = $this->navigator_factory->navigator($path, $root);
320 while ($navigator->hasNextStep() && $navigator->nextStep()->hasElements()) {
321 $navigator = $navigator->nextStep();
322 }
323 return $navigator;
324 }
nextStep()
Returns null if there is no next step.
$path
Definition: ltiservices.php:30

References ILIAS\MetaData\Paths\Navigator\NavigatorInterface\nextStep().

+ Here is the call graph for this function:

◆ insertConditionPathElementsAsScaffolds()

ILIAS\MetaData\Manipulator\Manipulator::insertConditionPathElementsAsScaffolds ( PathInterface  $condition_path,
ElementInterface  $root 
)
protected
Exceptions
ilMDPathException

Definition at line 378 of file Manipulator.php.

381 : void {
382 $navigator = $this->navigator_factory->navigator($condition_path, $root);
383 $navigator = $navigator->nextStep();
384 $scaffold = $root;
385 while (!is_null($navigator)) {
386 $scaffold = $this->addAndMarkScaffoldByStep($scaffold, $navigator->currentStep());
387 if (is_null($scaffold)) {
388 throw new ilMDPathException('Cannot create scaffold, invalid path.');
389 }
390 $navigator = $navigator->nextStep();
391 }
392 }
addAndMarkScaffoldByStep(ElementInterface $element, StepInterface $step)
also returns the added scaffold, if valid

◆ insertPathElementsAsScaffolds()

ILIAS\MetaData\Manipulator\Manipulator::insertPathElementsAsScaffolds ( PathInterface  $path,
ElementInterface  $root,
PathConditionsCollectionInterface  $path_conditions_collection 
)
protected
Exceptions
ilMDPathException

Definition at line 329 of file Manipulator.php.

334 $navigator = $this->navigator_factory->navigator($path, $root);
335 $navigator = $navigator->nextStep();
336 $scaffold = $root;
337 while (!is_null($navigator)) {
338 $scaffold = $this->addAndMarkScaffoldByStep($scaffold, $navigator->currentStep());
339 if (is_null($scaffold)) {
340 throw new ilMDPathException(
341 'Cannot create scaffold at step: ' . $navigator->currentStep()->name() . ', invalid path.'
342 );
343 }
344 $condition_path = $path_conditions_collection->getConditionPathByStepName($navigator->currentStep()->name());
345 if ($condition_path->steps()->valid()) {
346 $this->insertConditionPathElementsAsScaffolds($condition_path, $scaffold);
347 }
348 $navigator = $navigator->nextStep();
349 }
350 return $scaffold;
351 }
insertConditionPathElementsAsScaffolds(PathInterface $condition_path, ElementInterface $root)

References ILIAS\MetaData\Manipulator\Path\PathConditionsCollectionInterface\getConditionPathByStepName().

+ Here is the call graph for this function:

◆ markElementsCreateOrUpdate()

ILIAS\MetaData\Manipulator\Manipulator::markElementsCreateOrUpdate ( array  $target_elements,
array  $values 
)
protected
Parameters
ElementInterface[]$target_elements
array$values

Definition at line 430 of file Manipulator.php.

430 : void
431 {
432 array_map(function (ElementInterface $element, ?string $value) {
433 $element->mark($this->marker_factory, Action::CREATE_OR_UPDATE, $value);
434 }, $target_elements, $values);
435 }
mark(MarkerFactoryInterface $factory, Action $action, string $data_value='')
Leaves a trail of markers from this element up to the root element, or up to the first already marked...

References ILIAS\MetaData\Elements\Markers\MarkableInterface\mark().

+ Here is the call graph for this function:

◆ markElementsDelete()

ILIAS\MetaData\Manipulator\Manipulator::markElementsDelete ( array  $target_elements)
protected

Definition at line 437 of file Manipulator.php.

437 : void
438 {
439 array_map(function (ElementInterface $element) {
440 $element->mark($this->marker_factory, Action::DELETE);
441 }, $target_elements);
442 }

References ILIAS\MetaData\Elements\Markers\DELETE, and ILIAS\MetaData\Elements\Markers\MarkableInterface\mark().

+ Here is the call graph for this function:

◆ moveNavigatorBackwardsToFirstNonUnique()

ILIAS\MetaData\Manipulator\Manipulator::moveNavigatorBackwardsToFirstNonUnique ( NavigatorInterface  $navigator)
protected
Exceptions
ilMDPathException

Definition at line 291 of file Manipulator.php.

292 {
293 while ($navigator->hasPreviousStep() && $navigator->lastElement()->getDefinition()->unique()) {
294 $navigator = $navigator->previousStep();
295 }
296 return $navigator;
297 }
lastElement()
Returns only the first element at the current step, if one exists.

References ILIAS\MetaData\Paths\Navigator\BaseNavigatorInterface\hasPreviousStep(), ILIAS\MetaData\Paths\Navigator\NavigatorInterface\lastElement(), and ILIAS\MetaData\Paths\Navigator\NavigatorInterface\previousStep().

+ Here is the call graph for this function:

◆ prepareCreateOrUpdate()

ILIAS\MetaData\Manipulator\Manipulator::prepareCreateOrUpdate ( SetInterface  $set,
PathInterface  $path,
string ...  $values 
)
Exceptions
ilMDPathException

Implements ILIAS\MetaData\Manipulator\ManipulatorInterface.

Definition at line 88 of file Manipulator.php.

92 : SetInterface {
93 $my_set = clone $set;
94 $elements_to_update = $this->getElementsToUpdate($my_set->getRoot(), $path, ...$values);
95 $remaining_values = array_slice($values, 0, count($values) - count($elements_to_update));
96 $elements_to_create = $this->getElementsToCreate($my_set->getRoot(), $path, ...$remaining_values);
97 $target_elements = array_merge($elements_to_update, $elements_to_create);
98 $this->markElementsCreateOrUpdate($target_elements, $values);
99 return $my_set;
100 }
markElementsCreateOrUpdate(array $target_elements, array $values)

◆ prepareForceCreate()

ILIAS\MetaData\Manipulator\Manipulator::prepareForceCreate ( SetInterface  $set,
PathInterface  $path,
string ...  $values 
)
Exceptions
ilMDPathException

Implements ILIAS\MetaData\Manipulator\ManipulatorInterface.

Definition at line 105 of file Manipulator.php.

109 : SetInterface {
110 $my_set = clone $set;
111 $target_elements = $this->getElementsToCreate($my_set->getRoot(), $path, ...$values);
112 $this->markElementsCreateOrUpdate($target_elements, $values);
113 return $my_set;
114 }

◆ remainingPathOfNavigator()

ILIAS\MetaData\Manipulator\Manipulator::remainingPathOfNavigator ( NavigatorInterface  $navigator)
protected

Definition at line 299 of file Manipulator.php.

300 {
301 $builder = $this->path_factory->custom()
302 ->withRelative(true)
303 ->withLeadsToExactlyOneElement(false);
304 while (!is_null($navigator)) {
305 if (is_null($navigator->currentStep())) {
306 $navigator = $navigator->nextStep();
307 continue;
308 }
309 $builder = $builder->withNextStepFromStep($navigator->currentStep(), false);
310 $navigator = $navigator->nextStep();
311 }
312 return $builder->get();
313 }

References ILIAS\MetaData\Paths\Navigator\BaseNavigatorInterface\currentStep(), and ILIAS\MetaData\Paths\Navigator\NavigatorInterface\nextStep().

+ Here is the call graph for this function:

Field Documentation

◆ $marker_factory

MarkerFactoryInterface ILIAS\MetaData\Manipulator\Manipulator::$marker_factory
protected

Definition at line 44 of file Manipulator.php.

Referenced by ILIAS\MetaData\Manipulator\Manipulator\__construct().

◆ $navigator_factory

NavigatorFactoryInterface ILIAS\MetaData\Manipulator\Manipulator::$navigator_factory
protected

Definition at line 45 of file Manipulator.php.

Referenced by ILIAS\MetaData\Manipulator\Manipulator\__construct().

◆ $path_factory

PathFactoryInterface ILIAS\MetaData\Manipulator\Manipulator::$path_factory
protected

Definition at line 46 of file Manipulator.php.

Referenced by ILIAS\MetaData\Manipulator\Manipulator\__construct().

◆ $path_utilities_factory

PathUtilitiesFactoryInterface ILIAS\MetaData\Manipulator\Manipulator::$path_utilities_factory
protected

Definition at line 47 of file Manipulator.php.

Referenced by ILIAS\MetaData\Manipulator\Manipulator\__construct().

◆ $scaffold_provider

ScaffoldProviderInterface ILIAS\MetaData\Manipulator\Manipulator::$scaffold_provider
protected

Definition at line 43 of file Manipulator.php.

Referenced by ILIAS\MetaData\Manipulator\Manipulator\__construct().


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