src/Entity/Reduction.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ReductionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=ReductionRepository::class)
  9. */
  10. class Reduction
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private $titre;
  22. /**
  23. * @ORM\Column(type="date", nullable=true)
  24. */
  25. private $dateValidity;
  26. /**
  27. * @ORM\ManyToOne(targetEntity=Enterprise::class, inversedBy="reductions")
  28. */
  29. private $enterprise;
  30. /**
  31. * @ORM\OneToMany(targetEntity=ReductionItem::class, mappedBy="reduction",cascade={"persist"})
  32. */
  33. private $reductionItems;
  34. /**
  35. * @ORM\OneToMany(targetEntity=ReductionRequest::class, mappedBy="reduction",cascade={"persist"})
  36. */
  37. private $reductionRequests;
  38. public function __construct()
  39. {
  40. $this->reductionItems = new ArrayCollection();
  41. $this->reductionRequests = new ArrayCollection();
  42. }
  43. public function getId(): ?int
  44. {
  45. return $this->id;
  46. }
  47. public function getTitre(): ?string
  48. {
  49. return $this->titre;
  50. }
  51. public function setTitre(string $titre): self
  52. {
  53. $this->titre = $titre;
  54. return $this;
  55. }
  56. public function getDateValidity(): ?\DateTimeInterface
  57. {
  58. return $this->dateValidity;
  59. }
  60. public function setDateValidity(?\DateTimeInterface $dateValidity): self
  61. {
  62. $this->dateValidity = $dateValidity;
  63. return $this;
  64. }
  65. public function getEnterprise(): ?Enterprise
  66. {
  67. return $this->enterprise;
  68. }
  69. public function setEnterprise(?Enterprise $enterprise): self
  70. {
  71. $this->enterprise = $enterprise;
  72. return $this;
  73. }
  74. /**
  75. * @return Collection|ReductionItem[]
  76. */
  77. public function getReductionItems(): Collection
  78. {
  79. return $this->reductionItems;
  80. }
  81. public function addReductionItem(ReductionItem $reductionItem): self
  82. {
  83. if (!$this->reductionItems->contains($reductionItem)) {
  84. $this->reductionItems[] = $reductionItem;
  85. $reductionItem->setReduction($this);
  86. }
  87. return $this;
  88. }
  89. public function removeReductionItem(ReductionItem $reductionItem): self
  90. {
  91. if ($this->reductionItems->removeElement($reductionItem)) {
  92. // set the owning side to null (unless already changed)
  93. if ($reductionItem->getReduction() === $this) {
  94. $reductionItem->setReduction(null);
  95. }
  96. }
  97. return $this;
  98. }
  99. /**
  100. * @return Collection|ReductionRequest[]
  101. */
  102. public function getReductionRequests(): Collection
  103. {
  104. return $this->reductionRequests;
  105. }
  106. public function addReductionRequest(ReductionRequest $reductionRequest): self
  107. {
  108. if (!$this->reductionRequests->contains($reductionRequest)) {
  109. $this->reductionRequests[] = $reductionRequest;
  110. $reductionRequest->setReduction($this);
  111. }
  112. return $this;
  113. }
  114. public function removeReductionRequest(ReductionRequest $reductionRequest): self
  115. {
  116. if ($this->reductionRequests->removeElement($reductionRequest)) {
  117. // set the owning side to null (unless already changed)
  118. if ($reductionRequest->getReduction() === $this) {
  119. $reductionRequest->setReduction(null);
  120. }
  121. }
  122. return $this;
  123. }
  124. public function isValid():bool
  125. {
  126. $now = new \DateTime();
  127. if($now > $this->dateValidity)
  128. return false;
  129. return true;
  130. }
  131. }