@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function getEventData(\DateTime $start_date, \DateTime $end_date, $unit_ids) { |
29 | 29 | |
30 | - $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
30 | + $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
31 | 31 | |
32 | 32 | $results = array(); |
33 | 33 | // Run each query and store results |
@@ -38,31 +38,31 @@ discard block |
||
38 | 38 | $db_events = array(); |
39 | 39 | |
40 | 40 | // Cycle through day results and setup an event array |
41 | - while( $data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
41 | + while ($data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
42 | 42 | // Figure out how many days the current month has |
43 | - $temp_date = new \DateTime($data['year'] . "-" . $data['month']); |
|
43 | + $temp_date = new \DateTime($data['year']."-".$data['month']); |
|
44 | 44 | $days_in_month = (int)$temp_date->format('t'); |
45 | - for ($i = 1; $i<=$days_in_month; $i++) { |
|
46 | - $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d' . $i] = $data['d'.$i]; |
|
45 | + for ($i = 1; $i <= $days_in_month; $i++) { |
|
46 | + $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d'.$i] = $data['d'.$i]; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | 50 | // With the day events taken care off let's cycle through hours |
51 | - while( $data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
52 | - for ($i = 0; $i<=23; $i++) { |
|
53 | - $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d' . $data['day']]['h'. $i] = $data['h'.$i]; |
|
51 | + while ($data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
52 | + for ($i = 0; $i <= 23; $i++) { |
|
53 | + $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d'.$data['day']]['h'.$i] = $data['h'.$i]; |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | // With the hour events taken care off let's cycle through minutes |
58 | - while( $data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
59 | - for ($i = 0; $i<=59; $i++) { |
|
58 | + while ($data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
59 | + for ($i = 0; $i <= 59; $i++) { |
|
60 | 60 | if ($i <= 9) { |
61 | 61 | $index = 'm0'.$i; |
62 | 62 | } else { |
63 | 63 | $index = 'm'.$i; |
64 | 64 | } |
65 | - $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d' . $data['day']]['h' . $data['hour']][$index] = $data[$index]; |
|
65 | + $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d'.$data['day']]['h'.$data['hour']][$index] = $data[$index]; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 |
@@ -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 | } |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | if (!($this->event->getStartDate()->format('H:i') == '00:00' && $this->event->getEndDate()->format('H:i') == '23:59')) { |
219 | 219 | $period = new \DatePeriod($start_date, $interval, $end_date->add(new \DateInterval('PT1M'))); |
220 | 220 | $itemized_same_day = $this->createHourlyGranular($period, $start_date); |
221 | - $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
|
222 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
|
223 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
|
221 | + $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d'.$sd] = -1; |
|
222 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd]; |
|
223 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd]; |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | else { |
@@ -228,27 +228,27 @@ discard block |
||
228 | 228 | if (!($this->event->getStartDate()->format('H:i') == '00:00')) { |
229 | 229 | $start_period = new \DatePeriod($start_date, $interval, new \DateTime($start_date->format("Y-n-j 23:59:59"))); |
230 | 230 | $itemized_start = $this->createHourlyGranular($start_period, $start_date); |
231 | - $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
|
232 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
|
233 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
|
231 | + $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d'.$sd] = -1; |
|
232 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd]; |
|
233 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd]; |
|
234 | 234 | } |
235 | 235 | else { |
236 | 236 | // Just set an empty hour and minute |
237 | - $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = array(); |
|
238 | - $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = array(); |
|
237 | + $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d'.$sd] = array(); |
|
238 | + $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d'.$sd] = array(); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // Deal with the end date unless it ends just before midnight at which point we don't need to go further |
242 | 242 | if ($this->event->getEndDate()->format('H:i') == '23:59') { |
243 | - $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = array(); |
|
244 | - $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = array(); |
|
243 | + $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed] = array(); |
|
244 | + $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed] = array(); |
|
245 | 245 | } |
246 | 246 | else { |
247 | 247 | $end_period = new \DatePeriod(new \DateTime($end_date->format("Y-n-j 00:00:00")), $interval, $end_date->add(new \DateInterval('PT1M'))); |
248 | 248 | $itemized_end = $this->createHourlyGranular($end_period, new \DateTime($end_date->format("Y-n-j 00:00:00"))); |
249 | - $itemized[EventItemizer::BAT_DAY][$ey][$em]['d' . $ed] = -1; |
|
250 | - $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = $itemized_end[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed]; |
|
251 | - $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = $itemized_end[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed]; |
|
249 | + $itemized[EventItemizer::BAT_DAY][$ey][$em]['d'.$ed] = -1; |
|
250 | + $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed] = $itemized_end[EventItemizer::BAT_HOUR][$ey][$em]['d'.$ed]; |
|
251 | + $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed] = $itemized_end[EventItemizer::BAT_MINUTE][$ey][$em]['d'.$ed]; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | $start_minute = $counter; |
271 | 271 | foreach ($period as $minute) { |
272 | 272 | // Doing minutes so set the values in the minute array |
273 | - $itemized[EventItemizer::BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')]['m' . $minute->format('i')] = $this->event->getValue(); |
|
273 | + $itemized[EventItemizer::BAT_MINUTE][$minute->format('Y')][$minute->format('n')]['d'.$minute->format('j')]['h'.$minute->format('G')]['m'.$minute->format('i')] = $this->event->getValue(); |
|
274 | 274 | // Let the hours know that it cannot determine availability |
275 | - $itemized[EventItemizer::BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')] = -1; |
|
275 | + $itemized[EventItemizer::BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d'.$minute->format('j')]['h'.$minute->format('G')] = -1; |
|
276 | 276 | $counter++; |
277 | 277 | |
278 | 278 | if ($counter == 60 && $start_minute !== 0) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | } |
283 | 283 | elseif ($counter == 60 && $start_minute == 0) { |
284 | 284 | // Did a real whole hour so initialize the hour |
285 | - $itemized[EventItemizer::BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')] = $this->event->getValue(); |
|
285 | + $itemized[EventItemizer::BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d'.$minute->format('j')]['h'.$minute->format('G')] = $this->event->getValue(); |
|
286 | 286 | |
287 | 287 | $counter = 0; |
288 | 288 | $start_minute = 0; |
@@ -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 | |
@@ -222,8 +221,7 @@ discard block |
||
222 | 221 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
223 | 222 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_same_day[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
224 | 223 | } |
225 | - } |
|
226 | - else { |
|
224 | + } else { |
|
227 | 225 | // Deal with the start day unless it starts on midnight precisely at which point the whole day is booked |
228 | 226 | if (!($this->event->getStartDate()->format('H:i') == '00:00')) { |
229 | 227 | $start_period = new \DatePeriod($start_date, $interval, new \DateTime($start_date->format("Y-n-j 23:59:59"))); |
@@ -231,8 +229,7 @@ discard block |
||
231 | 229 | $itemized[EventItemizer::BAT_DAY][$sy][$sm]['d' . $sd] = -1; |
232 | 230 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd]; |
233 | 231 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = $itemized_start[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd]; |
234 | - } |
|
235 | - else { |
|
232 | + } else { |
|
236 | 233 | // Just set an empty hour and minute |
237 | 234 | $itemized[EventItemizer::BAT_HOUR][$sy][$sm]['d' . $sd] = array(); |
238 | 235 | $itemized[EventItemizer::BAT_MINUTE][$sy][$sm]['d' . $sd] = array(); |
@@ -242,8 +239,7 @@ discard block |
||
242 | 239 | if ($this->event->getEndDate()->format('H:i') == '23:59') { |
243 | 240 | $itemized[EventItemizer::BAT_HOUR][$ey][$em]['d' . $ed] = array(); |
244 | 241 | $itemized[EventItemizer::BAT_MINUTE][$ey][$em]['d' . $ed] = array(); |
245 | - } |
|
246 | - else { |
|
242 | + } else { |
|
247 | 243 | $end_period = new \DatePeriod(new \DateTime($end_date->format("Y-n-j 00:00:00")), $interval, $end_date->add(new \DateInterval('PT1M'))); |
248 | 244 | $itemized_end = $this->createHourlyGranular($end_period, new \DateTime($end_date->format("Y-n-j 00:00:00"))); |
249 | 245 | $itemized[EventItemizer::BAT_DAY][$ey][$em]['d' . $ed] = -1; |
@@ -279,8 +275,7 @@ discard block |
||
279 | 275 | // Not a real hour - leave as is and move on |
280 | 276 | $counter = 0; |
281 | 277 | $start_minute = 0; |
282 | - } |
|
283 | - elseif ($counter == 60 && $start_minute == 0) { |
|
278 | + } elseif ($counter == 60 && $start_minute == 0) { |
|
284 | 279 | // Did a real whole hour so initialize the hour |
285 | 280 | $itemized[EventItemizer::BAT_HOUR][$minute->format('Y')][$minute->format('n')]['d' . $minute->format('j')]['h' . $minute->format('G')] = $this->event->getValue(); |
286 | 281 |
@@ -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(); |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | public function getConstraints($constraint_class = NULL) { |
28 | 28 | if ($constraint_class == NULL) { |
29 | 29 | return $this->constraint; |
30 | - } |
|
31 | - else { |
|
30 | + } else { |
|
32 | 31 | return $this->constraint[$constraint_class]; |
33 | 32 | } |
34 | 33 | } |
@@ -58,12 +57,10 @@ discard block |
||
58 | 57 | public function normalizeConstraints($constraint_class = NULL) { |
59 | 58 | if ($constraint_class == NULL) { |
60 | 59 | $classes = array_keys($this->constraints); |
61 | - } |
|
62 | - else { |
|
60 | + } else { |
|
63 | 61 | if (isset($this->constraints[$constraint_class])) { |
64 | 62 | $classes = array($constraint_class); |
65 | - } |
|
66 | - else { |
|
63 | + } else { |
|
67 | 64 | return array(); |
68 | 65 | } |
69 | 66 | } |
@@ -89,8 +86,7 @@ discard block |
||
89 | 86 | |
90 | 87 | if ($constraint_class == NULL) { |
91 | 88 | return $new_constraints; |
92 | - } |
|
93 | - else { |
|
89 | + } else { |
|
94 | 90 | return $new_constraints[$constraint_class]; |
95 | 91 | } |
96 | 92 | } |
@@ -119,12 +115,10 @@ discard block |
||
119 | 115 | if ($start_date >= $new_start_date && $start_date <= $new_end_date) { |
120 | 116 | $new_end_date_clone = clone($new_end_date); |
121 | 117 | $constraint->setStartDate($new_end_date_clone->add(new \DateInterval('P1D'))); |
122 | - } |
|
123 | - elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
118 | + } elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
124 | 119 | $new_start_date_clone = clone($new_start_date); |
125 | 120 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
126 | - } |
|
127 | - elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
121 | + } elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
128 | 122 | if ($constraint->getEndDate() > $new_start_date) { |
129 | 123 | $new_start_date_clone = clone($new_start_date); |
130 | 124 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
@@ -136,8 +130,7 @@ discard block |
||
136 | 130 | $split_end_date = $end_date; |
137 | 131 | |
138 | 132 | $split_constraint = new MinMaxDaysConstraint($constraint->getUnits(), $constraint->getMinDays(), $constraint->getMaxDays(), $split_start_date, $split_end_date, $constraint->getCheckinDay()); |
139 | - } |
|
140 | - else { |
|
133 | + } else { |
|
141 | 134 | $split_start_date = $split_constraint->getStartDate(); |
142 | 135 | $split_end_date = $split_constraint->getEndDate(); |
143 | 136 | |
@@ -194,12 +187,10 @@ discard block |
||
194 | 187 | if ($start_date >= $new_start_date && $start_date <= $new_end_date) { |
195 | 188 | $new_end_date_clone = clone($new_end_date); |
196 | 189 | $constraint->setStartDate($new_end_date_clone->add(new \DateInterval('P1D'))); |
197 | - } |
|
198 | - elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
190 | + } elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) { |
|
199 | 191 | $new_start_date_clone = clone($new_start_date); |
200 | 192 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
201 | - } |
|
202 | - elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
193 | + } elseif ($start_date < $new_start_date && $end_date > $new_end_date) { |
|
203 | 194 | if ($constraint->getEndDate() > $new_start_date) { |
204 | 195 | $new_start_date_clone = clone($new_start_date); |
205 | 196 | $constraint->setEndDate($new_start_date_clone->sub(new \DateInterval('P1D'))); |
@@ -211,8 +202,7 @@ discard block |
||
211 | 202 | $split_end_date = $end_date; |
212 | 203 | |
213 | 204 | $split_constraint = new CheckInDayConstraint($constraint->getUnits(), $constraint->getCheckinDay(), $split_start_date, $split_end_date); |
214 | - } |
|
215 | - else { |
|
205 | + } else { |
|
216 | 206 | $split_start_date = $split_constraint->getStartDate(); |
217 | 207 | $split_end_date = $split_constraint->getEndDate(); |
218 | 208 |