vendor/croisiland/common-bundle/src/Entity/Price/Price.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Croisiland\CommonBundle\Entity\Price;
  4. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  5. use Croisiland\CommonBundle\Annotation\Price\PriceFormValidator;
  6. use Croisiland\CommonBundle\Entity\Cabin\CabinCategory;
  7. use Croisiland\CommonBundle\Entity\Cruise\Cruise;
  8. use Croisiland\CommonBundle\Entity\Flight\FlightPackage;
  9. use Croisiland\CommonBundle\Entity\Traits\CurrencyTrait;
  10. use Croisiland\CommonBundle\Entity\Offer\Offer;
  11. use Croisiland\CommonBundle\Repository\Price\PriceRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. /**
  16. * @PriceFormValidator(groups="price_form_validator")
  17. *
  18. * @ORM\Entity(repositoryClass=PriceRepository::class)
  19. *
  20. * @ORM\Table(name="price",
  21. * uniqueConstraints={
  22. * @ORM\UniqueConstraint(name="unique_price_fare_cruise_cabin", columns={"price_family_normalized", "cruise_id", "cabin_category_id"})
  23. * },
  24. * indexes={
  25. * @ORM\Index(name="idx_cruise_category_cost", columns={"cruise_id", "cabin_category_id", "base_cost_double"})
  26. * })
  27. */
  28. class Price
  29. {
  30. // TODO check relations
  31. // * @var CroisilandCabinCategoryStock <-- ne pas traiter pour l'instant
  32. use LifecycleUserIdentifierTrait;
  33. use CurrencyTrait;
  34. /**
  35. * @ORM\Id
  36. *
  37. * @ORM\GeneratedValue
  38. *
  39. * @ORM\Column(type="integer")
  40. */
  41. private ?int $id = null;
  42. /**
  43. * @ORM\Column(type="string", length=255, nullable=true)
  44. */
  45. private ?string $fareCode = null;
  46. /**
  47. * @ORM\Column(type="string", length=255, nullable=true)
  48. */
  49. private ?string $description = null;
  50. /**
  51. * @ORM\Column(type="string", length=255, nullable=true)
  52. */
  53. private ?string $priceFamily = null;
  54. /**
  55. * @ORM\Column(type="string", length=255, nullable=true)
  56. */
  57. private ?string $priceFamilyNormalized = null;
  58. /**
  59. * @ORM\Column(type="boolean", nullable=false, options={"default" = false})
  60. */
  61. private bool $flightPossible = false;
  62. /**
  63. * @ORM\Column(type="boolean", nullable=false, options={"default" = false})
  64. */
  65. private bool $flightIncluded = false;
  66. /**
  67. * @ORM\ManyToOne(targetEntity=Cruise::class, inversedBy="prices")
  68. *
  69. * @ORM\JoinColumn(nullable=false)
  70. */
  71. private ?Cruise $cruise = null;
  72. /**
  73. * @ORM\ManyToOne(targetEntity=CabinCategory::class, inversedBy="prices")
  74. *
  75. * @ORM\JoinColumn(nullable=false)
  76. */
  77. private ?CabinCategory $cabinCategory = null;
  78. /**
  79. * @var Collection<int, FlightPackage>
  80. *
  81. * @ORM\OneToMany(targetEntity=FlightPackage::class, mappedBy="price", orphanRemoval=true)
  82. */
  83. private Collection $flightPackages;
  84. /**
  85. * @var Collection<int, PriceCost>
  86. *
  87. * @ORM\OneToMany(targetEntity=PriceCost::class, mappedBy="price", orphanRemoval=true, cascade={"persist","remove"})
  88. *
  89. * @ORM\OrderBy({"position" = "ASC"})
  90. */
  91. private Collection $priceCosts;
  92. /**
  93. * @var Collection<int, ServiceCharge>
  94. *
  95. * @ORM\OneToMany(targetEntity=ServiceCharge::class, mappedBy="price", orphanRemoval=true, cascade={"persist","remove"})
  96. *
  97. * @ORM\OrderBy({"position" = "ASC"})
  98. */
  99. private Collection $serviceCharges;
  100. /**
  101. * @ORM\Column(type="float", nullable=true)
  102. */
  103. private ?float $baseCostDouble = null;
  104. /**
  105. * @ORM\Column(type="string", length=255, nullable=false, unique=true)
  106. */
  107. private ?string $code = null;
  108. /**
  109. * @ORM\ManyToOne(targetEntity=Offer::class, inversedBy="prices")
  110. *
  111. * @ORM\JoinColumn(nullable=true)
  112. */
  113. private ?Offer $offer = null;
  114. public function __construct()
  115. {
  116. $this->flightPackages = new ArrayCollection();
  117. $this->priceCosts = new ArrayCollection();
  118. $this->serviceCharges = new ArrayCollection();
  119. }
  120. public function getId(): ?int
  121. {
  122. return $this->id;
  123. }
  124. public function setId(int $id): self
  125. {
  126. $this->id = $id;
  127. return $this;
  128. }
  129. public function getFareCode(): ?string
  130. {
  131. return $this->fareCode;
  132. }
  133. public function setFareCode(?string $fareCode): self
  134. {
  135. $this->fareCode = $fareCode;
  136. return $this;
  137. }
  138. public function getDescription(): ?string
  139. {
  140. return $this->description;
  141. }
  142. public function setDescription(?string $description): self
  143. {
  144. $this->description = $description;
  145. return $this;
  146. }
  147. public function getPriceFamily(): ?string
  148. {
  149. return $this->priceFamily;
  150. }
  151. public function setPriceFamily(?string $priceFamily): self
  152. {
  153. $this->priceFamily = $priceFamily;
  154. return $this;
  155. }
  156. public function isFlightPossible(): bool
  157. {
  158. return $this->flightPossible;
  159. }
  160. public function setFlightPossible(bool $flightPossible): self
  161. {
  162. $this->flightPossible = $flightPossible;
  163. return $this;
  164. }
  165. public function isFlightIncluded(): bool
  166. {
  167. return $this->flightIncluded;
  168. }
  169. public function setFlightIncluded(bool $flightIncluded): self
  170. {
  171. $this->flightIncluded = $flightIncluded;
  172. return $this;
  173. }
  174. public function getCruise(): ?Cruise
  175. {
  176. return $this->cruise;
  177. }
  178. public function setCruise(?Cruise $cruise): self
  179. {
  180. $this->cruise = $cruise;
  181. return $this;
  182. }
  183. public function getCabinCategory(): ?CabinCategory
  184. {
  185. return $this->cabinCategory;
  186. }
  187. public function setCabinCategory(?CabinCategory $cabinCategory): self
  188. {
  189. $this->cabinCategory = $cabinCategory;
  190. return $this;
  191. }
  192. /**
  193. * @return Collection<int, FlightPackage>
  194. */
  195. public function getFlightPackages(): Collection
  196. {
  197. return $this->flightPackages;
  198. }
  199. public function addFlightPackage(FlightPackage $flightPackage): self
  200. {
  201. if (!$this->flightPackages->contains($flightPackage)) {
  202. $this->flightPackages[] = $flightPackage;
  203. $flightPackage->setPrice($this);
  204. }
  205. return $this;
  206. }
  207. public function removeFlightPackage(FlightPackage $flightPackage): self
  208. {
  209. if ($this->flightPackages->removeElement($flightPackage)) {
  210. // set the owning side to null (unless already changed)
  211. if ($flightPackage->getPrice() === $this) {
  212. $flightPackage->setPrice(null);
  213. }
  214. }
  215. return $this;
  216. }
  217. /**
  218. * @return Collection<int, PriceCost>
  219. */
  220. public function getPriceCosts(): Collection
  221. {
  222. return $this->priceCosts;
  223. }
  224. public function addPriceCost(PriceCost $priceCost): self
  225. {
  226. if (!$this->priceCosts->contains($priceCost)) {
  227. $this->priceCosts[] = $priceCost;
  228. $priceCost->setPrice($this);
  229. }
  230. return $this;
  231. }
  232. public function removePriceCost(PriceCost $priceCost): self
  233. {
  234. if ($this->priceCosts->removeElement($priceCost)) {
  235. // set the owning side to null (unless already changed)
  236. if ($priceCost->getPrice() === $this) {
  237. $priceCost->setPrice(null);
  238. }
  239. }
  240. return $this;
  241. }
  242. /**
  243. * @return Collection<int, ServiceCharge>
  244. */
  245. public function getServiceCharges(): Collection
  246. {
  247. return $this->serviceCharges;
  248. }
  249. public function addServiceCharge(ServiceCharge $serviceCharge): self
  250. {
  251. if (!$this->serviceCharges->contains($serviceCharge)) {
  252. $this->serviceCharges[] = $serviceCharge;
  253. $serviceCharge->setPrice($this);
  254. }
  255. return $this;
  256. }
  257. public function removeServiceCharge(ServiceCharge $serviceCharge): self
  258. {
  259. if ($this->serviceCharges->removeElement($serviceCharge)) {
  260. // set the owning side to null (unless already changed)
  261. if ($serviceCharge->getPrice() === $this) {
  262. $serviceCharge->setPrice(null);
  263. }
  264. }
  265. return $this;
  266. }
  267. public function getBaseCostDouble(): ?float
  268. {
  269. return $this->baseCostDouble;
  270. }
  271. public function setBaseCostDouble(?float $baseCostDouble): self
  272. {
  273. $this->baseCostDouble = $baseCostDouble;
  274. return $this;
  275. }
  276. public function getCode(): ?string
  277. {
  278. return $this->code;
  279. }
  280. public function setCode(?string $code): self
  281. {
  282. $this->code = $code;
  283. return $this;
  284. }
  285. public function getOffer(): ?Offer
  286. {
  287. return $this->offer;
  288. }
  289. public function setOffer(?Offer $offer): self
  290. {
  291. $this->offer = $offer;
  292. return $this;
  293. }
  294. /**
  295. * @ORM\PrePersist
  296. *
  297. * @ORM\PreUpdate
  298. */
  299. public function updateNormalizedColumn(): void
  300. {
  301. $this->priceFamilyNormalized = $this->priceFamily ? $this->priceFamily : '__NULL__';
  302. }
  303. }