@@ -7,8 +7,6 @@ |
||
| 7 | 7 | |
| 8 | 8 | namespace Roomify\Bat\Constraint; |
| 9 | 9 | |
| 10 | -use Roomify\Bat\ConstraintInterface; |
|
| 11 | - |
|
| 12 | 10 | |
| 13 | 11 | /** |
| 14 | 12 | * A constraint acts as a filter that can be applied to a Calendar Response to |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $current_states = array_keys($unit_states); |
| 130 | 130 | // Compare the current states with the set of valid states |
| 131 | 131 | $remaining_states = array_diff($current_states, $valid_states); |
| 132 | - if (count($remaining_states) == 0 ) { |
|
| 132 | + if (count($remaining_states) == 0) { |
|
| 133 | 133 | // Unit is in a state that is within the set of valid states so add to result set |
| 134 | 134 | $units[$unit] = $unit; |
| 135 | 135 | $response->addMatch($keyed_units[$unit], CalendarResponse::VALID_STATE); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | foreach ($months as $month => $days) { |
| 219 | 219 | foreach ($days as $day => $hours) { |
| 220 | 220 | foreach ($hours as $hour => $value) { |
| 221 | - $events[$unit][BAT_HOUR][$year][$month]['d'.$day][$hour] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
| 221 | + $events[$unit][BAT_HOUR][$year][$month]['d' . $day][$hour] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | foreach ($hours as $hour => $minutes) { |
| 233 | 233 | foreach ($minutes as $minute => $value) { |
| 234 | 234 | if (isset($db_events[$unit][BAT_MINUTE][$year][$month][$day][$hour][$minute])) { |
| 235 | - $events[$unit][BAT_MINUTE][$year][$month]['d' .$day]['h'.$hour][$minute] = ((int)$db_events[$unit][BAT_DAY][$year][$month][$day][$hour][$minute] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$db_events[$unit][BAT_DAY][$year][$month][$day][$hour][$minute]); |
|
| 235 | + $events[$unit][BAT_MINUTE][$year][$month]['d' . $day]['h' . $hour][$minute] = ((int)$db_events[$unit][BAT_DAY][$year][$month][$day][$hour][$minute] == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$db_events[$unit][BAT_DAY][$year][$month][$day][$hour][$minute]); |
|
| 236 | 236 | } |
| 237 | 237 | else { |
| 238 | 238 | // If nothing from db - then revert to the defaults |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | foreach ($days as $day => $hours) { |
| 251 | 251 | foreach ($hours as $hour => $minutes) { |
| 252 | 252 | foreach ($minutes as $minute => $value) { |
| 253 | - $events[$unit][BAT_MINUTE][$year][$month]['d'.$day]['h'.$hour][$minute] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
| 253 | + $events[$unit][BAT_MINUTE][$year][$month]['d' . $day]['h' . $hour][$minute] = ((int)$value == 0 ? $keyed_units[$unit]->getDefaultValue() : (int)$value); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -325,12 +325,12 @@ discard block |
||
| 325 | 325 | // Value just switched - let us wrap up with current event and start a new one |
| 326 | 326 | $normalized_events[$unit][] = new Event($start_event, $end_event, $unit, $current_value); |
| 327 | 327 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
| 328 | - $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute,1)); |
|
| 328 | + $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute, 1)); |
|
| 329 | 329 | $current_value = $minute_value; |
| 330 | 330 | } |
| 331 | 331 | if ($current_value === NULL) { |
| 332 | 332 | // We are down to minutes and haven't created and event yet - do one now |
| 333 | - $start_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute,1)); |
|
| 333 | + $start_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . substr($hour, 1) . ':' . substr($minute, 1)); |
|
| 334 | 334 | $end_event = clone($start_event); |
| 335 | 335 | } |
| 336 | 336 | $current_value = $minute_value; |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | $text = t('The stay') . ' '; |
| 135 | 135 | } |
| 136 | 136 | else { |
| 137 | - $text .= ' ' . t('the stay') . ' '; |
|
| 137 | + $text .= ' ' . t('the stay') . ' '; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | if ($minimum_stay && $maximum_stay) { |
@@ -444,14 +444,14 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | $counter = (int)$period_start->format('i'); |
| 446 | 446 | $start_minute = $counter; |
| 447 | - foreach($period as $minute) { |
|
| 447 | + foreach ($period as $minute) { |
|
| 448 | 448 | // Doing minutes so set the values in the minute array |
| 449 | - $itemized[BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d'. $minute->format('j')]['h'. $minute->format('G')]['m' .$minute->format('i')] = $this->getValue(); |
|
| 449 | + $itemized[BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')]['m' . $minute->format('i')] = $this->getValue(); |
|
| 450 | 450 | // Let the hours know that it cannot determine availability |
| 451 | - $itemized[BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d'. $minute->format('j')]['h'. $minute->format('G')] = -1; |
|
| 451 | + $itemized[BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')] = -1; |
|
| 452 | 452 | $counter++; |
| 453 | 453 | |
| 454 | - if ($counter == 60 && $start_minute!==0) { |
|
| 454 | + if ($counter == 60 && $start_minute !== 0) { |
|
| 455 | 455 | // Not a real hour - leave as is and move on |
| 456 | 456 | $counter = 0; |
| 457 | 457 | $start_minute = 0; |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | // Did a real whole hour so initialize the hour |
| 461 | 461 | $itemized[BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')] = $this->getValue(); |
| 462 | 462 | // We have a whole hour so get rid of the minute info |
| 463 | - unset($itemized[BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d'. $minute->format('j')]['h'. $minute->format('G')]); |
|
| 463 | + unset($itemized[BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')]); |
|
| 464 | 464 | $counter = 0; |
| 465 | 465 | $start_minute = 0; |
| 466 | 466 | } |
@@ -481,12 +481,12 @@ discard block |
||
| 481 | 481 | // Set the end date to the last day of the month so that we are sure to get that last month |
| 482 | 482 | $adjusted_end_day = new \DateTime($this->end_date->format('Y-n-t')); |
| 483 | 483 | |
| 484 | - $daterange = new \DatePeriod($this->start_date, $interval ,$adjusted_end_day); |
|
| 484 | + $daterange = new \DatePeriod($this->start_date, $interval, $adjusted_end_day); |
|
| 485 | 485 | |
| 486 | 486 | $itemized = array(); |
| 487 | 487 | |
| 488 | 488 | // Cycle through each month |
| 489 | - foreach($daterange as $date) { |
|
| 489 | + foreach ($daterange as $date) { |
|
| 490 | 490 | |
| 491 | 491 | $year = $date->format("Y"); |
| 492 | 492 | $dayinterval = new \DateInterval('P1D'); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function getEventData(\DateTime $start_date, \DateTime $end_date, $unit_ids) { |
| 80 | 80 | |
| 81 | - $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
| 81 | + $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
| 82 | 82 | |
| 83 | 83 | $results = array(); |
| 84 | 84 | // Run each query and store results |
@@ -89,30 +89,30 @@ discard block |
||
| 89 | 89 | $db_events = array(); |
| 90 | 90 | |
| 91 | 91 | // Cycle through day results and setup an event array |
| 92 | - while( $data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
| 92 | + while ($data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
| 93 | 93 | // Figure out how many days the current month has |
| 94 | 94 | $temp_date = new \DateTime($data['year'] . "-" . $data['month']); |
| 95 | 95 | $days_in_month = (int)$temp_date->format('t'); |
| 96 | - for ($i = 1; $i<=$days_in_month; $i++) { |
|
| 97 | - $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d' . $i] = $data['d'.$i]; |
|
| 96 | + for ($i = 1; $i <= $days_in_month; $i++) { |
|
| 97 | + $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d' . $i] = $data['d' . $i]; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // With the day events taken care off let's cycle through hours |
| 102 | - while( $data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
| 103 | - for ($i = 0; $i<=23; $i++) { |
|
| 104 | - $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']][$data['day']]['h'. $i] = $data['h'.$i]; |
|
| 102 | + while ($data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
| 103 | + for ($i = 0; $i <= 23; $i++) { |
|
| 104 | + $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']][$data['day']]['h' . $i] = $data['h' . $i]; |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // With the hour events taken care off let's cycle through minutes |
| 109 | - while( $data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
| 110 | - for ($i = 0; $i<=59; $i++) { |
|
| 109 | + while ($data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
| 110 | + for ($i = 0; $i <= 59; $i++) { |
|
| 111 | 111 | if ($i <= 9) { |
| 112 | - $index = 'm0'.$i; |
|
| 112 | + $index = 'm0' . $i; |
|
| 113 | 113 | } |
| 114 | 114 | else { |
| 115 | - $index = 'm'.$i; |
|
| 115 | + $index = 'm' . $i; |
|
| 116 | 116 | } |
| 117 | 117 | $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']][$data['day']][$data['hour']][$index] = $data[$index]; |
| 118 | 118 | } |
@@ -230,16 +230,16 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $query_parameters = ''; |
| 232 | 232 | |
| 233 | - foreach($itemized[BAT_DAY] as $year => $months) { |
|
| 233 | + foreach ($itemized[BAT_DAY] as $year => $months) { |
|
| 234 | 234 | if ($year_count > 0) { |
| 235 | 235 | // We are dealing with multiple years so add an OR |
| 236 | 236 | $query_parameters .= ' OR '; |
| 237 | 237 | } |
| 238 | 238 | $query_parameters .= 'year IN (' . $year . ') '; |
| 239 | - $query_parameters .= 'AND month IN (' . implode("," ,array_keys($months)) .') '; |
|
| 239 | + $query_parameters .= 'AND month IN (' . implode(",", array_keys($months)) . ') '; |
|
| 240 | 240 | if (count($unit_ids) > 0) { |
| 241 | 241 | // Unit ids are defined so add this as a filter |
| 242 | - $query_parameters .= 'AND unit_id in (' . implode("," , $unit_ids) .') '; |
|
| 242 | + $query_parameters .= 'AND unit_id in (' . implode(",", $unit_ids) . ') '; |
|
| 243 | 243 | } |
| 244 | 244 | $year_count++; |
| 245 | 245 | } |