src/V4/Model/ProductAttribute/ProductAttribute.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\V4\Model\ProductAttribute;
  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\Traits\ImportableObjectTrait;
  8. use App\Model\Traits\TimestampableTrait;
  9. use App\V4\Model\ProductConfiguration\ProductConfiguration;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. /**
  15.  * @ApiResource(
  16.  *     shortName="V4/ProductAttribute",
  17.  *     attributes={
  18.  *         "api_allow_update": true
  19.  *     },
  20.  *     collectionOperations={
  21.  *        "get": {
  22.  *             "path": "/V4/product_attributes",
  23.  *             "normalization_context": {
  24.  *                  "groups": {"product_attribute:list"},
  25.  *                  "isFromAdmin": true
  26.  *             }
  27.  *         },
  28.  *         "post_tab": {
  29.  *             "method": "POST",
  30.  *             "deserialize": false,
  31.  *             "write": false,
  32.  *             "controller": "App\V4\Controller\ProductAttribute\ProductAttributeDataPersisterAction",
  33.  *             "path": "/V4/product_attributes",
  34.  *             "input_formats": {
  35.  *                 "multipart": {"multipart/form-data"}
  36.  *             },
  37.  *             "normalization_context": {
  38.  *                  "groups": {"product_attribute:read"}
  39.  *             },
  40.  *             "denormalization_context": {
  41.  *                  "groups": {}
  42.  *             }
  43.  *         },
  44.  *         "get_form": {
  45.  *             "method": "GET",
  46.  *             "path": "/V4/product_attributes/form",
  47.  *             "controller": App\V4\Controller\ProductAttribute\GetProductAttributeFormAction::class
  48.  *         },
  49.  *     },
  50.  *     itemOperations={
  51.  *        "get": {
  52.  *             "path": "/V4/product_attributes/{id}",
  53.  *             "normalization_context": {
  54.  *                 "groups": {"product_attribute:read"}
  55.  *             }
  56.  *         },
  57.  *         "get_form": {
  58.  *             "method": "GET",
  59.  *             "path": "/V4/product_attributes/{id}/form",
  60.  *             "controller": App\V4\Controller\ProductAttribute\GetProductAttributeFormAction::class,
  61.  *             "normalization_context": {
  62.  *                  "isFromAdmin": true
  63.  *             },
  64.  *         },
  65.  *         "put_product_attribute": {
  66.  *             "method": "POST",
  67.  *             "deserialize": false,
  68.  *             "write": false,
  69.  *             "controller": "App\V4\Controller\ProductAttribute\ProductAttributeDataPersisterAction",
  70.  *             "path": "/V4/product_attributes/{id}",
  71.  *             "input_formats": {
  72.  *                 "multipart": {"multipart/form-data"}
  73.  *             },
  74.  *             "normalization_context": {
  75.  *                  "groups": {"product_attribute:read"}
  76.  *             },
  77.  *             "denormalization_context": {
  78.  *                  "groups": {}
  79.  *             }
  80.  *         },
  81.  *         "delete_product_attribute": {
  82.  *             "method": "DELETE",
  83.  *             "deserialize": false,
  84.  *             "write": false,
  85.  *             "controller": "App\V4\Controller\ProductAttribute\ProductAttributeDataPersisterAction",
  86.  *             "path": "/V4/product_attributes/{id}",
  87.  *             "normalization_context": {
  88.  *                  "isFromAdmin": true
  89.  *             },
  90.  *         }
  91.  *     }
  92.  * )
  93.  */
  94. class ProductAttribute implements IriNormalizableInterface
  95. {
  96.     use TimestampableTrait;
  97.     use ImportableObjectTrait;
  98.     use NormalizeAsIRITrait;
  99.     const TYPE_PROSPECT 'prospect';
  100.     const TYPE_STRING 'string';
  101.     const TYPE_INTEGER 'integer';
  102.     const TYPE_BOOLEAN 'boolean';
  103.     /**
  104.      * @ApiProperty(identifier=true)
  105.      *
  106.      * @var string|null
  107.      *
  108.      * @Groups({
  109.      *     "list",
  110.      *     "product_attribute:list", "product_attribute:read",
  111.      *     "product_configuration:list", "product_configuration:read"
  112.      * })
  113.      */
  114.     private $id;
  115.     /**
  116.      * @var string|null
  117.      *
  118.      * @Groups({
  119.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write"
  120.      * })
  121.      */
  122.     private $customerId;
  123.     /**
  124.      * @var string
  125.      *
  126.      * @Groups({
  127.      *     "list",
  128.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write", "product_attribute:update",
  129.      *     "product_configuration:list", "product_configuration:read"
  130.      * })
  131.      */
  132.     private $label;
  133.     /**
  134.      * @var string
  135.      *
  136.      * @Groups({
  137.      *     "list",
  138.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write", "product_attribute:update"
  139.      * })
  140.      */
  141.     private $type;
  142.     /**
  143.      * @MaxDepth(1)
  144.      *
  145.      * @var ProductConfiguration[]|Collection
  146.      *
  147.      * @Groups({
  148.      *     "product_attribute:list", "product_attribute:read"
  149.      * })
  150.      */
  151.     private $productConfigurations;
  152.     /**
  153.      * @var string|null
  154.      *
  155.      * @Groups({
  156.      *     "list",
  157.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write", "product_attribute:update"
  158.      * })
  159.      */
  160.     private $groupCode;
  161.     /**
  162.      * @var int
  163.      *
  164.      * @Groups({
  165.      *     "list",
  166.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write", "product_attribute:update"
  167.      * })
  168.      */
  169.     private $position;
  170.     /**
  171.      * @var string|null
  172.      *
  173.      * @Groups({
  174.      *     "list",
  175.      *     "product_attribute:list", "product_attribute:read", "product_attribute:write", "product_attribute:update"
  176.      * })
  177.      */
  178.     private $defaultValueField;
  179.     public function __construct()
  180.     {
  181.         $this->productConfigurations = new ArrayCollection();
  182.     }
  183.     /**
  184.      * @return string|null
  185.      */
  186.     public function getId(): ?string
  187.     {
  188.         return $this->id;
  189.     }
  190.     /**
  191.      * @param string|null $id
  192.      *
  193.      * @return $this
  194.      */
  195.     public function setId(?string $id): self
  196.     {
  197.         $this->id $id;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return string|null
  202.      */
  203.     public function getCustomerId(): ?string
  204.     {
  205.         return $this->customerId;
  206.     }
  207.     /**
  208.      * @param string|null $customerId
  209.      *
  210.      * @return $this
  211.      */
  212.     public function setCustomerId(?string $customerId): self
  213.     {
  214.         $this->customerId $customerId;
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return string|null
  219.      */
  220.     public function getLabel(): ?string
  221.     {
  222.         return $this->label;
  223.     }
  224.     /**
  225.      * @param string $label
  226.      *
  227.      * @return $this
  228.      */
  229.     public function setLabel(string $label): self
  230.     {
  231.         $this->label $label;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return string|null
  236.      */
  237.     public function getType(): ?string
  238.     {
  239.         return $this->type;
  240.     }
  241.     /**
  242.      * @param string $type
  243.      *
  244.      * @return $this
  245.      */
  246.     public function setType(string $type): self
  247.     {
  248.         $this->type $type;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection|ProductConfiguration[]
  253.      */
  254.     public function getProductConfigurations(): Collection
  255.     {
  256.         return $this->productConfigurations;
  257.     }
  258.     /**
  259.      * @param Collection|ProductConfiguration[] $productConfigurations
  260.      *
  261.      * @return $this
  262.      */
  263.     public function setProductConfigurations(Collection $productConfigurations): self
  264.     {
  265.         $this->productConfigurations $productConfigurations;
  266.         return $this;
  267.     }
  268.     /**
  269.      * @param ProductConfiguration $productConfiguration
  270.      *
  271.      * @return $this
  272.      */
  273.     public function addProductConfiguration(ProductConfiguration $productConfiguration): self
  274.     {
  275.         if (!$this->productConfigurations->contains($productConfiguration)) {
  276.             $this->productConfigurations[] = $productConfiguration;
  277.             $productConfiguration->addProductAttribute($this);
  278.         }
  279.         return $this;
  280.     }
  281.     /**
  282.      * @param ProductConfiguration $productConfiguration
  283.      *
  284.      * @return $this
  285.      */
  286.     public function removeProductConfiguration(ProductConfiguration $productConfiguration): self
  287.     {
  288.         if ($this->productConfigurations->contains($productConfiguration)) {
  289.             $this->productConfigurations->removeElement($productConfiguration);
  290.             $productConfiguration->removeProductAttribute($this);
  291.         }
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return string|null
  296.      */
  297.     public function getGroupCode(): ?string
  298.     {
  299.         return $this->groupCode;
  300.     }
  301.     /**
  302.      * @param string|null $groupCode
  303.      *
  304.      * @return ProductAttribute
  305.      */
  306.     public function setGroupCode(?string $groupCode): self
  307.     {
  308.         $this->groupCode $groupCode;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return int|null
  313.      */
  314.     public function getPosition(): ?int
  315.     {
  316.         return $this->position;
  317.     }
  318.     /**
  319.      * @param int $position
  320.      *
  321.      * @return ProductAttribute
  322.      */
  323.     public function setPosition(int $position): self
  324.     {
  325.         $this->position $position;
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return string|null
  330.      */
  331.     public function getDefaultValueField(): ?string
  332.     {
  333.         return $this->defaultValueField;
  334.     }
  335.     /**
  336.      * @param string|null $defaultValueField
  337.      *
  338.      * @return $this
  339.      */
  340.     public function setDefaultValueField(?string $defaultValueField): self
  341.     {
  342.         $this->defaultValueField $defaultValueField;
  343.         return $this;
  344.     }
  345. }