19 declare(strict_types=1);
74 $elements = $this->navigator_factory->navigator($path, $my_set->getRoot())->elementsAtFinalStep();
75 $target_elements = [];
76 foreach ($elements as $element) {
78 $target_elements[] = $element;
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);
110 $my_set = clone $set;
111 $target_elements = $this->getElementsToCreate($my_set->getRoot(),
$path, ...$values);
116 protected function getElementsToUpdate(
125 $path_conditions = $this->path_utilities_factory->pathConditionsCollection($path);
126 $path_checker = $this->path_utilities_factory->pathConditionChecker($path_conditions);
127 $target_elements = [];
128 $navigators = [$this->navigator_factory->navigator($path_conditions->getPathWithoutConditions(), $set_root)];
130 if (count($values) <= 0) {
135 while (count($navigators) > 0) {
136 $curr_navi = array_shift($navigators)->nextStep();
137 $at_least_one_path_condition_met = $path_checker->atLeastOnePathConditionIsMet(
138 $curr_navi->currentStep(),
139 ...$curr_navi->elements()
143 if ($at_least_one_path_condition_met && $curr_navi->hasElements() && !$curr_navi->hasNextStep()) {
144 $roots = iterator_to_array($path_checker->getRootsThatMeetPathCondition(
145 $curr_navi->currentStep(),
146 ...$curr_navi->elements()
149 $missing_target_count = max(0, count($values) - count($target_elements));
150 $targets = array_slice($roots, 0, $missing_target_count);
151 array_push($target_elements, ...$targets);
156 if ($at_least_one_path_condition_met && $curr_navi->hasElements() && $curr_navi->hasNextStep()) {
157 $roots = iterator_to_array($path_checker->getRootsThatMeetPathCondition(
158 $curr_navi->currentStep(),
159 ...$curr_navi->elements()
161 foreach ($roots as $root) {
162 $navigators[] = $this->navigator_factory->navigator(
170 return $target_elements;
173 protected function getElementsToCreate(
184 $path_conditions = $this->path_utilities_factory->pathConditionsCollection($path);
185 $path_checker = $this->path_utilities_factory->pathConditionChecker($path_conditions);
186 $target_elements = [];
187 $loose_end_roots = [];
188 $loose_end_paths = [];
189 $navigators = [$this->navigator_factory->navigator($path_conditions->getPathWithoutConditions(), $set_root)];
191 if (count($values) <= 0) {
196 while (count($navigators) > 0) {
197 $orig_navi = array_shift($navigators);
198 $curr_navi = $orig_navi->nextStep();
199 $at_least_one_path_condition_met = $path_checker->atLeastOnePathConditionIsMet(
200 $curr_navi->currentStep(),
201 ...$curr_navi->elements()
205 if (!$at_least_one_path_condition_met) {
206 $roots = iterator_to_array($orig_navi->elements());
208 array_push($loose_end_roots, ...$roots);
209 array_push($loose_end_paths, ...$paths);
214 if ($at_least_one_path_condition_met && !$curr_navi->hasElements() && !$curr_navi->hasNextStep()) {
215 $roots = iterator_to_array($orig_navi->elements());
217 array_push($loose_end_roots, ...$roots);
218 array_push($loose_end_paths, ...$paths);
223 if ($at_least_one_path_condition_met && !$curr_navi->hasElements() && $curr_navi->hasNextStep()) {
224 $roots = iterator_to_array($path_checker->getRootsThatMeetPathCondition(
225 $curr_navi->currentStep(),
226 ...$curr_navi->elements()
229 array_push($loose_end_roots, ...$roots);
230 array_push($loose_end_paths, ...$paths);
235 if ($at_least_one_path_condition_met && $curr_navi->hasElements() && $curr_navi->hasNextStep()) {
236 $roots = iterator_to_array($path_checker->getRootsThatMeetPathCondition(
237 $curr_navi->currentStep(),
238 ...$curr_navi->elements()
240 foreach ($roots as $root) {
241 $navigators[] = $this->navigator_factory->navigator(
250 $missing_target_count = max(0, count($values) - count($target_elements));
251 if (count($loose_end_roots) > 0 && $missing_target_count > 0) {
253 array_shift($loose_end_paths),
254 array_shift($loose_end_roots),
261 $path_conditions->getPathWithoutConditions(),
267 if ($navigator->hasPreviousStep()) {
268 $navigator = $navigator->previousStep();
272 $missing_target_count = max(0, count($values) - count($target_elements));
273 $loose_end_paths = array_slice($loose_end_paths, 0, $missing_target_count);
274 $loose_end_roots = array_slice($loose_end_roots, 0, $missing_target_count);
275 array_push($target_elements, ...$this->
createTargetElements($loose_end_roots, $loose_end_paths, $path_conditions));
278 $missing_target_count = max(0, count($values) - count($target_elements));
280 $root = $navigator->lastElement();
281 $target_paths = array_fill(0, $missing_target_count, $remaining_path);
282 $target_roots = array_fill(0, $missing_target_count, $root);
283 array_push($target_elements, ...$this->
createTargetElements($target_roots, $target_paths, $path_conditions));
285 return $target_elements;
301 $builder = $this->path_factory->custom()
303 ->withLeadsToExactlyOneElement(
false);
304 while (!is_null($navigator)) {
306 $navigator = $navigator->
nextStep();
309 $builder = $builder->withNextStepFromStep($navigator->
currentStep(),
false);
310 $navigator = $navigator->
nextStep();
312 return $builder->get();
319 $navigator = $this->navigator_factory->navigator($path, $root);
320 while ($navigator->hasNextStep() && $navigator->nextStep()->hasElements()) {
321 $navigator = $navigator->
nextStep();
334 $navigator = $this->navigator_factory->navigator($path, $root);
335 $navigator = $navigator->nextStep();
337 while (!is_null($navigator)) {
339 if (is_null($scaffold)) {
341 'Cannot create scaffold at step: ' . $navigator->currentStep()->name() .
', invalid path.' 345 if ($condition_path->steps()->valid()) {
348 $navigator = $navigator->nextStep();
364 $target_elements = [];
365 while (0 < count($paths)) {
372 return $target_elements;
382 $navigator = $this->navigator_factory->navigator($condition_path, $root);
383 $navigator = $navigator->nextStep();
385 while (!is_null($navigator)) {
387 if (is_null($scaffold)) {
390 $navigator = $navigator->nextStep();
405 $this->scaffold_provider,
408 if (!isset($scaffold)) {
412 foreach ($step->
filters() as $filter) {
414 $data = $filter->values()->current();
419 $this->marker_factory,
420 Action::CREATE_OR_UPDATE,
433 $element->
mark($this->marker_factory, Action::CREATE_OR_UPDATE, $value);
434 }, $target_elements, $values);
441 }, $target_elements);
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null