<?php
declare(strict_types=1);
namespace Croisiland\CommonBundle\Entity\Price;
use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
use Croisiland\CommonBundle\Annotation\Price\PriceFormValidator;
use Croisiland\CommonBundle\Entity\Cabin\CabinCategory;
use Croisiland\CommonBundle\Entity\Cruise\Cruise;
use Croisiland\CommonBundle\Entity\Flight\FlightPackage;
use Croisiland\CommonBundle\Entity\Traits\CurrencyTrait;
use Croisiland\CommonBundle\Entity\Offer\Offer;
use Croisiland\CommonBundle\Repository\Price\PriceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @PriceFormValidator(groups="price_form_validator")
*
* @ORM\Entity(repositoryClass=PriceRepository::class)
*
* @ORM\Table(name="price",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="unique_price_fare_cruise_cabin", columns={"price_family_normalized", "cruise_id", "cabin_category_id"})
* },
* indexes={
* @ORM\Index(name="idx_cruise_category_cost", columns={"cruise_id", "cabin_category_id", "base_cost_double"})
* })
*/
class Price
{
// TODO check relations
// * @var CroisilandCabinCategoryStock <-- ne pas traiter pour l'instant
use LifecycleUserIdentifierTrait;
use CurrencyTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fareCode = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $description = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $priceFamily = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $priceFamilyNormalized = null;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default" = false})
*/
private bool $flightPossible = false;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default" = false})
*/
private bool $flightIncluded = false;
/**
* @ORM\ManyToOne(targetEntity=Cruise::class, inversedBy="prices")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?Cruise $cruise = null;
/**
* @ORM\ManyToOne(targetEntity=CabinCategory::class, inversedBy="prices")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?CabinCategory $cabinCategory = null;
/**
* @var Collection<int, FlightPackage>
*
* @ORM\OneToMany(targetEntity=FlightPackage::class, mappedBy="price", orphanRemoval=true)
*/
private Collection $flightPackages;
/**
* @var Collection<int, PriceCost>
*
* @ORM\OneToMany(targetEntity=PriceCost::class, mappedBy="price", orphanRemoval=true, cascade={"persist","remove"})
*
* @ORM\OrderBy({"position" = "ASC"})
*/
private Collection $priceCosts;
/**
* @var Collection<int, ServiceCharge>
*
* @ORM\OneToMany(targetEntity=ServiceCharge::class, mappedBy="price", orphanRemoval=true, cascade={"persist","remove"})
*
* @ORM\OrderBy({"position" = "ASC"})
*/
private Collection $serviceCharges;
/**
* @ORM\Column(type="float", nullable=true)
*/
private ?float $baseCostDouble = null;
/**
* @ORM\Column(type="string", length=255, nullable=false, unique=true)
*/
private ?string $code = null;
/**
* @ORM\ManyToOne(targetEntity=Offer::class, inversedBy="prices")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?Offer $offer = null;
public function __construct()
{
$this->flightPackages = new ArrayCollection();
$this->priceCosts = new ArrayCollection();
$this->serviceCharges = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getFareCode(): ?string
{
return $this->fareCode;
}
public function setFareCode(?string $fareCode): self
{
$this->fareCode = $fareCode;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPriceFamily(): ?string
{
return $this->priceFamily;
}
public function setPriceFamily(?string $priceFamily): self
{
$this->priceFamily = $priceFamily;
return $this;
}
public function isFlightPossible(): bool
{
return $this->flightPossible;
}
public function setFlightPossible(bool $flightPossible): self
{
$this->flightPossible = $flightPossible;
return $this;
}
public function isFlightIncluded(): bool
{
return $this->flightIncluded;
}
public function setFlightIncluded(bool $flightIncluded): self
{
$this->flightIncluded = $flightIncluded;
return $this;
}
public function getCruise(): ?Cruise
{
return $this->cruise;
}
public function setCruise(?Cruise $cruise): self
{
$this->cruise = $cruise;
return $this;
}
public function getCabinCategory(): ?CabinCategory
{
return $this->cabinCategory;
}
public function setCabinCategory(?CabinCategory $cabinCategory): self
{
$this->cabinCategory = $cabinCategory;
return $this;
}
/**
* @return Collection<int, FlightPackage>
*/
public function getFlightPackages(): Collection
{
return $this->flightPackages;
}
public function addFlightPackage(FlightPackage $flightPackage): self
{
if (!$this->flightPackages->contains($flightPackage)) {
$this->flightPackages[] = $flightPackage;
$flightPackage->setPrice($this);
}
return $this;
}
public function removeFlightPackage(FlightPackage $flightPackage): self
{
if ($this->flightPackages->removeElement($flightPackage)) {
// set the owning side to null (unless already changed)
if ($flightPackage->getPrice() === $this) {
$flightPackage->setPrice(null);
}
}
return $this;
}
/**
* @return Collection<int, PriceCost>
*/
public function getPriceCosts(): Collection
{
return $this->priceCosts;
}
public function addPriceCost(PriceCost $priceCost): self
{
if (!$this->priceCosts->contains($priceCost)) {
$this->priceCosts[] = $priceCost;
$priceCost->setPrice($this);
}
return $this;
}
public function removePriceCost(PriceCost $priceCost): self
{
if ($this->priceCosts->removeElement($priceCost)) {
// set the owning side to null (unless already changed)
if ($priceCost->getPrice() === $this) {
$priceCost->setPrice(null);
}
}
return $this;
}
/**
* @return Collection<int, ServiceCharge>
*/
public function getServiceCharges(): Collection
{
return $this->serviceCharges;
}
public function addServiceCharge(ServiceCharge $serviceCharge): self
{
if (!$this->serviceCharges->contains($serviceCharge)) {
$this->serviceCharges[] = $serviceCharge;
$serviceCharge->setPrice($this);
}
return $this;
}
public function removeServiceCharge(ServiceCharge $serviceCharge): self
{
if ($this->serviceCharges->removeElement($serviceCharge)) {
// set the owning side to null (unless already changed)
if ($serviceCharge->getPrice() === $this) {
$serviceCharge->setPrice(null);
}
}
return $this;
}
public function getBaseCostDouble(): ?float
{
return $this->baseCostDouble;
}
public function setBaseCostDouble(?float $baseCostDouble): self
{
$this->baseCostDouble = $baseCostDouble;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getOffer(): ?Offer
{
return $this->offer;
}
public function setOffer(?Offer $offer): self
{
$this->offer = $offer;
return $this;
}
/**
* @ORM\PrePersist
*
* @ORM\PreUpdate
*/
public function updateNormalizedColumn(): void
{
$this->priceFamilyNormalized = $this->priceFamily ? $this->priceFamily : '__NULL__';
}
}