src/AdminBundle/Entity/BookingExtra.php line 253

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. #[ORM\Table(name: 'booking_extra')]
  8. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\BookingExtraRepository::class)]
  9. #[ORM\HasLifecycleCallbacks]
  10. class BookingExtra
  11. {
  12. const STATUS_INACTIVE = 0;
  13. const STATUS_ACTIVE = 1;
  14. static $statusTypes = [
  15. self::STATUS_ACTIVE => 'active',
  16. self::STATUS_INACTIVE => 'inactive',
  17. ];
  18. const BOOKING_EXTRA_FILE_FOLDER = 'upload/booking-extra/';
  19. /**
  20. * @var integer
  21. */
  22. #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
  23. #[ORM\Id]
  24. #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  25. protected $id;
  26. /**
  27. * @var string
  28. */
  29. #[ORM\Column(name: 'name', type: 'string', length: 255, nullable: false)]
  30. protected $name;
  31. /**
  32. * @var string
  33. */
  34. #[ORM\Column(name: 'short_name', type: 'string', length: 64, nullable: false)]
  35. protected $shortName;
  36. /**
  37. * @var string
  38. */
  39. #[ORM\Column(type: 'string', length: 64, nullable: true)]
  40. protected $icon;
  41. /**
  42. * @var string
  43. */
  44. #[ORM\Column(name: 'extras_details', type: 'text', nullable: true)]
  45. protected $extraDetails;
  46. /**
  47. * @var string
  48. */
  49. #[ORM\Column(name: 'image', type: 'string', length: 255, nullable: true)]
  50. protected $image;
  51. /**
  52. * @var string
  53. */
  54. #[ORM\Column(name: 'show_on_booking_form', type: 'boolean', nullable: true, options: ['default' => 1])]
  55. protected $showOnBookingForm = true;
  56. /**
  57. * @var string
  58. */
  59. #[ORM\Column(name: 'pre_checked', type: 'boolean', nullable: true, options: ['default' => 0])]
  60. protected $preChecked = false;
  61. /**
  62. * @var integer
  63. */
  64. #[ORM\GeneratedValue(strategy: 'AUTO')]
  65. #[ORM\Column(name: 'priority', type: 'integer', nullable: true)]
  66. protected $priority;
  67. #[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
  68. protected $imageFile;
  69. /**
  70. * @var integer
  71. */
  72. #[ORM\Column(name: 'status', type: 'integer')]
  73. protected $status;
  74. /**
  75. * @var float
  76. */
  77. #[ORM\Column(name: 'charge', type: 'decimal', precision: 7, scale: 2, nullable: false)]
  78. protected $charge;
  79. #[ORM\OneToMany(targetEntity: \BookingBookingExtra::class, mappedBy: 'bookingExtra')]
  80. protected $bookingBookingExtras;
  81. /**
  82. * @var \DateTime
  83. */
  84. #[ORM\Column(name: 'updated', type: 'datetime', nullable: true)]
  85. protected $updated;
  86. public function __construct()
  87. {
  88. $this->bookingBookingExtras = new ArrayCollection();
  89. $this->updated = new \DateTime();
  90. }
  91. /**
  92. * @return int
  93. */
  94. public function getId()
  95. {
  96. return $this->id;
  97. }
  98. /**
  99. * @param int $id
  100. */
  101. public function setId($id)
  102. {
  103. $this->id = $id;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getName()
  109. {
  110. return $this->name;
  111. }
  112. /**
  113. * @param string $name
  114. */
  115. public function setName($name)
  116. {
  117. $this->name = $name;
  118. }
  119. /**
  120. * @return mixed
  121. */
  122. public function getBookingBookingExtras()
  123. {
  124. return $this->bookingBookingExtras;
  125. }
  126. /**
  127. * @param mixed $bookingBookingExtras
  128. */
  129. public function setBookingBookingExtras($bookingBookingExtras)
  130. {
  131. $this->bookingBookingExtras = $bookingBookingExtras;
  132. }
  133. /**
  134. * @return string
  135. */
  136. public function getExtraDetails()
  137. {
  138. return $this->extraDetails;
  139. }
  140. /**
  141. * @param string $extraDetails
  142. */
  143. public function setExtraDetails($extraDetails)
  144. {
  145. $this->extraDetails = $extraDetails;
  146. }
  147. /**
  148. * @return array
  149. */
  150. public static function getStatusTypes()
  151. {
  152. return self::$statusTypes;
  153. }
  154. /**
  155. * @return string
  156. */
  157. public function getShortName()
  158. {
  159. return $this->shortName;
  160. }
  161. public function setShortName($shortName)
  162. {
  163. $this->shortName = $shortName;
  164. }
  165. /**
  166. * @return string
  167. */
  168. public function getIcon()
  169. {
  170. return $this->icon;
  171. }
  172. public function setIcon($icon)
  173. {
  174. $this->icon = $icon;
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function getImage()
  180. {
  181. return $this->image;
  182. }
  183. public function setImage($image)
  184. {
  185. $this->image = $image;
  186. }
  187. /**
  188. * @return int
  189. */
  190. public function getStatus()
  191. {
  192. return $this->status;
  193. }
  194. public function setStatus($status)
  195. {
  196. $this->status = $status;
  197. }
  198. /**
  199. * @return float
  200. */
  201. public function getCharge()
  202. {
  203. return $this->charge;
  204. }
  205. public function setCharge($charge)
  206. {
  207. $this->charge = $charge;
  208. }
  209. /**
  210. * @param UploadedFile $picture
  211. */
  212. public function setImageFile(UploadedFile $imageFile = null)
  213. {
  214. $this->imageFile = $imageFile;
  215. }
  216. public function getImageFile()
  217. {
  218. return $this->imageFile;
  219. }
  220. public function getImagePath()
  221. {
  222. if (!$this->image) {
  223. return ;
  224. }
  225. return self::BOOKING_EXTRA_FILE_FOLDER . $this->image;
  226. }
  227. public function uploadImage()
  228. {
  229. if (null === $this->getImageFile()) {
  230. return;
  231. }
  232. $this->removeImageFile();
  233. $filename = sha1(uniqid(mt_rand(), true));
  234. $this->image = $filename.'.'.$this->getImageFile()->guessExtension();
  235. $this->getImageFile()->move(
  236. self::BOOKING_EXTRA_FILE_FOLDER,
  237. $this->image
  238. );
  239. $this->setImageFile(null);
  240. }
  241. public function removeImageFile()
  242. {
  243. if ($imageFile = $this->getImagePath()) {
  244. @unlink($imageFile);
  245. }
  246. }
  247. public function setUpdated($updated)
  248. {
  249. $this->updated = $updated;
  250. }
  251. public function getUpdated()
  252. {
  253. return $this->updated;
  254. }
  255. public function refreshUpdated()
  256. {
  257. $this->setUpdated(new \DateTime());
  258. }
  259. #[ORM\PreUpdate]
  260. #[ORM\PrePersist]
  261. public function lifecycleFileUpload()
  262. {
  263. $this->uploadImage();
  264. }
  265. #[ORM\PostRemove]
  266. public function removeUpload()
  267. {
  268. $this->removeImageFile();
  269. }
  270. public function __toString()
  271. {
  272. return $this->getName() ? $this->getName() : 'n\a';
  273. }
  274. /**
  275. * @return mixed
  276. */
  277. public function getShowOnBookingForm()
  278. {
  279. return $this->showOnBookingForm;
  280. }
  281. /**
  282. * @param mixed $showOnBookingForm
  283. */
  284. public function setShowOnBookingForm($showOnBookingForm)
  285. {
  286. $this->showOnBookingForm = $showOnBookingForm;
  287. }
  288. /**
  289. * @return string
  290. */
  291. public function getPreChecked()
  292. {
  293. return $this->preChecked;
  294. }
  295. /**
  296. * @param string $preChecked
  297. */
  298. public function setPreChecked($preChecked)
  299. {
  300. $this->preChecked = $preChecked;
  301. }
  302. /**
  303. * @return int
  304. */
  305. public function getPriority()
  306. {
  307. return $this->priority;
  308. }
  309. /**
  310. * @param int $priority
  311. */
  312. public function setPriority($priority)
  313. {
  314. $this->priority = $priority;
  315. }
  316. }