src/Entity/Coupon.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Coupons
  6. *
  7. * @ORM\Table(name="coupons")
  8. * @ORM\Entity(repositoryClass="App\Repository\CouponRepository")
  9. */
  10. class Coupon
  11. {
  12. /**
  13. * @var int
  14. *
  15. * @ORM\Column(name="coupon_id", type="integer", nullable=false)
  16. * @ORM\Id
  17. * @ORM\GeneratedValue(strategy="IDENTITY")
  18. */
  19. private $id;
  20. /**
  21. * @var \App\Entity\MarketingRule
  22. *
  23. * @ORM\ManyToOne(targetEntity="App\Entity\MarketingRule", inversedBy="coupons")
  24. * @ORM\JoinColumn(name="marketing_rule_id", referencedColumnName="id", onDelete="CASCADE")
  25. */
  26. private $marketingRule;
  27. /**
  28. * @var string
  29. *
  30. * @ORM\Column(name="coupon_code", type="string", length=32, nullable=false)
  31. */
  32. private $code;
  33. /**
  34. * @var int
  35. *
  36. * @ORM\Column(name="uses_per_coupon", type="integer", nullable=false, options={"default"="1"})
  37. */
  38. private $usesPerCoupon = '1';
  39. /**
  40. * @var int
  41. *
  42. * @ORM\Column(name="uses_per_user", type="integer", nullable=false)
  43. */
  44. private $usesPerUser = '0';
  45. /**
  46. * @var int
  47. *
  48. * @ORM\Column(name="used", type="integer", nullable=false)
  49. */
  50. private $used = '0';
  51. /**
  52. * @var int
  53. *
  54. * @ORM\Column(name="active", type="boolean", nullable=false)
  55. */
  56. private $active = '0';
  57. /**
  58. * @var \DateTime
  59. *
  60. * @ORM\Column(name="date_created", type="datetime", nullable=true)
  61. */
  62. private $createdAt;
  63. /**
  64. * @var \DateTime
  65. *
  66. * @ORM\Column(name="date_modified", type="datetime", nullable=true)
  67. */
  68. private $modifiedAt;
  69. public function getId(): int {
  70. return $this->id;
  71. }
  72. public function getMarketingRule(): \App\Entity\MarketingRule {
  73. return $this->marketingRule;
  74. }
  75. public function getCode(): string {
  76. return $this->code;
  77. }
  78. public function getUsesPerCoupon(): int {
  79. return $this->usesPerCoupon;
  80. }
  81. public function getUsesPerUser(): int {
  82. return $this->usesPerUser;
  83. }
  84. public function getUsed(): int {
  85. return $this->used;
  86. }
  87. public function getActive(): int {
  88. return $this->active;
  89. }
  90. public function getCreatedAt(): \DateTime {
  91. return $this->createdAt;
  92. }
  93. public function getModifiedAt(): \DateTime {
  94. return $this->modifiedAt;
  95. }
  96. public function setId(int $id): void {
  97. $this->id = $id;
  98. }
  99. public function setMarketingRule(\App\Entity\MarketingRule $marketingRule): void {
  100. $this->marketingRule = $marketingRule;
  101. }
  102. public function setCode(string $code): void {
  103. $this->code = $code;
  104. }
  105. public function setUsesPerCoupon(int $usesPerCoupon): void {
  106. $this->usesPerCoupon = $usesPerCoupon;
  107. }
  108. public function setUsesPerUser(int $usesPerUser): void {
  109. $this->usesPerUser = $usesPerUser;
  110. }
  111. public function setUsed(int $used): void {
  112. $this->used = $used;
  113. }
  114. public function setActive(int $active): void {
  115. $this->active = $active;
  116. }
  117. public function setCreatedAt(\DateTime $createdAt): void {
  118. $this->createdAt = $createdAt;
  119. }
  120. public function setModifiedAt(\DateTime $modifiedAt): void {
  121. $this->modifiedAt = $modifiedAt;
  122. }
  123. public function isUsed(){
  124. return !empty($this->used);
  125. }
  126. public function toArray() {
  127. return [
  128. 'id' => $this->getId(),
  129. 'code' => $this->getCode()
  130. ];
  131. }
  132. /**
  133. * @ORM\PrePersist()
  134. */
  135. public function prePersist(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
  136. $this->setCreatedAt(new \DateTime());
  137. }
  138. /**
  139. * @ORM\PreUpdate()
  140. */
  141. public function preUpdate(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
  142. $this->setUpdatedAt(new \DateTime());
  143. }
  144. }