public function getImageAction($entityId, $imageId)
 {
     $request = $this->getRequest();
     $entity = $request->attributes->get('entity');
     $this->checkAuth($this->getAdminResources()->getResource($entity), [], AccessManager::VIEW);
     $this->checkEntityExists($entity, $entityId);
     $params = array_merge($request->query->all(), ['source' => strtolower($entity), 'source_id' => $entityId, 'id' => $imageId]);
     $imageLoop = new Image($this->getContainer());
     $imageLoop->initializeArgs($params);
     $results = $imageLoop->exec($paginate);
     if ($results->isEmpty()) {
         return JsonResponse::create(array('error' => sprintf('image with id %d not found', $imageId)), 404);
     }
     return JsonResponse::create($results);
 }
 /**
  * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
  */
 protected function getArgDefinitions()
 {
     $imageCollection = parent::getArgDefinitions();
     $collection = new ArgumentCollection();
     foreach ($imageCollection as $argument) {
         if (!in_array($argument->name, $this->possible_sources) and $argument->name != 'source') {
             $collection->addArgument($argument);
         }
     }
     return $collection;
 }
Example #3
0
 protected function getPSEImages(ProductSaleElementsModel $pse)
 {
     /**
      * Compute images with the associated loop
      */
     $imageLoop = new Image($this->container);
     $imageLoop->initializeArgs(["product" => $pse->getProductId(), "width" => 100, "height" => 75, "resize_mode" => "borders"]);
     $images = $imageLoop->exec($imagePagination);
     $imageAssoc = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElementsId($pse->getId())->find()->toArray();
     $data = [];
     /** @var \Thelia\Core\Template\Element\LoopResultRow $image */
     for ($images->rewind(); $images->valid(); $images->next()) {
         $image = $images->current();
         $isAssociated = $this->arrayHasEntries($imageAssoc, ["ProductImageId" => $image->get("ID"), "ProductSaleElementsId" => $pse->getId()]);
         $data[] = ["id" => $image->get("ID"), "url" => $image->get("IMAGE_URL"), "title" => $image->get("TITLE"), "is_associated" => $isAssociated, "filename" => $image->model->getFile()];
     }
     return $data;
 }