classes/XLite/Model/Image/Category/Image.php line 90

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\Category;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\CategoryIcon\DTO\CategoryIconInput;
  10. use XLite\API\Endpoint\CategoryIcon\DTO\CategoryIconOutput;
  11. use XLite\Controller\API\CategoryIcon\DeleteCategoryIcon;
  12. /**
  13.  * Category
  14.  *
  15.  * @ORM\Entity
  16.  * @ORM\Table  (name="category_images")
  17.  * @ApiPlatform\ApiResource(
  18.  *     shortName="Category Icon",
  19.  *     output=CategoryIconOutput::class,
  20.  *     itemOperations={
  21.  *         "get"={
  22.  *             "method"="GET",
  23.  *             "path"="/categories/{category_id}/icon.{_format}",
  24.  *             "identifiers"={"category_id"},
  25.  *             "requirements"={"category_id"="\d+"},
  26.  *             "openapi_context"={
  27.  *                  "summary"="Retrieve an icon from a category",
  28.  *                  "parameters"={
  29.  *                      {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  30.  *                  }
  31.  *             },
  32.  *          },
  33.  *         "delete"={
  34.  *             "method"="DELETE",
  35.  *             "path"="/categories/{category_id}/icon.{_format}",
  36.  *             "identifiers"={"category_id"},
  37.  *             "requirements"={"category_id"="\d+"},
  38.  *             "controller"=DeleteCategoryIcon::class,
  39.  *             "read"=false,
  40.  *             "openapi_context"={
  41.  *                  "summary"="Delete an icon from a category",
  42.  *                  "parameters"={
  43.  *                      {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  44.  *                  }
  45.  *             },
  46.  *         },
  47.  *     },
  48.  *     collectionOperations={
  49.  *         "post"={
  50.  *             "method"="POST",
  51.  *             "input"=CategoryIconInput::class,
  52.  *             "output"=CategoryIconOutput::class,
  53.  *             "path"="/categories/{category_id}/icon.{_format}",
  54.  *             "identifiers"={"category_id"},
  55.  *             "requirements"={"category_id"="\d+"},
  56.  *             "openapi_context"={
  57.  *                 "summary"="Add an icon to a category",
  58.  *                 "parameters"={
  59.  *                     {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  60.  *                 },
  61.  *                 "requestBody"={
  62.  *                     "content"={
  63.  *                         "application/json"={
  64.  *                             "schema"={
  65.  *                                 "type"="object",
  66.  *                                 "properties"={
  67.  *                                     "alt"={
  68.  *                                         "type"="string",
  69.  *                                         "description"="Alt text"
  70.  *                                     },
  71.  *                                     "externalUrl"={
  72.  *                                         "type"="string",
  73.  *                                         "description"="URL to the image file which will be downloaded from there"
  74.  *                                     },
  75.  *                                     "attachment"={
  76.  *                                         "type"="string",
  77.  *                                         "description"="base64-encoded image"
  78.  *                                     },
  79.  *                                     "filename"={
  80.  *                                         "type"="string",
  81.  *                                         "description"="Image name with correct extension. Required for 'attachement' field."
  82.  *                                     },
  83.  *                                 },
  84.  *                             },
  85.  *                         },
  86.  *                     },
  87.  *                 },
  88.  *             },
  89.  *         },
  90.  *     }
  91.  * )
  92.  */
  93. class Image extends \XLite\Model\Base\Image
  94. {
  95.     /**
  96.      * Relation to a category entity
  97.      *
  98.      * @var \XLite\Model\Category
  99.      *
  100.      * @ORM\OneToOne   (targetEntity="XLite\Model\Category", inversedBy="image")
  101.      * @ORM\JoinColumn (name="category_id", referencedColumnName="category_id", onDelete="CASCADE")
  102.      */
  103.     protected $category;
  104.     /**
  105.      * Alternative image text
  106.      *
  107.      * @var string
  108.      *
  109.      * @ORM\Column (type="string", length=255)
  110.      */
  111.     protected $alt '';
  112.     /**
  113.      * Set alt
  114.      *
  115.      * @param string $alt
  116.      * @return Image
  117.      */
  118.     public function setAlt($alt)
  119.     {
  120.         $this->alt $alt;
  121.         return $this;
  122.     }
  123.     /**
  124.      * Get alt
  125.      *
  126.      * @return string
  127.      */
  128.     public function getAlt()
  129.     {
  130.         return $this->alt;
  131.     }
  132.     /**
  133.      * Set category
  134.      *
  135.      * @param \XLite\Model\Category $category
  136.      * @return Image
  137.      */
  138.     public function setCategory(\XLite\Model\Category $category null)
  139.     {
  140.         $this->category $category;
  141.         return $this;
  142.     }
  143.     /**
  144.      * Get category
  145.      *
  146.      * @return \XLite\Model\Category
  147.      */
  148.     public function getCategory()
  149.     {
  150.         return $this->category;
  151.     }
  152.     protected function isSvgAllowed(): bool
  153.     {
  154.         return true;
  155.     }
  156. }