booking_agenda_helper.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/eventwizard/class/eventlocation.class.php';
  3. class BookingAgendaHelper
  4. {
  5. public $db;
  6. public function __construct($db)
  7. {
  8. $this->db = $db;
  9. }
  10. function getEventdayDates($year, $month, $day)
  11. {
  12. $dates = [];
  13. $eventday = $year . '-';
  14. $eventday .= (int) $month < 10 ? '0' : '';
  15. $eventday .= $month . '-';
  16. $eventday .= (int) $day < 10 ? '0' : '';
  17. $eventday .= $day;
  18. $eventday = str_replace("-00", "-0", $eventday);
  19. $dates['eventday'] = $eventday;
  20. $dates['eventdayprint'] = date("Y M d", strtotime($eventday));
  21. $dates['from'] = $eventday . ' 00:00:00';
  22. $dates['to'] = $eventday . ' 23:59:59';
  23. return $dates;
  24. }
  25. /* function getMaxNumFromEVENT($eventarray){
  26. foreach($eventarray as $event){
  27. return $event['max_num'];
  28. }
  29. } */
  30. function getsumReservation($eventsArray, $eventday, $hourText)
  31. {
  32. $count = 0;
  33. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  34. $to = strtotime($eventday . ' ' . $hourText . ':59:59');
  35. foreach ($eventsArray as $event) {
  36. $event_from = strtotime($event['datep']);
  37. $event_to = strtotime($event['datep2']);
  38. if (($from <= $event_from && $to >= $event_from) || $from >= $event_from && $to + 1 <= $event_to) {
  39. //print $eventday . ' ' . $fromtime . ' - ' . $eventday . ' ' . $totime . '<br>';
  40. //print ' - ' . $event['datep'] . ' - ' . $event['datep2'] . '<br>';
  41. $count = $count + (int)$event['participants'];
  42. }
  43. }
  44. return $count > 0 ? $count : '-';
  45. }
  46. function getsumOccupied($eventsArray, $eventday, $hourText)
  47. {
  48. $count = 0;
  49. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  50. $to = strtotime($eventday . ' ' . $hourText . ':59:59');
  51. foreach ($eventsArray as $event) {
  52. $event_from = strtotime($event['datep']);
  53. $event_to = strtotime($event['datep2']);
  54. if($from == $event_to){
  55. $count = $count + (int)$event['participants'];
  56. }
  57. if (($from <= $event_from && $to >= $event_from) || $from >= $event_from && $to + 1 <= $event_to) {
  58. $count = $count + (int)$event['participants'];
  59. }
  60. }
  61. return $count > 0 ? $count : '-';
  62. }
  63. function getsumService($eventsArray, $eventday, $hourText)
  64. {
  65. $count = 0;
  66. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  67. foreach ($eventsArray as $event) {
  68. $event_to = strtotime($event['datep2']);
  69. if($from == $event_to){
  70. $count = $count + (int)$event['participants'];
  71. }
  72. }
  73. return $count > 0 ? $count : '-';
  74. }
  75. function getlocations(){
  76. $locationArray = [];
  77. $eventwizardLocationsObj = new EventLocation($this->db);
  78. $result = $eventwizardLocationsObj->fetchAll('ASC', 'label', 0, 0);
  79. if(count($result) > 0){
  80. foreach($result as $location){
  81. $locationArray[$location->id] = $location->label;
  82. }
  83. }
  84. return $locationArray;
  85. }
  86. function getLocationLabel($event){
  87. foreach($event as $eventDetail){
  88. return $eventDetail['fk_elventlocation_departure'];
  89. }
  90. }
  91. function getOneColumnFromTable($sql, $array, $column)
  92. {
  93. $eventData = $this->db->query($sql);
  94. if ($this->db->num_rows($eventData) > 0) {
  95. while ($row = $this->db->fetch_object($eventData)) {
  96. $array[$row->fk_elventlocation_departure][$row->$column] = (array) $row;
  97. }
  98. }
  99. return $array;
  100. }
  101. function getBGColor($rowcolorCounter){
  102. return $rowcolorCounter % 2 ? 'white' : 'Gainsboro';
  103. }
  104. function getHourText($hour){
  105. return $hour < 10 ? '0' . $hour : $hour;
  106. }
  107. }