ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Manipulator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 
34 {
39 
40  public function __construct(
41  BaseManipulator $base_manipulator,
42  NavigatorFactoryInterface $navigator_factory,
43  RepositoryInterface $repository,
44  ScaffoldProviderInterface $scaffold_provider
45  ) {
46  $this->base_manipulator = $base_manipulator;
47  $this->navigator_factory = $navigator_factory;
48  $this->repository = $repository;
49  $this->scaffold_provider = $scaffold_provider;
50  }
51 
55  public function addScaffolds(
56  SetInterface $set,
58  ): SetInterface {
59  $set = clone $set;
60  $to_be_scaffolded = [];
61  foreach ($this->getElements($set, $path) as $el) {
62  $super = $el->getSuperElement() ?? $el;
63  if (!in_array($super, $to_be_scaffolded, true)) {
64  $to_be_scaffolded[] = $super;
65  }
66  }
67  while (!empty($to_be_scaffolded)) {
68  $next = [];
69  foreach ($to_be_scaffolded as $element) {
70  if (!($element instanceof ScaffoldableInterface)) {
71  continue;
72  }
73  $element->addScaffoldsToSubElements($this->scaffold_provider);
74  $next = array_merge(
75  $next,
76  iterator_to_array($element->getSubElements())
77  );
78  }
79  $to_be_scaffolded = $next;
80  }
81  return $set;
82  }
83 
84  public function prepareCreateOrUpdate(SetInterface $set, PathInterface $path, string ...$values): SetInterface
85  {
86  return $this->base_manipulator->prepareCreateOrUpdate(
87  $set,
88  $path,
89  ...$values
90  );
91  }
92 
93  public function prepareForceCreate(SetInterface $set, PathInterface $path, string ...$values): SetInterface
94  {
95  return $this->base_manipulator->prepareForceCreate(
96  $set,
97  $path,
98  ...$values
99  );
100  }
101 
103  {
104  return $this->base_manipulator->prepareDelete($set, $path);
105  }
106 
107  public function execute(SetInterface $set): void
108  {
109  $this->repository->manipulateMD($set);
110  }
111 
116  protected function getElements(
117  SetInterface $set,
119  ): \Generator {
120  if (!isset($path)) {
121  yield $set->getRoot();
122  return;
123  }
124  yield from $this->navigator_factory->navigator(
125  $path,
126  $set->getRoot()
127  )->elementsAtFinalStep();
128  }
129 }
getElements(SetInterface $set, ?PathInterface $path=null)
prepareCreateOrUpdate(SetInterface $set, PathInterface $path, string ... $values)
Follows the path, adding scaffolds where necessary to perform the step.
Definition: Manipulator.php:84
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
$path
Definition: ltiservices.php:29
getRoot()
Returns the root element of the metadata set.
ScaffoldProviderInterface $scaffold_provider
Definition: Manipulator.php:38
prepareForceCreate(SetInterface $set, PathInterface $path, string ... $values)
Definition: Manipulator.php:93
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
prepareDelete(SetInterface $set, PathInterface $path)
__construct(BaseManipulator $base_manipulator, NavigatorFactoryInterface $navigator_factory, RepositoryInterface $repository, ScaffoldProviderInterface $scaffold_provider)
Definition: Manipulator.php:40
NavigatorFactoryInterface $navigator_factory
Definition: Manipulator.php:36
addScaffolds(SetInterface $set, ?PathInterface $path=null)
Definition: Manipulator.php:55