/** * The process to calculate the nested set left, right, and depth. * * @param Collection $data * @param string $id * @param int $left * @param int $depth * * @return int * @throws \Exception */ private function calculateTree(Collection $data, $id = null, $left = 0, $depth = 0) { /** @var NestedSetInterface $node */ $node = $data->matching(Criteria::create()->where(Criteria::expr()->equal('id', $id)))->first(); if (!$node instanceof NestedSetInterface) { throw new \Exception('Node is not a NestedSetInterface'); } $left += 1; $prevRight = $left; $children = $data->matching(Criteria::create()->where(Criteria::expr()->equal('parentId', $id))); foreach ($children as $childNode) { $childNodeId = $childNode->getId(); $prevRight = $this->calculateTree($data, $childNodeId, $prevRight, $depth + 1); } $node->setLeft($left); $node->setRight($prevRight + 1); $node->setDepth($depth); $this->nestedSetRepository->save($node); return $node->getRight(); }
public function __construct(StorageInterface $storage) { parent::__construct($storage, 'Movie', '\\Borobudur\\Cqrs\\Test\\MovieReadModel'); }