@@ -62,7 +62,7 @@ |
||
62 | 62 | * @return int |
63 | 63 | */ |
64 | 64 | public function getValue() { |
65 | - return (int) $this->value; |
|
65 | + return (int)$this->value; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -44,7 +44,7 @@ |
||
44 | 44 | * {@inheritdoc} |
45 | 45 | */ |
46 | 46 | public function getDefaultValue() { |
47 | - return (int) $this->default_value; |
|
47 | + return (int)$this->default_value; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | protected function normalizeMinMaxDaysConstraints() { |
97 | 97 | $new_constraints = array(); |
98 | 98 | |
99 | - $constraints = array_map(function ($object) { return clone $object; }, $this->constraints['Roomify\Bat\Constraint\MinMaxDaysConstraint']); |
|
99 | + $constraints = array_map(function($object) { return clone $object; }, $this->constraints['Roomify\Bat\Constraint\MinMaxDaysConstraint']); |
|
100 | 100 | |
101 | 101 | foreach (array_reverse($constraints) as $constraint) { |
102 | 102 | $start_date = $constraint->getStartDate(); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | protected function normalizeCheckInDayConstraints() { |
173 | 173 | $new_constraints = array(); |
174 | 174 | |
175 | - $constraints = array_map(function ($object) { return clone $object; }, $this->constraints['Roomify\Bat\Constraint\CheckInDayConstraint']); |
|
175 | + $constraints = array_map(function($object) { return clone $object; }, $this->constraints['Roomify\Bat\Constraint\CheckInDayConstraint']); |
|
176 | 176 | |
177 | 177 | foreach (array_reverse($constraints) as $constraint) { |
178 | 178 | $start_date = $constraint->getStartDate(); |
@@ -115,12 +115,10 @@ discard block |
||
115 | 115 | if ($start_date >= $new_start_date && $start_date <= $new_end_date) { |
116 | 116 | $new_end_date_clone = clone($new_end_date); |
117 | 117 | $constraint->setStartDate($new_end_date_clone->add(new \DateInterval('P1D'))); |
118 | - } |
|
119 | - elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
118 | + } elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
120 | 119 | $new_start_date_clone = clone($new_start_date); |
121 | 120 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
122 | - } |
|
123 | - elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
121 | + } elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
124 | 122 | if ($constraint->getEndDate() > $new_start_date) { |
125 | 123 | $new_start_date_clone = clone($new_start_date); |
126 | 124 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
@@ -132,8 +130,7 @@ discard block |
||
132 | 130 | $split_end_date = $end_date; |
133 | 131 | |
134 | 132 | $split_constraint = new MinMaxDaysConstraint($constraint->getUnits(), $constraint->getMinDays(), $constraint->getMaxDays(), $split_start_date, $split_end_date, $constraint->getCheckinDay()); |
135 | - } |
|
136 | - else { |
|
133 | + } else { |
|
137 | 134 | $split_start_date = $split_constraint->getStartDate(); |
138 | 135 | $split_end_date = $split_constraint->getEndDate(); |
139 | 136 |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | // Create a mock itemized event for the period in question - since event data is either |
191 | 191 | // in the database or the default value we first create a mock event and then fill it in |
192 | 192 | // accordingly |
193 | - $mock_event = new Event($start_date, $end_date, new Unit(0,0), $this->default_value); |
|
193 | + $mock_event = new Event($start_date, $end_date, new Unit(0, 0), $this->default_value); |
|
194 | 194 | $itemized = $mock_event->itemize(new EventItemizer($mock_event, $granularity)); |
195 | 195 | |
196 | 196 | // Cycle through each unit retrieved and provide it with a fully configured itemized mock event |
@@ -281,11 +281,11 @@ discard block |
||
281 | 281 | foreach ($days as $day => $hours) { |
282 | 282 | foreach ($hours as $hour => $value) { |
283 | 283 | if (isset($db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour])) { |
284 | - $result[$year][$month][$day][$hour] = ((int) $db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour]); |
|
284 | + $result[$year][$month][$day][$hour] = ((int)$db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour]); |
|
285 | 285 | } |
286 | 286 | else { |
287 | 287 | // If nothing from db - then revert to the defaults |
288 | - $result[$year][$month][$day][$hour] = (int) $keyed_units[$unit]->getDefaultValue(); |
|
288 | + $result[$year][$month][$day][$hour] = (int)$keyed_units[$unit]->getDefaultValue(); |
|
289 | 289 | } |
290 | 290 | } |
291 | 291 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | foreach ($months as $month => $days) { |
300 | 300 | foreach ($days as $day => $hours) { |
301 | 301 | foreach ($hours as $hour => $value) { |
302 | - $result[$year][$month][$day][$hour] = ((int) $value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $value); |
|
302 | + $result[$year][$month][$day][$hour] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
303 | 303 | } |
304 | 304 | ksort($result[$year][$month][$day], SORT_NATURAL); |
305 | 305 | } |
@@ -330,11 +330,11 @@ discard block |
||
330 | 330 | foreach ($hours as $hour => $minutes) { |
331 | 331 | foreach ($minutes as $minute => $value) { |
332 | 332 | if (isset($db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute])) { |
333 | - $result[$year][$month][$day][$hour][$minute] = ((int) $db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute]); |
|
333 | + $result[$year][$month][$day][$hour][$minute] = ((int)$db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute]); |
|
334 | 334 | } |
335 | 335 | else { |
336 | 336 | // If nothing from db - then revert to the defaults |
337 | - $result[$year][$month][$day][$hour][$minute] = (int) $keyed_units[$unit]->getDefaultValue(); |
|
337 | + $result[$year][$month][$day][$hour][$minute] = (int)$keyed_units[$unit]->getDefaultValue(); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | } |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | foreach ($days as $day => $hours) { |
351 | 351 | foreach ($hours as $hour => $minutes) { |
352 | 352 | foreach ($minutes as $minute => $value) { |
353 | - $result[$year][$month][$day][$hour][$minute] = ((int) $value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $value); |
|
353 | + $result[$year][$month][$day][$hour][$minute] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
354 | 354 | } |
355 | 355 | ksort($result[$year][$month][$day][$hour], SORT_NATURAL); |
356 | 356 | } |
@@ -424,12 +424,12 @@ discard block |
||
424 | 424 | // Value just switched - let us wrap up with current event and start a new one |
425 | 425 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
426 | 426 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
427 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute,1)); |
|
427 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.substr($hour, 1).':'.substr($minute, 1)); |
|
428 | 428 | $current_value = $minute_value; |
429 | 429 | } |
430 | 430 | if ($current_value === NULL) { |
431 | 431 | // We are down to minutes and haven't created and event yet - do one now |
432 | - $start_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute,1)); |
|
432 | + $start_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.substr($hour, 1).':'.substr($minute, 1)); |
|
433 | 433 | $end_event = clone($start_event); |
434 | 434 | } |
435 | 435 | $current_value = $minute_value; |
@@ -454,22 +454,22 @@ discard block |
||
454 | 454 | // Start event becomes the end event with a minute added |
455 | 455 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
456 | 456 | // End event comes the current point in time |
457 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':59'); |
|
457 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.substr($hour, 1).':59'); |
|
458 | 458 | $current_value = $hour_value; |
459 | 459 | } |
460 | 460 | } |
461 | 461 | if ($current_value === NULL) { |
462 | 462 | // Got into hours and still haven't created an event so |
463 | - $start_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':00'); |
|
463 | + $start_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.substr($hour, 1).':00'); |
|
464 | 464 | // We will be occupying at least this hour so might as well mark it |
465 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':59'); |
|
465 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.substr($hour, 1).':59'); |
|
466 | 466 | $current_value = $hour_value; |
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
470 | 470 | elseif ($current_value === $value) { |
471 | 471 | // We are adding a whole day so the end event gets moved to the end of the day we are adding |
472 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '23:59'); |
|
472 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.'23:59'); |
|
473 | 473 | } |
474 | 474 | elseif (($current_value !== $value) && ($current_value !== NULL)) { |
475 | 475 | // Value just switched - let us wrap up with current event and start a new one |
@@ -477,13 +477,13 @@ discard block |
||
477 | 477 | // Start event becomes the end event with a minute added |
478 | 478 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
479 | 479 | // End event becomes the current day which we have not account for yet |
480 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '23:59'); |
|
480 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.'23:59'); |
|
481 | 481 | $current_value = $value; |
482 | 482 | } |
483 | 483 | if ($current_value === NULL) { |
484 | 484 | // We have not created an event yet so let's do it now |
485 | - $start_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '00:00'); |
|
486 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '23:59'); |
|
485 | + $start_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.'00:00'); |
|
486 | + $end_event = new \DateTime($year.'-'.$month.'-'.substr($day, 1).' '.'23:59'); |
|
487 | 487 | $current_value = $value; |
488 | 488 | } |
489 | 489 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | * @return Unit |
583 | 583 | */ |
584 | 584 | protected function getUnit($unit_id) { |
585 | - $keyed = $this->keyUnitsById(); |
|
585 | + $keyed = $this->keyUnitsById(); |
|
586 | 586 | return $keyed[$unit_id]; |
587 | 587 | } |
588 | 588 |
@@ -146,8 +146,7 @@ discard block |
||
146 | 146 | // Compare the current states with the set of valid states |
147 | 147 | if ($intersect) { |
148 | 148 | $remaining_states = array_intersect($current_states, $valid_states); |
149 | - } |
|
150 | - else { |
|
149 | + } else { |
|
151 | 150 | $remaining_states = array_diff($current_states, $valid_states); |
152 | 151 | } |
153 | 152 | |
@@ -155,8 +154,7 @@ discard block |
||
155 | 154 | // Unit is in a state that is within the set of valid states so add to result set |
156 | 155 | $units[$unit] = $unit; |
157 | 156 | $response->addMatch($keyed_units[$unit], CalendarResponse::VALID_STATE); |
158 | - } |
|
159 | - else { |
|
157 | + } else { |
|
160 | 158 | $response->addMiss($keyed_units[$unit], CalendarResponse::INVALID_STATE); |
161 | 159 | } |
162 | 160 | |
@@ -250,8 +248,7 @@ discard block |
||
250 | 248 | foreach ($days as $day => $value) { |
251 | 249 | $result[$year][$month][$day] = ((int)$db_events[$unit][Event::BAT_DAY][$year][$month][$day] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$db_events[$unit][Event::BAT_DAY][$year][$month][$day]); |
252 | 250 | } |
253 | - } |
|
254 | - else { |
|
251 | + } else { |
|
255 | 252 | foreach ($days as $day => $value) { |
256 | 253 | $result[$year][$month][$day] = $keyed_units[$unit]->getDefaultValue(); |
257 | 254 | } |
@@ -282,8 +279,7 @@ discard block |
||
282 | 279 | foreach ($hours as $hour => $value) { |
283 | 280 | if (isset($db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour])) { |
284 | 281 | $result[$year][$month][$day][$hour] = ((int) $db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour]); |
285 | - } |
|
286 | - else { |
|
282 | + } else { |
|
287 | 283 | // If nothing from db - then revert to the defaults |
288 | 284 | $result[$year][$month][$day][$hour] = (int) $keyed_units[$unit]->getDefaultValue(); |
289 | 285 | } |
@@ -331,8 +327,7 @@ discard block |
||
331 | 327 | foreach ($minutes as $minute => $value) { |
332 | 328 | if (isset($db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute])) { |
333 | 329 | $result[$year][$month][$day][$hour][$minute] = ((int) $db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int) $db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute]); |
334 | - } |
|
335 | - else { |
|
330 | + } else { |
|
336 | 331 | // If nothing from db - then revert to the defaults |
337 | 332 | $result[$year][$month][$day][$hour][$minute] = (int) $keyed_units[$unit]->getDefaultValue(); |
338 | 333 | } |
@@ -393,8 +388,12 @@ discard block |
||
393 | 388 | |
394 | 389 | // Make sure years are sorted |
395 | 390 | ksort($data[Event::BAT_DAY]); |
396 | - if (isset($data[Event::BAT_HOUR])) ksort($data[Event::BAT_HOUR]); |
|
397 | - if (isset($data[Event::BAT_MINUTE])) ksort($data[Event::BAT_MINUTE]); |
|
391 | + if (isset($data[Event::BAT_HOUR])) { |
|
392 | + ksort($data[Event::BAT_HOUR]); |
|
393 | + } |
|
394 | + if (isset($data[Event::BAT_MINUTE])) { |
|
395 | + ksort($data[Event::BAT_MINUTE]); |
|
396 | + } |
|
398 | 397 | |
399 | 398 | // Set up variables to keep track of stuff |
400 | 399 | $current_value = NULL; |
@@ -419,8 +418,7 @@ discard block |
||
419 | 418 | if ($current_value === $minute_value) { |
420 | 419 | // We are still in minutes and going through so add a minute |
421 | 420 | $end_event->add(new \DateInterval('PT1M')); |
422 | - } |
|
423 | - elseif (($current_value != $minute_value) && ($current_value !== NULL)) { |
|
421 | + } elseif (($current_value != $minute_value) && ($current_value !== NULL)) { |
|
424 | 422 | // Value just switched - let us wrap up with current event and start a new one |
425 | 423 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
426 | 424 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
@@ -434,12 +432,10 @@ discard block |
||
434 | 432 | } |
435 | 433 | $current_value = $minute_value; |
436 | 434 | } |
437 | - } |
|
438 | - elseif ($current_value === $hour_value) { |
|
435 | + } elseif ($current_value === $hour_value) { |
|
439 | 436 | // We are in hours and can add something |
440 | 437 | $end_event->add(new \DateInterval('PT1H')); |
441 | - } |
|
442 | - elseif (($current_value != $hour_value) && ($current_value !== NULL)) { |
|
438 | + } elseif (($current_value != $hour_value) && ($current_value !== NULL)) { |
|
443 | 439 | $skip_finalize_event = FALSE; |
444 | 440 | |
445 | 441 | if ($is_daylight_saving_time) { |
@@ -466,12 +462,10 @@ discard block |
||
466 | 462 | $current_value = $hour_value; |
467 | 463 | } |
468 | 464 | } |
469 | - } |
|
470 | - elseif ($current_value === $value) { |
|
465 | + } elseif ($current_value === $value) { |
|
471 | 466 | // We are adding a whole day so the end event gets moved to the end of the day we are adding |
472 | 467 | $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '23:59'); |
473 | - } |
|
474 | - elseif (($current_value !== $value) && ($current_value !== NULL)) { |
|
468 | + } elseif (($current_value !== $value) && ($current_value !== NULL)) { |
|
475 | 469 | // Value just switched - let us wrap up with current event and start a new one |
476 | 470 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
477 | 471 | // Start event becomes the end event with a minute added |
@@ -506,8 +500,7 @@ discard block |
||
506 | 500 | if ($event->endsLater($end_date)) { |
507 | 501 | $event->setEndDate($end_date); |
508 | 502 | } |
509 | - } |
|
510 | - else { |
|
503 | + } else { |
|
511 | 504 | // Event completely not in range so unset it |
512 | 505 | unset($normalized_events[$unit_id][$key]); |
513 | 506 | } |
@@ -538,8 +531,7 @@ discard block |
||
538 | 531 | $e++; |
539 | 532 | $flipped[$e][$value][$datum] = $datum; |
540 | 533 | $old_value = $value; |
541 | - } |
|
542 | - else { |
|
534 | + } else { |
|
543 | 535 | $flipped[$e][$value][$datum] = $datum; |
544 | 536 | } |
545 | 537 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $dayrange = new \DatePeriod($this->event->getStartDate(), $dayinterval, $this->event->endMonthDate($this->event->getStartDate())); |
161 | 161 | } |
162 | 162 | foreach ($dayrange as $day) { |
163 | - $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d' . $day->format('j')] = $this->event->getValue(); |
|
163 | + $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d'.$day->format('j')] = $this->event->getValue(); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | elseif ($this->event->isLastMonth($date)) { |
169 | 169 | $dayrange = new \DatePeriod(new \DateTime($date->format("Y-n-1")), $dayinterval, $this->event->getEndDate()); |
170 | 170 | foreach ($dayrange as $day) { |
171 | - $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d' . $day->format('j')] = $this->event->getValue(); |
|
171 | + $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d'.$day->format('j')] = $this->event->getValue(); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | else { |
177 | 177 | $dayrange = new \DatePeriod(new \DateTime($date->format("Y-n-1")), $dayinterval, new \DateTime($date->format("Y-n-t 23:59:59"))); |
178 | 178 | foreach ($dayrange as $day) { |
179 | - $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d' . $day->format('j')] = $this->event->getValue(); |
|
179 | + $itemized[EventItemizer::BAT_DAY][$year][$day->format('n')]['d'.$day->format('j')] = $this->event->getValue(); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -217,35 +217,35 @@ discard block |
||
217 | 217 | if ($this->event->isSameDay()) { |
218 | 218 | if (!($this->event->getStartDate()->format('H:i') == '00:00' && $this->event->getEndDate()->format('H:i') == '23:59')) { |
219 | 219 | $itemized_same_day = $this->createHourlyGranular($start_date, $end_date->add(new \DateInterval('PT1M')), $interval); |
220 | - $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
|
221 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
|
222 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
|
220 | + $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d'.$sd] = -1; |
|
221 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd]; |
|
222 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd]; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | else { |
226 | 226 | // Deal with the start day unless it starts on midnight precisely at which point the whole day is booked |
227 | 227 | if (!($this->event->getStartDate()->format('H:i') == '00:00')) { |
228 | 228 | $itemized_start = $this->createHourlyGranular($start_date, new \DateTime($start_date->format("Y-n-j 23:59:59")), $interval); |
229 | - $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
|
230 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
|
231 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
|
229 | + $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d'.$sd] = -1; |
|
230 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd]; |
|
231 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd]; |
|
232 | 232 | } |
233 | 233 | else { |
234 | 234 | // Just set an empty hour and minute |
235 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = array(); |
|
236 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = array(); |
|
235 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = array(); |
|
236 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = array(); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | // Deal with the end date unless it ends just before midnight at which point we don't need to go further |
240 | 240 | if ($this->event->getEndDate()->format('H:i') == '23:59') { |
241 | - $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = array(); |
|
242 | - $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = array(); |
|
241 | + $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed] = array(); |
|
242 | + $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed] = array(); |
|
243 | 243 | } |
244 | 244 | else { |
245 | 245 | $itemized_end = $this->createHourlyGranular(new \DateTime($end_date->format("Y-n-j 00:00:00")), $end_date->add(new \DateInterval('PT1M')), $interval); |
246 | - $itemized[EventItemizer::BAT_DAY][$ey][$em]['d' . $ed] = -1; |
|
247 | - $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = $itemized_end[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed]; |
|
248 | - $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = $itemized_end[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed]; |
|
246 | + $itemized[EventItemizer::BAT_DAY][$ey][$em]['d'.$ed] = -1; |
|
247 | + $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed] = $itemized_end[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed]; |
|
248 | + $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed] = $itemized_end[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed]; |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Doing minutes so set the values in the minute array |
290 | - $itemized[EventItemizer::BAT_MINUTE][$year][$month]['d' . $day]['h' . $hour]['m' . $min] = $event_value; |
|
290 | + $itemized[EventItemizer::BAT_MINUTE][$year][$month]['d'.$day]['h'.$hour]['m'.$min] = $event_value; |
|
291 | 291 | // Let the hours know that it cannot determine availability |
292 | - $itemized[EventItemizer::BAT_HOUR][$year][$month]['d' . $day]['h' . $hour] = -1; |
|
292 | + $itemized[EventItemizer::BAT_HOUR][$year][$month]['d'.$day]['h'.$hour] = -1; |
|
293 | 293 | $min++; |
294 | 294 | |
295 | 295 | if ($min == 60 && $start_minute !== 0) { |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | } |
301 | 301 | elseif ($min == 60 && $start_minute == 0) { |
302 | 302 | // Did a real whole hour so initialize the hour |
303 | - $itemized[EventItemizer::BAT_HOUR][$year][$month]['d' . $day]['h' . $hour] = $event_value; |
|
303 | + $itemized[EventItemizer::BAT_HOUR][$year][$month]['d'.$day]['h'.$hour] = $event_value; |
|
304 | 304 | |
305 | 305 | $min = 0; |
306 | 306 | $hour++; |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | |
323 | 323 | $hour = $date->format('G'); |
324 | 324 | for ($i = 0; $i < 60; $i++) { |
325 | - $minute = ($i < 10) ? '0' . $i : $i; |
|
325 | + $minute = ($i < 10) ? '0'.$i : $i; |
|
326 | 326 | |
327 | - $itemized[EventItemizer::BAT_MINUTE][$date->format('Y')][$date->format('n')]['d' . $date->format('j')]['h' . $hour]['m' . $minute] = $this->event->getValue(); |
|
327 | + $itemized[EventItemizer::BAT_MINUTE][$date->format('Y')][$date->format('n')]['d'.$date->format('j')]['h'.$hour]['m'.$minute] = $this->event->getValue(); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | } |
@@ -129,8 +129,7 @@ discard block |
||
129 | 129 | // We add a minute to compensate |
130 | 130 | elseif (($this->event->getStartDate()->format('Y-m-d H:i') == $this->event->getEndDate()->format('Y-m-d H:i')) && $this->granularity == EventItemizer::BAT_DAILY) { |
131 | 131 | $adjusted_end_day = new \DateTime($this->event->getEndDate()->add(new \DateInterval('PT1M'))->format('Y-m-d H:i')); |
132 | - } |
|
133 | - else { |
|
132 | + } else { |
|
134 | 133 | $adjusted_end_day = new \DateTime($this->event->getEndDate()->format('Y-m-d H:i')); |
135 | 134 | } |
136 | 135 | |
@@ -221,16 +220,14 @@ discard block |
||
221 | 220 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
222 | 221 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
223 | 222 | } |
224 | - } |
|
225 | - else { |
|
223 | + } else { |
|
226 | 224 | // Deal with the start day unless it starts on midnight precisely at which point the whole day is booked |
227 | 225 | if (!($this->event->getStartDate()->format('H:i') == '00:00')) { |
228 | 226 | $itemized_start = $this->createHourlyGranular($start_date, new \DateTime($start_date->format("Y-n-j 23:59:59")), $interval); |
229 | 227 | $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
230 | 228 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
231 | 229 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
232 | - } |
|
233 | - else { |
|
230 | + } else { |
|
234 | 231 | // Just set an empty hour and minute |
235 | 232 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = array(); |
236 | 233 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = array(); |
@@ -240,8 +237,7 @@ discard block |
||
240 | 237 | if ($this->event->getEndDate()->format('H:i') == '23:59') { |
241 | 238 | $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = array(); |
242 | 239 | $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = array(); |
243 | - } |
|
244 | - else { |
|
240 | + } else { |
|
245 | 241 | $itemized_end = $this->createHourlyGranular(new \DateTime($end_date->format("Y-n-j 00:00:00")), $end_date->add(new \DateInterval('PT1M')), $interval); |
246 | 242 | $itemized[EventItemizer::BAT_DAY][$ey][$em]['d' . $ed] = -1; |
247 | 243 | $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = $itemized_end[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed]; |
@@ -297,8 +293,7 @@ discard block |
||
297 | 293 | $min = 0; |
298 | 294 | $hour++; |
299 | 295 | $start_minute = 0; |
300 | - } |
|
301 | - elseif ($min == 60 && $start_minute == 0) { |
|
296 | + } elseif ($min == 60 && $start_minute == 0) { |
|
302 | 297 | // Did a real whole hour so initialize the hour |
303 | 298 | $itemized[EventItemizer::BAT_HOUR][$year][$month]['d' . $day]['h' . $hour] = $event_value; |
304 | 299 |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | $this->event_type = $event_type; |
78 | 78 | |
79 | 79 | if ($event_data == SqlDBStore::BAT_STATE) { |
80 | - $this->day_table = $prefix . 'bat_event_' . $event_type . '_day_' . SqlDBStore::BAT_STATE; |
|
81 | - $this->hour_table = $prefix . 'bat_event_' . $event_type . '_hour_' . SqlDBStore::BAT_STATE; |
|
82 | - $this->minute_table = $prefix . 'bat_event_' . $event_type . '_minute_' . SqlDBStore::BAT_STATE; |
|
80 | + $this->day_table = $prefix.'bat_event_'.$event_type.'_day_'.SqlDBStore::BAT_STATE; |
|
81 | + $this->hour_table = $prefix.'bat_event_'.$event_type.'_hour_'.SqlDBStore::BAT_STATE; |
|
82 | + $this->minute_table = $prefix.'bat_event_'.$event_type.'_minute_'.SqlDBStore::BAT_STATE; |
|
83 | 83 | |
84 | - $this->day_table_no_prefix = 'bat_event_' . $event_type . '_day_' . SqlDBStore::BAT_STATE; |
|
85 | - $this->hour_table_no_prefix = 'bat_event_' . $event_type . '_hour_' . SqlDBStore::BAT_STATE; |
|
86 | - $this->minute_table_no_prefix = 'bat_event_' . $event_type . '_minute_' . SqlDBStore::BAT_STATE; |
|
84 | + $this->day_table_no_prefix = 'bat_event_'.$event_type.'_day_'.SqlDBStore::BAT_STATE; |
|
85 | + $this->hour_table_no_prefix = 'bat_event_'.$event_type.'_hour_'.SqlDBStore::BAT_STATE; |
|
86 | + $this->minute_table_no_prefix = 'bat_event_'.$event_type.'_minute_'.SqlDBStore::BAT_STATE; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | if ($event_data == SqlDBStore::BAT_EVENT) { |
90 | - $this->day_table = $prefix . 'bat_event_' . $event_type . '_day_' . SqlDBStore::BAT_EVENT; |
|
91 | - $this->hour_table = $prefix . 'bat_event_' . $event_type . '_hour_' . SqlDBStore::BAT_EVENT; |
|
92 | - $this->minute_table = $prefix . 'bat_event_' . $event_type . '_minute_' . SqlDBStore::BAT_EVENT; |
|
90 | + $this->day_table = $prefix.'bat_event_'.$event_type.'_day_'.SqlDBStore::BAT_EVENT; |
|
91 | + $this->hour_table = $prefix.'bat_event_'.$event_type.'_hour_'.SqlDBStore::BAT_EVENT; |
|
92 | + $this->minute_table = $prefix.'bat_event_'.$event_type.'_minute_'.SqlDBStore::BAT_EVENT; |
|
93 | 93 | |
94 | - $this->day_table_no_prefix = 'bat_event_' . $event_type . '_day_' . SqlDBStore::BAT_EVENT; |
|
95 | - $this->hour_table_no_prefix = 'bat_event_' . $event_type . '_hour_' . SqlDBStore::BAT_EVENT; |
|
96 | - $this->minute_table_no_prefix = 'bat_event_' . $event_type . '_minute_' . SqlDBStore::BAT_EVENT; |
|
94 | + $this->day_table_no_prefix = 'bat_event_'.$event_type.'_day_'.SqlDBStore::BAT_EVENT; |
|
95 | + $this->hour_table_no_prefix = 'bat_event_'.$event_type.'_hour_'.SqlDBStore::BAT_EVENT; |
|
96 | + $this->minute_table_no_prefix = 'bat_event_'.$event_type.'_minute_'.SqlDBStore::BAT_EVENT; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | public function buildQueries(\DateTime $start_date, \DateTime $end_date, $unit_ids) { |
109 | 109 | $queries = array(); |
110 | 110 | |
111 | - $queries[Event::BAT_DAY] = 'SELECT * FROM ' . $this->day_table . ' WHERE '; |
|
112 | - $queries[Event::BAT_HOUR] = 'SELECT * FROM ' . $this->hour_table . ' WHERE '; |
|
113 | - $queries[Event::BAT_MINUTE] = 'SELECT * FROM ' . $this->minute_table . ' WHERE '; |
|
111 | + $queries[Event::BAT_DAY] = 'SELECT * FROM '.$this->day_table.' WHERE '; |
|
112 | + $queries[Event::BAT_HOUR] = 'SELECT * FROM '.$this->hour_table.' WHERE '; |
|
113 | + $queries[Event::BAT_MINUTE] = 'SELECT * FROM '.$this->minute_table.' WHERE '; |
|
114 | 114 | |
115 | 115 | // Create a mock event which we will use to determine how to query the database |
116 | 116 | $mock_event = new Event($start_date, $end_date, new Unit(0, 0, array()), -10); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | // We are dealing with multiple years so add an OR |
129 | 129 | $query_parameters .= ' OR '; |
130 | 130 | } |
131 | - $query_parameters .= 'year IN (' . $year . ') '; |
|
132 | - $query_parameters .= 'AND month IN (' . implode(",", array_keys($months)) . ') '; |
|
131 | + $query_parameters .= 'year IN ('.$year.') '; |
|
132 | + $query_parameters .= 'AND month IN ('.implode(",", array_keys($months)).') '; |
|
133 | 133 | if (count($unit_ids) > 0) { |
134 | 134 | // Unit ids are defined so add this as a filter |
135 | - $query_parameters .= 'AND unit_id in (' . implode("," , $unit_ids) . ') '; |
|
135 | + $query_parameters .= 'AND unit_id in ('.implode(",", $unit_ids).') '; |
|
136 | 136 | } |
137 | 137 | $year_count++; |
138 | 138 | } |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | $this->end_date = new \DateTime('2999-12-31'); |
63 | 63 | } |
64 | 64 | |
65 | - if ( (($calendar_response->getStartDate()->getTimestamp() >= $this->start_date->getTimestamp() && |
|
65 | + if ((($calendar_response->getStartDate()->getTimestamp() >= $this->start_date->getTimestamp() && |
|
66 | 66 | $calendar_response->getStartDate()->getTimestamp() <= $this->end_date->getTimestamp()) || |
67 | 67 | ($calendar_response->getEndDate()->getTimestamp() >= $this->start_date->getTimestamp() && |
68 | 68 | $calendar_response->getEndDate()->getTimestamp() <= $this->end_date->getTimestamp()) || |
69 | 69 | ($calendar_response->getStartDate()->getTimestamp() <= $this->start_date->getTimestamp() && |
70 | 70 | $calendar_response->getEndDate()->getTimestamp() >= $this->end_date->getTimestamp())) && |
71 | - ($this->checkin_day === NULL || $this->checkin_day == $calendar_response->getStartDate()->format('N')) ) { |
|
71 | + ($this->checkin_day === NULL || $this->checkin_day == $calendar_response->getStartDate()->format('N'))) { |
|
72 | 72 | |
73 | 73 | $units = $this->getUnits(); |
74 | 74 | |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $text = ''; |
108 | 108 | |
109 | 109 | // Min/max stay length constraint variables. |
110 | - $minimum_stay = empty($this->min_days) ? '' : (($this->min_days == 1) ? $this->min_days . ' day' : $this->min_days . ' days'); |
|
111 | - $maximum_stay = empty($this->max_days) ? '' : (($this->max_days == 1) ? $this->max_days . ' day' : $this->max_days . ' days'); |
|
110 | + $minimum_stay = empty($this->min_days) ? '' : (($this->min_days == 1) ? $this->min_days.' day' : $this->min_days.' days'); |
|
111 | + $maximum_stay = empty($this->max_days) ? '' : (($this->max_days == 1) ? $this->max_days.' day' : $this->max_days.' days'); |
|
112 | 112 | |
113 | 113 | // Day of the week constraint variable. |
114 | 114 | $day_of_the_week = $this->getWeekDay($this->checkin_day); |
@@ -45,11 +45,11 @@ |
||
45 | 45 | $this->end_date = new \DateTime('2999-12-31'); |
46 | 46 | } |
47 | 47 | |
48 | - if ( (($calendar_response->getStartDate()->getTimestamp() >= $this->start_date->getTimestamp() && |
|
48 | + if ((($calendar_response->getStartDate()->getTimestamp() >= $this->start_date->getTimestamp() && |
|
49 | 49 | $calendar_response->getStartDate()->getTimestamp() <= $this->end_date->getTimestamp()) || |
50 | 50 | ($calendar_response->getStartDate()->getTimestamp() <= $this->start_date->getTimestamp() && |
51 | 51 | $calendar_response->getEndDate()->getTimestamp() >= $this->end_date->getTimestamp())) && |
52 | - $this->checkin_day != $calendar_response->getStartDate()->format('N') ) { |
|
52 | + $this->checkin_day != $calendar_response->getStartDate()->format('N')) { |
|
53 | 53 | |
54 | 54 | $units = $this->getUnits(); |
55 | 55 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | if ($value === -1 && $existing_value > 0) { |
42 | 42 | $itemized_day = &$itemized[Event::BAT_HOUR][$year][$month][$day]; |
43 | 43 | for ($hour = 0; $hour < 24; $hour++) { |
44 | - $hour_key = 'h' . $hour; |
|
44 | + $hour_key = 'h'.$hour; |
|
45 | 45 | $var = &$itemized_day[$hour_key]; |
46 | 46 | $var = isset($var) && $var != 0 ? $var : $existing_value; |
47 | 47 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | if ($value === -1 && $existing_value > 0) { |
83 | 83 | $itemized_hour = &$itemized[Event::BAT_MINUTE][$year][$month][$day][$hour]; |
84 | 84 | for ($minute = 0; $minute < 60; $minute++) { |
85 | - $minute_key = 'm' . str_pad($minute, 2, '0', STR_PAD_LEFT); |
|
85 | + $minute_key = 'm'.str_pad($minute, 2, '0', STR_PAD_LEFT); |
|
86 | 86 | $var = &$itemized_hour[$minute_key]; |
87 | 87 | $var = isset($var) && $var != 0 ? $var : $existing_value; |
88 | 88 | } |
@@ -75,8 +75,7 @@ |
||
75 | 75 | protected function itemizeSplitHour(array $existing_events, array &$itemized, $value, $unit_id, $year, $month, $day, $hour) { |
76 | 76 | if (isset($existing_events[$unit_id][EVENT::BAT_HOUR][$year][$month][$day][$hour])) { |
77 | 77 | $existing_value = $existing_events[$unit_id][EVENT::BAT_HOUR][$year][$month][$day][$hour]; |
78 | - } |
|
79 | - else { |
|
78 | + } else { |
|
80 | 79 | $existing_value = $existing_events[$unit_id][EVENT::BAT_DAY][$year][$month][$day]; |
81 | 80 | } |
82 | 81 | if ($value === -1 && $existing_value > 0) { |