vendor/croisiland/common-bundle/src/Entity/Cabin/CabinCategory.php line 40

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Croisiland\CommonBundle\Entity\Cabin;
  4. use Crea\MediaBundle\Entity\MediaTagOwnerInterface;
  5. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  6. use Crea\ToolsBundle\Traits\KeyValueTrait;
  7. use Croisiland\CommonBundle\Annotation\Cabin\CabinCategoryFormValidator;
  8. use Croisiland\CommonBundle\Entity\Amenity\EquipmentCabinCategoryAssociation;
  9. use Croisiland\CommonBundle\Entity\Company\Atmosphere;
  10. use Croisiland\CommonBundle\Entity\Price\Price;
  11. use Croisiland\CommonBundle\Entity\Ship\Ship;
  12. use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
  13. use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
  14. use Croisiland\CommonBundle\Repository\Cabin\CabinCategoryRepository;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Doctrine\Common\Util\ClassUtils;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Doctrine\ORM\Mapping\UniqueConstraint;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. /**
  22. * @ORM\Table(
  23. * uniqueConstraints={
  24. *
  25. * @UniqueConstraint(name="cabin_category_unique",
  26. * columns={"code", "ship_id", "atmosphere_normalized"})
  27. * }
  28. * )
  29. *
  30. * @ORM\HasLifecycleCallbacks()
  31. *
  32. * @ORM\Entity(repositoryClass=CabinCategoryRepository::class)
  33. *
  34. * @CabinCategoryFormValidator(groups={"cabin_category_form_validator"})
  35. */
  36. class CabinCategory implements MediaTagOwnerInterface
  37. {
  38. use IsActiveTrait;
  39. use ListOrderTrait;
  40. use LifecycleUserIdentifierTrait;
  41. use KeyValueTrait;
  42. /**
  43. * @ORM\Id
  44. *
  45. * @ORM\GeneratedValue
  46. *
  47. * @ORM\Column(type="integer")
  48. */
  49. private ?int $id = null;
  50. /**
  51. * @ORM\Column(type="string", length=255, nullable=false)
  52. */
  53. private ?string $name = null;
  54. /**
  55. * @ORM\Column(type="string", length=100, unique=true)
  56. *
  57. * @Gedmo\Slug(fields={"name"}, updatable=false, unique=true)
  58. */
  59. private ?string $slug = null;
  60. /**
  61. * @ORM\Column(type="string", length=64)
  62. */
  63. private ?string $code = null;
  64. /**
  65. * @ORM\Column(type="text", nullable=true)
  66. */
  67. private ?string $description = null;
  68. /**
  69. * @ORM\Column(type="string", length=255, nullable=true)
  70. */
  71. private ?string $cabinAreaMin = null;
  72. /**
  73. * @ORM\Column(type="string", length=255, nullable=true)
  74. */
  75. private ?string $cabinAreaMax = null;
  76. /**
  77. * @ORM\Column(type="string", length=255, nullable=true)
  78. */
  79. private ?string $balconyAreaMin = null;
  80. /**
  81. * @ORM\Column(type="string", length=255, nullable=true)
  82. */
  83. private ?string $balconyAreaMax = null;
  84. /**
  85. * @ORM\Column(type="integer", nullable=true)
  86. */
  87. private ?int $nbPassengersMin = null;
  88. /**
  89. * @ORM\Column(type="integer", nullable=true)
  90. */
  91. private ?int $nbPassengersMax = null;
  92. /**
  93. * @ORM\ManyToOne(targetEntity=Ship::class, inversedBy="cabinCategories")
  94. *
  95. * @ORM\JoinColumn(nullable=false)
  96. */
  97. private ?Ship $ship = null;
  98. /**
  99. * @ORM\ManyToOne(targetEntity=Atmosphere::class, inversedBy="cabinCategories")
  100. *
  101. * @ORM\JoinColumn(nullable=true)
  102. */
  103. private ?Atmosphere $atmosphere = null;
  104. /**
  105. * @ORM\Column(type="string", length=8, nullable=false)
  106. */
  107. private ?string $atmosphereNormalized = null;
  108. /**
  109. * @ORM\ManyToOne(targetEntity=CabinSubType::class, inversedBy="cabinCategories")
  110. *
  111. * @ORM\JoinColumn(nullable=true)
  112. */
  113. private ?CabinSubType $cabinSubType = null;
  114. /**
  115. * @var Collection<int, Price>
  116. *
  117. * @ORM\OneToMany(targetEntity=Price::class, mappedBy="cabinCategory")
  118. */
  119. private Collection $prices;
  120. /**
  121. * @var Collection<int, EquipmentCabinCategoryAssociation>
  122. *
  123. * @ORM\OneToMany(targetEntity=EquipmentCabinCategoryAssociation::class, mappedBy="cabinCategory", orphanRemoval=true, cascade={"persist","remove"})
  124. */
  125. private Collection $equipmentCabinCategoryAssociations;
  126. /**
  127. * @var array<int, string>
  128. * TODO à convertir en entité pour permettre de donner plus d'informations sur les ponts de chaque bateau
  129. * @ORM\Column(type="array", nullable=false)
  130. */
  131. private array $decks = [];
  132. /**
  133. * @var Collection<int, CabinCategorySpecificity>
  134. * @ORM\ManyToMany(targetEntity=CabinCategorySpecificity::class, mappedBy="cabinCategories", cascade={"persist"})
  135. * @ORM\OrderBy({"listOrder" = "ASC"})
  136. */
  137. private Collection $specificities;
  138. /**
  139. * @var Collection<int, CabinCategoryHighlight>
  140. * @ORM\ManyToMany(targetEntity=CabinCategoryHighlight::class, mappedBy="cabinCategories", cascade={"persist"})
  141. * @ORM\OrderBy({"listOrder" = "ASC"})
  142. */
  143. private Collection $highlights;
  144. /**
  145. * @ORM\OneToMany(
  146. * targetEntity="CabinCategoryCharacteristicValue",
  147. * mappedBy="cabinCategory",
  148. * cascade={"persist", "remove"},
  149. * orphanRemoval=true
  150. * )
  151. */
  152. private Collection $cabinCategoryCharacteristicValues;
  153. public function __construct()
  154. {
  155. $this->prices = new ArrayCollection();
  156. $this->equipmentCabinCategoryAssociations = new ArrayCollection();
  157. $this->specificities = new ArrayCollection();
  158. $this->highlights = new ArrayCollection();
  159. $this->cabinCategoryCharacteristicValues = new ArrayCollection();
  160. }
  161. public function getId(): ?int
  162. {
  163. return $this->id;
  164. }
  165. public function getName(): ?string
  166. {
  167. return $this->name;
  168. }
  169. public function setName(?string $name): self
  170. {
  171. $this->name = $name;
  172. return $this;
  173. }
  174. public function getSlug(): ?string
  175. {
  176. return $this->slug;
  177. }
  178. public function setSlug(?string $slug): self
  179. {
  180. $this->slug = $slug;
  181. return $this;
  182. }
  183. public function getCode(): ?string
  184. {
  185. return $this->code;
  186. }
  187. public function setCode(?string $code): self
  188. {
  189. $this->code = $code;
  190. return $this;
  191. }
  192. public function getDescription(): ?string
  193. {
  194. return $this->description;
  195. }
  196. public function setDescription(?string $description): CabinCategory
  197. {
  198. $this->description = $description;
  199. return $this;
  200. }
  201. public function getCabinAreaMin(): ?string
  202. {
  203. return $this->cabinAreaMin;
  204. }
  205. public function setCabinAreaMin(?string $cabinAreaMin): self
  206. {
  207. $this->cabinAreaMin = $cabinAreaMin;
  208. return $this;
  209. }
  210. public function getCabinAreaMax(): ?string
  211. {
  212. return $this->cabinAreaMax;
  213. }
  214. public function setCabinAreaMax(?string $cabinAreaMax): self
  215. {
  216. $this->cabinAreaMax = $cabinAreaMax;
  217. return $this;
  218. }
  219. public function getBalconyAreaMin(): ?string
  220. {
  221. return $this->balconyAreaMin;
  222. }
  223. public function setBalconyAreaMin(?string $balconyAreaMin): self
  224. {
  225. $this->balconyAreaMin = $balconyAreaMin;
  226. return $this;
  227. }
  228. public function getBalconyAreaMax(): ?string
  229. {
  230. return $this->balconyAreaMax;
  231. }
  232. public function setBalconyAreaMax(?string $balconyAreaMax): self
  233. {
  234. $this->balconyAreaMax = $balconyAreaMax;
  235. return $this;
  236. }
  237. public function getNbPassengersMin(): ?int
  238. {
  239. return $this->nbPassengersMin;
  240. }
  241. public function setNbPassengersMin(?int $nbPassengersMin): self
  242. {
  243. $this->nbPassengersMin = $nbPassengersMin;
  244. return $this;
  245. }
  246. public function getNbPassengersMax(): ?int
  247. {
  248. return $this->nbPassengersMax;
  249. }
  250. public function setNbPassengersMax(?int $nbPassengersMax): self
  251. {
  252. $this->nbPassengersMax = $nbPassengersMax;
  253. return $this;
  254. }
  255. public function getShip(): ?Ship
  256. {
  257. return $this->ship;
  258. }
  259. public function setShip(?Ship $ship): self
  260. {
  261. $this->ship = $ship;
  262. return $this;
  263. }
  264. public function getAtmosphere(): ?Atmosphere
  265. {
  266. return $this->atmosphere;
  267. }
  268. public function setAtmosphere(?Atmosphere $atmosphere): self
  269. {
  270. $this->atmosphere = $atmosphere;
  271. return $this;
  272. }
  273. public function getCabinSubType(): ?CabinSubType
  274. {
  275. return $this->cabinSubType;
  276. }
  277. public function setCabinSubType(?CabinSubType $cabinSubType): self
  278. {
  279. $this->cabinSubType = $cabinSubType;
  280. return $this;
  281. }
  282. /**
  283. * @return Collection<int, Price>
  284. */
  285. public function getPrices(): Collection
  286. {
  287. return $this->prices;
  288. }
  289. public function addPrice(Price $price): self
  290. {
  291. if (!$this->prices->contains($price)) {
  292. $this->prices[] = $price;
  293. $price->setCabinCategory($this);
  294. }
  295. return $this;
  296. }
  297. public function removePrice(Price $price): self
  298. {
  299. if ($this->prices->removeElement($price)) {
  300. // set the owning side to null (unless already changed)
  301. if ($price->getCabinCategory() === $this) {
  302. $price->setCabinCategory(null);
  303. }
  304. }
  305. return $this;
  306. }
  307. /**
  308. * @return Collection<int, EquipmentCabinCategoryAssociation>
  309. */
  310. public function getEquipmentCabinCategoryAssociations(): Collection
  311. {
  312. return $this->equipmentCabinCategoryAssociations;
  313. }
  314. public function addEquipmentCabinCategoryAssociation(EquipmentCabinCategoryAssociation $equipmentCabinCategoryAssociation): self
  315. {
  316. if (!$this->equipmentCabinCategoryAssociations->contains($equipmentCabinCategoryAssociation)) {
  317. $this->equipmentCabinCategoryAssociations[] = $equipmentCabinCategoryAssociation;
  318. $equipmentCabinCategoryAssociation->setCabinCategory($this);
  319. }
  320. return $this;
  321. }
  322. public function removeEquipmentCabinCategoryAssociation(EquipmentCabinCategoryAssociation $equipmentCabinCategoryAssociation): self
  323. {
  324. if ($this->equipmentCabinCategoryAssociations->removeElement($equipmentCabinCategoryAssociation)) {
  325. // set the owning side to null (unless already changed)
  326. if ($equipmentCabinCategoryAssociation->getCabinCategory() === $this) {
  327. $equipmentCabinCategoryAssociation->setCabinCategory(null);
  328. }
  329. }
  330. return $this;
  331. }
  332. /**
  333. * @return array<int, string>
  334. */
  335. public function getDecks(): array
  336. {
  337. return $this->decks;
  338. }
  339. /**
  340. * @param array<int, string> $decks
  341. */
  342. public function setDecks(array $decks): self
  343. {
  344. $this->decks = $decks;
  345. return $this;
  346. }
  347. /**
  348. * @ORM\PrePersist
  349. *
  350. * @ORM\PreUpdate
  351. */
  352. public function updateNormalizedColumn(): void
  353. {
  354. $this->atmosphereNormalized = $this->atmosphere ? (string) $this->atmosphere->getId() : '__NULL__';
  355. }
  356. /**
  357. * @return Collection<int, CabinCategorySpecificity>
  358. */
  359. public function getSpecificities(): Collection
  360. {
  361. return $this->specificities;
  362. }
  363. public function addSpecificity(CabinCategorySpecificity $specificity): self
  364. {
  365. if (!$this->specificities->contains($specificity)) {
  366. $this->specificities[] = $specificity;
  367. $specificity->addCabinCategory($this);
  368. }
  369. return $this;
  370. }
  371. public function removeSpecificity(CabinCategorySpecificity $specificity): self
  372. {
  373. if ($this->specificities->removeElement($specificity)) {
  374. $specificity->removeCabinCategory($this);
  375. }
  376. return $this;
  377. }
  378. /**
  379. * @return Collection<int, CabinCategoryHighlight>
  380. */
  381. public function getHighlights(): Collection
  382. {
  383. return $this->highlights;
  384. }
  385. public function addHighlight(CabinCategoryHighlight $highlight): self
  386. {
  387. if (!$this->highlights->contains($highlight)) {
  388. $this->highlights[] = $highlight;
  389. $highlight->addCabinCategory($this);
  390. }
  391. return $this;
  392. }
  393. public function removeHighlight(CabinCategoryHighlight $highlight): self
  394. {
  395. if ($this->highlights->removeElement($highlight)) {
  396. $highlight->removeCabinCategory($this);
  397. }
  398. return $this;
  399. }
  400. /**
  401. * @return Collection<int, CabinCategoryCharacteristicValue>
  402. */
  403. public function getCabinCategoryCharacteristicValues(): Collection
  404. {
  405. return $this->cabinCategoryCharacteristicValues;
  406. }
  407. /**
  408. * Ajoute une valeur de caractéristique à cette catégorie de cabine.
  409. *
  410. * @param CabinCategoryCharacteristicValue $value
  411. * @return self
  412. */
  413. public function addCabinCategoryCharacteristicValue(CabinCategoryCharacteristicValue $value): self
  414. {
  415. if (!$this->cabinCategoryCharacteristicValues->contains($value)) {
  416. $this->cabinCategoryCharacteristicValues[] = $value;
  417. $value->setCabinCategory($this);
  418. }
  419. return $this;
  420. }
  421. /**
  422. * Retire une valeur de caractéristique de cette catégorie de cabine.
  423. *
  424. * @param CabinCategoryCharacteristicValue $value
  425. * @return self
  426. */
  427. public function removeCabinCategoryCharacteristicValue(CabinCategoryCharacteristicValue $value): self
  428. {
  429. if ($this->cabinCategoryCharacteristicValues->removeElement($value)) {
  430. if ($value->getCabinCategory() === $this) {
  431. $value->setCabinCategory(null);
  432. }
  433. }
  434. return $this;
  435. }
  436. /**
  437. * Method liée au Média Bundle
  438. */
  439. public function getMediaTagOwnerLabel(): ?string
  440. {
  441. return $this->getCode() . " (" . $this->getShip()->getName() . ') [' . $this->getId() . ']';
  442. }
  443. /**
  444. * Method liée au Média Bundle
  445. * @return class-string
  446. */
  447. public function getFqcn(): string
  448. {
  449. return ClassUtils::getClass($this);
  450. }
  451. }