src/ECommerceBundle/Entity/Coupon.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\ECommerceBundle\Entity;
  3. use App\ECommerceBundle\Model\CouponModel;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  7. use PN\ServiceBundle\Model\DateTimeTrait;
  8. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12. * Coupon
  13. * @ORM\Table("coupon")
  14. * @ORM\HasLifecycleCallbacks
  15. * @ORM\Entity(repositoryClass="App\ECommerceBundle\Repository\CouponRepository")
  16. * @UniqueEntity("code", message="This code is used before.")
  17. */
  18. class Coupon extends CouponModel implements DateTimeInterface
  19. {
  20. use VirtualDeleteTrait,
  21. DateTimeTrait;
  22. /**
  23. * @ORM\Column(name="id", type="integer")
  24. * @ORM\Id
  25. * @ORM\GeneratedValue(strategy="AUTO")
  26. */
  27. private ?int $id = null;
  28. /**
  29. * @Assert\NotBlank()
  30. * @ORM\Column(name="code", type="string", length=255, unique=true)
  31. */
  32. private ?string $code = null;
  33. /**
  34. * @ORM\Column(name="comment", type="text", nullable=true)
  35. */
  36. private ?string $comment = null;
  37. /**
  38. * @ORM\Column(name="description", type="text", nullable=true)
  39. */
  40. private ?string $description = null;
  41. /**
  42. * @ORM\OneToMany(targetEntity="CouponHasProduct", mappedBy="coupon", cascade={"persist"})
  43. * */
  44. private Collection $couponHasProducts;
  45. /**
  46. * @ORM\PrePersist
  47. */
  48. public function updatedTimestamps()
  49. {
  50. $this->setModified(new \DateTime(date('Y-m-d H:i:s')));
  51. if ($this->getCreated() == null) {
  52. $this->setCreated(new \DateTime(date('Y-m-d H:i:s')));
  53. }
  54. }
  55. /**
  56. * Constructor
  57. */
  58. public function __construct()
  59. {
  60. $this->couponHasProducts = new \Doctrine\Common\Collections\ArrayCollection();
  61. }
  62. public function getId(): ?int
  63. {
  64. return $this->id;
  65. }
  66. public function getCode(): ?string
  67. {
  68. return $this->code;
  69. }
  70. public function setCode(string $code): self
  71. {
  72. $this->code = $code;
  73. return $this;
  74. }
  75. public function getComment(): ?string
  76. {
  77. return $this->comment;
  78. }
  79. public function setComment(?string $comment): self
  80. {
  81. $this->comment = $comment;
  82. return $this;
  83. }
  84. public function getDescription(): ?string
  85. {
  86. return $this->description;
  87. }
  88. public function setDescription(?string $description): self
  89. {
  90. $this->description = $description;
  91. return $this;
  92. }
  93. /**
  94. * @return Collection<int, CouponHasProduct>
  95. */
  96. public function getCouponHasProducts(): Collection
  97. {
  98. return $this->couponHasProducts;
  99. }
  100. public function addCouponHasProduct(CouponHasProduct $couponHasProduct): self
  101. {
  102. if (!$this->couponHasProducts->contains($couponHasProduct)) {
  103. $this->couponHasProducts->add($couponHasProduct);
  104. $couponHasProduct->setCoupon($this);
  105. }
  106. return $this;
  107. }
  108. public function removeCouponHasProduct(CouponHasProduct $couponHasProduct): self
  109. {
  110. if ($this->couponHasProducts->removeElement($couponHasProduct)) {
  111. // set the owning side to null (unless already changed)
  112. if ($couponHasProduct->getCoupon() === $this) {
  113. $couponHasProduct->setCoupon(null);
  114. }
  115. }
  116. return $this;
  117. }
  118. }