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, nullable=true)
  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, nullable=true)
  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="float", 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, nullable=true)
  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. * @Expose
  93. * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  94. */
  95. private ?string $categoryValues;
  96. /**
  97. * Indique la catégorie de point par defaut
  98. *
  99. * @ORM\Column(type="string", nullable=true)
  100. * @Expose
  101. * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  102. */
  103. private ?string $defaultPointCategory = NULL;
  104. use DateTrait;
  105. public function __construct()
  106. {
  107. $this->purchaseItems = new ArrayCollection();
  108. $this->pointTransactionBoosters = new ArrayCollection();
  109. }
  110. public function __toString()
  111. {
  112. return $this->name;
  113. }
  114. /**
  115. * @return string
  116. * @Serializer\VirtualProperty()
  117. * @Serializer\SerializedName("ref_name")
  118. *
  119. * @Expose()
  120. * @Groups({"export_purchase_declaration_datatable"})
  121. */
  122. public function getRefName(): string
  123. {
  124. return $this->reference . ' - ' . $this->name;
  125. }
  126. /**
  127. * @Serializer\VirtualProperty()
  128. * @Serializer\SerializedName("array_category_values")
  129. *
  130. * @Expose()
  131. * @Groups({"purchase_product_list"})
  132. * @return mixed
  133. */
  134. public function getArrayCategoryValues()
  135. {
  136. return json_decode( $this->categoryValues, TRUE ) ?? [];
  137. }
  138. public function modifyValueToCategory( string $slug, int $value ): self
  139. {
  140. $newArray = $this->getArrayCategoryValues();
  141. $newArray[ $slug ] = $value;
  142. $this->categoryValues = json_encode( $newArray );
  143. return $this;
  144. }
  145. /**
  146. * @Serializer\VirtualProperty()
  147. * @Serializer\SerializedName("count_purchase_items")
  148. *
  149. * @Expose()
  150. * @Groups({"purchase_product_list", "export_purchase_product_datatable"})
  151. *
  152. * @return int
  153. */
  154. public function countPurchaseItems()
  155. {
  156. return count( $this->purchaseItems );
  157. }
  158. public function getId(): ?int
  159. {
  160. return $this->id;
  161. }
  162. public function getReference(): ?string
  163. {
  164. return $this->reference;
  165. }
  166. public function setReference( string $reference ): self
  167. {
  168. $this->reference = $reference;
  169. return $this;
  170. }
  171. public function getName(): ?string
  172. {
  173. return $this->name;
  174. }
  175. public function setName( ?string $name ): self
  176. {
  177. $this->name = $name;
  178. return $this;
  179. }
  180. public function getType(): ?string
  181. {
  182. return $this->type;
  183. }
  184. public function setType( ?string $type ): self
  185. {
  186. $this->type = $type;
  187. return $this;
  188. }
  189. public function getValue(): ?float
  190. {
  191. return $this->value;
  192. }
  193. public function setValue( ?float $value ): self
  194. {
  195. $this->value = $value;
  196. return $this;
  197. }
  198. public function getHierarchie(): ?string
  199. {
  200. return $this->hierarchie;
  201. }
  202. public function setHierarchie( ?string $hierarchie ): self
  203. {
  204. $this->hierarchie = $hierarchie;
  205. return $this;
  206. }
  207. public function getEnabled(): ?string
  208. {
  209. return $this->enabled;
  210. }
  211. public function setEnabled( string $enabled ): self
  212. {
  213. $this->enabled = $enabled;
  214. return $this;
  215. }
  216. /**
  217. * @return Collection|PurchaseProductItem[]
  218. */
  219. public function getPurchaseItems(): Collection
  220. {
  221. return $this->purchaseItems;
  222. }
  223. public function addPurchaseItem( PurchaseProductItem $purchaseItem ): self
  224. {
  225. if ( !$this->purchaseItems->contains( $purchaseItem ) ) {
  226. $this->purchaseItems[] = $purchaseItem;
  227. $purchaseItem->setProduct( $this );
  228. }
  229. return $this;
  230. }
  231. public function removePurchaseItem( PurchaseProductItem $purchaseItem ): self
  232. {
  233. if ( $this->purchaseItems->removeElement( $purchaseItem ) ) {
  234. // set the owning side to null (unless already changed)
  235. if ( $purchaseItem->getProduct() === $this ) {
  236. $purchaseItem->setProduct( NULL );
  237. }
  238. }
  239. return $this;
  240. }
  241. /**
  242. * @return Collection<int, PointTransactionBooster>
  243. */
  244. public function getPointTransactionBoosters(): Collection
  245. {
  246. return $this->pointTransactionBoosters;
  247. }
  248. public function addPointTransactionBooster( PointTransactionBooster $pointTransactionBooster ): self
  249. {
  250. if ( !$this->pointTransactionBoosters->contains( $pointTransactionBooster ) ) {
  251. $this->pointTransactionBoosters[] = $pointTransactionBooster;
  252. $pointTransactionBooster->addPurchaseProduct( $this );
  253. }
  254. return $this;
  255. }
  256. public function removePointTransactionBooster( PointTransactionBooster $pointTransactionBooster ): self
  257. {
  258. if ( $this->pointTransactionBoosters->removeElement( $pointTransactionBooster ) ) {
  259. $pointTransactionBooster->removePurchaseProduct( $this );
  260. }
  261. return $this;
  262. }
  263. public function getCategoryValues(): ?string
  264. {
  265. return $this->categoryValues;
  266. }
  267. public function setCategoryValues( ?string $categoryValues ): self
  268. {
  269. $this->categoryValues = $categoryValues;
  270. return $this;
  271. }
  272. public function getDefaultPointCategory(): ?string
  273. {
  274. return $this->defaultPointCategory;
  275. }
  276. public function setDefaultPointCategory(?string $defaultPointCategory): self
  277. {
  278. $this->defaultPointCategory = $defaultPointCategory;
  279. return $this;
  280. }
  281. }