@@ -108,8 +108,7 @@ |
||
108 | 108 | $command = rtrim($command, ','); |
109 | 109 | $command .= " WHERE unit_id = " . $event->getUnitId() . " AND year = $year AND month = $month"; |
110 | 110 | $this->pdo->exec($command); |
111 | - } |
|
112 | - else { |
|
111 | + } else { |
|
113 | 112 | $this->pdo->exec("INSERT INTO $this->day_table (unit_id, year, month, " . implode(', ', $keys) . ") VALUES (" . $event->getUnitId() . ", $year, $month, " . implode(', ', $values) . ")"); |
114 | 113 | } |
115 | 114 | } |
@@ -130,8 +130,7 @@ discard block |
||
130 | 130 | // Compare the current states with the set of valid states |
131 | 131 | if ($intersect) { |
132 | 132 | $remaining_states = array_intersect($current_states, $valid_states); |
133 | - } |
|
134 | - else { |
|
133 | + } else { |
|
135 | 134 | $remaining_states = array_diff($current_states, $valid_states); |
136 | 135 | } |
137 | 136 | |
@@ -139,8 +138,7 @@ discard block |
||
139 | 138 | // Unit is in a state that is within the set of valid states so add to result set |
140 | 139 | $units[$unit] = $unit; |
141 | 140 | $response->addMatch($keyed_units[$unit], CalendarResponse::VALID_STATE); |
142 | - } |
|
143 | - else { |
|
141 | + } else { |
|
144 | 142 | $response->addMiss($keyed_units[$unit], CalendarResponse::INVALID_STATE); |
145 | 143 | } |
146 | 144 | |
@@ -234,8 +232,7 @@ discard block |
||
234 | 232 | foreach ($days as $day => $value) { |
235 | 233 | $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]); |
236 | 234 | } |
237 | - } |
|
238 | - else { |
|
235 | + } else { |
|
239 | 236 | foreach ($days as $day => $value) { |
240 | 237 | $result[$year][$month][$day] = $keyed_units[$unit]->getDefaultValue(); |
241 | 238 | } |
@@ -266,8 +263,7 @@ discard block |
||
266 | 263 | foreach ($hours as $hour => $value) { |
267 | 264 | if (isset($db_events[$unit][Event::BAT_HOUR][$year][$month][$day][$hour])) { |
268 | 265 | $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]); |
269 | - } |
|
270 | - else { |
|
266 | + } else { |
|
271 | 267 | // If nothing from db - then revert to the defaults |
272 | 268 | $result[$year][$month][$day][$hour] = (int) $keyed_units[$unit]->getDefaultValue(); |
273 | 269 | } |
@@ -315,8 +311,7 @@ discard block |
||
315 | 311 | foreach ($minutes as $minute => $value) { |
316 | 312 | if (isset($db_events[$unit][Event::BAT_MINUTE][$year][$month][$day][$hour][$minute])) { |
317 | 313 | $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]); |
318 | - } |
|
319 | - else { |
|
314 | + } else { |
|
320 | 315 | // If nothing from db - then revert to the defaults |
321 | 316 | $result[$year][$month][$day][$hour][$minute] = (int) $keyed_units[$unit]->getDefaultValue(); |
322 | 317 | } |
@@ -365,8 +360,12 @@ discard block |
||
365 | 360 | |
366 | 361 | // Make sure years are sorted |
367 | 362 | ksort($data[Event::BAT_DAY]); |
368 | - if (isset($data[Event::BAT_HOUR])) ksort($data[Event::BAT_HOUR]); |
|
369 | - if (isset($data[Event::BAT_MINUTE])) ksort($data[Event::BAT_MINUTE]); |
|
363 | + if (isset($data[Event::BAT_HOUR])) { |
|
364 | + ksort($data[Event::BAT_HOUR]); |
|
365 | + } |
|
366 | + if (isset($data[Event::BAT_MINUTE])) { |
|
367 | + ksort($data[Event::BAT_MINUTE]); |
|
368 | + } |
|
370 | 369 | |
371 | 370 | // Set up variables to keep track of stuff |
372 | 371 | $current_value = NULL; |
@@ -391,8 +390,7 @@ discard block |
||
391 | 390 | if ($current_value === $minute_value) { |
392 | 391 | // We are still in minutes and going through so add a minute |
393 | 392 | $end_event->add(new \DateInterval('PT1M')); |
394 | - } |
|
395 | - elseif (($current_value != $minute_value) && ($current_value !== NULL)) { |
|
393 | + } elseif (($current_value != $minute_value) && ($current_value !== NULL)) { |
|
396 | 394 | // Value just switched - let us wrap up with current event and start a new one |
397 | 395 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
398 | 396 | $start_event = clone($end_event->add(new \DateInterval('PT1M'))); |
@@ -406,12 +404,10 @@ discard block |
||
406 | 404 | } |
407 | 405 | $current_value = $minute_value; |
408 | 406 | } |
409 | - } |
|
410 | - elseif ($current_value === $hour_value) { |
|
407 | + } elseif ($current_value === $hour_value) { |
|
411 | 408 | // We are in hours and can add something |
412 | 409 | $end_event->add(new \DateInterval('PT1H')); |
413 | - } |
|
414 | - elseif (($current_value != $hour_value) && ($current_value !== NULL)) { |
|
410 | + } elseif (($current_value != $hour_value) && ($current_value !== NULL)) { |
|
415 | 411 | // Value just switched - let us wrap up with current event and start a new one |
416 | 412 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
417 | 413 | // Start event becomes the end event with a minute added |
@@ -428,12 +424,10 @@ discard block |
||
428 | 424 | $current_value = $hour_value; |
429 | 425 | } |
430 | 426 | } |
431 | - } |
|
432 | - elseif ($current_value === $value) { |
|
427 | + } elseif ($current_value === $value) { |
|
433 | 428 | // We are adding a whole day so the end event gets moved to the end of the day we are adding |
434 | 429 | $end_event = new \DateTime($year . '-' . $month . '-' . substr($day, 1) . ' ' . '23:59'); |
435 | - } |
|
436 | - elseif (($current_value !== $value) && ($current_value !== NULL)) { |
|
430 | + } elseif (($current_value !== $value) && ($current_value !== NULL)) { |
|
437 | 431 | // Value just switched - let us wrap up with current event and start a new one |
438 | 432 | $normalized_events[$unit_id][] = new Event($start_event, $end_event, $this->getUnit($unit_id), $current_value); |
439 | 433 | // Start event becomes the end event with a minute added |
@@ -468,8 +462,7 @@ discard block |
||
468 | 462 | if ($event->endsLater($end_date)) { |
469 | 463 | $event->setEndDate($end_date); |
470 | 464 | } |
471 | - } |
|
472 | - else { |
|
465 | + } else { |
|
473 | 466 | // Event completely not in range so unset it |
474 | 467 | unset($normalized_events[$unit_id][$key]); |
475 | 468 | } |
@@ -500,8 +493,7 @@ discard block |
||
500 | 493 | $e++; |
501 | 494 | $flipped[$e][$value][$datum] = $datum; |
502 | 495 | $old_value = $value; |
503 | - } |
|
504 | - else { |
|
496 | + } else { |
|
505 | 497 | $flipped[$e][$value][$datum] = $datum; |
506 | 498 | } |
507 | 499 | } |
@@ -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 |
@@ -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 |