vendor/croisiland/common-bundle/src/Model/CruiseSearchModel.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Croisiland\CommonBundle\Model;
  4. use Croisiland\CommonBundle\Entity\Company\Company;
  5. use Croisiland\CommonBundle\Entity\Itinerary\DestinationMain;
  6. use Croisiland\CommonBundle\Entity\Itinerary\DestinationSecondary;
  7. use Croisiland\CommonBundle\Entity\Itinerary\Stopover;
  8. use Croisiland\CommonBundle\Entity\Offer\Offer;
  9. use Croisiland\CommonBundle\Entity\Partner\Partner;
  10. use Croisiland\CommonBundle\Entity\Ship\Ship;
  11. use Croisiland\CommonBundle\Entity\Tag\Tag;
  12. use DateTime;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. class CruiseSearchModel
  16. {
  17. /**
  18. * @var Collection<int, Company> companies Ids
  19. */
  20. private Collection $companies;
  21. /**
  22. * @var Collection<int, Ship> ship Ids
  23. */
  24. private Collection $ships;
  25. /**
  26. * @var Collection<int, Stopover> first Itinerary Segment stopover Id
  27. */
  28. private Collection $departurePorts;
  29. /**
  30. * @var Collection<int, DestinationMain> Main Destinations
  31. */
  32. private Collection $destinationsMain;
  33. /**
  34. * @var Collection<int, DestinationSecondary> Secondary Destinations
  35. */
  36. private Collection $destinationsSecondary;
  37. /**
  38. * @var Collection<int, Tag> tag Ids
  39. */
  40. private Collection $tags;
  41. /**
  42. * @var Collection<int, Offer> offer Ids
  43. */
  44. private Collection $offers;
  45. private ?Partner $partner = null;
  46. private ?\DateTimeInterface $periodStartDate = null;
  47. private ?\DateTimeInterface $periodEndDate = null;
  48. private ?int $priceMinimum = null;
  49. private ?int $priceMaximum = null;
  50. private ?string $keywords = null;
  51. private ?string $cruiseCode = null;
  52. /**
  53. * @var array<string> durations in range days min-max where min or max can be set to x for 0 or infinite.
  54. */
  55. private array $durations = [];
  56. /**
  57. * if worldTour or not, null for all cruises.
  58. */
  59. private ?bool $worldTour = null;
  60. private ?string $sortProperty = null;
  61. private ?string $sortOrder = null;
  62. private ?int $page = null;
  63. private ?int $perPage = null;
  64. private bool $randomized = false;
  65. public const int DEFAULT_PAGE = 1;
  66. public const int DEFAULT_PER_PAGE = 10;
  67. public const string DEFAULT_SORT_PROPERTY = 'departureDate';
  68. public const string DEFAULT_SORT_ORDER = 'ASC';
  69. public function __construct()
  70. {
  71. $this->companies = new ArrayCollection();
  72. $this->ships = new ArrayCollection();
  73. $this->departurePorts = new ArrayCollection();
  74. $this->destinationsMain = new ArrayCollection();
  75. $this->destinationsSecondary = new ArrayCollection();
  76. $this->tags = new ArrayCollection();
  77. $this->offers = new ArrayCollection();
  78. }
  79. /**
  80. * @return array<string, mixed> propertyName => value
  81. */
  82. public function getProperties(): array
  83. {
  84. return get_object_vars($this);
  85. }
  86. /**
  87. * @return Collection<int, Company>
  88. */
  89. public function getCompanies(): Collection
  90. {
  91. return $this->companies;
  92. }
  93. /**
  94. * @param Collection<int, Company> $companies
  95. */
  96. public function setCompanies(Collection $companies): static
  97. {
  98. $this->companies = $companies;
  99. return $this;
  100. }
  101. public function addCompany(Company $company): static
  102. {
  103. $this->companies->add($company);
  104. return $this;
  105. }
  106. /**
  107. * @return Collection<int, Ship>
  108. */
  109. public function getShips(): Collection
  110. {
  111. return $this->ships;
  112. }
  113. /**
  114. * @param Collection<int, Ship> $ships
  115. */
  116. public function setShips(Collection $ships): static
  117. {
  118. $this->ships = $ships;
  119. return $this;
  120. }
  121. public function addShip(Ship $ship): static
  122. {
  123. $this->ships->add($ship);
  124. return $this;
  125. }
  126. /**
  127. * @return Collection<int, Stopover>
  128. */
  129. public function getDeparturePorts(): Collection
  130. {
  131. return $this->departurePorts;
  132. }
  133. /**
  134. * @param Collection<int, Stopover> $departurePorts
  135. */
  136. public function setDeparturePorts(Collection $departurePorts): static
  137. {
  138. $this->departurePorts = $departurePorts;
  139. return $this;
  140. }
  141. public function addDeparturePort(Stopover $port): static
  142. {
  143. $this->departurePorts->add($port);
  144. return $this;
  145. }
  146. /**
  147. * @return Collection<int, DestinationMain>
  148. */
  149. public function getDestinationsMain(): Collection
  150. {
  151. return $this->destinationsMain;
  152. }
  153. /**
  154. * @param Collection<int, DestinationMain> $destinationsMain
  155. */
  156. public function setDestinationsMain(Collection $destinationsMain): static
  157. {
  158. $this->destinationsMain = $destinationsMain;
  159. return $this;
  160. }
  161. public function addDestinationMain(DestinationMain $destination): static
  162. {
  163. $this->destinationsMain->add($destination);
  164. return $this;
  165. }
  166. /**
  167. * @return Collection<int, DestinationSecondary>
  168. */
  169. public function getDestinationsSecondary(): Collection
  170. {
  171. return $this->destinationsSecondary;
  172. }
  173. /**
  174. * @param Collection<int, DestinationSecondary> $destinationsSecondary
  175. */
  176. public function setDestinationsSecondary(Collection $destinationsSecondary): static
  177. {
  178. $this->destinationsSecondary = $destinationsSecondary;
  179. return $this;
  180. }
  181. public function addDestinationSecondary(DestinationSecondary $destination): static
  182. {
  183. $this->destinationsSecondary->add($destination);
  184. return $this;
  185. }
  186. public function destinationsIsSet(): bool
  187. {
  188. return !$this->destinationsSecondary->isEmpty() || !$this->destinationsMain->isEmpty();
  189. }
  190. /**
  191. * @return Collection<int,Tag>
  192. */
  193. public function getTags(): Collection
  194. {
  195. return $this->tags;
  196. }
  197. /**
  198. * @param Collection<int,Tag> $tags
  199. */
  200. public function setTags(Collection $tags): static
  201. {
  202. $this->tags = $tags;
  203. return $this;
  204. }
  205. public function addTag(Tag $tag): static
  206. {
  207. $this->tags->add($tag);
  208. return $this;
  209. }
  210. /**
  211. * @return Collection<int, Offer>
  212. */
  213. public function getOffers(): Collection
  214. {
  215. return $this->offers;
  216. }
  217. /**
  218. * @param Collection<int, Offer> $offers
  219. */
  220. public function setOffers(Collection $offers): static
  221. {
  222. $this->offers = $offers;
  223. return $this;
  224. }
  225. public function addOffer(Offer $offer): static
  226. {
  227. $this->offers->add($offer);
  228. return $this;
  229. }
  230. public function getPartner(): ?Partner
  231. {
  232. return $this->partner;
  233. }
  234. public function setPartner(?Partner $partner): static
  235. {
  236. $this->partner = $partner;
  237. return $this;
  238. }
  239. public function getPeriodStartDate(): ?\DateTimeInterface
  240. {
  241. return $this->periodStartDate;
  242. }
  243. public function setPeriodStartDate(?\DateTimeInterface $periodStartDate): static
  244. {
  245. $this->periodStartDate = $periodStartDate;
  246. return $this;
  247. }
  248. public function getPeriodEndDate(): ?\DateTimeInterface
  249. {
  250. return $this->periodEndDate;
  251. }
  252. public function setPeriodEndDate(?\DateTimeInterface $periodEndDate): static
  253. {
  254. if ($periodEndDate) {
  255. /** @var DateTime $periodEndDate */
  256. $periodEndDate->setTime(23, 59, 59);
  257. }
  258. $this->periodEndDate = $periodEndDate;
  259. return $this;
  260. }
  261. public function periodIsSet(): bool
  262. {
  263. return null !== $this->periodEndDate || null !== $this->periodStartDate;
  264. }
  265. /**
  266. * @return string[]
  267. */
  268. public function getDurations(): array
  269. {
  270. return $this->durations;
  271. }
  272. /**
  273. * @param string[] $durations
  274. */
  275. public function setDurations(array $durations): static
  276. {
  277. $this->durations = $durations;
  278. return $this;
  279. }
  280. public function getWorldTour(): ?bool
  281. {
  282. return $this->worldTour;
  283. }
  284. public function setWorldTour(?bool $worldTour): static
  285. {
  286. $this->worldTour = $worldTour;
  287. return $this;
  288. }
  289. public function getSortProperty(): ?string
  290. {
  291. return $this->sortProperty;
  292. }
  293. public function setSortProperty(?string $sortProperty): static
  294. {
  295. $this->sortProperty = $sortProperty;
  296. return $this;
  297. }
  298. public function getPriceMinimum(): ?int
  299. {
  300. return $this->priceMinimum;
  301. }
  302. public function setPriceMinimum(?int $priceMinimum): static
  303. {
  304. $this->priceMinimum = $priceMinimum;
  305. return $this;
  306. }
  307. public function getPriceMaximum(): ?int
  308. {
  309. return $this->priceMaximum;
  310. }
  311. public function setPriceMaximum(?int $priceMaximum): static
  312. {
  313. $this->priceMaximum = $priceMaximum;
  314. return $this;
  315. }
  316. public function priceRangeIsSet(): bool
  317. {
  318. return null !== $this->priceMaximum || null !== $this->priceMinimum;
  319. }
  320. public function getSortOrder(): ?string
  321. {
  322. return $this->sortOrder;
  323. }
  324. public function setSortOrder(?string $sortOrder): static
  325. {
  326. $this->sortOrder = $sortOrder;
  327. return $this;
  328. }
  329. public function getPage(): ?int
  330. {
  331. return $this->page;
  332. }
  333. public function setPage(?int $page): static
  334. {
  335. $this->page = max(1, $page);
  336. return $this;
  337. }
  338. public function getPerPage(): ?int
  339. {
  340. return $this->perPage;
  341. }
  342. public function setPerPage(?int $perPage): static
  343. {
  344. $this->perPage = max(1, $perPage);
  345. return $this;
  346. }
  347. public function getOffset(): int
  348. {
  349. return ($this->page - 1) * $this->perPage;
  350. }
  351. public function getLimit(): ?int
  352. {
  353. return $this->perPage;
  354. }
  355. public function getKeywords(): ?string
  356. {
  357. return $this->keywords;
  358. }
  359. public function setKeywords(?string $keywords): static
  360. {
  361. $this->keywords = $keywords;
  362. return $this;
  363. }
  364. public function getCruiseCode(): ?string
  365. {
  366. return $this->cruiseCode;
  367. }
  368. public function setCruiseCode(?string $cruiseCode): static
  369. {
  370. $this->cruiseCode = $cruiseCode;
  371. return $this;
  372. }
  373. public function isRandomized(): bool
  374. {
  375. return $this->randomized;
  376. }
  377. public function setRandomized(bool $randomized): CruiseSearchModel
  378. {
  379. $this->randomized = $randomized;
  380. return $this;
  381. }
  382. }