src/Entity/Discount.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DiscountRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=DiscountRepository::class)
  9. */
  10. class Discount
  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, nullable=true)
  20. */
  21. private $content;
  22. /**
  23. * @ORM\Column(type="string", length=255, nullable=true)
  24. */
  25. private $postContent;
  26. /**
  27. * @ORM\ManyToMany(targetEntity=Restriction::class, inversedBy="discounts", cascade={"persist"})
  28. */
  29. private $restrictions;
  30. /**
  31. * @ORM\ManyToOne(targetEntity=DiscountName::class, inversedBy="discounts", cascade={"persist"})
  32. */
  33. private $discountName;
  34. /**
  35. * @ORM\ManyToOne(targetEntity=DiscountType::class, inversedBy="discounts")
  36. */
  37. private $discountType;
  38. /**
  39. * @ORM\ManyToOne(targetEntity=Provider::class, inversedBy="discounts")
  40. */
  41. private $provider;
  42. /**
  43. * @ORM\Column(type="boolean", nullable=true)
  44. */
  45. private $isActivo;
  46. public function __construct()
  47. {
  48. $this->restrictions = new ArrayCollection();
  49. $this->providers = new ArrayCollection();
  50. }
  51. public function getId(): ?int
  52. {
  53. return $this->id;
  54. }
  55. public function getContent(): ?string
  56. {
  57. return $this->content;
  58. }
  59. public function setContent(?string $content): self
  60. {
  61. $this->content = $content;
  62. return $this;
  63. }
  64. public function getPostContent(): ?string
  65. {
  66. return $this->postContent;
  67. }
  68. public function setPostContent(?string $postContent): self
  69. {
  70. $this->postContent = $postContent;
  71. return $this;
  72. }
  73. /**
  74. * @return Collection|Restriction[]
  75. */
  76. public function getRestrictions(): Collection
  77. {
  78. return $this->restrictions;
  79. }
  80. /**
  81. * @return Collection|Restriction[]
  82. */
  83. public function getFeatures(): Collection
  84. {
  85. $arr = [];
  86. $rs = $this->getRestrictions();
  87. foreach ($rs as $r){
  88. if($r->getIsFeature()) $arr[] = $r->getIfFeature();
  89. }
  90. return new ArrayCollection($arr);
  91. }
  92. public function addRestriction(Restriction $restriction): self
  93. {
  94. if (!$this->restrictions->contains($restriction)) {
  95. $this->restrictions[] = $restriction;
  96. }
  97. return $this;
  98. }
  99. public function removeRestriction(Restriction $restriction): self
  100. {
  101. if ($this->restrictions->contains($restriction)) {
  102. $this->restrictions->removeElement($restriction);
  103. }
  104. return $this;
  105. }
  106. public function getDiscountName(): ?DiscountName
  107. {
  108. return $this->discountName;
  109. }
  110. public function setDiscountName(?DiscountName $discountName): self
  111. {
  112. $this->discountName = $discountName;
  113. return $this;
  114. }
  115. public function getDiscountType(): ?DiscountType
  116. {
  117. return $this->discountType;
  118. }
  119. public function setDiscountType(?DiscountType $discountType): self
  120. {
  121. $this->discountType = $discountType;
  122. return $this;
  123. }
  124. public function __toString()
  125. {
  126. $arr = [
  127. $this->content,
  128. $this->getDiscountName(),
  129. $this->postContent
  130. ];
  131. return join(' ', $arr);
  132. }
  133. public function getFullName()
  134. {
  135. $provider = $this->getProvider()? $this->getProvider()->getContent() : '';
  136. return join(" ", [$provider . ': ', $this->content, $this->discountName, $this->postContent]);
  137. }
  138. public function getNombreParcial()
  139. {
  140. return join(" ", [$this->content, $this->discountName, $this->postContent]);
  141. }
  142. public function getProvider(): ?Provider
  143. {
  144. return $this->provider;
  145. }
  146. public function setProvider(?Provider $provider): self
  147. {
  148. $this->provider = $provider;
  149. return $this;
  150. }
  151. public function getIsActivo(): ?bool
  152. {
  153. return $this->isActivo;
  154. }
  155. public function setIsActivo(?bool $isActivo): self
  156. {
  157. $this->isActivo = $isActivo;
  158. return $this;
  159. }
  160. }