ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ManipulatorAdapter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
32{
35 protected PathFactory $path_factory;
37
38 public function __construct(
41 PathFactory $path_factory,
43 ) {
44 $this->manipulator = $manipulator;
45 $this->form_factory = $form_factory;
46 $this->path_factory = $path_factory;
47 $this->navigator_factory = $navigator_factory;
48 }
49
50 public function prepare(
51 SetInterface $set,
53 ): SetInterface {
54 return $this->manipulator->addScaffolds($set, $path);
55 }
56
60 public function createOrUpdate(
61 SetInterface $set,
62 PathInterface $base_path,
63 PathInterface $action_path,
65 ): bool {
66 $action_element = $this->navigator_factory->navigator($action_path, $set->getRoot())
67 ->lastElementAtFinalStep();
68 $form = $this->form_factory->getCreateForm(
69 $base_path,
70 $action_element,
71 );
72 $data = [];
73 if (
74 !empty($form->getInputs()) &&
75 !($data = $request->applyRequestToForm($form)->getData())
76 ) {
77 return false;
78 }
79
84 $set = $this->manipulator->prepareCreateOrUpdate($set, $action_path, '');
85
86 $data = $data[0] ?? [];
87 foreach ($data as $path_string => $value) {
88 $path = $this->path_factory->fromString($path_string);
89 if ($value !== '' && $value !== null) {
90 $set = $this->manipulator->prepareCreateOrUpdate($set, $path, $value);
91 } else {
92 $set = $this->manipulator->prepareDelete($set, $path);
93 }
94 }
95 $this->manipulator->execute($set);
96 return true;
97 }
98
103 public function deleteAndTrimBasePath(
104 SetInterface $set,
105 PathInterface $base_path,
106 PathInterface $action_path,
107 ): PathInterface {
108 $set = $this->manipulator->prepareDelete($set, $action_path);
109 $this->manipulator->execute($set);
110
111 $base_elements = $this->navigator_factory->navigator($base_path, $set->getRoot())
112 ->elementsAtFinalStep();
113 $action_element = $this->navigator_factory->navigator($action_path, $set->getRoot())
114 ->lastElementAtFinalStep();
115 $base_elements = iterator_to_array($base_elements);
116 if (count($base_elements) === 1 && $action_element === $base_elements[0]) {
117 $base_path = $this->path_factory->toElement(
118 $action_element->getSuperElement(),
119 true
120 );
121 }
122 return $base_path;
123 }
124}
__construct(ManipulatorInterface $manipulator, FormFactory $form_factory, PathFactory $path_factory, NavigatorFactoryInterface $navigator_factory)
createOrUpdate(SetInterface $set, PathInterface $base_path, PathInterface $action_path, RequestForFormInterface $request)
Returns false if the data from the request is invalid.
deleteAndTrimBasePath(SetInterface $set, PathInterface $base_path, PathInterface $action_path,)
Returns a trimmed node path if deleted element was the only one at the end of the path.
prepare(SetInterface $set, PathInterface $path)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRoot()
Returns the root element of the metadata set.
$path
Definition: ltiservices.php:30