ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ManipulatorAdapter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29
31{
34 protected PathFactory $path_factory;
36
37 public function __construct(
40 PathFactory $path_factory,
42 ) {
43 $this->manipulator = $manipulator;
44 $this->form_factory = $form_factory;
45 $this->path_factory = $path_factory;
46 $this->navigator_factory = $navigator_factory;
47 }
48
49 public function prepare(
50 SetInterface $set,
52 ): SetInterface {
53 return $this->manipulator->addScaffolds($set, $path);
54 }
55
59 public function createOrUpdate(
60 SetInterface $set,
61 PathInterface $base_path,
62 PathInterface $action_path,
64 ): bool {
65 $action_element = $this->navigator_factory->navigator($action_path, $set->getRoot())
66 ->lastElementAtFinalStep();
67 $form = $this->form_factory->getCreateForm(
68 $base_path,
69 $action_element,
70 );
71 $data = [];
72 if (
73 !empty($form->getInputs()) &&
74 !($data = $request->applyRequestToForm($form)->getData())
75 ) {
76 return false;
77 }
78
83 $set = $this->manipulator->prepareCreateOrUpdate($set, $action_path, '');
84
85 $data = $data[0] ?? [];
86 foreach ($data as $path_string => $value) {
87 $path = $this->path_factory->fromString($path_string);
88 if ($value !== '' && $value !== null) {
89 $set = $this->manipulator->prepareCreateOrUpdate($set, $path, $value);
90 } else {
91 $set = $this->manipulator->prepareDelete($set, $path);
92 }
93 }
94 $this->manipulator->execute($set);
95 return true;
96 }
97
102 public function deleteAndTrimBasePath(
103 SetInterface $set,
104 PathInterface $base_path,
105 PathInterface $action_path,
106 ): PathInterface {
107 $set = $this->manipulator->prepareDelete($set, $action_path);
108 $this->manipulator->execute($set);
109
110 $base_elements = $this->navigator_factory->navigator($base_path, $set->getRoot())
111 ->elementsAtFinalStep();
112 $action_element = $this->navigator_factory->navigator($action_path, $set->getRoot())
113 ->lastElementAtFinalStep();
114 $base_elements = iterator_to_array($base_elements);
115 if (count($base_elements) === 1 && $action_element === $base_elements[0]) {
116 $base_path = $this->path_factory->toElement(
117 $action_element->getSuperElement(),
118 true
119 );
120 }
121 return $base_path;
122 }
123}
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.
createOrUpdate(SetInterface $set, PathInterface $base_path, PathInterface $action_path, RequestForFormInterface $request)
Returns false if the data from the request is invalid.
__construct(ManipulatorInterface $manipulator, FormFactory $form_factory, PathFactory $path_factory, NavigatorFactoryInterface $navigator_factory)
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