src/V4/Model/ProductConfiguration/ProductConfiguration.php line 98

Open in your IDE?
  1. <?php
  2. namespace App\V4\Model\ProductConfiguration;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Model\IriNormalizableInterface;
  6. use App\Model\NormalizeAsIRITrait;
  7. use App\Model\Product\Product;
  8. use App\Model\Traits\ImportableObjectTrait;
  9. use App\Model\Traits\TimestampableTrait;
  10. use App\V4\Model\ProductAttribute\ProductAttribute;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Serializer\Annotation\MaxDepth;
  15. /**
  16.  * @ApiResource(
  17.  *     shortName="V4/ProductConfiguration",
  18.  *     attributes={
  19.  *         "api_allow_update": true
  20.  *     },
  21.  *     collectionOperations={
  22.  *        "get": {
  23.  *             "path": "/V4/product_configurations",
  24.  *             "normalization_context": {
  25.  *                  "groups": {"product_configuration:list"},
  26.  *                  "isFromAdmin": true
  27.  *             }
  28.  *         },
  29.  *         "post_tab": {
  30.  *             "method": "POST",
  31.  *             "deserialize": false,
  32.  *             "write": false,
  33.  *             "controller": "App\V4\Controller\ProductConfiguration\ProductConfigurationDataPersisterAction",
  34.  *             "path": "/V4/product_configurations",
  35.  *             "input_formats": {
  36.  *                 "multipart": {"multipart/form-data"}
  37.  *             },
  38.  *             "normalization_context": {
  39.  *                  "groups": {"product_configuration:read"}
  40.  *             },
  41.  *             "denormalization_context": {
  42.  *                  "groups": {}
  43.  *             }
  44.  *         },
  45.  *         "get_form": {
  46.  *             "method": "GET",
  47.  *             "path": "/V4/product_configurations/form",
  48.  *             "controller": App\V4\Controller\ProductConfiguration\GetProductConfigurationFormAction::class
  49.  *         },
  50.  *     },
  51.  *     itemOperations={
  52.  *        "get": {
  53.  *             "path": "/V4/product_configurations/{id}",
  54.  *             "normalization_context": {
  55.  *                 "groups": {"product_configuration:read"}
  56.  *             }
  57.  *         },
  58.  *         "get_form": {
  59.  *             "method": "GET",
  60.  *             "path": "/V4/product_configurations/{id}/form",
  61.  *             "controller": App\V4\Controller\ProductConfiguration\GetProductConfigurationFormAction::class,
  62.  *             "normalization_context": {
  63.  *                  "isFromAdmin": true
  64.  *             },
  65.  *         },
  66.  *         "put_product_configuration": {
  67.  *             "method": "POST",
  68.  *             "deserialize": false,
  69.  *             "write": false,
  70.  *             "controller": "App\V4\Controller\ProductConfiguration\ProductConfigurationDataPersisterAction",
  71.  *             "path": "/V4/product_configurations/{id}",
  72.  *             "input_formats": {
  73.  *                 "multipart": {"multipart/form-data"}
  74.  *             },
  75.  *             "normalization_context": {
  76.  *                  "groups": {"product_configuration:read"}
  77.  *             },
  78.  *             "denormalization_context": {
  79.  *                  "groups": {}
  80.  *             }
  81.  *         },
  82.  *         "delete_product_configuration": {
  83.  *             "method": "DELETE",
  84.  *             "deserialize": false,
  85.  *             "write": false,
  86.  *             "controller": "App\V4\Controller\ProductConfiguration\ProductConfigurationDataPersisterAction",
  87.  *             "path": "/V4/product_configurations/{id}",
  88.  *             "normalization_context": {
  89.  *                  "isFromAdmin": true
  90.  *             },
  91.  *         }
  92.  *     }
  93.  * )
  94.  */
  95. class ProductConfiguration implements IriNormalizableInterface
  96. {
  97.     use TimestampableTrait;
  98.     use ImportableObjectTrait;
  99.     use NormalizeAsIRITrait;
  100.     /**
  101.      * @ApiProperty(identifier=true)
  102.      *
  103.      * @var string|null
  104.      *
  105.      * @Groups({
  106.      *     "list",
  107.      *     "product_configuration:list", "product_configuration:read",
  108.      *     "product_attribute:list", "product_attribute:read",
  109.      *     "product:list", "product:read"
  110.      * })
  111.      */
  112.     private $id;
  113.     /**
  114.      * @var string|null
  115.      *
  116.      * @Groups({
  117.      *     "product_configuration:list", "product_configuration:read", "product_configuration:write"
  118.      * })
  119.      */
  120.     private $customerId;
  121.     /**
  122.      * @var string
  123.      *
  124.      * @Groups({
  125.      *     "list",
  126.      *     "product_configuration:list", "product_configuration:read", "product_configuration:write", "product_configuration:update",
  127.      *     "product_attribute:list", "product_attribute:read",
  128.      *     "product:list", "product:read"
  129.      * })
  130.      */
  131.     private $label;
  132.     /**
  133.      * @MaxDepth(1)
  134.      *
  135.      * @var ProductAttribute[]|Collection
  136.      *
  137.      * @Groups({
  138.      *     "list",
  139.      *     "product_configuration:list", "product_configuration:read", "product_configuration:write", "product_configuration:update"
  140.      * })
  141.      */
  142.     private $productAttributes;
  143.     /**
  144.      * @var Product[]|Collection
  145.      */
  146.     private $products;
  147.     public function __construct()
  148.     {
  149.         $this->productAttributes = new ArrayCollection();
  150.         $this->products = new ArrayCollection();
  151.     }
  152.     /**
  153.      * @return string|null
  154.      */
  155.     public function getId(): ?string
  156.     {
  157.         return $this->id;
  158.     }
  159.     /**
  160.      * @param string $id
  161.      *
  162.      * @return $this
  163.      */
  164.     public function setId(string $id): self
  165.     {
  166.         $this->id $id;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return string|null
  171.      */
  172.     public function getCustomerId(): ?string
  173.     {
  174.         return $this->customerId;
  175.     }
  176.     /**
  177.      * @param string|null $customerId
  178.      *
  179.      * @return $this
  180.      */
  181.     public function setCustomerId(?string $customerId): self
  182.     {
  183.         $this->customerId $customerId;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return string|null
  188.      */
  189.     public function getLabel(): ?string
  190.     {
  191.         return $this->label;
  192.     }
  193.     /**
  194.      * @param string $label
  195.      *
  196.      * @return $this
  197.      */
  198.     public function setLabel(string $label): self
  199.     {
  200.         $this->label $label;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection|ProductAttribute[]
  205.      */
  206.     public function getProductAttributes(): Collection
  207.     {
  208.         return $this->productAttributes;
  209.     }
  210.     /**
  211.      * @param Collection|ProductAttribute[] $productAttributes
  212.      *
  213.      * @return $this
  214.      */
  215.     public function setProductAttributes(Collection $productAttributes): self
  216.     {
  217.         $this->productAttributes $productAttributes;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @param ProductAttribute $productAttribute
  222.      *
  223.      * @return $this
  224.      */
  225.     public function addProductAttribute(ProductAttribute $productAttribute): self
  226.     {
  227.         if (!$this->productAttributes->contains($productAttribute)) {
  228.             $this->productAttributes[] = $productAttribute;
  229.             $productAttribute->addProductConfiguration($this);
  230.         }
  231.         return $this;
  232.     }
  233.     /**
  234.      * @param ProductAttribute $productAttribute
  235.      *
  236.      * @return $this
  237.      */
  238.     public function removeProductAttribute(ProductAttribute $productAttribute): self
  239.     {
  240.         if ($this->productAttributes->contains($productAttribute)) {
  241.             $this->productAttributes->removeElement($productAttribute);
  242.             $productAttribute->removeProductConfiguration($this);
  243.         }
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return Product[]|Collection
  248.      */
  249.     public function getProducts()
  250.     {
  251.         return $this->products;
  252.     }
  253.     /**
  254.      * @param Product[]|Collection $products
  255.      *
  256.      * @return $this
  257.      */
  258.     public function setProducts(Collection $products): self
  259.     {
  260.         $this->products $products;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @param Product $product
  265.      *
  266.      * @return $this
  267.      */
  268.     public function addProduct(Product $product): self
  269.     {
  270.         if (!$this->products->contains($product)) {
  271.             $this->products[] = $product;
  272.         }
  273.         return $this;
  274.     }
  275.     /**
  276.      * @param Product $product
  277.      *
  278.      * @return $this
  279.      */
  280.     public function removeProduct(Product $product): self
  281.     {
  282.         if ($this->products->contains($product)) {
  283.             $this->products->removeElement($product);
  284.         }
  285.         return $this;
  286.     }
  287. }