src/Entity/PurchaseProduct.php line 20

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\PurchaseProductRepository;
  4.     use App\Traits\DateTrait;
  5.     use Doctrine\Common\Collections\ArrayCollection;
  6.     use Doctrine\Common\Collections\Collection;
  7.     use Doctrine\ORM\Mapping as ORM;
  8.     use JMS\Serializer\Annotation as Serializer;
  9.     use JMS\Serializer\Annotation\Expose;
  10.     use JMS\Serializer\Annotation\Groups;
  11.     /**
  12.      * @ORM\Entity(repositoryClass=PurchaseProductRepository::class)
  13.      * @ORM\HasLifecycleCallbacks()
  14.      *
  15.      * @Serializer\ExclusionPolicy("ALL")
  16.      */
  17.     class PurchaseProduct
  18.     {
  19.         /**
  20.          * @ORM\Id
  21.          * @ORM\GeneratedValue
  22.          * @ORM\Column(type="integer")
  23.          *
  24.          * @Expose
  25.          * @Groups({"purchaseProducts", "purchase_product_list", "export_purchase_product_datatable"})
  26.          */
  27.         private $id;
  28.         /**
  29.          * @ORM\Column(type="string", length=255)
  30.          *
  31.          * @Expose
  32.          * @Groups({"purchaseProducts", "purchase_product_list", "export_purchase_product_datatable"})
  33.          */
  34.         private $reference;
  35.         /**
  36.          * Désignation
  37.          *
  38.          * @ORM\Column(type="string", length=255)
  39.          *
  40.          * @Expose
  41.          * @Groups({"purchaseProducts", "purchase_product_list", "export_purchase_product_datatable"})
  42.          */
  43.         private $name;
  44.         /**
  45.          * "Catégorie" de produit (chaudière murale, chaudière sol etc)
  46.          *
  47.          * @ORM\Column(type="string", length=255)
  48.          *
  49.          * @Expose
  50.          * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  51.          */
  52.         private $type;
  53.         /**
  54.          * Valeur en points
  55.          *
  56.          * @ORM\Column(type="integer", nullable=true)
  57.          *
  58.          * @Expose
  59.          * @Groups({"purchaseProducts", "purchase_product_list", "export_purchase_product_datatable"})
  60.          */
  61.         private $value;
  62.         /**
  63.          * "Hiérarchie" de produit (chaudière murale, chaudière sol etc)
  64.          *
  65.          * @ORM\Column(type="string", length=255)
  66.          *
  67.          * @Expose
  68.          * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  69.          */
  70.         private $hierarchie;
  71.         /**
  72.          * @ORM\OneToMany(targetEntity=PurchaseProductItem::class, mappedBy="product")
  73.          *
  74.          * @Expose
  75.          * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  76.          */
  77.         private $purchaseItems;
  78.         /**
  79.          * Activation référence produit
  80.          * @ORM\Column(type="boolean", nullable=true, options={"default":"0"})
  81.          *
  82.          * @Expose
  83.          * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  84.          */
  85.         private $enabled;
  86.         /**
  87.          * @ORM\ManyToMany(targetEntity=PointTransactionBooster::class, mappedBy="purchaseProducts")
  88.          */
  89.         private $pointTransactionBoosters;
  90.         /**
  91.          * @ORM\Column(type="text", nullable=true)
  92.          */
  93.         private $categoryValues;
  94.         use DateTrait;
  95.         public function __construct()
  96.         {
  97.             $this->purchaseItems            = new ArrayCollection();
  98.             $this->pointTransactionBoosters = new ArrayCollection();
  99.         }
  100.         public function __toString()
  101.         {
  102.             return $this->name;
  103.         }
  104.         /**
  105.          * @return string
  106.          * @Serializer\VirtualProperty()
  107.          * @Serializer\SerializedName("ref_name")
  108.          *
  109.          * @Expose()
  110.          * @Groups({"export_purchase_declaration_datatable"})
  111.          */
  112.         public function getRefName(): string
  113.         {
  114.             return $this->reference ' - ' $this->name;
  115.         }
  116.         /**
  117.          * @Serializer\VirtualProperty()
  118.          * @Serializer\SerializedName("array_category_values")
  119.          *
  120.          * @Expose()
  121.          * @Groups({"purchase_product_list"})
  122.          * @return mixed
  123.          */
  124.         public function getArrayCategoryValues()
  125.         {
  126.             return json_decode$this->categoryValuesTRUE ) ?? [];
  127.         }
  128.         public function modifyValueToCategorystring $slugint $value ): self
  129.         {
  130.             $newArray             $this->getArrayCategoryValues();
  131.             $newArray$slug ]    = $value;
  132.             $this->categoryValues json_encode$newArray );
  133.             return $this;
  134.         }
  135.         /**
  136.          * @Serializer\VirtualProperty()
  137.          * @Serializer\SerializedName("count_purchase_items")
  138.          *
  139.          * @Expose()
  140.          * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  141.          *
  142.          * @return int
  143.          */
  144.         public function countPurchaseItems()
  145.         {
  146.             return count$this->purchaseItems );
  147.         }
  148.         public function getId(): ?int
  149.         {
  150.             return $this->id;
  151.         }
  152.         public function getReference(): ?string
  153.         {
  154.             return $this->reference;
  155.         }
  156.         public function setReferencestring $reference ): self
  157.         {
  158.             $this->reference $reference;
  159.             return $this;
  160.         }
  161.         public function getName(): ?string
  162.         {
  163.             return $this->name;
  164.         }
  165.         public function setNamestring $name ): self
  166.         {
  167.             $this->name $name;
  168.             return $this;
  169.         }
  170.         public function getType(): ?string
  171.         {
  172.             return $this->type;
  173.         }
  174.         public function setTypestring $type ): self
  175.         {
  176.             $this->type $type;
  177.             return $this;
  178.         }
  179.         public function getValue(): ?int
  180.         {
  181.             return $this->value;
  182.         }
  183.         public function setValueint $value ): self
  184.         {
  185.             $this->value $value;
  186.             return $this;
  187.         }
  188.         public function getHierarchie(): ?string
  189.         {
  190.             return $this->hierarchie;
  191.         }
  192.         public function setHierarchiestring $hierarchie ): self
  193.         {
  194.             $this->hierarchie $hierarchie;
  195.             return $this;
  196.         }
  197.         public function getEnabled(): ?string
  198.         {
  199.             return $this->enabled;
  200.         }
  201.         public function setEnabledstring $enabled ): self
  202.         {
  203.             $this->enabled $enabled;
  204.             return $this;
  205.         }
  206.         /**
  207.          * @return Collection|PurchaseProductItem[]
  208.          */
  209.         public function getPurchaseItems(): Collection
  210.         {
  211.             return $this->purchaseItems;
  212.         }
  213.         public function addPurchaseItemPurchaseProductItem $purchaseItem ): self
  214.         {
  215.             if ( !$this->purchaseItems->contains$purchaseItem ) ) {
  216.                 $this->purchaseItems[] = $purchaseItem;
  217.                 $purchaseItem->setProduct$this );
  218.             }
  219.             return $this;
  220.         }
  221.         public function removePurchaseItemPurchaseProductItem $purchaseItem ): self
  222.         {
  223.             if ( $this->purchaseItems->removeElement$purchaseItem ) ) {
  224.                 // set the owning side to null (unless already changed)
  225.                 if ( $purchaseItem->getProduct() === $this ) {
  226.                     $purchaseItem->setProductNULL );
  227.                 }
  228.             }
  229.             return $this;
  230.         }
  231.         /**
  232.          * @return Collection<int, PointTransactionBooster>
  233.          */
  234.         public function getPointTransactionBoosters(): Collection
  235.         {
  236.             return $this->pointTransactionBoosters;
  237.         }
  238.         public function addPointTransactionBoosterPointTransactionBooster $pointTransactionBooster ): self
  239.         {
  240.             if ( !$this->pointTransactionBoosters->contains$pointTransactionBooster ) ) {
  241.                 $this->pointTransactionBoosters[] = $pointTransactionBooster;
  242.                 $pointTransactionBooster->addPurchaseProduct$this );
  243.             }
  244.             return $this;
  245.         }
  246.         public function removePointTransactionBoosterPointTransactionBooster $pointTransactionBooster ): self
  247.         {
  248.             if ( $this->pointTransactionBoosters->removeElement$pointTransactionBooster ) ) {
  249.                 $pointTransactionBooster->removePurchaseProduct$this );
  250.             }
  251.             return $this;
  252.         }
  253.         public function getCategoryValues(): ?string
  254.         {
  255.             return $this->categoryValues;
  256.         }
  257.         public function setCategoryValues( ?string $categoryValues ): self
  258.         {
  259.             $this->categoryValues $categoryValues;
  260.             return $this;
  261.         }
  262.     }