Skip to content

Commit

Permalink
Added 3 additional fields to the instances hierarchy array required f…
Browse files Browse the repository at this point in the history
…or the report generation.
  • Loading branch information
ruslanbaidan committed Nov 13, 2024
1 parent c6878b7 commit 91da565
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Entity/InstanceSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ public function removeAllOperationalInstanceRisks(): self

/**
* Returns the instance hierarchy array ordered from its root through all the children to the instance itself.
* Each element is a normalized array of the instances' names.
* Each element is a normalized array of the instances' names, ids, parent and root objects.
*/
public function getHierarchyArray(): array
{
if ($this->isRoot()) {
return [$this->getNames()];
return [array_merge($this->getNames(), ['id' => $this->id, 'root' => null, 'parent' => null])];
}

return $this->getParents();
Expand All @@ -513,10 +513,18 @@ public function getHierarchyArray(): array
private function getParents(): array
{
if ($this->isRoot() || $this->getParent() === null) {
return [$this->getNames()];
return [array_merge($this->getNames(), ['id' => $this->getId(), 'root' => null, 'parent' => null])];
}

return array_merge($this->getParent()->getParents(), [$this->getNames()]);
return array_merge(
$this->getParent()->getParents(),
[
array_merge(
$this->getNames(),
['id' => $this->getId(), 'root' => $this->getRoot(), 'parent' => $this->getParent()]
)
]
);
}

/**
Expand Down

0 comments on commit 91da565

Please sign in to comment.