findTree() public method

Finds the parent collections and all the sliblings of them + the children of given id.
public findTree ( id $id, string $locale ) : Collection[]
$id id
$locale string
return Collection[]
Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function getTreeById($id, $locale)
 {
     $collectionSet = $this->collectionRepository->findTree($id, $locale);
     /** @var Collection[] $collections sorted by id */
     $collections = [];
     /** @var Collection[] $result collections without parent */
     $result = [];
     foreach ($collectionSet as $collection) {
         $apiEntity = new Collection($collection, $locale);
         $this->addPreview($apiEntity);
         $collections[$collection->getId()] = $apiEntity;
         if ($collection->getParent() !== null) {
             $collections[$collection->getParent()->getId()]->addChild($apiEntity);
         } else {
             $result[] = $apiEntity;
         }
     }
     return $result;
 }