vendor/croisiland/common-bundle/src/Entity/Offer/Offer.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Croisiland\CommonBundle\Entity\Offer;
  4. use Crea\ToolsBundle\Entity\CreaIconIdentifiedInterface;
  5. use Crea\ToolsBundle\Entity\CreaIconTrait;
  6. use Crea\MediaBundle\Entity\MediaTagOwnerInterface;
  7. use Crea\ParameterBundle\Entity\Parameter;
  8. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  9. use Croisiland\CommonBundle\Annotation\Offer\OfferFormValidator;
  10. use Croisiland\CommonBundle\Entity\Company\Company;
  11. use Croisiland\CommonBundle\Entity\Partner\Partner;
  12. use Croisiland\CommonBundle\Entity\Price\Price;
  13. use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
  14. use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
  15. use Croisiland\CommonBundle\Repository\Offer\OfferRepository;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\Common\Util\ClassUtils;
  19. use Doctrine\ORM\Mapping as ORM;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. /**
  22. * @ORM\Entity(repositoryClass=OfferRepository::class)
  23. *
  24. * @OfferFormValidator(groups={"offer_form_validator"})
  25. */
  26. class Offer implements MediaTagOwnerInterface, CreaIconIdentifiedInterface
  27. {
  28. use LifecycleUserIdentifierTrait;
  29. use IsActiveTrait;
  30. use ListOrderTrait;
  31. /**
  32. * @ORM\Id
  33. *
  34. * @ORM\GeneratedValue
  35. *
  36. * @ORM\Column(type="integer")
  37. */
  38. private ?int $id = null;
  39. /**
  40. * @var Collection<int, Company>
  41. *
  42. * @ORM\ManyToMany(targetEntity=Company::class, inversedBy="offers")
  43. */
  44. private Collection $companies;
  45. /**
  46. * @ORM\Column(type="string", length=255, nullable=true)
  47. */
  48. private ?string $shortConditions = null;
  49. /**
  50. * @ORM\Column(type="text", nullable=true)
  51. */
  52. private ?string $conditions = null;
  53. /**
  54. * @ORM\Column(type="string", length=255, nullable=true)
  55. */
  56. private ?string $shortDescription = null;
  57. /**
  58. * @ORM\Column(type="text", nullable=true)
  59. */
  60. private ?string $description = null;
  61. /**
  62. * @ORM\Column(type="text", nullable=true)
  63. */
  64. private ?string $headerDescription = null;
  65. /**
  66. * @ORM\Column(type="string", length=255)
  67. */
  68. private ?string $displayedName = null;
  69. /**
  70. * @ORM\Column(type="text", nullable=true)
  71. */
  72. private ?string $metaDescription = null;
  73. /**
  74. * @ORM\Column(type="string", length=255)
  75. */
  76. private ?string $name = null;
  77. /**
  78. * @ORM\ManyToOne(targetEntity=OfferCategory::class, inversedBy="offers")
  79. */
  80. private ?OfferCategory $offerCategory = null;
  81. /**
  82. * @var Collection<int, OfferCruise>
  83. *
  84. * @ORM\OneToMany(targetEntity=OfferCruise::class, mappedBy="offer", orphanRemoval=true)
  85. */
  86. private Collection $offerCruises;
  87. /**
  88. * @ORM\ManyToOne(targetEntity=Parameter::class)
  89. *
  90. * @ORM\JoinColumn(nullable=false)
  91. */
  92. private ?Parameter $offerType = null;
  93. /**
  94. * @var Collection<int, Partner>
  95. *
  96. * @ORM\ManyToMany(targetEntity=Partner::class, inversedBy="offers")
  97. */
  98. private Collection $partners;
  99. /**
  100. * @ORM\Column(type="boolean")
  101. */
  102. private bool $permanent = false;
  103. /**
  104. * @var Collection<int, Price>
  105. *
  106. * @ORM\OneToMany(targetEntity=Price::class, mappedBy="offer", orphanRemoval=false)
  107. */
  108. private Collection $prices;
  109. /**
  110. * @ORM\Column(type="text", nullable=true)
  111. */
  112. private ?string $summary = null;
  113. /**
  114. * @ORM\Column(type="string", length=100, unique=true)
  115. *
  116. * @Gedmo\Slug(fields={"name"}, updatable=false, unique=true)
  117. */
  118. private ?string $slug = null;
  119. /**
  120. * @ORM\Column(type="date", nullable=true)
  121. */
  122. private ?\DateTimeInterface $validityEndsAt = null;
  123. /**
  124. * @ORM\Column(type="date", nullable=true)
  125. */
  126. private ?\DateTimeInterface $validityStartsAt = null;
  127. /**
  128. * @var Collection<int, Parameter>
  129. *
  130. * @ORM\ManyToMany(targetEntity=Parameter::class)
  131. */
  132. private Collection $visibilities;
  133. /**
  134. * @ORM\Column(type="boolean")
  135. */
  136. private bool $webReservation = true;
  137. public function __construct()
  138. {
  139. $this->companies = new ArrayCollection();
  140. $this->offerCruises = new ArrayCollection();
  141. $this->partners = new ArrayCollection();
  142. $this->prices = new ArrayCollection();
  143. $this->visibilities = new ArrayCollection();
  144. }
  145. public function getId(): ?int
  146. {
  147. return $this->id;
  148. }
  149. public function addCompany(Company $company): self
  150. {
  151. if (!$this->companies->contains($company)) {
  152. $this->companies[] = $company;
  153. }
  154. return $this;
  155. }
  156. /**
  157. * @return Collection<int, Company>
  158. */
  159. public function getCompanies(): Collection
  160. {
  161. return $this->companies;
  162. }
  163. public function removeCompany(Company $company): self
  164. {
  165. $this->companies->removeElement($company);
  166. return $this;
  167. }
  168. public function getShortConditions(): ?string
  169. {
  170. return $this->shortConditions;
  171. }
  172. public function setShortConditions(?string $shortConditions): self
  173. {
  174. $this->shortConditions = $shortConditions;
  175. return $this;
  176. }
  177. public function getConditions(): ?string
  178. {
  179. return $this->conditions;
  180. }
  181. public function setConditions(?string $conditions): self
  182. {
  183. $this->conditions = $conditions;
  184. return $this;
  185. }
  186. public function getShortDescription(): ?string
  187. {
  188. return $this->shortDescription;
  189. }
  190. public function setShortDescription(?string $shortDescription): self
  191. {
  192. $this->shortDescription = $shortDescription;
  193. return $this;
  194. }
  195. public function getDescription(): ?string
  196. {
  197. return $this->description;
  198. }
  199. public function setDescription(?string $description): self
  200. {
  201. $this->description = $description;
  202. return $this;
  203. }
  204. public function getHeaderDescription(): ?string
  205. {
  206. return $this->headerDescription;
  207. }
  208. public function setHeaderDescription(?string $headerDescription): self
  209. {
  210. $this->headerDescription = $headerDescription;
  211. return $this;
  212. }
  213. public function getDisplayedName(): ?string
  214. {
  215. return $this->displayedName;
  216. }
  217. public function setDisplayedName(?string $displayedName): self
  218. {
  219. $this->displayedName = $displayedName;
  220. return $this;
  221. }
  222. /**
  223. * Method liée au Média Bundle
  224. */
  225. public function getMediaTagOwnerLabel(): ?string
  226. {
  227. return $this->getName();
  228. }
  229. public function getMetaDescription(): ?string
  230. {
  231. return $this->metaDescription;
  232. }
  233. public function setMetaDescription(?string $metaDescription): self
  234. {
  235. $this->metaDescription = $metaDescription;
  236. return $this;
  237. }
  238. public function getName(): ?string
  239. {
  240. return $this->name;
  241. }
  242. public function setName(?string $name): self
  243. {
  244. $this->name = $name;
  245. return $this;
  246. }
  247. public function getOfferCategory(): ?OfferCategory
  248. {
  249. return $this->offerCategory;
  250. }
  251. public function setOfferCategory(?OfferCategory $offerCategory): self
  252. {
  253. $this->offerCategory = $offerCategory;
  254. return $this;
  255. }
  256. public function addOfferCruise(OfferCruise $offerCruise): self
  257. {
  258. if (!$this->offerCruises->contains($offerCruise)) {
  259. $this->offerCruises[] = $offerCruise;
  260. $offerCruise->setOffer($this);
  261. }
  262. return $this;
  263. }
  264. /**
  265. * @return Collection<int, OfferCruise>
  266. */
  267. public function getOfferCruises(): Collection
  268. {
  269. return $this->offerCruises;
  270. }
  271. public function removeOfferCruise(OfferCruise $offerCruise): self
  272. {
  273. if ($this->offerCruises->removeElement($offerCruise)) {
  274. if ($offerCruise->getOffer() === $this) {
  275. $offerCruise->setOffer(null);
  276. }
  277. }
  278. return $this;
  279. }
  280. public function getOfferType(): ?Parameter
  281. {
  282. return $this->offerType;
  283. }
  284. public function setOfferType(?Parameter $offerType): self
  285. {
  286. $this->offerType = $offerType;
  287. return $this;
  288. }
  289. public function addPartner(Partner $partner): self
  290. {
  291. if (!$this->partners->contains($partner)) {
  292. $this->partners[] = $partner;
  293. }
  294. return $this;
  295. }
  296. /**
  297. * @return Collection<int, Partner>
  298. */
  299. public function getPartners(): Collection
  300. {
  301. return $this->partners;
  302. }
  303. public function removePartner(Partner $partner): self
  304. {
  305. $this->partners->removeElement($partner);
  306. return $this;
  307. }
  308. public function isPermanent(): ?bool
  309. {
  310. return $this->permanent;
  311. }
  312. public function setPermanent(bool $permanent): self
  313. {
  314. $this->permanent = $permanent;
  315. return $this;
  316. }
  317. public function addPrice(Price $price): self
  318. {
  319. if (!$this->prices->contains($price)) {
  320. $this->prices[] = $price;
  321. $price->setOffer($this);
  322. }
  323. return $this;
  324. }
  325. /**
  326. * @return Collection<int, Price>
  327. */
  328. public function getPrices(): Collection
  329. {
  330. return $this->prices;
  331. }
  332. public function removePrice(Price $price): self
  333. {
  334. if ($this->prices->removeElement($price)) {
  335. if ($price->getOffer() === $this) {
  336. $price->setOffer(null);
  337. }
  338. }
  339. return $this;
  340. }
  341. public function getSummary(): ?string
  342. {
  343. return $this->summary;
  344. }
  345. public function setSummary(?string $summary): self
  346. {
  347. $this->summary = $summary;
  348. return $this;
  349. }
  350. public function getSlug(): ?string
  351. {
  352. return $this->slug;
  353. }
  354. public function setSlug(?string $slug): self
  355. {
  356. $this->slug = $slug;
  357. return $this;
  358. }
  359. public function getValidityEndsAt(): ?\DateTimeInterface
  360. {
  361. return $this->validityEndsAt;
  362. }
  363. public function setValidityEndsAt(?\DateTimeInterface $validityEndsAt): self
  364. {
  365. $this->validityEndsAt = $validityEndsAt;
  366. return $this;
  367. }
  368. public function getValidityStartsAt(): ?\DateTimeInterface
  369. {
  370. return $this->validityStartsAt;
  371. }
  372. public function setValidityStartsAt(?\DateTimeInterface $validityStartsAt): self
  373. {
  374. $this->validityStartsAt = $validityStartsAt;
  375. return $this;
  376. }
  377. public function addVisibility(Parameter $visibility): self
  378. {
  379. if (!$this->visibilities->contains($visibility)) {
  380. $this->visibilities[] = $visibility;
  381. }
  382. return $this;
  383. }
  384. /**
  385. * @return Collection<int, Parameter>
  386. */
  387. public function getVisibilities(): Collection
  388. {
  389. return $this->visibilities;
  390. }
  391. public function removeVisibility(Parameter $visibility): self
  392. {
  393. $this->visibilities->removeElement($visibility);
  394. return $this;
  395. }
  396. public function isWebReservation(): ?bool
  397. {
  398. return $this->webReservation;
  399. }
  400. public function setWebReservation(bool $webReservation): self
  401. {
  402. $this->webReservation = $webReservation;
  403. return $this;
  404. }
  405. /**
  406. * Method liée au Média Bundle
  407. * @return class-string
  408. */
  409. public function getFqcn(): string
  410. {
  411. return ClassUtils::getClass($this);
  412. }
  413. public function setIcon(?string $icon): static
  414. {
  415. return $this->offerCategory->setIcon($icon);
  416. }
  417. public function getIcon(): ?string
  418. {
  419. return $this->offerCategory->getIcon();
  420. }
  421. public function getIconLabel(): ?string
  422. {
  423. return $this->getName();
  424. }
  425. /**
  426. * @return array<string,int|string>
  427. */
  428. public function getIconOptions(): array
  429. {
  430. $options = [
  431. 'fill' => $this->offerCategory->getIconColorFill(),
  432. 'stroke' => $this->offerCategory->getIconColorStroke(),
  433. 'stroke-width' => $this->offerCategory->getIconStrokeWidth(),
  434. 'stroke-linecap' => $this->offerCategory->getIconStrokeLinecap(),
  435. 'stroke-linejoin' => $this->offerCategory->getIconStrokeLinejoin(),
  436. ];
  437. return array_filter($options);
  438. }
  439. }