src/Entity/CustomerProduct.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerProductRepository;
  4. use App\Traits\DateTrait;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use JMS\Serializer\Annotation\Expose;
  9. use JMS\Serializer\Annotation\Groups;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass=CustomerProductRepository::class)
  15.  * @ORM\HasLifecycleCallbacks()
  16.  *
  17.  * @Vich\Uploadable
  18.  * @Serializer\ExclusionPolicy("ALL")
  19.  */
  20. class CustomerProduct
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      *
  27.      * @Expose()
  28.      * @Groups({"id"})
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      *
  34.      * @Expose()
  35.      * @Groups({"name"})
  36.      */
  37.     private $name;
  38.     /**
  39.      * @ORM\Column(type="text", nullable=true)
  40.      */
  41.     private $description;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      *
  45.      * @Expose()
  46.      * @Serializer\Groups({"image"})
  47.      */
  48.     private $image;
  49.     // Vich Uploader
  50.     /**
  51.      * @Vich\UploadableField(mapping="customer_product_images", fileNameProperty="image")
  52.      * @var File
  53.      */
  54.     private $imageFile;
  55.     /**
  56.      * @ORM\Column(type="float", nullable=true)
  57.      */
  58.     private $price;
  59.     /**
  60.      * @ORM\Column(type="text", nullable=true)
  61.      */
  62.     private $categoryValues;
  63.     /**
  64.      * @ORM\Column(type="string", length=128, nullable=true)
  65.      *
  66.      * @Expose()
  67.      * @Serializer\Groups({"category"})
  68.      */
  69.     private $category;
  70.     /**
  71.      * @ORM\Column(type="boolean")
  72.      *
  73.      * @Expose()
  74.      * @Serializer\Groups({"enabled"})
  75.      */
  76.     private $enabled;
  77.     use DateTrait;
  78.     /**
  79.      * @Serializer\VirtualProperty()
  80.      * @Serializer\SerializedName("array_category_values")
  81.      *
  82.      * @Expose()
  83.      * @Groups({"array_category_values"})
  84.      * @return mixed
  85.      */
  86.     public function getArrayCategoryValues()
  87.     {
  88.         return json_decode($this->categoryValuesTRUE) ?? [];
  89.     }
  90.     /**
  91.      * @param string $slug
  92.      * @param int $value
  93.      * @return $this
  94.      */
  95.     public function modifyValueToCategory(string $slugint $value): self
  96.     {
  97.         $newArray $this->getArrayCategoryValues();
  98.         $newArray[$slug] = $value;
  99.         $this->categoryValues json_encode($newArray);
  100.         return $this;
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getName(): ?string
  107.     {
  108.         return $this->name;
  109.     }
  110.     public function setName(string $name): self
  111.     {
  112.         $this->name $name;
  113.         return $this;
  114.     }
  115.     public function getDescription(): ?string
  116.     {
  117.         return $this->description;
  118.     }
  119.     public function setDescription(?string $description): self
  120.     {
  121.         $this->description $description;
  122.         return $this;
  123.     }
  124.     public function getImage(): ?string
  125.     {
  126.         return $this->image;
  127.     }
  128.     public function setImage(?string $image): self
  129.     {
  130.         $this->image $image;
  131.         return $this;
  132.     }
  133.     public function getImageFile()
  134.     {
  135.         return $this->imageFile;
  136.     }
  137.     /**
  138.      * @param File|UploadedFile|null $imageFile
  139.      */
  140.     public function setImageFileFile $imageFile ): void
  141.     {
  142.         $this->imageFile $imageFile;
  143.         if ( NULL !== $imageFile ) {
  144.             // It is required that at least one field changes if you are using doctrine
  145.             // otherwise the event listeners won't be called and the file is lost
  146.             $this->updatedAt = new DateTime();
  147.         }
  148.     }
  149.     public function getPrice(): ?float
  150.     {
  151.         return $this->price;
  152.     }
  153.     public function setPrice(?float $price): self
  154.     {
  155.         $this->price $price;
  156.         return $this;
  157.     }
  158.     public function getCategory(): ?string
  159.     {
  160.         return $this->category;
  161.     }
  162.     public function setCategory(?string $category): self
  163.     {
  164.         $this->category $category;
  165.         return $this;
  166.     }
  167.     public function getCategoryValues()
  168.     {
  169.         return $this->categoryValues;
  170.     }
  171.     public function setCategoryValues($categoryValues)
  172.     {
  173.         $this->categoryValues $categoryValues;
  174.         return $this;
  175.     }
  176.     /**
  177.      * @return mixed
  178.      */
  179.     public function getEnabled()
  180.     {
  181.         return $this->enabled;
  182.     }
  183.     /**
  184.      * @param mixed $enabled
  185.      * @return CustomerProduct
  186.      */
  187.     public function setEnabled($enabled)
  188.     {
  189.         $this->enabled $enabled;
  190.         return $this;
  191.     }
  192. }