src/AdminBundle/Entity/PeriodSettings.php line 12

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * PeriodSettings
  7. */
  8. #[ORM\Table(name: 'period_settings')]
  9. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\PeriodSettingsRepository::class)]
  10. class PeriodSettings extends BaseEntity
  11. {
  12. const PERIOD_REPEATABLE_DAILY = 0;
  13. const PERIOD_REPEATABLE_WEEKLY = 1;
  14. const PERIOD_REPEATABLE_MONTHLY = 2;
  15. const PERIOD_REPEATABLE_YEARLY = 3;
  16. public static $periodRepeatableTypes = array(
  17. self::PERIOD_REPEATABLE_DAILY => 'daily',
  18. self::PERIOD_REPEATABLE_WEEKLY => 'weekly',
  19. self::PERIOD_REPEATABLE_MONTHLY => 'monthly',
  20. self::PERIOD_REPEATABLE_YEARLY => 'yearly'
  21. );
  22. const PERIOD_SPECIFIC_CHARGE_PERCENTAGE = 0;
  23. const PERIOD_SPECIFIC_CHARGE_VALUE = 1;
  24. public static $periodSpecificChargeTypes = array(
  25. self::PERIOD_SPECIFIC_CHARGE_PERCENTAGE => '%',
  26. self::PERIOD_SPECIFIC_CHARGE_VALUE => 'value'
  27. );
  28. const PERIOD_CHARGE_ADDED = 0;
  29. const PERIOD_CHARGE_SUBSTRACTED = 1;
  30. public static $periodChargeTypes = array(
  31. self::PERIOD_CHARGE_ADDED => '+',
  32. self::PERIOD_CHARGE_SUBSTRACTED => '-'
  33. );
  34. /**
  35. * @var integer
  36. */
  37. #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
  38. #[ORM\Id]
  39. #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  40. protected $id;
  41. /**
  42. * @var \String
  43. */
  44. #[ORM\Column(name: 'period_name', type: 'string', length: 64)]
  45. protected $periodName;
  46. /**
  47. * @var array
  48. */
  49. #[ORM\Column(name: 'period_start', type: 'array')]
  50. protected $periodStart;
  51. /**
  52. * @var array
  53. */
  54. #[ORM\Column(name: 'period_end', type: 'array')]
  55. protected $periodEnd;
  56. /**
  57. * @var \DateTime
  58. */
  59. #[ORM\Column(name: 'period_start_time', type: 'time')]
  60. protected $periodStartTime;
  61. /**
  62. * @var \DateTime
  63. */
  64. #[ORM\Column(name: 'period_end_time', type: 'time')]
  65. protected $periodEndTime;
  66. /**
  67. * @var \Integer
  68. */
  69. #[ORM\Column(name: 'period_repeatable', type: 'integer')]
  70. protected $periodRepeatable;
  71. /**
  72. * @var \Integer
  73. */
  74. #[ORM\Column(name: 'period_specific_charge_type', type: 'integer')]
  75. protected $periodSpecificChargeType;
  76. /**
  77. * @var \Integer
  78. */
  79. #[ORM\Column(name: 'period_specific_charge_value', type: 'integer', nullable: true)]
  80. protected $periodSpecificChargeValue;
  81. /**
  82. * @var \Integer
  83. */
  84. #[ORM\Column(name: 'period_charge_type', type: 'integer')]
  85. protected $periodChargeType;
  86. /**
  87. * @var integer
  88. */
  89. #[ORM\Column(name: 'booking_disabled', type: 'boolean', nullable: true)]
  90. protected $bookingDisabled = false;
  91. /**
  92. * @var \String
  93. */
  94. #[ORM\Column(name: 'disabled_messages', type: 'string', nullable: true)]
  95. protected $disabledMessages;
  96. /**
  97. * @var \String
  98. */
  99. #[ORM\Column(name: 'operator_disabled_messages', type: 'string', nullable: true)]
  100. protected $operatorDisabledMessage;
  101. /**
  102. * @var float
  103. */
  104. #[ORM\Column(name: 'minimum_price_booking', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  105. protected $minimumPriceBooking = 0;
  106. /**
  107. * @var \Integer
  108. */
  109. #[ORM\Column(name: 'period_priority', type: 'integer')]
  110. protected $periodPriority;
  111. #[ORM\JoinTable(name: 'periods_cartypes')]
  112. #[ORM\JoinColumn(name: 'cartype_id', referencedColumnName: 'id')]
  113. #[ORM\InverseJoinColumn(name: 'period_id', referencedColumnName: 'id')]
  114. #[ORM\ManyToMany(targetEntity: \CarType::class)]
  115. protected $carTypes;
  116. static function convertToDateTime($dateString)
  117. {
  118. $dateArray = explode('/', $dateString);
  119. return new \DateTime($dateArray[2]. '-' . $dateArray[0]. '-'. $dateArray[1]);
  120. }
  121. public function __construct()
  122. {
  123. $this->carTypes = new ArrayCollection();
  124. $this->periodStartTime = new \DateTime();
  125. $this->periodEndTime = new \DateTime();
  126. }
  127. /**
  128. * @return mixed
  129. */
  130. public function getCarTypes() {
  131. return $this->carTypes;
  132. }
  133. /**
  134. * @param mixed $var
  135. */
  136. public function setCarTypes($var) {
  137. $this->carTypes = $var;
  138. }
  139. /**
  140. * @return array
  141. */
  142. public function getCarTypeIds() {
  143. $ids = [];
  144. foreach ($this->getCarTypes() as $carType) {
  145. $ids[] = $carType->getId();
  146. }
  147. return $ids;
  148. }
  149. /**
  150. * @return int
  151. */
  152. public function getId()
  153. {
  154. return $this->id;
  155. }
  156. /**
  157. * @param int $id
  158. */
  159. public function setId($id)
  160. {
  161. $this->id = $id;
  162. }
  163. /**
  164. * @return String
  165. */
  166. public function getPeriodName()
  167. {
  168. return $this->periodName;
  169. }
  170. /**
  171. * @param String $periodName
  172. */
  173. public function setPeriodName($periodName)
  174. {
  175. $this->periodName = $periodName;
  176. }
  177. public function getPeriodStartTimeDateFormat()
  178. {
  179. $periodStartTime = new \DateTime();
  180. $periodStartTime->setTime(
  181. intval($this->periodStartTime->format('G')),
  182. intval($this->periodStartTime->format('i')),
  183. intval($this->periodStartTime->format('s'))
  184. );
  185. return $periodStartTime;
  186. }
  187. public function getPeriodStartTime()
  188. {
  189. if (! $this->periodStartTime) {
  190. return ;
  191. }
  192. return $this->periodStartTime->format('H:i');
  193. }
  194. public function setPeriodStartTime($periodStartTime)
  195. {
  196. if (is_string($periodStartTime)) {
  197. $timeArray = explode(':', $periodStartTime);
  198. $periodStartTime = new \DateTime();
  199. $periodStartTime->setTime(
  200. intval($timeArray[0]),
  201. intval($timeArray[1])
  202. );
  203. }
  204. $date = clone $this->periodStartTime;
  205. $date->setTime(
  206. intval($periodStartTime->format('G')),
  207. intval($periodStartTime->format('i')),
  208. intval($periodStartTime->format('s'))
  209. );
  210. $this->periodStartTime = $date;
  211. }
  212. /**
  213. * @return array
  214. */
  215. public function getPeriodStart()
  216. {
  217. return $this->periodStart;
  218. }
  219. /**
  220. * @param array $periodStart
  221. */
  222. public function setPeriodStart($periodStart)
  223. {
  224. $this->periodStart = $periodStart;
  225. }
  226. /**
  227. * @return array
  228. */
  229. public function getPeriodEnd()
  230. {
  231. return $this->periodEnd;
  232. }
  233. /**
  234. * @param array $periodEnd
  235. */
  236. public function setPeriodEnd($periodEnd)
  237. {
  238. $this->periodEnd = $periodEnd;
  239. }
  240. public function getPeriodEndTimeDateFormat()
  241. {
  242. $periodEndTime = new \DateTime();
  243. $periodEndTime->setTime(
  244. intval($this->periodEndTime->format('G')),
  245. intval($this->periodEndTime->format('i')),
  246. intval($this->periodEndTime->format('s'))
  247. );
  248. return $periodEndTime;
  249. }
  250. public function getPeriodEndTime()
  251. {
  252. if (! $this->periodEndTime) {
  253. return ;
  254. }
  255. return $this->periodEndTime->format('H:i');
  256. }
  257. public function setPeriodEndTime($periodEndTime)
  258. {
  259. if (is_string($periodEndTime)) {
  260. $timeArray = explode(':', $periodEndTime);
  261. $periodEndTime = new \DateTime();
  262. $periodEndTime->setTime(
  263. intval($timeArray[0]),
  264. intval($timeArray[1])
  265. );
  266. }
  267. $date = clone $this->periodEndTime;
  268. $date->setTime(
  269. intval($periodEndTime->format('G')),
  270. intval($periodEndTime->format('i')),
  271. intval($periodEndTime->format('s'))
  272. );
  273. $this->periodEndTime = $date;
  274. }
  275. /**
  276. * @return int
  277. */
  278. public function getPeriodRepeatable()
  279. {
  280. return $this->periodRepeatable;
  281. }
  282. /**
  283. * @param int $periodRepeatable
  284. */
  285. public function setPeriodRepeatable($periodRepeatable)
  286. {
  287. $this->periodRepeatable = $periodRepeatable;
  288. }
  289. /**
  290. * @return int
  291. */
  292. public function getPeriodSpecificChargeType()
  293. {
  294. return $this->periodSpecificChargeType;
  295. }
  296. /**
  297. * @param int $periodSpecificChargeType
  298. */
  299. public function setPeriodSpecificChargeType($periodSpecificChargeType)
  300. {
  301. $this->periodSpecificChargeType = $periodSpecificChargeType;
  302. }
  303. /**
  304. * @return int
  305. */
  306. public function getPeriodSpecificChargeValue()
  307. {
  308. return $this->periodSpecificChargeValue;
  309. }
  310. /**
  311. * @param int $periodSpecificChargeValue
  312. */
  313. public function setPeriodSpecificChargeValue($periodSpecificChargeValue)
  314. {
  315. $this->periodSpecificChargeValue = $periodSpecificChargeValue;
  316. }
  317. /**
  318. * @return int
  319. */
  320. public function getPeriodChargeType()
  321. {
  322. return $this->periodChargeType;
  323. }
  324. /**
  325. * @param int $periodChargeType
  326. */
  327. public function setPeriodChargeType($periodChargeType)
  328. {
  329. $this->periodChargeType = $periodChargeType;
  330. }
  331. /**
  332. * @return int
  333. */
  334. public function getPeriodPriority()
  335. {
  336. return $this->periodPriority;
  337. }
  338. /**
  339. * @param int $periodPriority
  340. */
  341. public function setPeriodPriority($periodPriority)
  342. {
  343. $this->periodPriority = $periodPriority;
  344. }
  345. /**
  346. * @return boolean
  347. */
  348. public function getBookingDisabled()
  349. {
  350. return $this->bookingDisabled;
  351. }
  352. /**
  353. * @param boolean $bookingDisabled
  354. */
  355. public function setBookingDisabled($bookingDisabled)
  356. {
  357. $this->bookingDisabled = $bookingDisabled;
  358. }
  359. /**
  360. * @return String
  361. */
  362. public function getDisabledMessages()
  363. {
  364. return $this->disabledMessages;
  365. }
  366. /**
  367. * @param String $disabledMessages
  368. */
  369. public function setDisabledMessages($disabledMessages)
  370. {
  371. $this->disabledMessages = $disabledMessages;
  372. }
  373. /**
  374. * @return String
  375. */
  376. public function getOperatorDisabledMessage()
  377. {
  378. return $this->operatorDisabledMessage;
  379. }
  380. /**
  381. * @param String $operatorDisabledMessage
  382. */
  383. public function setOperatorDisabledMessage($operatorDisabledMessage)
  384. {
  385. $this->operatorDisabledMessage = $operatorDisabledMessage;
  386. }
  387. /**
  388. * @return float
  389. */
  390. public function getMinimumPriceBooking()
  391. {
  392. return $this->minimumPriceBooking;
  393. }
  394. /**
  395. * @param float $minimumPriceBooking
  396. */
  397. public function setMinimumPriceBooking($minimumPriceBooking)
  398. {
  399. $this->minimumPriceBooking = $minimumPriceBooking;
  400. }
  401. public function __toString()
  402. {
  403. return $this->getId() ? $this->getPeriodName().'' : 'n\a';
  404. }
  405. }