src/AppBundle/Repository/BlockRepository.php line 81

Open in your IDE?
  1. <?php
  2. /**
  3.  *
  4.  * Copyright (c) 2017. The Cocktail
  5.  *
  6.  * This file is part of the Movistar Originales package.
  7.  *
  8.  */
  9. namespace AppBundle\Repository;
  10. use AppBundle\Exception\ContentNotFoundException;
  11. use AppBundle\QueryType\BlockQueryType;
  12. use eZ\Publish\API\Repository\ContentService;
  13. use eZ\Publish\API\Repository\ContentTypeService;
  14. use eZ\Publish\API\Repository\SearchService;
  15. class BlockRepository
  16. {
  17.     /**
  18.      * @var SearchService
  19.      */
  20.     protected $searchService;
  21.     /**
  22.      * @var ContentService
  23.      */
  24.     protected $contentService;
  25.     /**
  26.      * @var ContentTypeService
  27.      */
  28.     protected $contentTypeService;
  29.     /**
  30.      * @var BlockQueryType
  31.      */
  32.     protected $blockQueryType;
  33.     public function __construct(
  34.         SearchService $searchService,
  35.         ContentService $contentService,
  36.         ContentTypeService $contentTypeService,
  37.         BlockQueryType $blockQueryType
  38.     ) {
  39.         $this->searchService $searchService;
  40.         $this->contentService $contentService;
  41.         $this->contentTypeService $contentTypeService;
  42.         $this->blockQueryType $blockQueryType;
  43.     }
  44.     /**
  45.     /**
  46.      * Busca los bloques dentro de la carpeta bloques del locationid recibido
  47.      *
  48.      * @param integer $locationId
  49.      * @param bool $container
  50.      *
  51.      * @return \eZ\Publish\API\Repository\Values\Content\Content[]
  52.      *
  53.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  54.      * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
  55.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
  56.      */
  57.     public function loadBlocksByParentLocation(int $locationIdbool $container false)
  58.     {
  59.         $parameters = ['locationId' => $locationId'container' => $container];
  60.         try {
  61.             $locationQuery $this->blockQueryType->getQuery($parameters);
  62.         } catch (ContentNotFoundException $exception) {
  63.             return [];
  64.         }
  65.         $locationSearchResults $this->searchService->findLocations($locationQuery);
  66.         $blocks = [];
  67.         foreach ($locationSearchResults->searchHits as $hit) {
  68.             $blocks[] = $this->contentService->loadContent($hit->valueObject->contentId);
  69.         }
  70.         return $blocks;
  71.     }
  72.     /**
  73.      * Busca los bloques dentro de la carpeta bloques del locationid recibido con tipo de bloque especificado
  74.      *
  75.      * @param integer $locationId
  76.      * @param string $renderer
  77.      * @param bool $container
  78.      * @return array
  79.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  80.      * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
  81.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
  82.      */
  83.     public function loadBlocksByParentLocationAndRenderer(int $locationIdstring $rendererbool $container false)
  84.     {
  85.         $parameters = ['locationId' => $locationId'container' => $container];
  86.         $locationQuery $this->blockQueryType->getQueryByRenderer($renderer$parameters);
  87.         $locationSearchResults $this->searchService->findLocations($locationQuery);
  88.         $blocks = [];
  89.         foreach ($locationSearchResults->searchHits as $hit) {
  90.             $content $this->contentService->loadContent($hit->valueObject->contentId);
  91.             $blocks[] = $content;
  92.         }
  93.         return $blocks;
  94.     }
  95. }