classes/XLite/Model/Image/Product/Image.php line 110

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model\Image\Product;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\ProductImage\DTO\ProductImageInput;
  10. use XLite\API\Endpoint\ProductImage\DTO\ProductImageOutput;
  11. use XLite\API\Endpoint\ProductImage\DTO\ProductImageUpdateInput;
  12. use XLite\Controller\API\ProductImage\DeleteProductImage;
  13. /**
  14.  * Product image
  15.  *
  16.  * @ORM\Entity
  17.  * @ORM\Table  (name="product_images")
  18.  * @ApiPlatform\ApiResource(
  19.  *     shortName="Product Image",
  20.  *     output=ProductImageOutput::class,
  21.  *     itemOperations={
  22.  *         "get"={
  23.  *             "method"="GET",
  24.  *             "path"="/products/{product_id}/images/{image_id}.{_format}",
  25.  *             "identifiers"={"product_id", "image_id"},
  26.  *             "requirements"={"product_id"="\d+", "image_id"="\d+"},
  27.  *             "openapi_context"={
  28.  *                  "summary"="Retrieve an image from a product",
  29.  *                  "parameters"={
  30.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  31.  *                      {"name"="image_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  32.  *                  },
  33.  *             },
  34.  *          },
  35.  *         "put"={
  36.  *             "method"="PUT",
  37.  *             "input"=ProductImageUpdateInput::class,
  38.  *             "path"="/products/{product_id}/images/{image_id}.{_format}",
  39.  *             "identifiers"={"product_id", "image_id"},
  40.  *             "requirements"={"product_id"="\d+", "image_id"="\d+"},
  41.  *             "read"=false,
  42.  *             "openapi_context"={
  43.  *                  "summary"="Update the properties of a product image",
  44.  *                  "parameters"={
  45.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  46.  *                      {"name"="image_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  47.  *                  },
  48.  *             },
  49.  *         },
  50.  *         "delete"={
  51.  *             "method"="DELETE",
  52.  *             "path"="/products/{product_id}/images/{image_id}.{_format}",
  53.  *             "identifiers"={"product_id", "image_id"},
  54.  *             "requirements"={"product_id"="\d+", "image_id"="\d+"},
  55.  *             "controller"=DeleteProductImage::class,
  56.  *             "read"=false,
  57.  *             "openapi_context"={
  58.  *                  "summary"="Delete an image from a product",
  59.  *                  "parameters"={
  60.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  61.  *                      {"name"="image_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  62.  *                  },
  63.  *             },
  64.  *         },
  65.  *     },
  66.  *     collectionOperations={
  67.  *         "post"={
  68.  *             "method"="POST",
  69.  *             "input"=ProductImageInput::class,
  70.  *             "path"="/products/{product_id}/images.{_format}",
  71.  *             "identifiers"={"product_id", "image_id"},
  72.  *             "requirements"={"product_id"="\d+"},
  73.  *             "openapi_context"={
  74.  *                  "summary"="Add an image to a product",
  75.  *                  "parameters"={
  76.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  77.  *                  },
  78.  *                  "requestBody"={
  79.  *                      "content"={
  80.  *                          "application/json"={
  81.  *                              "schema"={
  82.  *                                  "type"="object",
  83.  *                                  "properties"={
  84.  *                                      "position"={
  85.  *                                          "type"="integer"
  86.  *                                      },
  87.  *                                      "alt"={
  88.  *                                          "type"="string",
  89.  *                                          "description"="Alt text"
  90.  *                                      },
  91.  *                                      "externalUrl"={
  92.  *                                          "type"="string",
  93.  *                                          "description"="URL to the image file which will be downloaded from there"
  94.  *                                      },
  95.  *                                      "attachment"={
  96.  *                                          "type"="string",
  97.  *                                          "description"="base64-encoded image"
  98.  *                                      },
  99.  *                                      "filename"={
  100.  *                                          "type"="string",
  101.  *                                          "description"="Image name with correct extension. Required for 'attachement' field."
  102.  *                                      },
  103.  *                                  },
  104.  *                              },
  105.  *                          },
  106.  *                      },
  107.  *                  },
  108.  *              },
  109.  *          }
  110.  *     }
  111.  * )
  112.  */
  113. class Image extends \XLite\Model\Base\Image
  114. {
  115.     /**
  116.      * Image position
  117.      *
  118.      * @var integer
  119.      *
  120.      * @ORM\Column (type="integer")
  121.      */
  122.     protected $orderby 0;
  123.     /**
  124.      * Relation to a product entity
  125.      *
  126.      * @var \XLite\Model\Product
  127.      *
  128.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="images")
  129.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  130.      */
  131.     protected $product;
  132.     /**
  133.      * Alternative image text
  134.      *
  135.      * @var string
  136.      *
  137.      * @ORM\Column (type="string", length=255)
  138.      */
  139.     protected $alt '';
  140.     /**
  141.      * Set orderby
  142.      *
  143.      * @param integer $orderby
  144.      * @return Image
  145.      */
  146.     public function setOrderby($orderby)
  147.     {
  148.         $this->orderby $orderby;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get orderby
  153.      *
  154.      * @return integer
  155.      */
  156.     public function getOrderby()
  157.     {
  158.         return $this->orderby;
  159.     }
  160.     /**
  161.      * Set alt
  162.      *
  163.      * @param string $alt
  164.      * @return Image
  165.      */
  166.     public function setAlt($alt)
  167.     {
  168.         $this->alt $alt;
  169.         return $this;
  170.     }
  171.     /**
  172.      * Get alt
  173.      *
  174.      * @return string
  175.      */
  176.     public function getAlt()
  177.     {
  178.         return $this->alt;
  179.     }
  180.     /**
  181.      * Set product
  182.      *
  183.      * @param \XLite\Model\Product $product
  184.      * @return Image
  185.      */
  186.     public function setProduct(\XLite\Model\Product $product null)
  187.     {
  188.         $this->product $product;
  189.         return $this;
  190.     }
  191.     /**
  192.      * Get product
  193.      *
  194.      * @return \XLite\Model\Product
  195.      */
  196.     public function getProduct()
  197.     {
  198.         return $this->product;
  199.     }
  200. }