@@ -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) { |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function getEventData(\DateTime $start_date, \DateTime $end_date, $unit_ids) { |
| 30 | 30 | |
| 31 | - $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
| 31 | + $queries = $this->buildQueries($start_date, $end_date, $unit_ids); |
|
| 32 | 32 | |
| 33 | 33 | $results = array(); |
| 34 | 34 | // Run each query and store results |
@@ -43,31 +43,31 @@ discard block |
||
| 43 | 43 | $db_events = array(); |
| 44 | 44 | |
| 45 | 45 | // Cycle through day results and setup an event array |
| 46 | - while( $data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
| 46 | + while ($data = $results[Event::BAT_DAY]->fetchAssoc()) { |
|
| 47 | 47 | // Figure out how many days the current month has |
| 48 | - $temp_date = new \DateTime($data['year'] . "-" . $data['month']); |
|
| 48 | + $temp_date = new \DateTime($data['year']."-".$data['month']); |
|
| 49 | 49 | $days_in_month = (int)$temp_date->format('t'); |
| 50 | - for ($i = 1; $i<=$days_in_month; $i++) { |
|
| 51 | - $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d' . $i] = $data['d'.$i]; |
|
| 50 | + for ($i = 1; $i <= $days_in_month; $i++) { |
|
| 51 | + $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d'.$i] = $data['d'.$i]; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // With the day events taken care off let's cycle through hours |
| 56 | - while( $data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
| 57 | - for ($i = 0; $i<=23; $i++) { |
|
| 58 | - $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d' . $data['day']]['h'. $i] = $data['h'.$i]; |
|
| 56 | + while ($data = $results[Event::BAT_HOUR]->fetchAssoc()) { |
|
| 57 | + for ($i = 0; $i <= 23; $i++) { |
|
| 58 | + $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d'.$data['day']]['h'.$i] = $data['h'.$i]; |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // With the hour events taken care off let's cycle through minutes |
| 63 | - while( $data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
| 64 | - for ($i = 0; $i<=59; $i++) { |
|
| 63 | + while ($data = $results[Event::BAT_MINUTE]->fetchAssoc()) { |
|
| 64 | + for ($i = 0; $i <= 59; $i++) { |
|
| 65 | 65 | if ($i <= 9) { |
| 66 | 66 | $index = 'm0'.$i; |
| 67 | 67 | } else { |
| 68 | 68 | $index = 'm'.$i; |
| 69 | 69 | } |
| 70 | - $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d' . $data['day']]['h' . $data['hour']][$index] = $data[$index]; |
|
| 70 | + $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d'.$data['day']]['h'.$data['hour']][$index] = $data[$index]; |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | foreach ($days as $day => $hours) { |
| 133 | 133 | // Count required as we may receive empty hours for granular events that start and end on midnight |
| 134 | 134 | if (count($hours) > 0) { |
| 135 | - foreach ($hours as $hour => $value){ |
|
| 135 | + foreach ($hours as $hour => $value) { |
|
| 136 | 136 | $this->itemizeSplitHour($existing_events, $itemized, $value, $event->getUnitId(), $year, $month, $day, $hour); |
| 137 | 137 | } |
| 138 | 138 | if (class_exists('Drupal') && floatval(\Drupal::VERSION) >= 9) { |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | // Cycle through day results and setup an event array |
| 50 | 50 | foreach ($results[Event::BAT_DAY]->fetchAll() as $data) { |
| 51 | 51 | // Figure out how many days the current month has |
| 52 | - $temp_date = new \DateTime($data['year'] . "-" . $data['month']); |
|
| 52 | + $temp_date = new \DateTime($data['year']."-".$data['month']); |
|
| 53 | 53 | $days_in_month = (int)$temp_date->format('t'); |
| 54 | 54 | for ($i = 1; $i <= $days_in_month; $i++) { |
| 55 | - $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d' . $i] = $data['d' . $i]; |
|
| 55 | + $db_events[$data['unit_id']][Event::BAT_DAY][$data['year']][$data['month']]['d'.$i] = $data['d'.$i]; |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // With the day events taken care off let's cycle through hours |
| 60 | 60 | foreach ($results[Event::BAT_HOUR]->fetchAll() as $data) { |
| 61 | 61 | for ($i = 0; $i <= 23; $i++) { |
| 62 | - $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d' . $data['day']]['h' . $i] = $data['h' . $i]; |
|
| 62 | + $db_events[$data['unit_id']][Event::BAT_HOUR][$data['year']][$data['month']]['d'.$data['day']]['h'.$i] = $data['h'.$i]; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | foreach ($results[Event::BAT_MINUTE]->fetchAll() as $data) { |
| 68 | 68 | for ($i = 0; $i <= 59; $i++) { |
| 69 | 69 | if ($i <= 9) { |
| 70 | - $index = 'm0' . $i; |
|
| 70 | + $index = 'm0'.$i; |
|
| 71 | 71 | } else { |
| 72 | - $index = 'm' . $i; |
|
| 72 | + $index = 'm'.$i; |
|
| 73 | 73 | } |
| 74 | - $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d' . $data['day']]['h' . $data['hour']][$index] = $data[$index]; |
|
| 74 | + $db_events[$data['unit_id']][Event::BAT_MINUTE][$data['year']][$data['month']]['d'.$data['day']]['h'.$data['hour']][$index] = $data[$index]; |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | $command .= "$day = $value,"; |
| 111 | 111 | } |
| 112 | 112 | $command = rtrim($command, ','); |
| 113 | - $command .= " WHERE unit_id = " . $unit_id . " AND year = $year AND month = $month"; |
|
| 113 | + $command .= " WHERE unit_id = ".$unit_id." AND year = $year AND month = $month"; |
|
| 114 | 114 | $this->pdo->exec($command); |
| 115 | 115 | } |
| 116 | 116 | else { |
| 117 | - $this->pdo->exec("INSERT INTO $this->day_table (unit_id, year, month, " . implode(', ', $keys) . ") VALUES (" . $unit_id . ", $year, $month, " . implode(', ', $values) . ")"); |
|
| 117 | + $this->pdo->exec("INSERT INTO $this->day_table (unit_id, year, month, ".implode(', ', $keys).") VALUES (".$unit_id.", $year, $month, ".implode(', ', $values).")"); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | $keys = array_keys($hours); |
| 131 | 131 | if (isset($existing_events[$unit_id][EVENT::BAT_HOUR][$year][$month][$day])) { |
| 132 | 132 | $command = "UPDATE $this->hour_table SET "; |
| 133 | - foreach ($hours as $hour => $value){ |
|
| 133 | + foreach ($hours as $hour => $value) { |
|
| 134 | 134 | $this->itemizeSplitHour($existing_events, $itemized, $value, $unit_id, $year, $month, $day, $hour); |
| 135 | 135 | $command .= "$hour = $value,"; |
| 136 | 136 | } |
| 137 | 137 | $command = rtrim($command, ','); |
| 138 | - $command .= " WHERE unit_id = " . $unit_id . " AND year = $year AND month = $month AND day = " . substr($day,1); |
|
| 138 | + $command .= " WHERE unit_id = ".$unit_id." AND year = $year AND month = $month AND day = ".substr($day, 1); |
|
| 139 | 139 | $this->pdo->exec($command); |
| 140 | 140 | } else { |
| 141 | 141 | if (isset($existing_events[$unit_id][EVENT::BAT_DAY][$year][$month][$day])) { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $this->itemizeSplitHour($existing_events, $itemized, $value, $unit_id, $year, $month, $day, $hour); |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - $this->pdo->exec("INSERT INTO $this->hour_table (unit_id, year, month, day, " . implode(', ', $keys) . ") VALUES (" . $unit_id . ", $year, $month, " . substr($day, 1) . ", " . implode(', ', $values) . ")"); |
|
| 146 | + $this->pdo->exec("INSERT INTO $this->hour_table (unit_id, year, month, day, ".implode(', ', $keys).") VALUES (".$unit_id.", $year, $month, ".substr($day, 1).", ".implode(', ', $values).")"); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | $keys = array_keys($minutes); |
| 160 | 160 | if (isset($existing_events[$unit_id][EVENT::BAT_MINUTE][$year][$month][$day][$hour])) { |
| 161 | 161 | $command = "UPDATE $this->minute_table SET "; |
| 162 | - foreach ($minutes as $minute => $value){ |
|
| 162 | + foreach ($minutes as $minute => $value) { |
|
| 163 | 163 | $command .= "$minute = $value,"; |
| 164 | 164 | } |
| 165 | 165 | $command = rtrim($command, ','); |
| 166 | - $command .= " WHERE unit_id = " . $unit_id . " AND year = $year AND month = $month AND day = " . substr($day,1) . " AND hour = " . substr($hour,1); |
|
| 166 | + $command .= " WHERE unit_id = ".$unit_id." AND year = $year AND month = $month AND day = ".substr($day, 1)." AND hour = ".substr($hour, 1); |
|
| 167 | 167 | $this->pdo->exec($command); |
| 168 | 168 | } else { |
| 169 | - $this->pdo->exec("INSERT INTO $this->minute_table (unit_id, year, month, day, hour, " . implode(', ', $keys) . ") VALUES (" . $unit_id . ", $year, $month, " . substr($day, 1) . ", " . substr($hour, 1) . ", " . implode(', ', $values) . ")"); |
|
| 169 | + $this->pdo->exec("INSERT INTO $this->minute_table (unit_id, year, month, day, hour, ".implode(', ', $keys).") VALUES (".$unit_id.", $year, $month, ".substr($day, 1).", ".substr($hour, 1).", ".implode(', ', $values).")"); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | } |
@@ -112,8 +112,7 @@ |
||
| 112 | 112 | $command = rtrim($command, ','); |
| 113 | 113 | $command .= " WHERE unit_id = " . $unit_id . " AND year = $year AND month = $month"; |
| 114 | 114 | $this->pdo->exec($command); |
| 115 | - } |
|
| 116 | - else { |
|
| 115 | + } else { |
|
| 117 | 116 | $this->pdo->exec("INSERT INTO $this->day_table (unit_id, year, month, " . implode(', ', $keys) . ") VALUES (" . $unit_id . ", $year, $month, " . implode(', ', $values) . ")"); |
| 118 | 117 | } |
| 119 | 118 | } |