1 | <?php |
||
11 | abstract class MoveStrategyAbstract implements MoveStrategyInterface |
||
12 | { |
||
13 | private $manipulator; |
||
14 | |||
15 | private $sourceNodeInfo; |
||
16 | private $targetNodeInfo; |
||
17 | |||
18 | /** |
||
19 | * @param ManipulatorInterface $manipulator |
||
20 | */ |
||
21 | public function __construct(ManipulatorInterface $manipulator) |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | public function move($sourceNodeId, $targetNodeId): void |
||
81 | |||
82 | /** |
||
83 | * Check if can move node. |
||
84 | * |
||
85 | * @throws ValidationException if cannot move branch |
||
86 | */ |
||
87 | abstract protected function canMoveBranch(): void; |
||
88 | |||
89 | /** |
||
90 | * @return bool |
||
91 | */ |
||
92 | abstract protected function isSourceNodeAtRequiredPosition(): bool; |
||
93 | |||
94 | /** |
||
95 | * @param NodeInfo $sourceNodeInfo |
||
96 | * @param null|int|string $newParentId |
||
97 | */ |
||
98 | protected function _updateParentId(NodeInfo $sourceNodeInfo, $newParentId): void |
||
104 | |||
105 | /** |
||
106 | * Update parent id. |
||
107 | */ |
||
108 | abstract protected function updateParentId(): void; |
||
109 | |||
110 | /** |
||
111 | * @param NodeInfo $sourceNodeInfo |
||
112 | * @param int $levelShift |
||
113 | */ |
||
114 | protected function _updateLevels(NodeInfo $sourceNodeInfo, int $levelShift): void |
||
126 | |||
127 | /** |
||
128 | * Update levels. |
||
129 | */ |
||
130 | abstract protected function updateLevels(): void; |
||
131 | |||
132 | /** |
||
133 | * @param int $holeFromIndex |
||
134 | * @param int $indexShift |
||
135 | * @param null|int|string $scope |
||
136 | */ |
||
137 | protected function _makeHole(int $holeFromIndex, int $indexShift, $scope): void |
||
142 | |||
143 | /** |
||
144 | * Make hole for moved branch. |
||
145 | */ |
||
146 | abstract protected function makeHole(): void; |
||
147 | |||
148 | /** |
||
149 | * @param int $leftIndex |
||
150 | * @param int $rightIndex |
||
151 | * @param int $indexShift |
||
152 | * @param null|int|string $scope |
||
153 | */ |
||
154 | protected function _moveBranchToTheHole(int $leftIndex, int $rightIndex, int $indexShift, $scope): void |
||
159 | |||
160 | /** |
||
161 | * Move branch to the Hole. |
||
162 | */ |
||
163 | abstract protected function moveBranchToTheHole(): void; |
||
164 | |||
165 | /** |
||
166 | * @param int $holeFromIndex |
||
167 | * @param int $indexShift |
||
168 | * @param null|int|string $scope |
||
169 | */ |
||
170 | protected function _patchHole(int $holeFromIndex, int $indexShift, $scope): void |
||
178 | |||
179 | /** |
||
180 | * Patch hole. |
||
181 | */ |
||
182 | abstract protected function patchHole(): void; |
||
183 | |||
184 | /** |
||
185 | * @return int |
||
186 | */ |
||
187 | protected function getIndexShift(): int |
||
193 | |||
194 | /** |
||
195 | * @return bool |
||
196 | */ |
||
197 | protected function isMovedUp(): bool |
||
201 | |||
202 | /** |
||
203 | * @return bool |
||
204 | */ |
||
205 | protected function isMovedDown(): bool |
||
209 | |||
210 | /** |
||
211 | * @return bool |
||
212 | */ |
||
213 | protected function isMovedToRoot(): bool |
||
220 | |||
221 | /** |
||
222 | * @return bool |
||
223 | */ |
||
224 | protected function isTargetNodeInsideSourceBranch(): bool |
||
231 | |||
232 | /** |
||
233 | * @return ManipulatorInterface |
||
234 | */ |
||
235 | protected function getManipulator(): ManipulatorInterface |
||
239 | |||
240 | /** |
||
241 | * @return NodeInfo |
||
242 | */ |
||
243 | protected function getSourceNodeInfo(): NodeInfo |
||
247 | |||
248 | /** |
||
249 | * @param NodeInfo $sourceNodeInfo |
||
250 | */ |
||
251 | private function setSourceNodeInfo(NodeInfo $sourceNodeInfo): void |
||
255 | |||
256 | /** |
||
257 | * @return NodeInfo |
||
258 | */ |
||
259 | protected function getTargetNodeInfo(): NodeInfo |
||
263 | |||
264 | /** |
||
265 | * @param NodeInfo $targetNodeInfo |
||
266 | */ |
||
267 | private function setTargetNodeInfo(NodeInfo $targetNodeInfo): void |
||
271 | } |
||
272 |