src/Entity/CustomProduct.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomProductRepository;
  4. use App\Traits\DateTrait;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as Serializer;
  10. use JMS\Serializer\Annotation\Expose;
  11. use JMS\Serializer\Annotation\Groups;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. /**
  16. * Produit personnalisé
  17. *
  18. * @ORM\Entity(repositoryClass=CustomProductRepository::class)
  19. *
  20. * @Serializer\ExclusionPolicy("ALL")
  21. * @Vich\Uploadable
  22. */
  23. class CustomProduct
  24. {
  25. /**
  26. * @ORM\Id
  27. * @ORM\GeneratedValue
  28. * @ORM\Column(type="integer")
  29. *
  30. * @Expose
  31. * @Groups({"customProduct:list", "customProduct:item"})
  32. */
  33. private ?int $id = null;
  34. /**
  35. * Label du produit
  36. *
  37. * @ORM\Column(type="string", length=255)
  38. *
  39. * @Assert\Length(
  40. * min = 2,
  41. * max = 255,
  42. * )
  43. *
  44. * @Expose
  45. * @Groups({"customProduct:list", "customProduct:item"})
  46. */
  47. private ?string $label = null;
  48. /**
  49. * Description du produit
  50. *
  51. * @ORM\Column(type="text", nullable=true)
  52. *
  53. * @Expose
  54. * @Groups({"customProduct:item"})
  55. */
  56. private ?string $description = null;
  57. /**
  58. * Valeur (prix) du produit
  59. *
  60. * @ORM\Column(type="float", nullable=false)
  61. *
  62. * @Assert\PositiveOrZero
  63. *
  64. * @Expose
  65. * @Groups({"customProduct:list", "customProduct:item"})
  66. */
  67. private ?float $value = null;
  68. /**
  69. * Indique si le produit est actif
  70. *
  71. * @ORM\Column(type="boolean")
  72. *
  73. * @Expose
  74. * @Groups({"customProduct:list", "customProduct:item"})
  75. */
  76. private bool $enabled = true;
  77. /**
  78. * Image du produit
  79. *
  80. * @ORM\Column(type="string", length=255, nullable=true)
  81. *
  82. * @Expose
  83. * @Groups({"customProduct:list", "customProduct:item"})
  84. */
  85. private ?string $image = null;
  86. /**
  87. * Vich Uploader
  88. *
  89. * @Vich\UploadableField(mapping="custom_product_images", fileNameProperty="image")
  90. * @var null|File
  91. */
  92. private ?File $imageFile = null;
  93. /**
  94. * Liste des contacts (email) quand il y a une demande pour ce produit
  95. *
  96. * @ORM\Column(type="array", nullable=true)
  97. *
  98. * @Expose
  99. * @Groups({"customProduct:item"})
  100. */
  101. private array $contacts = [];
  102. /**
  103. * Liste des champs pour commander ce produit
  104. *
  105. * @ORM\OneToMany(
  106. * targetEntity=CustomProductField::class,
  107. * mappedBy="product",
  108. * orphanRemoval=true,
  109. * cascade={"persist","remove"}
  110. * )
  111. */
  112. private $fields;
  113. /**
  114. * @ORM\ManyToOne(targetEntity=CustomProductTemplate::class)
  115. */
  116. private ?CustomProductTemplate $template = null;
  117. /**
  118. * Type de produit
  119. *
  120. * @ORM\ManyToOne(targetEntity=CustomProductType::class, inversedBy="templates")
  121. * @ORM\JoinColumn(nullable=false, name="type", referencedColumnName="slug")
  122. *
  123. * @Expose
  124. * @Groups({"customProduct:list", "customProduct:item"})
  125. */
  126. private ?CustomProductType $type = null;
  127. /**
  128. * @ORM\Column(type="string", length=10, nullable=true)
  129. *
  130. * @Expose
  131. * @Groups({"customProduct:list", "customProduct:item"})
  132. */
  133. private $sku;
  134. /**
  135. * @ORM\Column(type="integer", nullable=true)
  136. */
  137. private $stockAlert;
  138. /**
  139. * @ORM\Column(type="string", length=255, nullable=true)
  140. */
  141. private $reference;
  142. /**
  143. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="customProducts")
  144. */
  145. private $createdBy;
  146. /**
  147. * @ORM\Column(type="text", nullable=true)
  148. */
  149. private $categoryValues;
  150. /**
  151. * @ORM\Column(type="text", nullable=true)
  152. */
  153. private $furtherInformation;
  154. /**
  155. * Stock du produit
  156. *
  157. * @ORM\Column(type="integer", nullable=true)
  158. *
  159. * @Assert\PositiveOrZero
  160. *
  161. * @Expose
  162. * @Groups({"customProduct:list", "customProduct:item"})
  163. */
  164. private ?int $stock = null;
  165. /**
  166. * Indique si on peut commander plusieurs fois le produit par commande
  167. *
  168. * @ORM\Column(type="boolean")
  169. *
  170. * @Expose
  171. * @Groups({"customProduct:list", "customProduct:item"})
  172. */
  173. private bool $allowedMultiple = true;
  174. /**
  175. * Indique si le prix du produit est fixe
  176. *
  177. * @ORM\Column(type="boolean")
  178. *
  179. * @Expose
  180. * @Groups({"customProduct:list", "customProduct:item"})
  181. */
  182. private bool $fixedValue = true;
  183. /**
  184. * Indique la catégorie de point par defaut
  185. *
  186. * @ORM\Column(type="string", nullable=true)
  187. *
  188. * @Expose
  189. * @Groups({"customProduct:list", "customProduct:item"})
  190. */
  191. private ?string $defaultPointCategory = null;
  192. /**
  193. * @ORM\Column(type="integer", nullable=true)
  194. */
  195. private $productUserQuota;
  196. /**
  197. * @ORM\OneToMany(targetEntity=QuotaProductUser::class, mappedBy="customProduct", orphanRemoval=true)
  198. */
  199. private $quotaProductUsers;
  200. /**
  201. * @ORM\Column(type="json", nullable=true)
  202. */
  203. private $visibilityFromJobs = [];
  204. /**
  205. * @ORM\OneToMany(targetEntity=QuotaProductJob::class, mappedBy="customProduct", cascade={"persist", "remove"}, orphanRemoval=true)
  206. */
  207. private $quotaProductJobs;
  208. /**
  209. * Indique si une transaction de débit est créé lors de la commande
  210. *
  211. * @ORM\Column(type="boolean")
  212. */
  213. private $debitAtOrder = false;
  214. use DateTrait;
  215. public function __construct()
  216. {
  217. $this->fields = new ArrayCollection();
  218. $this->quotaProductUsers = new ArrayCollection();
  219. $this->quotaProductJobs = new ArrayCollection();
  220. }
  221. /**
  222. * @Serializer\VirtualProperty()
  223. * @Serializer\SerializedName("array_category_values")
  224. *
  225. * @Expose
  226. * @Groups({"customProduct:list", "customProduct:item"})
  227. */
  228. public function getArrayCategoryValues()
  229. {
  230. return json_decode($this->categoryValues, true) ?? [];
  231. }
  232. public function modifyValueToCategory(string $slug, int $value): CustomProduct
  233. {
  234. $newArray = $this->getArrayCategoryValues();
  235. $newArray[$slug] = $value;
  236. $this->categoryValues = json_encode($newArray);
  237. return $this;
  238. }
  239. public function getId(): ?int
  240. {
  241. return $this->id;
  242. }
  243. public function setId(int $id): self
  244. {
  245. $this->id = $id;
  246. return $this;
  247. }
  248. public function getTemplate(): ?CustomProductTemplate
  249. {
  250. return $this->template;
  251. }
  252. public function setTemplate(?CustomProductTemplate $template): self
  253. {
  254. $this->template = $template;
  255. return $this;
  256. }
  257. public function getImageFile(): ?File
  258. {
  259. return $this->imageFile;
  260. }
  261. public function setImageFile(File $imageFile): CustomProduct
  262. {
  263. $this->imageFile = $imageFile;
  264. $this->updatedAt = new DateTime();
  265. return $this;
  266. }
  267. public function getLabel(): ?string
  268. {
  269. return $this->label;
  270. }
  271. public function setLabel(string $label): self
  272. {
  273. $this->label = $label;
  274. return $this;
  275. }
  276. public function getDescription(): ?string
  277. {
  278. return $this->description;
  279. }
  280. public function setDescription(?string $description): self
  281. {
  282. $this->description = $description;
  283. return $this;
  284. }
  285. public function getValue(): ?float
  286. {
  287. return $this->value;
  288. }
  289. public function setValue(?float $value): self
  290. {
  291. $this->value = $value;
  292. return $this;
  293. }
  294. public function isEnabled(): ?bool
  295. {
  296. return $this->enabled;
  297. }
  298. public function setEnabled(bool $enabled): self
  299. {
  300. $this->enabled = $enabled;
  301. return $this;
  302. }
  303. public function getImage(): ?string
  304. {
  305. return $this->image;
  306. }
  307. public function setImage(?string $image): self
  308. {
  309. $this->image = $image;
  310. return $this;
  311. }
  312. public function getContacts(): ?array
  313. {
  314. return $this->contacts;
  315. }
  316. public function setContacts(array $contacts): self
  317. {
  318. $this->contacts = $contacts;
  319. return $this;
  320. }
  321. /**
  322. * @return Collection<int, CustomProductField>
  323. */
  324. public function getFields(): Collection
  325. {
  326. return $this->fields;
  327. }
  328. public function addField(CustomProductField $field): self
  329. {
  330. if (!$this->fields->contains($field)) {
  331. $this->fields[] = $field;
  332. $field->setProduct($this);
  333. }
  334. return $this;
  335. }
  336. public function removeField(CustomProductField $field): self
  337. {
  338. if ($this->fields->removeElement($field)) {
  339. // set the owning side to null (unless already changed)
  340. if ($field->getProduct() === $this) {
  341. $field->setProduct(null);
  342. }
  343. }
  344. return $this;
  345. }
  346. public function getType(): ?CustomProductType
  347. {
  348. return $this->type;
  349. }
  350. public function setType(?CustomProductType $type): self
  351. {
  352. $this->type = $type;
  353. return $this;
  354. }
  355. public function getSku(): ?string
  356. {
  357. return $this->sku;
  358. }
  359. public function setSku(?string $sku): self
  360. {
  361. $this->sku = $sku;
  362. return $this;
  363. }
  364. public function getStockAlert(): ?int
  365. {
  366. return $this->stockAlert;
  367. }
  368. public function setStockAlert(?int $stockAlert): self
  369. {
  370. $this->stockAlert = $stockAlert;
  371. return $this;
  372. }
  373. public function getStock(): ?int
  374. {
  375. return $this->stock;
  376. }
  377. public function setStock(?int $stock): self
  378. {
  379. $this->stock = $stock;
  380. return $this;
  381. }
  382. public function getReference(): ?string
  383. {
  384. return $this->reference;
  385. }
  386. public function setReference(?string $reference): self
  387. {
  388. $this->reference = $reference;
  389. return $this;
  390. }
  391. public function getCreatedBy(): ?User
  392. {
  393. return $this->createdBy;
  394. }
  395. public function setCreatedBy(?User $createdBy): self
  396. {
  397. $this->createdBy = $createdBy;
  398. return $this;
  399. }
  400. public function getCategoryValues(): ?string
  401. {
  402. return $this->categoryValues;
  403. }
  404. public function setCategoryValues(?string $categoryValues): self
  405. {
  406. $this->categoryValues = $categoryValues;
  407. return $this;
  408. }
  409. public function getFurtherInformation(): ?string
  410. {
  411. return $this->furtherInformation;
  412. }
  413. public function setFurtherInformation(?string $furtherInformation): self
  414. {
  415. $this->furtherInformation = $furtherInformation;
  416. return $this;
  417. }
  418. public function isAllowedMultiple(): ?bool
  419. {
  420. return $this->allowedMultiple;
  421. }
  422. public function setAllowedMultiple(bool $allowedMultiple): self
  423. {
  424. $this->allowedMultiple = $allowedMultiple;
  425. return $this;
  426. }
  427. public function isFixedValue(): ?bool
  428. {
  429. return $this->fixedValue;
  430. }
  431. public function setFixedValue(bool $fixedValue): self
  432. {
  433. $this->fixedValue = $fixedValue;
  434. return $this;
  435. }
  436. public function getDefaultPointCategory(): ?string
  437. {
  438. return $this->defaultPointCategory;
  439. }
  440. public function setDefaultPointCategory(?string $defaultPointCategory): self
  441. {
  442. $this->defaultPointCategory = $defaultPointCategory;
  443. return $this;
  444. }
  445. public function getProductUserQuota(): ?int
  446. {
  447. return $this->productUserQuota;
  448. }
  449. public function setProductUserQuota(?int $productUserQuota): self
  450. {
  451. $this->productUserQuota = $productUserQuota;
  452. return $this;
  453. }
  454. /**
  455. * @return Collection<int, QuotaProductUser>
  456. */
  457. public function getQuotaProductUsers(): Collection
  458. {
  459. return $this->quotaProductUsers;
  460. }
  461. public function addQuotaProductUser(QuotaProductUser $quotaProductUser): self
  462. {
  463. if (!$this->quotaProductUsers->contains($quotaProductUser)) {
  464. $this->quotaProductUsers[] = $quotaProductUser;
  465. $quotaProductUser->setCustomProduct($this);
  466. }
  467. return $this;
  468. }
  469. public function removeQuotaProductUser(QuotaProductUser $quotaProductUser): self
  470. {
  471. if ($this->quotaProductUsers->removeElement($quotaProductUser)) {
  472. // set the owning side to null (unless already changed)
  473. if ($quotaProductUser->getCustomProduct() === $this) {
  474. $quotaProductUser->setCustomProduct(null);
  475. }
  476. }
  477. return $this;
  478. }
  479. public function getVisibilityFromJobs(): ?array
  480. {
  481. return $this->visibilityFromJobs;
  482. }
  483. public function setVisibilityFromJobs(?array $visibilityFromJobs): self
  484. {
  485. $this->visibilityFromJobs = $visibilityFromJobs;
  486. return $this;
  487. }
  488. public function getQuotaProductJobs(): Collection
  489. {
  490. return $this->quotaProductJobs;
  491. }
  492. public function addQuotaProductJob(QuotaProductJob $quotaProductJob): self
  493. {
  494. if (!$this->quotaProductJobs->contains($quotaProductJob)) {
  495. $this->quotaProductJobs->add($quotaProductJob);
  496. $quotaProductJob->setCustomProduct($this);
  497. }
  498. return $this;
  499. }
  500. public function removeQuotaProductJob(QuotaProductJob $quotaProductJob): self
  501. {
  502. if ($this->quotaProductJobs->removeElement($quotaProductJob)) {
  503. if ($quotaProductJob->getCustomProduct() === $this) {
  504. $quotaProductJob->setCustomProduct(null);
  505. }
  506. }
  507. return $this;
  508. }
  509. public function isDebitAtOrder(): ?bool
  510. {
  511. return $this->debitAtOrder;
  512. }
  513. public function setDebitAtOrder(bool $debitAtOrder): self
  514. {
  515. $this->debitAtOrder = $debitAtOrder;
  516. return $this;
  517. }
  518. }