コード例 #1
0
ファイル: ProductImage.php プロジェクト: margery/thelia
 /**
  * @param    ProductSaleElements $productSaleElements The productSaleElements object to add.
  */
 protected function doAddProductSaleElements($productSaleElements)
 {
     $productSaleElementsProductImage = new ChildProductSaleElementsProductImage();
     $productSaleElementsProductImage->setProductSaleElements($productSaleElements);
     $this->addProductSaleElementsProductImage($productSaleElementsProductImage);
     // set the back reference to this object directly as using provided method either results
     // in endless loop or in multiple relations
     if (!$productSaleElements->getProductImages()->contains($this)) {
         $foreignCollection = $productSaleElements->getProductImages();
         $foreignCollection[] = $this;
     }
 }
コード例 #2
0
 public function getAssociationResponseData($pseId, $type, $typeId)
 {
     $responseData = [];
     if (null !== ($msg = $this->checkFileType($type))) {
         throw new \Exception($msg);
     }
     $responseData["product_sale_elements_id"] = $pseId;
     $pse = ProductSaleElementsQuery::create()->findPk($pseId);
     if (null === $pse) {
         throw new \Exception($this->getTranslator()->trans("The product sale elements id %id doesn't exists", ["%id" => $pseId]));
     }
     $assoc = null;
     if ($type === "image") {
         $image = ProductImageQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product image id %id doesn't exists", ["%id" => $typeId]));
         }
         $assoc = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElementsId($pseId)->findOneByProductImageId($typeId);
         if (null === $assoc) {
             $assoc = new ProductSaleElementsProductImage();
             $assoc->setProductSaleElementsId($pseId)->setProductImageId($typeId)->save();
         } else {
             $assoc->delete();
         }
         $responseData["product_image_id"] = $typeId;
         $responseData["is-associated"] = (int) (!$assoc->isDeleted());
     } elseif ($type === "document") {
         $image = ProductDocumentQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product document id %id doesn't exists", ["%id" => $pseId]));
         }
         $assoc = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElementsId($pseId)->findOneByProductDocumentId($typeId);
         if (null === $assoc) {
             $assoc = new ProductSaleElementsProductDocument();
             $assoc->setProductSaleElementsId($pseId)->setProductDocumentId($typeId)->save();
         } else {
             $assoc->delete();
         }
         $responseData["product_document_id"] = $typeId;
         $responseData["is-associated"] = (int) (!$assoc->isDeleted());
     } elseif ($type === "virtual") {
         $image = ProductDocumentQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product document id %id doesn't exists", ["%id" => $pseId]));
         }
         $documentId = intval(MetaDataQuery::getVal('virtual', MetaData::PSE_KEY, $pseId));
         if ($documentId === intval($typeId)) {
             $assocEvent = new MetaDataDeleteEvent('virtual', MetaData::PSE_KEY, $pseId);
             $this->dispatch(TheliaEvents::META_DATA_DELETE, $assocEvent);
             $responseData["is-associated"] = 0;
         } else {
             $assocEvent = new MetaDataCreateOrUpdateEvent('virtual', MetaData::PSE_KEY, $pseId, $typeId);
             $this->dispatch(TheliaEvents::META_DATA_UPDATE, $assocEvent);
             $responseData["is-associated"] = 1;
         }
         $responseData["product_document_id"] = $typeId;
     }
     return $responseData;
 }
コード例 #3
0
 /**
  * Exclude object from result
  *
  * @param   ChildProductSaleElementsProductImage $productSaleElementsProductImage Object to remove from the list of results
  *
  * @return ChildProductSaleElementsProductImageQuery The current query, for fluid interface
  */
 public function prune($productSaleElementsProductImage = null)
 {
     if ($productSaleElementsProductImage) {
         $this->addUsingAlias(ProductSaleElementsProductImageTableMap::ID, $productSaleElementsProductImage->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #4
0
 public function clonePSEAssociatedFiles($clonedProductId, $clonedProductPSEId, $originalProductPSEFiles, $type)
 {
     /** @var ProductSaleElementsDocument|ProductSaleElementsImage $originalProductPSEFile */
     foreach ($originalProductPSEFiles as $originalProductPSEFile) {
         $originalProductFilePositionQuery = [];
         $originalProductPSEFileId = null;
         // Get file's original position
         switch ($type) {
             case 'image':
                 $originalProductFilePositionQuery = ProductImageQuery::create();
                 $originalProductPSEFileId = $originalProductPSEFile->getProductImageId();
                 break;
             case 'document':
                 $originalProductFilePositionQuery = ProductDocumentQuery::create();
                 $originalProductPSEFileId = $originalProductPSEFile->getProductDocumentId();
                 break;
         }
         $originalProductFilePosition = $originalProductFilePositionQuery->select(['POSITION'])->findPk($originalProductPSEFileId);
         // Get cloned file ID to link to the cloned PSE
         switch ($type) {
             case 'image':
                 $clonedProductFileIdToLinkToPSEQuery = ProductImageQuery::create();
                 break;
             case 'document':
                 $clonedProductFileIdToLinkToPSEQuery = ProductDocumentQuery::create();
                 break;
         }
         $clonedProductFileIdToLinkToPSE = $clonedProductFileIdToLinkToPSEQuery->filterByProductId($clonedProductId)->filterByPosition($originalProductFilePosition)->select(['ID'])->findOne();
         // Save association
         switch ($type) {
             case 'image':
                 $assoc = new ProductSaleElementsProductImage();
                 $assoc->setProductImageId($clonedProductFileIdToLinkToPSE);
                 break;
             case 'document':
                 $assoc = new ProductSaleElementsProductDocument();
                 $assoc->setProductDocumentId($clonedProductFileIdToLinkToPSE);
                 break;
         }
         $assoc->setProductSaleElementsId($clonedProductPSEId)->save();
     }
 }
コード例 #5
0
 /**
  * Filter the query by a related \Thelia\Model\ProductSaleElementsProductImage object
  *
  * @param \Thelia\Model\ProductSaleElementsProductImage|ObjectCollection $productSaleElementsProductImage  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildProductSaleElementsQuery The current query, for fluid interface
  */
 public function filterByProductSaleElementsProductImage($productSaleElementsProductImage, $comparison = null)
 {
     if ($productSaleElementsProductImage instanceof \Thelia\Model\ProductSaleElementsProductImage) {
         return $this->addUsingAlias(ProductSaleElementsTableMap::ID, $productSaleElementsProductImage->getProductSaleElementsId(), $comparison);
     } elseif ($productSaleElementsProductImage instanceof ObjectCollection) {
         return $this->useProductSaleElementsProductImageQuery()->filterByPrimaryKeys($productSaleElementsProductImage->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByProductSaleElementsProductImage() only accepts arguments of type \\Thelia\\Model\\ProductSaleElementsProductImage or Collection');
     }
 }