src/AdminBundle/Entity/CarType.php line 14

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. /**
  7. * CarType
  8. */
  9. #[ORM\Table(name: 'car_type')]
  10. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\CarTypeRepository::class)]
  11. #[ORM\HasLifecycleCallbacks]
  12. class CarType extends BaseEntity
  13. {
  14. const CAR_TYPE_FILE_FOLDER = 'upload/vehicleType/';
  15. /**
  16. * @var integer
  17. */
  18. #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
  19. #[ORM\Id]
  20. #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  21. protected $id;
  22. /**
  23. * @var string
  24. */
  25. #[ORM\Column(name: 'name', type: 'string', length: 64)]
  26. protected $name;
  27. /**
  28. * @var string
  29. */
  30. #[ORM\Column(name: 'short_name', type: 'string', length: 64)]
  31. protected $shortName;
  32. /**
  33. * @var string
  34. */
  35. #[ORM\Column(name: 'description', type: 'string', length: 64)]
  36. protected $description;
  37. /**
  38. * @var integer
  39. */
  40. #[ORM\Column(name: 'passengers', type: 'integer')]
  41. protected $passengers;
  42. /**
  43. * @var integer
  44. */
  45. #[ORM\Column(name: 'luggage', type: 'integer')]
  46. protected $luggage;
  47. /**
  48. * @var integer
  49. */
  50. #[ORM\Column(name: 'hand_luggage', type: 'integer')]
  51. protected $handLuggage;
  52. /**
  53. * @var float
  54. */
  55. #[ORM\Column(name: 'price_unit', type: 'float')]
  56. protected $priceUnit;
  57. /**
  58. * @var integer
  59. */
  60. #[ORM\Column(name: 'long_distance', type: 'integer')]
  61. protected $longDistance;
  62. /**
  63. * @var integer
  64. */
  65. #[ORM\Column(name: 'long_distance_adjustment', type: 'integer')]
  66. protected $longDistanceAdjustment;
  67. /**
  68. * @var integer
  69. */
  70. #[ORM\Column(name: 'duration_extra_charge', type: 'float')]
  71. protected $durationExtraCharge;
  72. /**
  73. * @var integer
  74. */
  75. #[ORM\Column(name: 'duration_extra_charge_after', type: 'integer')]
  76. protected $durationExtraChargeAfter;
  77. /**
  78. * @var integer
  79. */
  80. #[ORM\Column(name: 'every_extra_distance', type: 'integer')]
  81. protected $everyExtraDistance;
  82. /**
  83. * @var integer
  84. */
  85. #[ORM\Column(name: 'every_extra_distance_cost', type: 'integer')]
  86. protected $everyExtraDistanceCost;
  87. /**
  88. * @var bool
  89. */
  90. #[ORM\Column(name: 'status', type: 'boolean')]
  91. protected $status;
  92. /**
  93. * @var float
  94. */
  95. #[ORM\Column(name: 'minimum_charge', type: 'float')]
  96. protected $minimumCharge;
  97. /**
  98. * @var float
  99. */
  100. #[ORM\Column(name: 'bookfornow_charge_min', type: 'float', options: ['default' => 0])]
  101. protected $bookfornowChargeMin;
  102. /**
  103. * @var float
  104. */
  105. #[ORM\Column(name: 'dynamic_pricing_charge', type: 'decimal', precision: 7, scale: 2)]
  106. protected $dynamicPricingCharge;
  107. /**
  108. * @var float
  109. */
  110. #[ORM\Column(name: 'tour_extra_price_per_hour', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  111. protected $tourExtraPricePerHour = 15;
  112. /**
  113. * @var float
  114. */
  115. #[ORM\Column(name: 'quick_quote_pricing', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  116. protected $quickQuotePricing = 0;
  117. /**
  118. * @var float
  119. */
  120. #[ORM\Column(name: 'max_price_undispatched_booking', type: 'decimal', precision: 7, scale: 2, nullable: true, options: ['default' => 0])]
  121. protected $maxPriceUndispatchedBooking = 0;
  122. /**
  123. * @var \Doctrine\Common\Collections\ArrayCollection
  124. */
  125. #[ORM\JoinTable(name: 'car_type_replacements')]
  126. #[ORM\JoinColumn(name: 'car_a_id', referencedColumnName: 'id')]
  127. #[ORM\InverseJoinColumn(name: 'car_b_id', referencedColumnName: 'id')]
  128. #[ORM\ManyToMany(targetEntity: \CarType::class)]
  129. protected $replacements;
  130. /**
  131. * @var boolean
  132. */
  133. #[ORM\Column(name: 'show_on_booking_form', type: 'boolean', nullable: true, options: ['default' => 1])]
  134. protected $showOnBookingForm = 1;
  135. /**
  136. * @var string
  137. */
  138. #[ORM\Column(name: 'image', type: 'string', length: 255, nullable: true)]
  139. protected $image;
  140. /**
  141. * @var \DateTime
  142. */
  143. #[ORM\Column(name: 'creation_date', type: 'date', nullable: true)]
  144. protected $creationDate;
  145. private $imageFile;
  146. public function __construct()
  147. {
  148. $this->replacements = new ArrayCollection();
  149. $this->creationDate = new \DateTime();
  150. $this->bookfornowChargeMin = 0;
  151. }
  152. /**
  153. * @return int
  154. */
  155. public function getId()
  156. {
  157. return $this->id;
  158. }
  159. /**
  160. * @param int $id
  161. */
  162. public function setId($id)
  163. {
  164. $this->id = $id;
  165. }
  166. /**
  167. * @return string
  168. */
  169. public function getName()
  170. {
  171. return $this->name;
  172. }
  173. /**
  174. * @param string $name
  175. */
  176. public function setName($name)
  177. {
  178. $this->name = $name;
  179. }
  180. /**
  181. * @return string
  182. */
  183. public function getShortName()
  184. {
  185. return $this->shortName;
  186. }
  187. /**
  188. * @param string $shortName
  189. */
  190. public function setShortName($shortName)
  191. {
  192. $this->shortName = $shortName;
  193. }
  194. /**
  195. * @return string
  196. */
  197. public function getDescription()
  198. {
  199. return $this->description;
  200. }
  201. /**
  202. * @param string $description
  203. */
  204. public function setDescription($description)
  205. {
  206. $this->description = $description;
  207. }
  208. /**
  209. * @return mixed
  210. */
  211. public function getReplacements()
  212. {
  213. return $this->replacements;
  214. }
  215. /**
  216. * @param mixed $replacements
  217. */
  218. public function setReplacements($replacements)
  219. {
  220. $this->replacements = $replacements;
  221. }
  222. /**
  223. * @return array
  224. */
  225. public function getReplacementIds()
  226. {
  227. $ids = [];
  228. foreach ($this->getReplacements() as $replacement) {
  229. $ids[] = $replacement->getId();
  230. }
  231. return $ids;
  232. }
  233. /**
  234. * @return int
  235. */
  236. public function getPassengers()
  237. {
  238. return $this->passengers;
  239. }
  240. /**
  241. * @param int $passengers
  242. */
  243. public function setPassengers($passengers)
  244. {
  245. $this->passengers = $passengers;
  246. }
  247. /**
  248. * @return int
  249. */
  250. public function getLuggage()
  251. {
  252. return $this->luggage;
  253. }
  254. /**
  255. * @param int $luggage
  256. */
  257. public function setLuggage($luggage)
  258. {
  259. $this->luggage = $luggage;
  260. }
  261. /**
  262. * @return int
  263. */
  264. public function getHandLuggage()
  265. {
  266. return $this->handLuggage;
  267. }
  268. /**
  269. * @param int $handLuggage
  270. */
  271. public function setHandLuggage($handLuggage)
  272. {
  273. $this->handLuggage = $handLuggage;
  274. }
  275. /**
  276. * @return int
  277. */
  278. public function getPriceUnit()
  279. {
  280. return $this->priceUnit;
  281. }
  282. /**
  283. * @param int $priceUnit
  284. */
  285. public function setPriceUnit($priceUnit)
  286. {
  287. $this->priceUnit = $priceUnit;
  288. }
  289. /**
  290. * @return int
  291. */
  292. public function getLongDistance()
  293. {
  294. return $this->longDistance;
  295. }
  296. /**
  297. * @param int $longDistance
  298. */
  299. public function setLongDistance($longDistance)
  300. {
  301. $this->longDistance = $longDistance;
  302. }
  303. /**
  304. * @return int
  305. */
  306. public function getLongDistanceAdjustment()
  307. {
  308. return $this->longDistanceAdjustment;
  309. }
  310. /**
  311. * @param int $longDistanceAdjustment
  312. */
  313. public function setLongDistanceAdjustment($longDistanceAdjustment)
  314. {
  315. $this->longDistanceAdjustment = $longDistanceAdjustment;
  316. }
  317. /**
  318. * @return int
  319. */
  320. public function getDurationExtraCharge()
  321. {
  322. return $this->durationExtraCharge;
  323. }
  324. /**
  325. * @param int $durationExtraCharge
  326. */
  327. public function setDurationExtraCharge($durationExtraCharge)
  328. {
  329. $this->durationExtraCharge = $durationExtraCharge;
  330. }
  331. /**
  332. * @return int
  333. */
  334. public function getDurationExtraChargeAfter()
  335. {
  336. return $this->durationExtraChargeAfter;
  337. }
  338. /**
  339. * @param int $durationExtraChargeAfter
  340. */
  341. public function setDurationExtraChargeAfter($durationExtraChargeAfter)
  342. {
  343. $this->durationExtraChargeAfter = $durationExtraChargeAfter;
  344. }
  345. /**
  346. * @return int
  347. */
  348. public function getEveryExtraDistance()
  349. {
  350. return $this->everyExtraDistance;
  351. }
  352. /**
  353. * @param int $everyExtraDistance
  354. */
  355. public function setEveryExtraDistance($everyExtraDistance)
  356. {
  357. $this->everyExtraDistance = $everyExtraDistance;
  358. }
  359. /**
  360. * @return int
  361. */
  362. public function getEveryExtraDistanceCost()
  363. {
  364. return $this->everyExtraDistanceCost;
  365. }
  366. /**
  367. * @param int $everyExtraDistanceCost
  368. */
  369. public function setEveryExtraDistanceCost($everyExtraDistanceCost)
  370. {
  371. $this->everyExtraDistanceCost = $everyExtraDistanceCost;
  372. }
  373. /**
  374. * @return boolean
  375. */
  376. public function isStatus()
  377. {
  378. return $this->status;
  379. }
  380. /**
  381. * @param boolean $status
  382. */
  383. public function setStatus($status)
  384. {
  385. $this->status = $status;
  386. }
  387. /**
  388. * @return float
  389. */
  390. public function getMinimumCharge()
  391. {
  392. return $this->minimumCharge;
  393. }
  394. /**
  395. * @param float $minimumCharge
  396. */
  397. public function setMinimumCharge($minimumCharge)
  398. {
  399. $this->minimumCharge = $minimumCharge;
  400. }
  401. /**
  402. * @return float
  403. */
  404. public function getBookfornowChargeMin() {
  405. return $this->bookfornowChargeMin;
  406. }
  407. /**
  408. * @param float $bookfornowChargeMin
  409. */
  410. public function setBookfornowChargeMin($bookfornowChargeMin) {
  411. $this->bookfornowChargeMin = $bookfornowChargeMin;
  412. }
  413. public function __toString()
  414. {
  415. return $this->getName() ? $this->getName() . ' (' . $this->getPassengers() . ')' : 'n\a';
  416. }
  417. /**
  418. * @return float
  419. */
  420. public function getDynamicPricingCharge()
  421. {
  422. return $this->dynamicPricingCharge;
  423. }
  424. /**
  425. * @param float $dynamicPricingCharge
  426. */
  427. public function setDynamicPricingCharge($dynamicPricingCharge)
  428. {
  429. $this->dynamicPricingCharge = $dynamicPricingCharge;
  430. }
  431. /**
  432. * @return float
  433. */
  434. public function getTourExtraPricePerHour()
  435. {
  436. return $this->tourExtraPricePerHour;
  437. }
  438. /**
  439. * @param float $tourExtraPricePerHour
  440. */
  441. public function setTourExtraPricePerHour($tourExtraPricePerHour)
  442. {
  443. $this->tourExtraPricePerHour = $tourExtraPricePerHour;
  444. }
  445. /**
  446. * @return float
  447. */
  448. public function getQuickQuotePricing()
  449. {
  450. return $this->quickQuotePricing;
  451. }
  452. /**
  453. * @param float $quickQuotePricing
  454. */
  455. public function setQuickQuotePricing($quickQuotePricing)
  456. {
  457. $this->quickQuotePricing = $quickQuotePricing;
  458. }
  459. /**
  460. * @return mixed
  461. */
  462. public function getMaxPriceUndispatchedBooking()
  463. {
  464. return $this->maxPriceUndispatchedBooking;
  465. }
  466. /**
  467. * @param mixed $maxPriceUndispatchedBooking
  468. */
  469. public function setMaxPriceUndispatchedBooking($maxPriceUndispatchedBooking)
  470. {
  471. $this->maxPriceUndispatchedBooking = $maxPriceUndispatchedBooking;
  472. }
  473. /**
  474. * @return bool
  475. */
  476. public function getShowOnBookingForm()
  477. {
  478. return $this->showOnBookingForm;
  479. }
  480. /**
  481. * @param bool $showOnBookingForm
  482. */
  483. public function setShowOnBookingForm($showOnBookingForm)
  484. {
  485. $this->showOnBookingForm = $showOnBookingForm;
  486. }
  487. /**
  488. * @return string
  489. */
  490. public function getImage()
  491. {
  492. return $this->image;
  493. }
  494. /**
  495. * @param string $image
  496. */
  497. public function setImage($image)
  498. {
  499. $this->image = $image;
  500. }
  501. /**
  502. * @param UploadedFile $imageFile
  503. */
  504. public function setImageFile(UploadedFile $imageFile = null)
  505. {
  506. $this->imageFile = $imageFile;
  507. }
  508. /**
  509. * @return UploadedFile
  510. */
  511. public function getImageFile()
  512. {
  513. return $this->imageFile;
  514. }
  515. public function getUploadFilePath()
  516. {
  517. if (!is_dir(self::CAR_TYPE_FILE_FOLDER.$this->id)) {
  518. mkdir(self::CAR_TYPE_FILE_FOLDER.$this->id, 0777, true);
  519. }
  520. return self::CAR_TYPE_FILE_FOLDER.$this->id.'/';
  521. }
  522. public function getImageFilePath()
  523. {
  524. if (!$this->image) {
  525. return ;
  526. }
  527. return $this->getUploadFilePath() . $this->image;
  528. }
  529. public function uploadImage()
  530. {
  531. if (null === $this->getImageFile()) {
  532. return;
  533. }
  534. $this->removeImageFile();
  535. $nDate= new \DateTime();
  536. $filename = 'VEHICLE_TYPE_IMAGE_'.$nDate->format('Y-m-d');
  537. $this->image = $filename.'.'.$this->getImageFile()->guessExtension();
  538. $this->getImageFile()->move(
  539. $this->getUploadFilePath(),
  540. $this->image
  541. );
  542. $this->setImageFile(null);
  543. }
  544. #[ORM\PreUpdate]
  545. #[ORM\PrePersist]
  546. public function lifecycleFileUpload()
  547. {
  548. $this->uploadImage();
  549. }
  550. #[ORM\PostRemove]
  551. public function removeUpload()
  552. {
  553. $this->removeImageFile();
  554. }
  555. public function removeImageFile()
  556. {
  557. if ($imageFile = $this->getImageFilePath()) {
  558. @unlink($imageFile);
  559. }
  560. }
  561. /**
  562. * @return \DateTime
  563. */
  564. public function getCreationDate()
  565. {
  566. return $this->creationDate;
  567. }
  568. /**
  569. * @param \DateTime $creationDate
  570. */
  571. public function setCreationDate(\DateTime $creationDate)
  572. {
  573. $this->creationDate = $creationDate;
  574. }
  575. }