filter for non parent nodes in create plan
This commit is contained in:
parent
844813499a
commit
a527c8b01e
1 changed files with 21 additions and 1 deletions
|
|
@ -35,7 +35,9 @@ class CreatePlan
|
|||
}
|
||||
$textId = $request->textId;
|
||||
$text = $this->textRepo->find($textId);
|
||||
$nodesOfText = $this->nodeRepo->findByTextId($textId);
|
||||
$nodesOfText = $this->filterForNonParentNodes(
|
||||
$this->nodeRepo->findByTextId($textId)
|
||||
);
|
||||
$plan = $this->planRepo->create(new CreatePlanDto(
|
||||
name: $request->name,
|
||||
user: $user,
|
||||
|
|
@ -51,4 +53,22 @@ class CreatePlan
|
|||
|
||||
return $plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
* @return Node[]
|
||||
*/
|
||||
private function filterForNonParentNodes(array $nodes): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($nodes as $node) {
|
||||
$result[$node->getId()] = $node;
|
||||
|
||||
$parentNode = $node->getParentNode();
|
||||
if ($parentNode !== null) {
|
||||
unset($result[$parentNode->getId()]);
|
||||
}
|
||||
}
|
||||
return array_values($result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue