Example #1
0
 /**
  * Prepare an api entity.
  *
  * @param CollectionInterface $entity
  * @param string $locale
  * @param CollectionEntity[] $entities nested set
  * @param array $breadcrumbEntities
  *
  * @return Collection
  */
 protected function getApiEntity(CollectionInterface $entity, $locale, $entities = null, $breadcrumbEntities = null)
 {
     $apiEntity = new Collection($entity, $locale);
     $children = [];
     if ($entities !== null) {
         foreach ($entities as $possibleChild) {
             if (($parent = $possibleChild->getParent()) !== null && $parent->getId() === $entity->getId()) {
                 $children[] = $this->getApiEntity($possibleChild, $locale, $entities);
             }
         }
     }
     $apiEntity->setChildren($children);
     if ($entity->getParent() !== null) {
         $apiEntity->setParent($this->getApiEntity($entity->getParent(), $locale));
     }
     if ($breadcrumbEntities !== null) {
         $breadcrumbApiEntities = [];
         foreach ($breadcrumbEntities as $entity) {
             $breadcrumbApiEntities[] = $this->getApiEntity($entity, $locale);
         }
         $apiEntity->setBreadcrumb($breadcrumbApiEntities);
     }
     if ($entity && $entity->getId()) {
         $apiEntity->setMediaCount($this->collectionRepository->countMedia($entity));
         $apiEntity->setSubCollectionCount($this->collectionRepository->countSubCollections($entity));
     }
     return $this->addPreview($apiEntity);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function move($id, $locale, $destinationId = null)
 {
     try {
         $collectionEntity = $this->collectionRepository->findCollectionById($id);
         if ($collectionEntity === null) {
             throw new CollectionNotFoundException($id);
         }
         $destinationEntity = null;
         if ($destinationId !== null) {
             $destinationEntity = $this->collectionRepository->findCollectionById($destinationId);
         }
         $collectionEntity->setParent($destinationEntity);
         $this->em->flush();
         return $this->getApiEntity($collectionEntity, $locale);
     } catch (DBALException $ex) {
         throw new CollectionNotFoundException($destinationId);
     }
 }