<?php
declare(strict_types=1);
namespace Croisiland\CommonBundle\Entity\Cabin;
use Crea\MediaBundle\Entity\MediaTagOwnerInterface;
use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
use Crea\ToolsBundle\Traits\KeyValueTrait;
use Croisiland\CommonBundle\Annotation\Cabin\CabinCategoryFormValidator;
use Croisiland\CommonBundle\Entity\Amenity\EquipmentCabinCategoryAssociation;
use Croisiland\CommonBundle\Entity\Company\Atmosphere;
use Croisiland\CommonBundle\Entity\Price\Price;
use Croisiland\CommonBundle\Entity\Ship\Ship;
use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
use Croisiland\CommonBundle\Repository\Cabin\CabinCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(
* uniqueConstraints={
*
* @UniqueConstraint(name="cabin_category_unique",
* columns={"code", "ship_id", "atmosphere_normalized"})
* }
* )
*
* @ORM\HasLifecycleCallbacks()
*
* @ORM\Entity(repositoryClass=CabinCategoryRepository::class)
*
* @CabinCategoryFormValidator(groups={"cabin_category_form_validator"})
*/
class CabinCategory implements MediaTagOwnerInterface
{
use IsActiveTrait;
use ListOrderTrait;
use LifecycleUserIdentifierTrait;
use KeyValueTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private ?string $name = null;
/**
* @ORM\Column(type="string", length=100, unique=true)
*
* @Gedmo\Slug(fields={"name"}, updatable=false, unique=true)
*/
private ?string $slug = null;
/**
* @ORM\Column(type="string", length=64)
*/
private ?string $code = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $cabinAreaMin = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $cabinAreaMax = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $balconyAreaMin = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $balconyAreaMax = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $nbPassengersMin = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $nbPassengersMax = null;
/**
* @ORM\ManyToOne(targetEntity=Ship::class, inversedBy="cabinCategories")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?Ship $ship = null;
/**
* @ORM\ManyToOne(targetEntity=Atmosphere::class, inversedBy="cabinCategories")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?Atmosphere $atmosphere = null;
/**
* @ORM\Column(type="string", length=8, nullable=false)
*/
private ?string $atmosphereNormalized = null;
/**
* @ORM\ManyToOne(targetEntity=CabinSubType::class, inversedBy="cabinCategories")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?CabinSubType $cabinSubType = null;
/**
* @var Collection<int, Price>
*
* @ORM\OneToMany(targetEntity=Price::class, mappedBy="cabinCategory")
*/
private Collection $prices;
/**
* @var Collection<int, EquipmentCabinCategoryAssociation>
*
* @ORM\OneToMany(targetEntity=EquipmentCabinCategoryAssociation::class, mappedBy="cabinCategory", orphanRemoval=true, cascade={"persist","remove"})
*/
private Collection $equipmentCabinCategoryAssociations;
/**
* @var array<int, string>
* TODO à convertir en entité pour permettre de donner plus d'informations sur les ponts de chaque bateau
* @ORM\Column(type="array", nullable=false)
*/
private array $decks = [];
/**
* @var Collection<int, CabinCategorySpecificity>
* @ORM\ManyToMany(targetEntity=CabinCategorySpecificity::class, mappedBy="cabinCategories", cascade={"persist"})
* @ORM\OrderBy({"listOrder" = "ASC"})
*/
private Collection $specificities;
/**
* @var Collection<int, CabinCategoryHighlight>
* @ORM\ManyToMany(targetEntity=CabinCategoryHighlight::class, mappedBy="cabinCategories", cascade={"persist"})
* @ORM\OrderBy({"listOrder" = "ASC"})
*/
private Collection $highlights;
/**
* @ORM\OneToMany(
* targetEntity="CabinCategoryCharacteristicValue",
* mappedBy="cabinCategory",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
*/
private Collection $cabinCategoryCharacteristicValues;
public function __construct()
{
$this->prices = new ArrayCollection();
$this->equipmentCabinCategoryAssociations = new ArrayCollection();
$this->specificities = new ArrayCollection();
$this->highlights = new ArrayCollection();
$this->cabinCategoryCharacteristicValues = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): CabinCategory
{
$this->description = $description;
return $this;
}
public function getCabinAreaMin(): ?string
{
return $this->cabinAreaMin;
}
public function setCabinAreaMin(?string $cabinAreaMin): self
{
$this->cabinAreaMin = $cabinAreaMin;
return $this;
}
public function getCabinAreaMax(): ?string
{
return $this->cabinAreaMax;
}
public function setCabinAreaMax(?string $cabinAreaMax): self
{
$this->cabinAreaMax = $cabinAreaMax;
return $this;
}
public function getBalconyAreaMin(): ?string
{
return $this->balconyAreaMin;
}
public function setBalconyAreaMin(?string $balconyAreaMin): self
{
$this->balconyAreaMin = $balconyAreaMin;
return $this;
}
public function getBalconyAreaMax(): ?string
{
return $this->balconyAreaMax;
}
public function setBalconyAreaMax(?string $balconyAreaMax): self
{
$this->balconyAreaMax = $balconyAreaMax;
return $this;
}
public function getNbPassengersMin(): ?int
{
return $this->nbPassengersMin;
}
public function setNbPassengersMin(?int $nbPassengersMin): self
{
$this->nbPassengersMin = $nbPassengersMin;
return $this;
}
public function getNbPassengersMax(): ?int
{
return $this->nbPassengersMax;
}
public function setNbPassengersMax(?int $nbPassengersMax): self
{
$this->nbPassengersMax = $nbPassengersMax;
return $this;
}
public function getShip(): ?Ship
{
return $this->ship;
}
public function setShip(?Ship $ship): self
{
$this->ship = $ship;
return $this;
}
public function getAtmosphere(): ?Atmosphere
{
return $this->atmosphere;
}
public function setAtmosphere(?Atmosphere $atmosphere): self
{
$this->atmosphere = $atmosphere;
return $this;
}
public function getCabinSubType(): ?CabinSubType
{
return $this->cabinSubType;
}
public function setCabinSubType(?CabinSubType $cabinSubType): self
{
$this->cabinSubType = $cabinSubType;
return $this;
}
/**
* @return Collection<int, Price>
*/
public function getPrices(): Collection
{
return $this->prices;
}
public function addPrice(Price $price): self
{
if (!$this->prices->contains($price)) {
$this->prices[] = $price;
$price->setCabinCategory($this);
}
return $this;
}
public function removePrice(Price $price): self
{
if ($this->prices->removeElement($price)) {
// set the owning side to null (unless already changed)
if ($price->getCabinCategory() === $this) {
$price->setCabinCategory(null);
}
}
return $this;
}
/**
* @return Collection<int, EquipmentCabinCategoryAssociation>
*/
public function getEquipmentCabinCategoryAssociations(): Collection
{
return $this->equipmentCabinCategoryAssociations;
}
public function addEquipmentCabinCategoryAssociation(EquipmentCabinCategoryAssociation $equipmentCabinCategoryAssociation): self
{
if (!$this->equipmentCabinCategoryAssociations->contains($equipmentCabinCategoryAssociation)) {
$this->equipmentCabinCategoryAssociations[] = $equipmentCabinCategoryAssociation;
$equipmentCabinCategoryAssociation->setCabinCategory($this);
}
return $this;
}
public function removeEquipmentCabinCategoryAssociation(EquipmentCabinCategoryAssociation $equipmentCabinCategoryAssociation): self
{
if ($this->equipmentCabinCategoryAssociations->removeElement($equipmentCabinCategoryAssociation)) {
// set the owning side to null (unless already changed)
if ($equipmentCabinCategoryAssociation->getCabinCategory() === $this) {
$equipmentCabinCategoryAssociation->setCabinCategory(null);
}
}
return $this;
}
/**
* @return array<int, string>
*/
public function getDecks(): array
{
return $this->decks;
}
/**
* @param array<int, string> $decks
*/
public function setDecks(array $decks): self
{
$this->decks = $decks;
return $this;
}
/**
* @ORM\PrePersist
*
* @ORM\PreUpdate
*/
public function updateNormalizedColumn(): void
{
$this->atmosphereNormalized = $this->atmosphere ? (string) $this->atmosphere->getId() : '__NULL__';
}
/**
* @return Collection<int, CabinCategorySpecificity>
*/
public function getSpecificities(): Collection
{
return $this->specificities;
}
public function addSpecificity(CabinCategorySpecificity $specificity): self
{
if (!$this->specificities->contains($specificity)) {
$this->specificities[] = $specificity;
$specificity->addCabinCategory($this);
}
return $this;
}
public function removeSpecificity(CabinCategorySpecificity $specificity): self
{
if ($this->specificities->removeElement($specificity)) {
$specificity->removeCabinCategory($this);
}
return $this;
}
/**
* @return Collection<int, CabinCategoryHighlight>
*/
public function getHighlights(): Collection
{
return $this->highlights;
}
public function addHighlight(CabinCategoryHighlight $highlight): self
{
if (!$this->highlights->contains($highlight)) {
$this->highlights[] = $highlight;
$highlight->addCabinCategory($this);
}
return $this;
}
public function removeHighlight(CabinCategoryHighlight $highlight): self
{
if ($this->highlights->removeElement($highlight)) {
$highlight->removeCabinCategory($this);
}
return $this;
}
/**
* @return Collection<int, CabinCategoryCharacteristicValue>
*/
public function getCabinCategoryCharacteristicValues(): Collection
{
return $this->cabinCategoryCharacteristicValues;
}
/**
* Ajoute une valeur de caractéristique à cette catégorie de cabine.
*
* @param CabinCategoryCharacteristicValue $value
* @return self
*/
public function addCabinCategoryCharacteristicValue(CabinCategoryCharacteristicValue $value): self
{
if (!$this->cabinCategoryCharacteristicValues->contains($value)) {
$this->cabinCategoryCharacteristicValues[] = $value;
$value->setCabinCategory($this);
}
return $this;
}
/**
* Retire une valeur de caractéristique de cette catégorie de cabine.
*
* @param CabinCategoryCharacteristicValue $value
* @return self
*/
public function removeCabinCategoryCharacteristicValue(CabinCategoryCharacteristicValue $value): self
{
if ($this->cabinCategoryCharacteristicValues->removeElement($value)) {
if ($value->getCabinCategory() === $this) {
$value->setCabinCategory(null);
}
}
return $this;
}
/**
* Method liée au Média Bundle
*/
public function getMediaTagOwnerLabel(): ?string
{
return $this->getCode() . " (" . $this->getShip()->getName() . ') [' . $this->getId() . ']';
}
/**
* Method liée au Média Bundle
* @return class-string
*/
public function getFqcn(): string
{
return ClassUtils::getClass($this);
}
}