Complex classes like Spotter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Spotter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class Spotter{ |
||
| 8 | public $aircraft_correct_icaotype = array('CL64' => 'CL60', |
||
| 9 | 'F9LX' => 'F900', |
||
| 10 | 'K35T' => 'K35R', |
||
| 11 | 'F5EX' => 'FA50', |
||
| 12 | 'G102' => 'GLID', |
||
| 13 | 'LJ36' => 'LJ35', |
||
| 14 | 'G500' => 'EGRT', |
||
| 15 | 'A300' => 'A30B', |
||
| 16 | 'ROT' => 'B77W', |
||
| 17 | 'BPN' => 'B772', |
||
| 18 | '0011' => 'B77W', |
||
| 19 | 'F9DX' => 'F900', |
||
| 20 | 'B757' => 'B752', |
||
| 21 | '4/05' => 'A332', |
||
| 22 | 'F/A3' => 'A320', |
||
| 23 | 'F2EX' => 'F2TH', |
||
| 24 | 'EA55' => 'EA50', |
||
| 25 | 'B73B' => 'B737', |
||
| 26 | 'G450' => 'GLF4', |
||
| 27 | 'H25X' => 'H25B', |
||
| 28 | 'E175' => 'E75S', |
||
| 29 | 'B777' => 'B77W', |
||
| 30 | 'F2LX' => 'F2TH', |
||
| 31 | 'CL65' => 'CL60', |
||
| 32 | 'A380' => 'A388', |
||
| 33 | 'G550' => 'GLF5', |
||
| 34 | 'F9EX' => 'F900', |
||
| 35 | 'E195' => 'E190', |
||
| 36 | 'H750' => 'H25B', |
||
| 37 | 'B747' => 'B744', |
||
| 38 | 'B767' => 'B763', |
||
| 39 | 'PA39' => 'PA30', |
||
| 40 | 'H900' => 'H25B', |
||
| 41 | 'AN74' => 'AN72', |
||
| 42 | 'CL85' => 'CRJ2', |
||
| 43 | 'G400' => 'GLF4', |
||
| 44 | 'CL61' => 'CL60', |
||
| 45 | 'F2TS' => 'F2TH', |
||
| 46 | 'Z602' => 'CH60', |
||
| 47 | 'G100' => 'ASTR'); |
||
| 48 | |||
| 49 | |||
| 50 | public $db; |
||
| 51 | |||
| 52 | public function __construct($dbc = null) { |
||
| 53 | $Connection = new Connection($dbc); |
||
| 54 | $this->db = $Connection->db(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get SQL query part for filter used |
||
| 59 | * @param Array $filter the filter |
||
| 60 | * @return Array the SQL part |
||
| 61 | */ |
||
| 62 | public function getFilter($filter = array(),$where = false,$and = false) { |
||
| 63 | global $globalFilter, $globalStatsFilters, $globalFilterName; |
||
| 64 | $filters = array(); |
||
| 65 | if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
||
| 66 | if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
||
| 67 | $filters = $globalStatsFilters[$globalFilterName]; |
||
| 68 | } else { |
||
| 69 | $filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
||
| 73 | $filter_query_join = ''; |
||
| 74 | $filter_query_where = ''; |
||
| 75 | foreach($filters as $flt) { |
||
| 76 | if (isset($flt['airlines']) && !empty($flt['airlines'])) { |
||
| 77 | if ($flt['airlines'][0] != '') { |
||
| 78 | if (isset($flt['source'])) { |
||
| 79 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 80 | } else { |
||
| 81 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) { |
||
| 86 | if (isset($flt['source'])) { |
||
| 87 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 88 | } else { |
||
| 89 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']))) { |
||
| 93 | if (isset($flt['source'])) { |
||
| 94 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
||
| 99 | if ($filter['airlines'][0] != '') { |
||
| 100 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
||
| 104 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_output.flightaware_id "; |
||
| 105 | } |
||
| 106 | if (isset($filter['alliance']) && !empty($filter['alliance'])) { |
||
| 107 | $filter_query_join .= " INNER JOIN (SELECT icao FROM airlines WHERE alliance = '".$filter['alliance']."') sal ON sal.icao = spotter_output.airline_icao "; |
||
| 108 | } |
||
| 109 | if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
||
| 110 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
| 111 | } |
||
| 112 | if (isset($filter['source']) && !empty($filter['source'])) { |
||
| 113 | $filter_query_where = " WHERE format_source IN ('".implode("','",$filter['source'])."')"; |
||
| 114 | } |
||
| 115 | if (isset($filter['ident']) && !empty($filter['ident'])) { |
||
| 116 | $filter_query_where = " WHERE ident = '".$filter['ident']."'"; |
||
| 117 | } |
||
| 118 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
||
| 119 | if ($filter_query_where == '') { |
||
| 120 | $filter_query_where = " WHERE format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
| 121 | } else { |
||
| 122 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
||
| 126 | elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
||
| 127 | $filter_query = $filter_query_join.$filter_query_where; |
||
| 128 | return $filter_query; |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Executes the SQL statements to get the spotter information |
||
| 133 | * |
||
| 134 | * @param String $query the SQL query |
||
| 135 | * @param Array $params parameter of the query |
||
| 136 | * @param String $limitQuery the limit query |
||
| 137 | * @return Array the spotter information |
||
| 138 | * |
||
| 139 | */ |
||
| 140 | public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false) |
||
| 141 | { |
||
| 142 | global $globalSquawkCountry, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalAirlinesSource, $globalVAM; |
||
| 143 | $Image = new Image($this->db); |
||
| 144 | $Schedule = new Schedule($this->db); |
||
| 145 | $ACARS = new ACARS($this->db); |
||
| 146 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
| 147 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
| 148 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
| 149 | if (!isset($globalVAM)) $globalVAM = FALSE; |
||
| 150 | date_default_timezone_set('UTC'); |
||
| 151 | |||
| 152 | if (!is_string($query)) |
||
| 153 | { |
||
| 154 | return false; |
||
| 155 | } |
||
| 156 | |||
| 157 | if ($limitQuery != "") |
||
| 158 | { |
||
| 159 | if (!is_string($limitQuery)) |
||
| 160 | { |
||
| 161 | return false; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | |||
| 166 | try { |
||
| 167 | $sth = $this->db->prepare($query.$limitQuery); |
||
| 168 | $sth->execute($params); |
||
| 169 | } catch (PDOException $e) { |
||
| 170 | printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery); |
||
| 171 | exit(); |
||
| 172 | } |
||
| 173 | |||
| 174 | // $num_rows = count($sth->fetchAll()); |
||
| 175 | $num_rows = 0; |
||
| 176 | |||
| 177 | $spotter_array = array(); |
||
| 178 | |||
| 179 | |||
| 180 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 181 | { |
||
| 182 | $num_rows++; |
||
| 183 | $temp_array = array(); |
||
| 184 | if (isset($row['spotter_live_id'])) { |
||
| 185 | //$temp_array['spotter_id'] = $row['spotter_live_id']; |
||
| 186 | $temp_array['spotter_id'] = $this->getSpotterIDBasedOnFlightAwareID($row['flightaware_id']); |
||
| 187 | } elseif (isset($row['spotter_archive_id'])) { |
||
| 188 | $temp_array['spotter_id'] = $row['spotter_archive_id']; |
||
| 189 | } elseif (isset($row['spotter_archive_output_id'])) { |
||
| 190 | $temp_array['spotter_id'] = $row['spotter_archive_output_id']; |
||
| 191 | } elseif (isset($row['spotter_id'])) { |
||
| 192 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 193 | } else { |
||
| 194 | $temp_array['spotter_id'] = ''; |
||
| 195 | } |
||
| 196 | if (isset($row['flightaware_id'])) $temp_array['flightaware_id'] = $row['flightaware_id']; |
||
| 197 | if (isset($row['modes'])) $temp_array['modes'] = $row['modes']; |
||
| 198 | $temp_array['ident'] = $row['ident']; |
||
| 199 | if (isset($row['registration']) && $row['registration'] != '') { |
||
| 200 | $temp_array['registration'] = $row['registration']; |
||
| 201 | } elseif (isset($temp_array['modes'])) { |
||
| 202 | $temp_array['registration'] = $this->getAircraftRegistrationBymodeS($temp_array['modes']); |
||
| 203 | } else $temp_array['registration'] = ''; |
||
| 204 | if (isset($row['aircraft_icao'])) $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
| 205 | |||
| 206 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
| 207 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
| 208 | if (isset($row['real_arrival_airport_icao']) && $row['real_arrival_airport_icao'] != NULL) $temp_array['real_arrival_airport'] = $row['real_arrival_airport_icao']; |
||
| 209 | if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude']; |
||
| 210 | if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude']; |
||
| 211 | /* |
||
| 212 | if (Connection->tableExists('countries')) { |
||
| 213 | $country_info = $this->getCountryFromLatitudeLongitude($temp_array['latitude'],$temp_array['longitude']); |
||
| 214 | if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) { |
||
| 215 | $temp_array['country'] = $country_info['name']; |
||
| 216 | $temp_array['country_iso2'] = $country_info['iso2']; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | */ |
||
| 220 | if (isset($row['waypoints'])) $temp_array['waypoints'] = $row['waypoints']; |
||
| 221 | if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source']; |
||
| 222 | if (isset($row['route_stop']) && $row['route_stop'] != '') { |
||
| 223 | $temp_array['route_stop'] = $row['route_stop']; |
||
| 224 | $allroute = explode(' ',$row['route_stop']); |
||
| 225 | foreach ($allroute as $route) { |
||
| 226 | $route_airport_array = $this->getAllAirportInfo($route); |
||
| 227 | if (isset($route_airport_array[0]['name'])) { |
||
| 228 | $route_stop_details = array(); |
||
| 229 | $route_stop_details['airport_name'] = $route_airport_array[0]['name']; |
||
| 230 | $route_stop_details['airport_city'] = $route_airport_array[0]['city']; |
||
| 231 | $route_stop_details['airport_country'] = $route_airport_array[0]['country']; |
||
| 232 | $route_stop_details['airport_icao'] = $route_airport_array[0]['icao']; |
||
| 233 | $temp_array['route_stop_details'][] = $route_stop_details; |
||
| 234 | } |
||
| 235 | } |
||
| 236 | } |
||
| 237 | if (isset($row['altitude'])) $temp_array['altitude'] = $row['altitude']; |
||
| 238 | if (isset($row['heading'])) { |
||
| 239 | $temp_array['heading'] = $row['heading']; |
||
| 240 | $heading_direction = $this->parseDirection($row['heading']); |
||
| 241 | if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
||
| 242 | } |
||
| 243 | if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed']; |
||
| 244 | $temp_array['image'] = ""; |
||
| 245 | $temp_array['image_thumbnail'] = ""; |
||
| 246 | $temp_array['image_source'] = ""; |
||
| 247 | $temp_array['image_copyright'] = ""; |
||
| 248 | |||
| 249 | if (isset($row['highlight'])) { |
||
| 250 | $temp_array['highlight'] = $row['highlight']; |
||
| 251 | } else $temp_array['highlight'] = ''; |
||
| 252 | |||
| 253 | if (isset($row['date'])) { |
||
| 254 | $dateArray = $this->parseDateString($row['date']); |
||
| 255 | if ($dateArray['seconds'] < 10) |
||
| 256 | { |
||
| 257 | $temp_array['date'] = "a few seconds ago"; |
||
| 258 | } elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) |
||
| 259 | { |
||
| 260 | $temp_array['date'] = "half a minute ago"; |
||
| 261 | } elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) |
||
| 262 | { |
||
| 263 | $temp_array['date'] = "about a minute ago"; |
||
| 264 | } elseif ($dateArray['minutes'] < 5) |
||
| 265 | { |
||
| 266 | $temp_array['date'] = "a few minutes ago"; |
||
| 267 | } elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) |
||
| 268 | { |
||
| 269 | $temp_array['date'] = "about ".$dateArray['minutes']." minutes ago"; |
||
| 270 | } elseif ($dateArray['hours'] < 2) |
||
| 271 | { |
||
| 272 | $temp_array['date'] = "about an hour ago"; |
||
| 273 | } elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) |
||
| 274 | { |
||
| 275 | $temp_array['date'] = "about ".$dateArray['hours']." hours ago"; |
||
| 276 | } else { |
||
| 277 | $temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC")); |
||
| 278 | } |
||
| 279 | $temp_array['date_minutes_past'] = $dateArray['minutes']; |
||
| 280 | $temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC")); |
||
| 281 | $temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC")); |
||
| 282 | $temp_array['date_unix'] = strtotime($row['date']." UTC"); |
||
| 283 | if (isset($row['last_seen']) && $row['last_seen'] != '') { |
||
| 284 | $temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']); |
||
| 285 | $temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC")); |
||
| 286 | $temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC")); |
||
| 287 | $temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC"); |
||
| 288 | } |
||
| 289 | } |
||
| 290 | |||
| 291 | if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') { |
||
| 292 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 293 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 294 | if (isset($row['aircraft_shadow'])) { |
||
| 295 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
| 296 | } |
||
| 297 | } elseif (isset($row['aircraft_icao'])) { |
||
| 298 | $aircraft_array = $this->getAllAircraftInfo($row['aircraft_icao']); |
||
| 299 | if (count($aircraft_array) > 0) { |
||
| 300 | $temp_array['aircraft_name'] = $aircraft_array[0]['type']; |
||
| 301 | $temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer']; |
||
| 302 | |||
| 303 | if ($aircraft_array[0]['aircraft_shadow'] != NULL) { |
||
| 304 | $temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow']; |
||
| 305 | } else $temp_array['aircraft_shadow'] = 'default.png'; |
||
| 306 | } else { |
||
| 307 | $temp_array['aircraft_shadow'] = 'default.png'; |
||
| 308 | $temp_array['aircraft_name'] = 'N/A'; |
||
| 309 | $temp_array['aircraft_manufacturer'] = 'N/A'; |
||
| 310 | } |
||
| 311 | } |
||
| 312 | $fromsource = NULL; |
||
| 313 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
||
| 314 | elseif (isset($row['format_source']) && $row['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
||
| 315 | elseif (isset($row['format_source']) && $row['format_source'] == 'whazzup') $fromsource = 'ivao'; |
||
| 316 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
||
| 317 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
||
| 318 | if (!isset($row['airline_name']) || $row['airline_name'] == '') { |
||
| 319 | if (!is_numeric(substr($row['ident'], 0, 3))) { |
||
| 320 | if (is_numeric(substr($row['ident'], 2, 1))) { |
||
| 321 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 2),$fromsource); |
||
| 322 | } elseif (is_numeric(substr($row['ident'], 3, 1))) { |
||
| 323 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3),$fromsource); |
||
| 324 | } else { |
||
| 325 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 326 | } |
||
| 327 | } else { |
||
| 328 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 329 | } |
||
| 330 | if (count($airline_array) > 0) { |
||
| 331 | $temp_array['airline_icao'] = $airline_array[0]['icao']; |
||
| 332 | $temp_array['airline_iata'] = $airline_array[0]['iata']; |
||
| 333 | $temp_array['airline_name'] = $airline_array[0]['name']; |
||
| 334 | $temp_array['airline_country'] = $airline_array[0]['country']; |
||
| 335 | $temp_array['airline_callsign'] = $airline_array[0]['callsign']; |
||
| 336 | $temp_array['airline_type'] = $airline_array[0]['type']; |
||
| 337 | } |
||
| 338 | } else { |
||
| 339 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 340 | if (isset($row['airline_iata'])) $temp_array['airline_iata'] = $row['airline_iata']; |
||
| 341 | else $temp_array['airline_iata'] = 'N/A'; |
||
| 342 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 343 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 344 | if (isset($row['airline_callsign'])) $temp_array['airline_callsign'] = $row['airline_callsign']; |
||
| 345 | else $temp_array['airline_callsign'] = 'N/A'; |
||
| 346 | $temp_array['airline_type'] = $row['airline_type']; |
||
| 347 | if ($temp_array['airline_icao'] != '' && $temp_array['airline_iata'] == 'N/A') { |
||
| 348 | $airline_array = $this->getAllAirlineInfo($temp_array['airline_icao']); |
||
| 349 | if (count($airline_array) > 0) { |
||
| 350 | $temp_array['airline_icao'] = $airline_array[0]['icao']; |
||
| 351 | $temp_array['airline_iata'] = $airline_array[0]['iata']; |
||
| 352 | $temp_array['airline_name'] = $airline_array[0]['name']; |
||
| 353 | $temp_array['airline_country'] = $airline_array[0]['country']; |
||
| 354 | $temp_array['airline_callsign'] = $airline_array[0]['callsign']; |
||
| 355 | $temp_array['airline_type'] = $airline_array[0]['type']; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | if (isset($temp_array['airline_iata']) && $temp_array['airline_iata'] != '') { |
||
| 360 | $acars_array = $ACARS->getLiveAcarsData($temp_array['airline_iata'].substr($temp_array['ident'],3)); |
||
| 361 | //$acars_array = ACARS->getLiveAcarsData('BA40YL'); |
||
| 362 | if (count($acars_array) > 0) { |
||
| 363 | $temp_array['acars'] = $acars_array; |
||
| 364 | //print_r($acars_array); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | if (isset($row['owner_name']) && $row['owner_name'] != '' && $row['owner_name'] != NULL) { |
||
| 368 | $temp_array['aircraft_owner'] = $row['owner_name']; |
||
| 369 | } |
||
| 370 | if ($temp_array['registration'] != "" && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && !isset($temp_array['aircraft_owner'])) { |
||
| 371 | $owner_info = $this->getAircraftOwnerByRegistration($temp_array['registration']); |
||
| 372 | if ($owner_info['owner'] != '') $temp_array['aircraft_owner'] = ucwords(strtolower($owner_info['owner'])); |
||
| 373 | $temp_array['aircraft_base'] = $owner_info['base']; |
||
| 374 | $temp_array['aircraft_date_first_reg'] = $owner_info['date_first_reg']; |
||
| 375 | } |
||
| 376 | |||
| 377 | if($temp_array['registration'] != "" || ($globalIVAO && isset($temp_array['aircraft_type']) && $temp_array['aircraft_type'] != '')) |
||
| 378 | { |
||
| 379 | if ($globalIVAO) { |
||
| 380 | if (isset($temp_array['airline_icao'])) $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type'],$temp_array['airline_icao']); |
||
| 381 | else $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type']); |
||
| 382 | } else $image_array = $Image->getSpotterImage($temp_array['registration']); |
||
| 383 | if (count($image_array) > 0) { |
||
| 384 | $temp_array['image'] = $image_array[0]['image']; |
||
| 385 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 386 | $temp_array['image_source'] = $image_array[0]['image_source']; |
||
| 387 | $temp_array['image_source_website'] = $image_array[0]['image_source_website']; |
||
| 388 | if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') { |
||
| 389 | $planespotter_url_array = explode("_", $temp_array['image']); |
||
| 390 | $planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]); |
||
| 391 | $temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id; |
||
| 392 | } |
||
| 393 | $temp_array['image_copyright'] = $image_array[0]['image_copyright']; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | |||
| 398 | if (isset($row['departure_airport_time']) && $row['departure_airport_time'] != '') { |
||
| 399 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
| 400 | } |
||
| 401 | if (isset($row['arrival_airport_time']) && $row['arrival_airport_time'] != '') { |
||
| 402 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
| 403 | } |
||
| 404 | |||
| 405 | if ((!isset($globalIVAO) || ! $globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalVAM) || !$globalVAM)) { |
||
| 406 | if ($schedules === true) { |
||
| 407 | $schedule_array = $Schedule->getSchedule($temp_array['ident']); |
||
| 408 | //print_r($schedule_array); |
||
| 409 | if (count($schedule_array) > 0) { |
||
| 410 | if ($schedule_array['departure_airport_icao'] != '') { |
||
| 411 | $row['departure_airport_icao'] = $schedule_array['departure_airport_icao']; |
||
| 412 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
| 413 | } |
||
| 414 | if ($schedule_array['arrival_airport_icao'] != '') { |
||
| 415 | $row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao']; |
||
| 416 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
| 417 | } |
||
| 418 | $temp_array['departure_airport_time'] = $schedule_array['departure_airport_time']; |
||
| 419 | $temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time']; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | } else { |
||
| 423 | if (isset($row['real_departure_airport_time']) && $row['real_departure_airport_time'] != '') { |
||
| 424 | $temp_array['departure_airport_time'] = $row['real_departure_airport_time']; |
||
| 425 | } |
||
| 426 | if (isset($row['real_arrival_airport_time']) && $row['real_arrival_airport_time'] != '') { |
||
| 427 | $temp_array['real_arrival_airport_time'] = $row['real_arrival_airport_time']; |
||
| 428 | } |
||
| 429 | } |
||
| 430 | |||
| 431 | //if ($row['departure_airport_icao'] != '' && $row['departure_airport_name'] == '') { |
||
| 432 | if ($row['departure_airport_icao'] != '') { |
||
| 433 | $departure_airport_array = $this->getAllAirportInfo($row['departure_airport_icao']); |
||
| 434 | if (!isset($departure_airport_array[0]['name'])) $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 435 | /* |
||
| 436 | } elseif ($row['departure_airport_name'] != '') { |
||
| 437 | $temp_array['departure_airport_name'] = $row['departure_airport_name']; |
||
| 438 | $temp_array['departure_airport_city'] = $row['departure_airport_city']; |
||
| 439 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 440 | $temp_array['departure_airport_icao'] = $row['departure_airport_icao']; |
||
| 441 | */ |
||
| 442 | } else $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 443 | if (isset($departure_airport_array[0]['name'])) { |
||
| 444 | $temp_array['departure_airport_name'] = $departure_airport_array[0]['name']; |
||
| 445 | $temp_array['departure_airport_city'] = $departure_airport_array[0]['city']; |
||
| 446 | $temp_array['departure_airport_country'] = $departure_airport_array[0]['country']; |
||
| 447 | $temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata']; |
||
| 448 | $temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao']; |
||
| 449 | $temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude']; |
||
| 450 | $temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude']; |
||
| 451 | $temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude']; |
||
| 452 | } |
||
| 453 | |||
| 454 | /* |
||
| 455 | if (isset($row['departure_airport_time'])) { |
||
| 456 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
| 457 | } |
||
| 458 | */ |
||
| 459 | |||
| 460 | if ($row['arrival_airport_icao'] != '') { |
||
| 461 | $arrival_airport_array = $this->getAllAirportInfo($row['arrival_airport_icao']); |
||
| 462 | if (count($arrival_airport_array) == 0) $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 463 | } else $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 464 | if (isset($arrival_airport_array[0]['name'])) { |
||
| 465 | $temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name']; |
||
| 466 | $temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city']; |
||
| 467 | $temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country']; |
||
| 468 | $temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata']; |
||
| 469 | $temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao']; |
||
| 470 | $temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude']; |
||
| 471 | $temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude']; |
||
| 472 | $temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude']; |
||
| 473 | } |
||
| 474 | /* |
||
| 475 | if (isset($row['arrival_airport_time'])) { |
||
| 476 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
| 477 | } |
||
| 478 | */ |
||
| 479 | if (isset($row['pilot_id']) && $row['pilot_id'] != '') $temp_array['pilot_id'] = $row['pilot_id']; |
||
| 480 | if (isset($row['pilot_name']) && $row['pilot_name'] != '') $temp_array['pilot_name'] = $row['pilot_name']; |
||
| 481 | if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; |
||
| 482 | if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; |
||
| 483 | if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
||
| 484 | if (isset($row['squawk'])) { |
||
| 485 | $temp_array['squawk'] = $row['squawk']; |
||
| 486 | if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) { |
||
| 487 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['country_iso2']); |
||
| 488 | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
| 489 | } elseif ($row['squawk'] != '' && isset($temp_array['over_country'])) { |
||
| 490 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['over_country']); |
||
| 491 | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
| 492 | } elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
| 493 | } |
||
| 494 | |||
| 495 | $temp_array['query_number_rows'] = $num_rows; |
||
| 496 | |||
| 497 | $spotter_array[] = $temp_array; |
||
| 498 | } |
||
| 499 | if ($num_rows == 0) return array(); |
||
| 500 | $spotter_array[0]['query_number_rows'] = $num_rows; |
||
| 501 | return $spotter_array; |
||
| 502 | } |
||
| 503 | |||
| 504 | |||
| 505 | /** |
||
| 506 | * Gets all the spotter information |
||
| 507 | * |
||
| 508 | * @return Array the spotter information |
||
| 509 | * |
||
| 510 | */ |
||
| 511 | public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array()) |
||
| 512 | { |
||
| 513 | global $globalTimezone, $globalDBdriver; |
||
| 514 | require_once(dirname(__FILE__).'/class.Translation.php'); |
||
| 515 | $Translation = new Translation(); |
||
| 516 | |||
| 517 | date_default_timezone_set('UTC'); |
||
| 518 | |||
| 519 | $query_values = array(); |
||
| 520 | $additional_query = ''; |
||
| 521 | $filter_query = $this->getFilter($filters,true,true); |
||
| 522 | if ($q != "") |
||
| 523 | { |
||
| 524 | if (!is_string($q)) |
||
| 525 | { |
||
| 526 | return false; |
||
| 527 | } else { |
||
| 528 | $q_array = explode(" ", $q); |
||
| 529 | foreach ($q_array as $q_item){ |
||
| 530 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
| 531 | $additional_query .= " AND ("; |
||
| 532 | if (is_int($q_item)) $additional_query .= "(spotter_output.spotter_id like '%".$q_item."%') OR "; |
||
| 533 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
| 534 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
| 535 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
| 536 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
| 537 | $additional_query .= "(spotter_output.airline_name like '%".$q_item."%') OR "; |
||
| 538 | $additional_query .= "(spotter_output.airline_country like '%".$q_item."%') OR "; |
||
| 539 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
| 540 | $additional_query .= "(spotter_output.departure_airport_name like '%".$q_item."%') OR "; |
||
| 541 | $additional_query .= "(spotter_output.departure_airport_city like '%".$q_item."%') OR "; |
||
| 542 | $additional_query .= "(spotter_output.departure_airport_country like '%".$q_item."%') OR "; |
||
| 543 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
| 544 | $additional_query .= "(spotter_output.arrival_airport_name like '%".$q_item."%') OR "; |
||
| 545 | $additional_query .= "(spotter_output.arrival_airport_city like '%".$q_item."%') OR "; |
||
| 546 | $additional_query .= "(spotter_output.arrival_airport_country like '%".$q_item."%') OR "; |
||
| 547 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
| 548 | $additional_query .= "(spotter_output.owner_name like '%".$q_item."%') OR "; |
||
| 549 | $additional_query .= "(spotter_output.pilot_id like '%".$q_item."%') OR "; |
||
| 550 | $additional_query .= "(spotter_output.pilot_name like '%".$q_item."%') OR "; |
||
| 551 | $additional_query .= "(spotter_output.ident like '%".$q_item."%') OR "; |
||
| 552 | $translate = $Translation->ident2icao($q_item); |
||
| 553 | if ($translate != $q_item) $additional_query .= "(spotter_output.ident like '%".$translate."%') OR "; |
||
| 554 | $additional_query .= "(spotter_output.highlight like '%".$q_item."%')"; |
||
| 555 | $additional_query .= ")"; |
||
| 556 | } |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | if ($registration != "") |
||
| 561 | { |
||
| 562 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 563 | if (!is_string($registration)) |
||
| 564 | { |
||
| 565 | return false; |
||
| 566 | } else { |
||
| 567 | $additional_query .= " AND spotter_output.registration = :registration"; |
||
| 568 | $query_values = array_merge($query_values,array(':registration' => $registration)); |
||
| 569 | } |
||
| 570 | } |
||
| 571 | |||
| 572 | if ($aircraft_icao != "") |
||
| 573 | { |
||
| 574 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 575 | if (!is_string($aircraft_icao)) |
||
| 576 | { |
||
| 577 | return false; |
||
| 578 | } else { |
||
| 579 | $additional_query .= " AND spotter_output.aircraft_icao = :aircraft_icao"; |
||
| 580 | $query_values = array_merge($query_values,array(':aircraft_icao' => $aircraft_icao)); |
||
| 581 | } |
||
| 582 | } |
||
| 583 | |||
| 584 | if ($aircraft_manufacturer != "") |
||
| 585 | { |
||
| 586 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 587 | if (!is_string($aircraft_manufacturer)) |
||
| 588 | { |
||
| 589 | return false; |
||
| 590 | } else { |
||
| 591 | $additional_query .= " AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer"; |
||
| 592 | $query_values = array_merge($query_values,array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 593 | } |
||
| 594 | } |
||
| 595 | |||
| 596 | if ($highlights == "true") |
||
| 597 | { |
||
| 598 | if (!is_string($highlights)) |
||
| 599 | { |
||
| 600 | return false; |
||
| 601 | } else { |
||
| 602 | $additional_query .= " AND (spotter_output.highlight <> '')"; |
||
| 603 | } |
||
| 604 | } |
||
| 605 | |||
| 606 | if ($airline_icao != "") |
||
| 607 | { |
||
| 608 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 609 | if (!is_string($airline_icao)) |
||
| 610 | { |
||
| 611 | return false; |
||
| 612 | } else { |
||
| 613 | $additional_query .= " AND spotter_output.airline_icao = :airline_icao"; |
||
| 614 | $query_values = array_merge($query_values,array(':airline_icao' => $airline_icao)); |
||
| 615 | } |
||
| 616 | } |
||
| 617 | |||
| 618 | if ($airline_country != "") |
||
| 619 | { |
||
| 620 | $airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING); |
||
| 621 | if (!is_string($airline_country)) |
||
| 622 | { |
||
| 623 | return false; |
||
| 624 | } else { |
||
| 625 | $additional_query .= " AND spotter_output.airline_country = :airline_country"; |
||
| 626 | $query_values = array_merge($query_values,array(':airline_country' => $airline_country)); |
||
| 627 | } |
||
| 628 | } |
||
| 629 | |||
| 630 | if ($airline_type != "") |
||
| 631 | { |
||
| 632 | if (!is_string($airline_type)) |
||
| 633 | { |
||
| 634 | return false; |
||
| 635 | } else { |
||
| 636 | if ($airline_type == "passenger") |
||
| 637 | { |
||
| 638 | $additional_query .= " AND (spotter_output.airline_type = 'passenger')"; |
||
| 639 | } |
||
| 640 | if ($airline_type == "cargo") |
||
| 641 | { |
||
| 642 | $additional_query .= " AND (spotter_output.airline_type = 'cargo')"; |
||
| 643 | } |
||
| 644 | if ($airline_type == "military") |
||
| 645 | { |
||
| 646 | $additional_query .= " AND (spotter_output.airline_type = 'military')"; |
||
| 647 | } |
||
| 648 | } |
||
| 649 | } |
||
| 650 | |||
| 651 | if ($airport != "") |
||
| 652 | { |
||
| 653 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
| 654 | if (!is_string($airport)) |
||
| 655 | { |
||
| 656 | return false; |
||
| 657 | } else { |
||
| 658 | $additional_query .= " AND (spotter_output.departure_airport_icao = :airport OR spotter_output.arrival_airport_icao = :airport)"; |
||
| 659 | $query_values = array_merge($query_values,array(':airport' => $airport)); |
||
| 660 | } |
||
| 661 | } |
||
| 662 | |||
| 663 | if ($airport_country != "") |
||
| 664 | { |
||
| 665 | $airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING); |
||
| 666 | if (!is_string($airport_country)) |
||
| 667 | { |
||
| 668 | return false; |
||
| 669 | } else { |
||
| 670 | $additional_query .= " AND (spotter_output.departure_airport_country = :airport_country OR spotter_output.arrival_airport_country = :airport_country)"; |
||
| 671 | $query_values = array_merge($query_values,array(':airport_country' => $airport_country)); |
||
| 672 | } |
||
| 673 | } |
||
| 674 | |||
| 675 | if ($callsign != "") |
||
| 676 | { |
||
| 677 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
| 678 | if (!is_string($callsign)) |
||
| 679 | { |
||
| 680 | return false; |
||
| 681 | } else { |
||
| 682 | $translate = $Translation->ident2icao($callsign); |
||
| 683 | if ($translate != $callsign) { |
||
| 684 | $additional_query .= " AND (spotter_output.ident = :callsign OR spotter_output.ident = :translate)"; |
||
| 685 | $query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate)); |
||
| 686 | } else { |
||
| 687 | $additional_query .= " AND spotter_output.ident = :callsign"; |
||
| 688 | $query_values = array_merge($query_values,array(':callsign' => $callsign)); |
||
| 689 | } |
||
| 690 | } |
||
| 691 | } |
||
| 692 | |||
| 693 | if ($owner != "") |
||
| 694 | { |
||
| 695 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 696 | if (!is_string($owner)) |
||
| 697 | { |
||
| 698 | return false; |
||
| 699 | } else { |
||
| 700 | $additional_query .= " AND spotter_output.owner_name = :owner"; |
||
| 701 | $query_values = array_merge($query_values,array(':owner' => $owner)); |
||
| 702 | } |
||
| 703 | } |
||
| 704 | |||
| 705 | if ($pilot_name != "") |
||
| 706 | { |
||
| 707 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
| 708 | if (!is_string($pilot_name)) |
||
| 709 | { |
||
| 710 | return false; |
||
| 711 | } else { |
||
| 712 | $additional_query .= " AND spotter_output.pilot_name = :pilot_name"; |
||
| 713 | $query_values = array_merge($query_values,array(':pilot_name' => $pilot_name)); |
||
| 714 | } |
||
| 715 | } |
||
| 716 | |||
| 717 | if ($pilot_id != "") |
||
| 718 | { |
||
| 719 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT); |
||
| 720 | if (!is_string($pilot_id)) |
||
| 721 | { |
||
| 722 | return false; |
||
| 723 | } else { |
||
| 724 | $additional_query .= " AND spotter_output.pilot_id = :pilot_id"; |
||
| 725 | $query_values = array_merge($query_values,array(':pilot_id' => $pilot_id)); |
||
| 726 | } |
||
| 727 | } |
||
| 728 | |||
| 729 | if ($departure_airport_route != "") |
||
| 730 | { |
||
| 731 | $departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING); |
||
| 732 | if (!is_string($departure_airport_route)) |
||
| 733 | { |
||
| 734 | return false; |
||
| 735 | } else { |
||
| 736 | $additional_query .= " AND spotter_output.departure_airport_icao = :departure_airport_route"; |
||
| 737 | $query_values = array_merge($query_values,array(':departure_airport_route' => $departure_airport_route)); |
||
| 738 | } |
||
| 739 | } |
||
| 740 | |||
| 741 | if ($arrival_airport_route != "") |
||
| 742 | { |
||
| 743 | $arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING); |
||
| 744 | if (!is_string($arrival_airport_route)) |
||
| 745 | { |
||
| 746 | return false; |
||
| 747 | } else { |
||
| 748 | $additional_query .= " AND spotter_output.arrival_airport_icao = :arrival_airport_route"; |
||
| 749 | $query_values = array_merge($query_values,array(':arrival_airport_route' => $arrival_airport_route)); |
||
| 750 | } |
||
| 751 | } |
||
| 752 | |||
| 753 | if ($altitude != "") |
||
| 754 | { |
||
| 755 | $altitude_array = explode(",", $altitude); |
||
| 756 | $altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 757 | $altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 758 | |||
| 759 | if ($altitude_array[1] != "") |
||
| 760 | { |
||
| 761 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
| 762 | $altitude_array[1] = substr($altitude_array[1], 0, -2); |
||
| 763 | $additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' "; |
||
| 764 | } else { |
||
| 765 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
| 766 | $additional_query .= " AND altitude <= '".$altitude_array[0]."' "; |
||
| 767 | } |
||
| 768 | } |
||
| 769 | |||
| 770 | if ($date_posted != "") |
||
| 771 | { |
||
| 772 | $date_array = explode(",", $date_posted); |
||
| 773 | $date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); |
||
| 774 | $date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); |
||
| 775 | |||
| 776 | if ($globalTimezone != '') { |
||
| 777 | date_default_timezone_set($globalTimezone); |
||
| 778 | $datetime = new DateTime(); |
||
| 779 | $offset = $datetime->format('P'); |
||
| 780 | } else $offset = '+00:00'; |
||
| 781 | |||
| 782 | if ($date_array[1] != "") |
||
| 783 | { |
||
| 784 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
| 785 | $date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
||
| 786 | if ($globalDBdriver == 'mysql') { |
||
| 787 | $additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' "; |
||
| 788 | } else { |
||
| 789 | $additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) <= '".$date_array[1]."' "; |
||
| 790 | } |
||
| 791 | } else { |
||
| 792 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
| 793 | if ($globalDBdriver == 'mysql') { |
||
| 794 | $additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; |
||
| 795 | } else { |
||
| 796 | $additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' "; |
||
| 797 | } |
||
| 798 | } |
||
| 799 | } |
||
| 800 | |||
| 801 | if ($limit != "") |
||
| 802 | { |
||
| 803 | $limit_array = explode(",", $limit); |
||
| 804 | |||
| 805 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 806 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 807 | |||
| 808 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 809 | { |
||
| 810 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 811 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 812 | } else $limit_query = ""; |
||
| 813 | } else $limit_query = ""; |
||
| 814 | |||
| 815 | |||
| 816 | if ($sort != "") |
||
| 817 | { |
||
| 818 | $search_orderby_array = $this->getOrderBy(); |
||
| 819 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 820 | } else { |
||
| 821 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
| 822 | $orderby_query = " ORDER BY distance ASC"; |
||
| 823 | } else { |
||
| 824 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 825 | } |
||
| 826 | } |
||
| 827 | |||
| 828 | if ($includegeodata == "true") |
||
| 829 | { |
||
| 830 | $additional_query .= " AND spotter_output.waypoints <> ''"; |
||
| 831 | } |
||
| 832 | |||
| 833 | |||
| 834 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
| 835 | $dist = number_format($dist*0.621371,2,'.',''); // convert km to mile |
||
| 836 | |||
| 837 | if ($globalDBdriver == 'mysql') { |
||
| 838 | $query="SELECT spotter_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - spotter_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(spotter_archive.latitude*pi()/180)*POWER(SIN(($origLon-spotter_archive.longitude)*pi()/180/2),2))) as distance |
||
| 839 | FROM spotter_archive,spotter_output".$filter_query." spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND spotter_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and spotter_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
| 840 | AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - spotter_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(spotter_archive.latitude*pi()/180)*POWER(SIN(($origLon-spotter_archive.longitude)*pi()/180/2),2)))) < $dist".$orderby_query; |
||
| 841 | } else { |
||
| 842 | $query="SELECT spotter_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(spotter_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(spotter_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2))) as distance |
||
| 843 | FROM spotter_archive,spotter_output".$filter_query." spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
| 844 | AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(spotter_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(spotter_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query.$orderby_query; |
||
| 845 | } |
||
| 846 | } else { |
||
| 847 | $query = "SELECT spotter_output.* FROM spotter_output".$filter_query." spotter_output.ident <> '' |
||
| 848 | ".$additional_query." |
||
| 849 | ".$orderby_query; |
||
| 850 | } |
||
| 851 | $spotter_array = $this->getDataFromDB($query, $query_values,$limit_query); |
||
| 852 | return $spotter_array; |
||
| 853 | } |
||
| 854 | |||
| 855 | |||
| 856 | /** |
||
| 857 | * Gets all the spotter information based on the latest data entry |
||
| 858 | * |
||
| 859 | * @return Array the spotter information |
||
| 860 | * |
||
| 861 | */ |
||
| 862 | public function getLatestSpotterData($limit = '', $sort = '', $filter = array()) |
||
| 863 | { |
||
| 864 | global $global_query; |
||
| 865 | |||
| 866 | date_default_timezone_set('UTC'); |
||
| 867 | |||
| 868 | $filter_query = $this->getFilter($filter); |
||
| 869 | |||
| 870 | if ($limit != "") |
||
| 871 | { |
||
| 872 | $limit_array = explode(",", $limit); |
||
| 873 | |||
| 874 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 875 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 876 | |||
| 877 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 878 | { |
||
| 879 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 880 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 881 | } else $limit_query = ""; |
||
| 882 | } else $limit_query = ""; |
||
| 883 | |||
| 884 | if ($sort != "") |
||
| 885 | { |
||
| 886 | $search_orderby_array = $this->getOrderBy(); |
||
| 887 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 888 | } else { |
||
| 889 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 890 | } |
||
| 891 | |||
| 892 | $query = $global_query.$filter_query." ".$orderby_query; |
||
| 893 | |||
| 894 | $spotter_array = $this->getDataFromDB($query, array(),$limit_query,true); |
||
| 895 | |||
| 896 | return $spotter_array; |
||
| 897 | } |
||
| 898 | |||
| 899 | |||
| 900 | /** |
||
| 901 | * Gets all the spotter information based on a user's latitude and longitude |
||
| 902 | * |
||
| 903 | * @return Array the spotter information |
||
| 904 | * |
||
| 905 | */ |
||
| 906 | public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
||
| 907 | { |
||
| 908 | date_default_timezone_set('UTC'); |
||
| 909 | $limit_query = ''; |
||
| 910 | if ($lat != "") |
||
| 911 | { |
||
| 912 | if (!is_numeric($lat)) |
||
| 913 | { |
||
| 914 | return false; |
||
| 915 | } |
||
| 916 | } |
||
| 917 | |||
| 918 | if ($lng != "") |
||
| 919 | { |
||
| 920 | if (!is_numeric($lng)) |
||
| 921 | { |
||
| 922 | return false; |
||
| 923 | } |
||
| 924 | } |
||
| 925 | |||
| 926 | if ($radius != "") |
||
| 927 | { |
||
| 928 | if (!is_numeric($radius)) |
||
| 929 | { |
||
| 930 | return false; |
||
| 931 | } |
||
| 932 | } |
||
| 933 | $additional_query = ''; |
||
| 934 | if ($interval != "") |
||
| 935 | { |
||
| 936 | if (!is_string($interval)) |
||
| 937 | { |
||
| 938 | return false; |
||
| 939 | } else { |
||
| 940 | if ($interval == "30m"){ |
||
| 941 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) <= $this_output.date '; |
||
| 942 | } else if ($interval == "1h"){ |
||
| 943 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) <= $this_output.date '; |
||
| 944 | } else if ($interval == "3h"){ |
||
| 945 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 3 HOUR) <= $this_output.date '; |
||
| 946 | } else if ($interval == "6h"){ |
||
| 947 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 6 HOUR) <= $this_output.date '; |
||
| 948 | } else if ($interval == "12h"){ |
||
| 949 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 HOUR) <= $this_output.date '; |
||
| 950 | } else if ($interval == "24h"){ |
||
| 951 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) <= $this_output.date '; |
||
| 952 | } else if ($interval == "7d"){ |
||
| 953 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) <= $this_output.date '; |
||
| 954 | } else if ($interval == "30d"){ |
||
| 955 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 DAY) <= $this_output.date '; |
||
| 956 | } |
||
| 957 | } |
||
| 958 | } |
||
| 959 | |||
| 960 | $query = "SELECT spotter_output.*, ( 6371 * acos( cos( radians($lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_output |
||
| 961 | WHERE spotter_output.latitude <> '' |
||
| 962 | AND spotter_output.longitude <> '' |
||
| 963 | ".$additional_query." |
||
| 964 | HAVING distance < :radius |
||
| 965 | ORDER BY distance"; |
||
| 966 | |||
| 967 | $spotter_array = $this->getDataFromDB($query, array(':radius' => $radius),$limit_query); |
||
| 968 | |||
| 969 | return $spotter_array; |
||
| 970 | } |
||
| 971 | |||
| 972 | |||
| 973 | /** |
||
| 974 | * Gets all the spotter information sorted by the newest aircraft type |
||
| 975 | * |
||
| 976 | * @return Array the spotter information |
||
| 977 | * |
||
| 978 | */ |
||
| 979 | public function getNewestSpotterDataSortedByAircraftType($limit = '', $sort = '',$filter = array()) |
||
| 980 | { |
||
| 981 | global $global_query; |
||
| 982 | |||
| 983 | date_default_timezone_set('UTC'); |
||
| 984 | |||
| 985 | $filter_query = $this->getFilter($filter,true,true); |
||
| 986 | |||
| 987 | $limit_query = ''; |
||
| 988 | if ($limit != "") |
||
| 989 | { |
||
| 990 | $limit_array = explode(",", $limit); |
||
| 991 | |||
| 992 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 993 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 994 | |||
| 995 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 996 | { |
||
| 997 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 998 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 999 | } |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | if ($sort != "") |
||
| 1003 | { |
||
| 1004 | $search_orderby_array = $this->getOrderBy(); |
||
| 1005 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1006 | } else { |
||
| 1007 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | $query = $global_query." ".$filter_query." spotter_output.aircraft_name <> '' GROUP BY spotter_output.aircraft_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
| 1011 | |||
| 1012 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1013 | |||
| 1014 | return $spotter_array; |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Gets all the spotter information sorted by the newest aircraft registration |
||
| 1020 | * |
||
| 1021 | * @return Array the spotter information |
||
| 1022 | * |
||
| 1023 | */ |
||
| 1024 | public function getNewestSpotterDataSortedByAircraftRegistration($limit = '', $sort = '', $filter = array()) |
||
| 1025 | { |
||
| 1026 | global $global_query; |
||
| 1027 | |||
| 1028 | date_default_timezone_set('UTC'); |
||
| 1029 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1030 | |||
| 1031 | $limit_query = ''; |
||
| 1032 | if ($limit != "") |
||
| 1033 | { |
||
| 1034 | $limit_array = explode(",", $limit); |
||
| 1035 | |||
| 1036 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1037 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1038 | |||
| 1039 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1040 | { |
||
| 1041 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1042 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1043 | } |
||
| 1044 | } |
||
| 1045 | |||
| 1046 | if ($sort != "") |
||
| 1047 | { |
||
| 1048 | $search_orderby_array = $this->getOrderBy(); |
||
| 1049 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1050 | } else { |
||
| 1051 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1052 | } |
||
| 1053 | |||
| 1054 | $query = $global_query." ".$filter_query." spotter_output.registration <> '' GROUP BY spotter_output.registration,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
| 1055 | |||
| 1056 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1057 | |||
| 1058 | return $spotter_array; |
||
| 1059 | } |
||
| 1060 | |||
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Gets all the spotter information sorted by the newest airline |
||
| 1064 | * |
||
| 1065 | * @return Array the spotter information |
||
| 1066 | * |
||
| 1067 | */ |
||
| 1068 | public function getNewestSpotterDataSortedByAirline($limit = '', $sort = '',$filter = array()) |
||
| 1069 | { |
||
| 1070 | global $global_query; |
||
| 1071 | |||
| 1072 | date_default_timezone_set('UTC'); |
||
| 1073 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1074 | |||
| 1075 | $limit_query = ''; |
||
| 1076 | if ($limit != "") |
||
| 1077 | { |
||
| 1078 | $limit_array = explode(",", $limit); |
||
| 1079 | |||
| 1080 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1081 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1082 | |||
| 1083 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1084 | { |
||
| 1085 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1086 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1087 | } |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | if ($sort != "") |
||
| 1091 | { |
||
| 1092 | $search_orderby_array = $this->getOrderBy(); |
||
| 1093 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1094 | } else { |
||
| 1095 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1096 | } |
||
| 1097 | |||
| 1098 | $query = $global_query." ".$filter_query." spotter_output.airline_name <> '' GROUP BY spotter_output.airline_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
| 1099 | |||
| 1100 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1101 | |||
| 1102 | return $spotter_array; |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Gets all the spotter information sorted by the newest departure airport |
||
| 1108 | * |
||
| 1109 | * @return Array the spotter information |
||
| 1110 | * |
||
| 1111 | */ |
||
| 1112 | public function getNewestSpotterDataSortedByDepartureAirport($limit = '', $sort = '', $filter = array()) |
||
| 1113 | { |
||
| 1114 | global $global_query; |
||
| 1115 | |||
| 1116 | date_default_timezone_set('UTC'); |
||
| 1117 | |||
| 1118 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1119 | |||
| 1120 | $limit_query = ''; |
||
| 1121 | |||
| 1122 | if ($limit != "") |
||
| 1123 | { |
||
| 1124 | $limit_array = explode(",", $limit); |
||
| 1125 | |||
| 1126 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1127 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1128 | |||
| 1129 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1130 | { |
||
| 1131 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1132 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1133 | } |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | if ($sort != "") |
||
| 1137 | { |
||
| 1138 | $search_orderby_array = $this->getOrderBy(); |
||
| 1139 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1140 | } else { |
||
| 1141 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1142 | } |
||
| 1143 | |||
| 1144 | $query = $global_query." ".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' GROUP BY spotter_output.departure_airport_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
| 1145 | |||
| 1146 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1147 | |||
| 1148 | return $spotter_array; |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Gets all the spotter information sorted by the newest arrival airport |
||
| 1154 | * |
||
| 1155 | * @return Array the spotter information |
||
| 1156 | * |
||
| 1157 | */ |
||
| 1158 | public function getNewestSpotterDataSortedByArrivalAirport($limit = '', $sort = '', $filter = array()) |
||
| 1159 | { |
||
| 1160 | global $global_query; |
||
| 1161 | |||
| 1162 | date_default_timezone_set('UTC'); |
||
| 1163 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1164 | $limit_query = ''; |
||
| 1165 | if ($limit != "") |
||
| 1166 | { |
||
| 1167 | $limit_array = explode(",", $limit); |
||
| 1168 | |||
| 1169 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1170 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1171 | |||
| 1172 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1173 | { |
||
| 1174 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1175 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1176 | } |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | if ($sort != "") |
||
| 1180 | { |
||
| 1181 | $search_orderby_array = $this->getOrderBy(); |
||
| 1182 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1183 | } else { |
||
| 1184 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | $query = $global_query.$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' GROUP BY spotter_output.arrival_airport_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
| 1188 | |||
| 1189 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1190 | |||
| 1191 | return $spotter_array; |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * Gets all the spotter information based on the spotter id |
||
| 1197 | * |
||
| 1198 | * @return Array the spotter information |
||
| 1199 | * |
||
| 1200 | */ |
||
| 1201 | public function getSpotterDataByID($id = '') |
||
| 1202 | { |
||
| 1203 | global $global_query; |
||
| 1204 | |||
| 1205 | date_default_timezone_set('UTC'); |
||
| 1206 | if ($id == '') return array(); |
||
| 1207 | $additional_query = "spotter_output.spotter_id = :id"; |
||
| 1208 | $query_values = array(':id' => $id); |
||
| 1209 | |||
| 1210 | //$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." "; |
||
| 1211 | $query = $global_query." WHERE ".$additional_query." "; |
||
| 1212 | |||
| 1213 | $spotter_array = $this->getDataFromDB($query,$query_values); |
||
| 1214 | |||
| 1215 | return $spotter_array; |
||
| 1216 | } |
||
| 1217 | |||
| 1218 | |||
| 1219 | |||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Gets all the spotter information based on the callsign |
||
| 1223 | * |
||
| 1224 | * @return Array the spotter information |
||
| 1225 | * |
||
| 1226 | */ |
||
| 1227 | public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') |
||
| 1228 | { |
||
| 1229 | global $global_query; |
||
| 1230 | |||
| 1231 | date_default_timezone_set('UTC'); |
||
| 1232 | |||
| 1233 | $query_values = array(); |
||
| 1234 | $limit_query = ''; |
||
| 1235 | $additional_query = ''; |
||
| 1236 | if ($ident != "") |
||
| 1237 | { |
||
| 1238 | if (!is_string($ident)) |
||
| 1239 | { |
||
| 1240 | return false; |
||
| 1241 | } else { |
||
| 1242 | $additional_query = " AND (spotter_output.ident = :ident)"; |
||
| 1243 | $query_values = array(':ident' => $ident); |
||
| 1244 | } |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | if ($limit != "") |
||
| 1248 | { |
||
| 1249 | $limit_array = explode(",", $limit); |
||
| 1250 | |||
| 1251 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1252 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1253 | |||
| 1254 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1255 | { |
||
| 1256 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1257 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1258 | } |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | if ($sort != "") |
||
| 1262 | { |
||
| 1263 | $search_orderby_array = $this->getOrderBy(); |
||
| 1264 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1265 | } else { |
||
| 1266 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1267 | } |
||
| 1268 | |||
| 1269 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1270 | |||
| 1271 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1272 | |||
| 1273 | return $spotter_array; |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Gets all the spotter information based on the owner |
||
| 1278 | * |
||
| 1279 | * @return Array the spotter information |
||
| 1280 | * |
||
| 1281 | */ |
||
| 1282 | public function getSpotterDataByOwner($owner = '', $limit = '', $sort = '') |
||
| 1283 | { |
||
| 1284 | global $global_query; |
||
| 1285 | |||
| 1286 | date_default_timezone_set('UTC'); |
||
| 1287 | |||
| 1288 | $query_values = array(); |
||
| 1289 | $limit_query = ''; |
||
| 1290 | $additional_query = ''; |
||
| 1291 | if ($owner != "") |
||
| 1292 | { |
||
| 1293 | if (!is_string($owner)) |
||
| 1294 | { |
||
| 1295 | return false; |
||
| 1296 | } else { |
||
| 1297 | $additional_query = " AND (spotter_output.owner_name = :owner)"; |
||
| 1298 | $query_values = array(':owner' => $owner); |
||
| 1299 | } |
||
| 1300 | } |
||
| 1301 | |||
| 1302 | if ($limit != "") |
||
| 1303 | { |
||
| 1304 | $limit_array = explode(",", $limit); |
||
| 1305 | |||
| 1306 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1307 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1308 | |||
| 1309 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1310 | { |
||
| 1311 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1312 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1313 | } |
||
| 1314 | } |
||
| 1315 | |||
| 1316 | if ($sort != "") |
||
| 1317 | { |
||
| 1318 | $search_orderby_array = $this->getOrderBy(); |
||
| 1319 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1320 | } else { |
||
| 1321 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1322 | } |
||
| 1323 | |||
| 1324 | $query = $global_query." WHERE spotter_output.owner_name <> '' ".$additional_query." ".$orderby_query; |
||
| 1325 | |||
| 1326 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1327 | |||
| 1328 | return $spotter_array; |
||
| 1329 | } |
||
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Gets all the spotter information based on the pilot |
||
| 1333 | * |
||
| 1334 | * @return Array the spotter information |
||
| 1335 | * |
||
| 1336 | */ |
||
| 1337 | public function getSpotterDataByPilot($pilot = '', $limit = '', $sort = '') |
||
| 1338 | { |
||
| 1339 | global $global_query; |
||
| 1340 | |||
| 1341 | date_default_timezone_set('UTC'); |
||
| 1342 | |||
| 1343 | $query_values = array(); |
||
| 1344 | $limit_query = ''; |
||
| 1345 | $additional_query = ''; |
||
| 1346 | if ($pilot != "") |
||
| 1347 | { |
||
| 1348 | $additional_query = " AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot)"; |
||
| 1349 | $query_values = array(':pilot' => $pilot); |
||
| 1350 | } |
||
| 1351 | |||
| 1352 | if ($limit != "") |
||
| 1353 | { |
||
| 1354 | $limit_array = explode(",", $limit); |
||
| 1355 | |||
| 1356 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1357 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1358 | |||
| 1359 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1360 | { |
||
| 1361 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1362 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1363 | } |
||
| 1364 | } |
||
| 1365 | |||
| 1366 | if ($sort != "") |
||
| 1367 | { |
||
| 1368 | $search_orderby_array = $this->getOrderBy(); |
||
| 1369 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1370 | } else { |
||
| 1371 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1372 | } |
||
| 1373 | |||
| 1374 | $query = $global_query." WHERE spotter_output.pilot_name <> '' ".$additional_query." ".$orderby_query; |
||
| 1375 | |||
| 1376 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1377 | |||
| 1378 | return $spotter_array; |
||
| 1379 | } |
||
| 1380 | |||
| 1381 | |||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Gets all the spotter information based on the aircraft type |
||
| 1385 | * |
||
| 1386 | * @return Array the spotter information |
||
| 1387 | * |
||
| 1388 | */ |
||
| 1389 | public function getSpotterDataByAircraft($aircraft_type = '', $limit = '', $sort = '', $filter = array()) |
||
| 1390 | { |
||
| 1391 | global $global_query; |
||
| 1392 | |||
| 1393 | date_default_timezone_set('UTC'); |
||
| 1394 | |||
| 1395 | $query_values = array(); |
||
| 1396 | $limit_query = ''; |
||
| 1397 | $additional_query = ''; |
||
| 1398 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1399 | |||
| 1400 | if ($aircraft_type != "") |
||
| 1401 | { |
||
| 1402 | if (!is_string($aircraft_type)) |
||
| 1403 | { |
||
| 1404 | return false; |
||
| 1405 | } else { |
||
| 1406 | $additional_query = " AND (spotter_output.aircraft_icao = :aircraft_type)"; |
||
| 1407 | $query_values = array(':aircraft_type' => $aircraft_type); |
||
| 1408 | } |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | if ($limit != "") |
||
| 1412 | { |
||
| 1413 | $limit_array = explode(",", $limit); |
||
| 1414 | |||
| 1415 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1416 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1417 | |||
| 1418 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1419 | { |
||
| 1420 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1421 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1422 | } |
||
| 1423 | } |
||
| 1424 | |||
| 1425 | if ($sort != "") |
||
| 1426 | { |
||
| 1427 | $search_orderby_array = $this->getOrderBy(); |
||
| 1428 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1429 | } else { |
||
| 1430 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1431 | } |
||
| 1432 | |||
| 1433 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1434 | |||
| 1435 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1436 | |||
| 1437 | return $spotter_array; |
||
| 1438 | } |
||
| 1439 | |||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Gets all the spotter information based on the aircraft registration |
||
| 1443 | * |
||
| 1444 | * @return Array the spotter information |
||
| 1445 | * |
||
| 1446 | */ |
||
| 1447 | public function getSpotterDataByRegistration($registration = '', $limit = '', $sort = '', $filter = array()) |
||
| 1448 | { |
||
| 1449 | global $global_query; |
||
| 1450 | |||
| 1451 | date_default_timezone_set('UTC'); |
||
| 1452 | |||
| 1453 | $query_values = array(); |
||
| 1454 | $limit_query = ''; |
||
| 1455 | $additional_query = ''; |
||
| 1456 | |||
| 1457 | if ($registration != "") |
||
| 1458 | { |
||
| 1459 | if (!is_string($registration)) |
||
| 1460 | { |
||
| 1461 | return false; |
||
| 1462 | } else { |
||
| 1463 | $additional_query = " (spotter_output.registration = :registration)"; |
||
| 1464 | $query_values = array(':registration' => $registration); |
||
| 1465 | } |
||
| 1466 | } |
||
| 1467 | |||
| 1468 | if ($limit != "") |
||
| 1469 | { |
||
| 1470 | $limit_array = explode(",", $limit); |
||
| 1471 | |||
| 1472 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1473 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1474 | |||
| 1475 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1476 | { |
||
| 1477 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1478 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1479 | } |
||
| 1480 | } |
||
| 1481 | |||
| 1482 | if ($sort != "") |
||
| 1483 | { |
||
| 1484 | $search_orderby_array = $this->getOrderBy(); |
||
| 1485 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1486 | } else { |
||
| 1487 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1488 | } |
||
| 1489 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1490 | |||
| 1491 | //$query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1492 | $query = $global_query.$filter_query." ".$additional_query." ".$orderby_query; |
||
| 1493 | |||
| 1494 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1495 | |||
| 1496 | return $spotter_array; |
||
| 1497 | } |
||
| 1498 | |||
| 1499 | |||
| 1500 | |||
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Gets all the spotter information based on the airline |
||
| 1504 | * |
||
| 1505 | * @return Array the spotter information |
||
| 1506 | * |
||
| 1507 | */ |
||
| 1508 | public function getSpotterDataByAirline($airline = '', $limit = '', $sort = '',$filters = array()) |
||
| 1509 | { |
||
| 1510 | global $global_query; |
||
| 1511 | |||
| 1512 | date_default_timezone_set('UTC'); |
||
| 1513 | |||
| 1514 | $query_values = array(); |
||
| 1515 | $limit_query = ''; |
||
| 1516 | $additional_query = ''; |
||
| 1517 | $filter_query = $this->getFilter($filters,true,true); |
||
| 1518 | |||
| 1519 | if ($airline != "") |
||
| 1520 | { |
||
| 1521 | if (!is_string($airline)) |
||
| 1522 | { |
||
| 1523 | return false; |
||
| 1524 | } else { |
||
| 1525 | $additional_query = " AND (spotter_output.airline_icao = :airline)"; |
||
| 1526 | $query_values = array(':airline' => $airline); |
||
| 1527 | } |
||
| 1528 | } |
||
| 1529 | |||
| 1530 | if ($limit != "") |
||
| 1531 | { |
||
| 1532 | $limit_array = explode(",", $limit); |
||
| 1533 | |||
| 1534 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1535 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1536 | |||
| 1537 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1538 | { |
||
| 1539 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1540 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1541 | } |
||
| 1542 | } |
||
| 1543 | |||
| 1544 | if ($sort != "") |
||
| 1545 | { |
||
| 1546 | $search_orderby_array = $this->getOrderBy(); |
||
| 1547 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1548 | } else { |
||
| 1549 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1553 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1554 | |||
| 1555 | return $spotter_array; |
||
| 1556 | } |
||
| 1557 | |||
| 1558 | |||
| 1559 | /** |
||
| 1560 | * Gets all the spotter information based on the airport |
||
| 1561 | * |
||
| 1562 | * @return Array the spotter information |
||
| 1563 | * |
||
| 1564 | */ |
||
| 1565 | public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) |
||
| 1566 | { |
||
| 1567 | global $global_query; |
||
| 1568 | |||
| 1569 | date_default_timezone_set('UTC'); |
||
| 1570 | $query_values = array(); |
||
| 1571 | $limit_query = ''; |
||
| 1572 | $additional_query = ''; |
||
| 1573 | $filter_query = $this->getFilter($filters,true,true); |
||
| 1574 | |||
| 1575 | if ($airport != "") |
||
| 1576 | { |
||
| 1577 | if (!is_string($airport)) |
||
| 1578 | { |
||
| 1579 | return false; |
||
| 1580 | } else { |
||
| 1581 | $additional_query .= " AND ((spotter_output.departure_airport_icao = :airport) OR (spotter_output.arrival_airport_icao = :airport))"; |
||
| 1582 | $query_values = array(':airport' => $airport); |
||
| 1583 | } |
||
| 1584 | } |
||
| 1585 | |||
| 1586 | if ($limit != "") |
||
| 1587 | { |
||
| 1588 | $limit_array = explode(",", $limit); |
||
| 1589 | |||
| 1590 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1591 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1592 | |||
| 1593 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1594 | { |
||
| 1595 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1596 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1597 | } |
||
| 1598 | } |
||
| 1599 | |||
| 1600 | if ($sort != "") |
||
| 1601 | { |
||
| 1602 | $search_orderby_array = $this->getOrderBy(); |
||
| 1603 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1604 | } else { |
||
| 1605 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1606 | } |
||
| 1607 | |||
| 1608 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." AND ((spotter_output.departure_airport_icao <> 'NA') AND (spotter_output.arrival_airport_icao <> 'NA')) ".$orderby_query; |
||
| 1609 | |||
| 1610 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1611 | |||
| 1612 | return $spotter_array; |
||
| 1613 | } |
||
| 1614 | |||
| 1615 | |||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Gets all the spotter information based on the date |
||
| 1619 | * |
||
| 1620 | * @return Array the spotter information |
||
| 1621 | * |
||
| 1622 | */ |
||
| 1623 | public function getSpotterDataByDate($date = '', $limit = '', $sort = '',$filter = array()) |
||
| 1624 | { |
||
| 1625 | global $global_query, $globalTimezone, $globalDBdriver; |
||
| 1626 | |||
| 1627 | $query_values = array(); |
||
| 1628 | $limit_query = ''; |
||
| 1629 | $additional_query = ''; |
||
| 1630 | |||
| 1631 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1632 | |||
| 1633 | if ($date != "") |
||
| 1634 | { |
||
| 1635 | if ($globalTimezone != '') { |
||
| 1636 | date_default_timezone_set($globalTimezone); |
||
| 1637 | $datetime = new DateTime($date); |
||
| 1638 | $offset = $datetime->format('P'); |
||
| 1639 | } else { |
||
| 1640 | date_default_timezone_set('UTC'); |
||
| 1641 | $datetime = new DateTime($date); |
||
| 1642 | $offset = '+00:00'; |
||
| 1643 | } |
||
| 1644 | if ($globalDBdriver == 'mysql') { |
||
| 1645 | $additional_query = " AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date "; |
||
| 1646 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset); |
||
| 1647 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 1648 | //$globalTimezone = 'UTC'; |
||
| 1649 | $additional_query = " AND to_char(spotter_output.date AT TIME ZONE :timezone,'YYYY-mm-dd') = :date "; |
||
| 1650 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone); |
||
| 1651 | //$additional_query = " AND to_char(spotter_output.date,'YYYY-mm-dd') = :date "; |
||
| 1652 | //$query_values = array(':date' => $datetime->format('Y-m-d')); |
||
| 1653 | } |
||
| 1654 | } |
||
| 1655 | |||
| 1656 | if ($limit != "") |
||
| 1657 | { |
||
| 1658 | $limit_array = explode(",", $limit); |
||
| 1659 | |||
| 1660 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1661 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1662 | |||
| 1663 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1664 | { |
||
| 1665 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1666 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1667 | } |
||
| 1668 | } |
||
| 1669 | |||
| 1670 | if ($sort != "") |
||
| 1671 | { |
||
| 1672 | $search_orderby_array = $this->getOrderBy(); |
||
| 1673 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1674 | } else { |
||
| 1675 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1676 | } |
||
| 1677 | |||
| 1678 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query.$orderby_query; |
||
| 1679 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1680 | return $spotter_array; |
||
| 1681 | } |
||
| 1682 | |||
| 1683 | |||
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Gets all the spotter information based on the country name |
||
| 1687 | * |
||
| 1688 | * @return Array the spotter information |
||
| 1689 | * |
||
| 1690 | */ |
||
| 1691 | public function getSpotterDataByCountry($country = '', $limit = '', $sort = '',$filters = array()) |
||
| 1692 | { |
||
| 1693 | global $global_query; |
||
| 1694 | |||
| 1695 | date_default_timezone_set('UTC'); |
||
| 1696 | |||
| 1697 | $query_values = array(); |
||
| 1698 | $limit_query = ''; |
||
| 1699 | $additional_query = ''; |
||
| 1700 | $filter_query = $this->getFilter($filters,true,true); |
||
| 1701 | if ($country != "") |
||
| 1702 | { |
||
| 1703 | if (!is_string($country)) |
||
| 1704 | { |
||
| 1705 | return false; |
||
| 1706 | } else { |
||
| 1707 | $additional_query .= " AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country))"; |
||
| 1708 | $additional_query .= " OR spotter_output.airline_country = :country"; |
||
| 1709 | $query_values = array(':country' => $country); |
||
| 1710 | } |
||
| 1711 | } |
||
| 1712 | |||
| 1713 | if ($limit != "") |
||
| 1714 | { |
||
| 1715 | $limit_array = explode(",", $limit); |
||
| 1716 | |||
| 1717 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1718 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1719 | |||
| 1720 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1721 | { |
||
| 1722 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1723 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1724 | } |
||
| 1725 | } |
||
| 1726 | |||
| 1727 | if ($sort != "") |
||
| 1728 | { |
||
| 1729 | $search_orderby_array = $this->getOrderBy(); |
||
| 1730 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1731 | } else { |
||
| 1732 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1733 | } |
||
| 1734 | |||
| 1735 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1736 | |||
| 1737 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1738 | |||
| 1739 | return $spotter_array; |
||
| 1740 | } |
||
| 1741 | |||
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Gets all the spotter information based on the manufacturer name |
||
| 1745 | * |
||
| 1746 | * @return Array the spotter information |
||
| 1747 | * |
||
| 1748 | */ |
||
| 1749 | public function getSpotterDataByManufacturer($aircraft_manufacturer = '', $limit = '', $sort = '', $filters = array()) |
||
| 1750 | { |
||
| 1751 | global $global_query; |
||
| 1752 | |||
| 1753 | date_default_timezone_set('UTC'); |
||
| 1754 | |||
| 1755 | $query_values = array(); |
||
| 1756 | $additional_query = ''; |
||
| 1757 | $limit_query = ''; |
||
| 1758 | $filter_query = $this->getFilter($filters,true,true); |
||
| 1759 | |||
| 1760 | if ($aircraft_manufacturer != "") |
||
| 1761 | { |
||
| 1762 | if (!is_string($aircraft_manufacturer)) |
||
| 1763 | { |
||
| 1764 | return false; |
||
| 1765 | } else { |
||
| 1766 | $additional_query .= " AND (spotter_output.aircraft_manufacturer = :aircraft_manufacturer)"; |
||
| 1767 | $query_values = array(':aircraft_manufacturer' => $aircraft_manufacturer); |
||
| 1768 | } |
||
| 1769 | } |
||
| 1770 | |||
| 1771 | if ($limit != "") |
||
| 1772 | { |
||
| 1773 | $limit_array = explode(",", $limit); |
||
| 1774 | |||
| 1775 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1776 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1777 | |||
| 1778 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1779 | { |
||
| 1780 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1781 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1782 | } |
||
| 1783 | } |
||
| 1784 | |||
| 1785 | if ($sort != "") |
||
| 1786 | { |
||
| 1787 | $search_orderby_array = $this->getOrderBy(); |
||
| 1788 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1789 | } else { |
||
| 1790 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1791 | } |
||
| 1792 | |||
| 1793 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1794 | |||
| 1795 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1796 | |||
| 1797 | return $spotter_array; |
||
| 1798 | } |
||
| 1799 | |||
| 1800 | |||
| 1801 | |||
| 1802 | |||
| 1803 | /** |
||
| 1804 | * Gets a list of all aircraft that take a route |
||
| 1805 | * |
||
| 1806 | * @param String $departure_airport_icao ICAO code of departure airport |
||
| 1807 | * @param String $arrival_airport_icao ICAO code of arrival airport |
||
| 1808 | * @return Array the spotter information |
||
| 1809 | * |
||
| 1810 | */ |
||
| 1811 | public function getSpotterDataByRoute($departure_airport_icao = '', $arrival_airport_icao = '', $limit = '', $sort = '', $filters = array()) |
||
| 1812 | { |
||
| 1813 | global $global_query; |
||
| 1814 | |||
| 1815 | $query_values = array(); |
||
| 1816 | $additional_query = ''; |
||
| 1817 | $limit_query = ''; |
||
| 1818 | $filter_query = $this->getFilter($filters,true,true); |
||
| 1819 | if ($departure_airport_icao != "") |
||
| 1820 | { |
||
| 1821 | if (!is_string($departure_airport_icao)) |
||
| 1822 | { |
||
| 1823 | return false; |
||
| 1824 | } else { |
||
| 1825 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1826 | $additional_query .= " AND (spotter_output.departure_airport_icao = :departure_airport_icao)"; |
||
| 1827 | //$additional_query .= " AND (spotter_output.departure_airport_icao = :departure_airport_icao AND spotter_output.real_departure_airport_icao IS NULL) OR spotter_output.real_departure_airport_icao = :departure_airport_icao"; |
||
| 1828 | $query_values = array(':departure_airport_icao' => $departure_airport_icao); |
||
| 1829 | } |
||
| 1830 | } |
||
| 1831 | |||
| 1832 | if ($arrival_airport_icao != "") |
||
| 1833 | { |
||
| 1834 | if (!is_string($arrival_airport_icao)) |
||
| 1835 | { |
||
| 1836 | return false; |
||
| 1837 | } else { |
||
| 1838 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1839 | $additional_query .= " AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)"; |
||
| 1840 | //$additional_query .= " AND ((spotter_output.arrival_airport_icao = :arrival_airport_icao AND spotter_output.real_arrival_airport_icao IS NULL) OR spotter_output.real_arrival_airport_icao = :arrival_airport_icao)"; |
||
| 1841 | $query_values = array_merge($query_values,array(':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 1842 | } |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | if ($limit != "") |
||
| 1846 | { |
||
| 1847 | $limit_array = explode(",", $limit); |
||
| 1848 | |||
| 1849 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1850 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1851 | |||
| 1852 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1853 | { |
||
| 1854 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1855 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1856 | } |
||
| 1857 | } |
||
| 1858 | |||
| 1859 | if ($sort != "") |
||
| 1860 | { |
||
| 1861 | $search_orderby_array = $this->getOrderBy(); |
||
| 1862 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1863 | } else { |
||
| 1864 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1865 | } |
||
| 1866 | |||
| 1867 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1868 | |||
| 1869 | //$result = mysqli_query($GLOBALS["___mysqli_ston"], $query); |
||
| 1870 | |||
| 1871 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1872 | |||
| 1873 | return $spotter_array; |
||
| 1874 | } |
||
| 1875 | |||
| 1876 | |||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * Gets all the spotter information based on the special column in the table |
||
| 1880 | * |
||
| 1881 | * @return Array the spotter information |
||
| 1882 | * |
||
| 1883 | */ |
||
| 1884 | public function getSpotterDataByHighlight($limit = '', $sort = '', $filter = array()) |
||
| 1885 | { |
||
| 1886 | global $global_query; |
||
| 1887 | |||
| 1888 | date_default_timezone_set('UTC'); |
||
| 1889 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1890 | $limit_query = ''; |
||
| 1891 | |||
| 1892 | if ($limit != "") |
||
| 1893 | { |
||
| 1894 | $limit_array = explode(",", $limit); |
||
| 1895 | |||
| 1896 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1897 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1898 | |||
| 1899 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1900 | { |
||
| 1901 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1902 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1903 | } |
||
| 1904 | } |
||
| 1905 | |||
| 1906 | if ($sort != "") |
||
| 1907 | { |
||
| 1908 | $search_orderby_array = $this->getOrderBy(); |
||
| 1909 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1910 | } else { |
||
| 1911 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | $query = $global_query.$filter_query." spotter_output.highlight <> '' ".$orderby_query; |
||
| 1915 | |||
| 1916 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1917 | |||
| 1918 | return $spotter_array; |
||
| 1919 | } |
||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Gets all the highlight based on a aircraft registration |
||
| 1923 | * |
||
| 1924 | * @return String the highlight text |
||
| 1925 | * |
||
| 1926 | */ |
||
| 1927 | public function getHighlightByRegistration($registration,$filter = array()) |
||
| 1928 | { |
||
| 1929 | global $global_query; |
||
| 1930 | |||
| 1931 | date_default_timezone_set('UTC'); |
||
| 1932 | $filter_query = $this->getFilter($filter,true,true); |
||
| 1933 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 1934 | |||
| 1935 | $query = $global_query.$filter_query." spotter_output.highlight <> '' AND spotter_output.registration = :registration"; |
||
| 1936 | $sth = $this->db->prepare($query); |
||
| 1937 | $sth->execute(array(':registration' => $registration)); |
||
| 1938 | |||
| 1939 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1940 | { |
||
| 1941 | $highlight = $row['highlight']; |
||
| 1942 | } |
||
| 1943 | if (isset($highlight)) return $highlight; |
||
| 1944 | } |
||
| 1945 | |||
| 1946 | |||
| 1947 | /** |
||
| 1948 | * Gets the squawk usage from squawk code |
||
| 1949 | * |
||
| 1950 | * @param String $squawk squawk code |
||
| 1951 | * @param String $country country |
||
| 1952 | * @return String usage |
||
| 1953 | * |
||
| 1954 | */ |
||
| 1955 | public function getSquawkUsage($squawk = '',$country = 'FR') |
||
| 1956 | { |
||
| 1957 | |||
| 1958 | $squawk = filter_var($squawk,FILTER_SANITIZE_STRING); |
||
| 1959 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 1960 | |||
| 1961 | $query = "SELECT squawk.* FROM squawk WHERE squawk.code = :squawk AND squawk.country = :country LIMIT 1"; |
||
| 1962 | $query_values = array(':squawk' => ltrim($squawk,'0'), ':country' => $country); |
||
| 1963 | |||
| 1964 | $sth = $this->db->prepare($query); |
||
| 1965 | $sth->execute($query_values); |
||
| 1966 | |||
| 1967 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 1968 | $sth->closeCursor(); |
||
| 1969 | if (count($row) > 0) { |
||
| 1970 | return $row['usage']; |
||
| 1971 | } else return ''; |
||
| 1972 | } |
||
| 1973 | |||
| 1974 | /** |
||
| 1975 | * Gets the airport icao from the iata |
||
| 1976 | * |
||
| 1977 | * @param String $airport_iata the iata code of the airport |
||
| 1978 | * @return String airport iata |
||
| 1979 | * |
||
| 1980 | */ |
||
| 1981 | public function getAirportIcao($airport_iata = '') |
||
| 1982 | { |
||
| 1983 | |||
| 1984 | $airport_iata = filter_var($airport_iata,FILTER_SANITIZE_STRING); |
||
| 1985 | |||
| 1986 | $query = "SELECT airport.* FROM airport WHERE airport.iata = :airport LIMIT 1"; |
||
| 1987 | $query_values = array(':airport' => $airport_iata); |
||
| 1988 | |||
| 1989 | $sth = $this->db->prepare($query); |
||
| 1990 | $sth->execute($query_values); |
||
| 1991 | |||
| 1992 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 1993 | $sth->closeCursor(); |
||
| 1994 | if (count($row) > 0) { |
||
| 1995 | return $row['icao']; |
||
| 1996 | } else return ''; |
||
| 1997 | } |
||
| 1998 | |||
| 1999 | /** |
||
| 2000 | * Gets the airport distance |
||
| 2001 | * |
||
| 2002 | * @param String $airport_icao the icao code of the airport |
||
| 2003 | * @param Float $latitude the latitude |
||
| 2004 | * @param Float $longitude the longitude |
||
| 2005 | * @return Float distance to the airport |
||
| 2006 | * |
||
| 2007 | */ |
||
| 2008 | public function getAirportDistance($airport_icao,$latitude,$longitude) |
||
| 2009 | { |
||
| 2010 | |||
| 2011 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 2012 | |||
| 2013 | $query = "SELECT airport.latitude, airport.longitude FROM airport WHERE airport.icao = :airport LIMIT 1"; |
||
| 2014 | $query_values = array(':airport' => $airport_icao); |
||
| 2015 | $sth = $this->db->prepare($query); |
||
| 2016 | $sth->execute($query_values); |
||
| 2017 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2018 | $sth->closeCursor(); |
||
| 2019 | if (count($row) > 0) { |
||
| 2020 | $airport_latitude = $row['latitude']; |
||
| 2021 | $airport_longitude = $row['longitude']; |
||
| 2022 | $Common = new Common(); |
||
| 2023 | return $Common->distance($latitude,$longitude,$airport_latitude,$airport_longitude); |
||
| 2024 | } else return ''; |
||
| 2025 | } |
||
| 2026 | |||
| 2027 | /** |
||
| 2028 | * Gets the airport info based on the icao |
||
| 2029 | * |
||
| 2030 | * @param String $airport the icao code of the airport |
||
| 2031 | * @return Array airport information |
||
| 2032 | * |
||
| 2033 | */ |
||
| 2034 | public function getAllAirportInfo($airport = '') |
||
| 2035 | { |
||
| 2036 | |||
| 2037 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
| 2038 | |||
| 2039 | $query_values = array(); |
||
| 2040 | if ($airport == 'NA') { |
||
| 2041 | return array(array('name' => 'Not available','city' => 'N/A', 'country' => 'N/A','iata' => 'NA','icao' => 'NA','altitude' => NULL,'latitude' => 0,'longitude' => 0,'type' => 'NA','home_link' => '','wikipedia_link' => '','image_thumb' => '', 'image' => '')); |
||
| 2042 | } elseif ($airport == '') { |
||
| 2043 | $query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport"; |
||
| 2044 | } else { |
||
| 2045 | $query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport WHERE airport.icao = :airport LIMIT 1"; |
||
| 2046 | $query_values = array(':airport' => $airport); |
||
| 2047 | } |
||
| 2048 | |||
| 2049 | $sth = $this->db->prepare($query); |
||
| 2050 | $sth->execute($query_values); |
||
| 2051 | /* |
||
| 2052 | $airport_array = array(); |
||
| 2053 | $temp_array = array(); |
||
| 2054 | |||
| 2055 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2056 | { |
||
| 2057 | $temp_array['name'] = $row['name']; |
||
| 2058 | $temp_array['city'] = $row['city']; |
||
| 2059 | $temp_array['country'] = $row['country']; |
||
| 2060 | $temp_array['iata'] = $row['iata']; |
||
| 2061 | $temp_array['icao'] = $row['icao']; |
||
| 2062 | $temp_array['latitude'] = $row['latitude']; |
||
| 2063 | $temp_array['longitude'] = $row['longitude']; |
||
| 2064 | $temp_array['altitude'] = $row['altitude']; |
||
| 2065 | $temp_array['home_link'] = $row['home_link']; |
||
| 2066 | $temp_array['wikipedia_link'] = $row['wikipedia_link']; |
||
| 2067 | $temp_array['image'] = $row['image']; |
||
| 2068 | $temp_array['image_thumb'] = $row['image_thumb']; |
||
| 2069 | |||
| 2070 | $airport_array[] = $temp_array; |
||
| 2071 | } |
||
| 2072 | |||
| 2073 | return $airport_array; |
||
| 2074 | */ |
||
| 2075 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2076 | } |
||
| 2077 | |||
| 2078 | /** |
||
| 2079 | * Gets the airport info based on the country |
||
| 2080 | * |
||
| 2081 | * @param Array $countries Airports countries |
||
| 2082 | * @return Array airport information |
||
| 2083 | * |
||
| 2084 | */ |
||
| 2085 | public function getAllAirportInfobyCountry($countries) |
||
| 2086 | { |
||
| 2087 | $lst_countries = ''; |
||
| 2088 | foreach ($countries as $country) { |
||
| 2089 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 2090 | if ($lst_countries == '') { |
||
| 2091 | $lst_countries = "'".$country."'"; |
||
| 2092 | } else { |
||
| 2093 | $lst_countries .= ",'".$country."'"; |
||
| 2094 | } |
||
| 2095 | } |
||
| 2096 | $query = "SELECT airport.* FROM airport WHERE airport.country IN (".$lst_countries.")"; |
||
| 2097 | |||
| 2098 | $sth = $this->db->prepare($query); |
||
| 2099 | $sth->execute(); |
||
| 2100 | |||
| 2101 | $airport_array = array(); |
||
| 2102 | $temp_array = array(); |
||
| 2103 | |||
| 2104 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2105 | { |
||
| 2106 | $temp_array['name'] = $row['name']; |
||
| 2107 | $temp_array['city'] = $row['city']; |
||
| 2108 | $temp_array['country'] = $row['country']; |
||
| 2109 | $temp_array['iata'] = $row['iata']; |
||
| 2110 | $temp_array['icao'] = $row['icao']; |
||
| 2111 | $temp_array['latitude'] = $row['latitude']; |
||
| 2112 | $temp_array['longitude'] = $row['longitude']; |
||
| 2113 | $temp_array['altitude'] = $row['altitude']; |
||
| 2114 | |||
| 2115 | $airport_array[] = $temp_array; |
||
| 2116 | } |
||
| 2117 | |||
| 2118 | return $airport_array; |
||
| 2119 | } |
||
| 2120 | |||
| 2121 | /** |
||
| 2122 | * Gets airports info based on the coord |
||
| 2123 | * |
||
| 2124 | * @param Array $coord Airports longitude min,latitude min, longitude max, latitude max |
||
| 2125 | * @return Array airport information |
||
| 2126 | * |
||
| 2127 | */ |
||
| 2128 | public function getAllAirportInfobyCoord($coord) |
||
| 2129 | { |
||
| 2130 | global $globalDBdriver; |
||
| 2131 | if (is_array($coord)) { |
||
| 2132 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2133 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2134 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2135 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2136 | } else return array(); |
||
| 2137 | if ($globalDBdriver == 'mysql') { |
||
| 2138 | $query = "SELECT airport.* FROM airport WHERE airport.latitude BETWEEN ".$minlat." AND ".$maxlat." AND airport.longitude BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'"; |
||
| 2139 | } else { |
||
| 2140 | $query = "SELECT airport.* FROM airport WHERE CAST(airport.latitude AS FLOAT) BETWEEN ".$minlat." AND ".$maxlat." AND CAST(airport.longitude AS FLOAT) BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'"; |
||
| 2141 | } |
||
| 2142 | $sth = $this->db->prepare($query); |
||
| 2143 | $sth->execute(); |
||
| 2144 | |||
| 2145 | $airport_array = array(); |
||
| 2146 | |||
| 2147 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2148 | { |
||
| 2149 | $temp_array = $row; |
||
| 2150 | |||
| 2151 | $airport_array[] = $temp_array; |
||
| 2152 | } |
||
| 2153 | |||
| 2154 | return $airport_array; |
||
| 2155 | } |
||
| 2156 | |||
| 2157 | /** |
||
| 2158 | * Gets waypoints info based on the coord |
||
| 2159 | * |
||
| 2160 | * @param Array $coord waypoints coord |
||
| 2161 | * @return Array airport information |
||
| 2162 | * |
||
| 2163 | */ |
||
| 2164 | public function getAllWaypointsInfobyCoord($coord) |
||
| 2165 | { |
||
| 2166 | if (is_array($coord)) { |
||
| 2167 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2168 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2169 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2170 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 2171 | } else return array(); |
||
| 2172 | //$query = "SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong; |
||
| 2173 | $query = "SELECT waypoints.* FROM waypoints WHERE (waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong.") OR (waypoints.latitude_end BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_end BETWEEN ".$minlong." AND ".$maxlong.")"; |
||
| 2174 | //$query = "SELECT waypoints.* FROM waypoints"; |
||
| 2175 | //$query = "SELECT waypoints.* FROM waypoints INNER JOIN (SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong.") w ON w.name_end = waypoints.name_begin OR w.name_begin = waypoints.name_begin OR w.name_begin = waypoints.name_end OR w.name_end = waypoints.name_end"; |
||
| 2176 | //$query = "SELECT * FROM waypoints LEFT JOIN waypoints w ON waypoints.name_end = w.name_begin WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong; |
||
| 2177 | //$query = "SELECT z.name_begin as name_begin, z.name_end as name_end, z.latitude_begin as latitude_begin, z.longitude_begin as longitude_begin, z.latitude_end as latitude_end, z.longitude_end as longitude_end, z.segment_name as segment_name, w.name_end as name_end_seg2, w.latitude_end as latitude_end_seg2, w.longitude_end as longitude_end_seg2, w.segment_name as segment_name_seg2 FROM waypoints z INNER JOIN waypoints w ON z.name_end = w.name_begin WHERE z.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND z.longitude_begin BETWEEN ".$minlong." AND ".$maxlong; |
||
| 2178 | //echo $query; |
||
| 2179 | |||
| 2180 | $sth = $this->db->prepare($query); |
||
| 2181 | $sth->execute(); |
||
| 2182 | |||
| 2183 | $waypoints_array = array(); |
||
| 2184 | |||
| 2185 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2186 | { |
||
| 2187 | $temp_array = $row; |
||
| 2188 | |||
| 2189 | $waypoints_array[] = $temp_array; |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | return $waypoints_array; |
||
| 2193 | } |
||
| 2194 | |||
| 2195 | |||
| 2196 | /** |
||
| 2197 | * Gets the airline info based on the icao code or iata code |
||
| 2198 | * |
||
| 2199 | * @param String $airline_icao the iata code of the airport |
||
| 2200 | * @return Array airport information |
||
| 2201 | * |
||
| 2202 | */ |
||
| 2203 | public function getAllAirlineInfo($airline_icao, $fromsource = NULL) |
||
| 2204 | { |
||
| 2205 | global $globalUseRealAirlines; |
||
| 2206 | if (isset($globalUseRealAirlines) && $globalUseRealAirlines) $fromsource = NULL; |
||
| 2207 | $airline_icao = strtoupper(filter_var($airline_icao,FILTER_SANITIZE_STRING)); |
||
| 2208 | if ($airline_icao == 'NA') { |
||
| 2209 | $airline_array = array(); |
||
| 2210 | $airline_array[] = array('name' => 'Not Available','iata' => 'NA', 'icao' => 'NA', 'callsign' => '', 'country' => 'NA', 'type' =>''); |
||
| 2211 | return $airline_array; |
||
| 2212 | } else { |
||
| 2213 | if (strlen($airline_icao) == 2) { |
||
| 2214 | if ($fromsource === NULL) { |
||
| 2215 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.iata = :airline_icao AND airlines.active = 'Y' AND airlines.forsource IS NULL LIMIT 1"; |
||
| 2216 | } else { |
||
| 2217 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.iata = :airline_icao AND airlines.active = 'Y' AND airlines.forsource = :fromsource LIMIT 1"; |
||
| 2218 | } |
||
| 2219 | } else { |
||
| 2220 | if ($fromsource === NULL) { |
||
| 2221 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.icao = :airline_icao AND airlines.active = 'Y' AND airlines.forsource IS NULL LIMIT 1"; |
||
| 2222 | } else { |
||
| 2223 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.icao = :airline_icao AND airlines.active = 'Y' AND airlines.forsource = :fromsource LIMIT 1"; |
||
| 2224 | } |
||
| 2225 | } |
||
| 2226 | |||
| 2227 | $sth = $this->db->prepare($query); |
||
| 2228 | if ($fromsource === NULL) { |
||
| 2229 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 2230 | } else { |
||
| 2231 | $sth->execute(array(':airline_icao' => $airline_icao,':fromsource' => $fromsource)); |
||
| 2232 | } |
||
| 2233 | /* |
||
| 2234 | $airline_array = array(); |
||
| 2235 | $temp_array = array(); |
||
| 2236 | |||
| 2237 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2238 | { |
||
| 2239 | $temp_array['name'] = $row['name']; |
||
| 2240 | $temp_array['iata'] = $row['iata']; |
||
| 2241 | $temp_array['icao'] = $row['icao']; |
||
| 2242 | $temp_array['callsign'] = $row['callsign']; |
||
| 2243 | $temp_array['country'] = $row['country']; |
||
| 2244 | $temp_array['type'] = $row['type']; |
||
| 2245 | $airline_array[] = $temp_array; |
||
| 2246 | } |
||
| 2247 | return $airline_array; |
||
| 2248 | */ |
||
| 2249 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2250 | if (empty($result) && $fromsource !== NULL) { |
||
| 2251 | /* |
||
| 2252 | $query = 'SELECT COUNT(*) AS nb FROM airlines WHERE forsource = :fromsource'; |
||
| 2253 | $sth = $this->db->prepare($query); |
||
| 2254 | $sth->execute(array(':fromsource' => $fromsource)); |
||
| 2255 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2256 | $sth->closeCursor(); |
||
| 2257 | if ($row['nb'] == 0) $result = $this->getAllAirlineInfo($airline_icao); |
||
| 2258 | */ |
||
| 2259 | $result = $this->getAllAirlineInfo($airline_icao); |
||
| 2260 | } |
||
| 2261 | return $result; |
||
| 2262 | } |
||
| 2263 | } |
||
| 2264 | |||
| 2265 | /** |
||
| 2266 | * Gets the airline info based on the airline name |
||
| 2267 | * |
||
| 2268 | * @param String $airline_name the name of the airline |
||
| 2269 | * @return Array airline information |
||
| 2270 | * |
||
| 2271 | */ |
||
| 2272 | public function getAllAirlineInfoByName($airline_name, $fromsource = NULL) |
||
| 2273 | { |
||
| 2274 | global $globalUseRealAirlines; |
||
| 2275 | if (isset($globalUseRealAirlines) && $globalUseRealAirlines) $fromsource = NULL; |
||
| 2276 | $airline_name = strtolower(filter_var($airline_name,FILTER_SANITIZE_STRING)); |
||
| 2277 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE lower(airlines.name) = :airline_name AND airlines.active = 'Y' AND airlines.forsource IS NULL LIMIT 1"; |
||
| 2278 | $sth = $this->db->prepare($query); |
||
| 2279 | if ($fromsource === NULL) { |
||
| 2280 | $sth->execute(array(':airline_name' => $airline_name)); |
||
| 2281 | } else { |
||
| 2282 | $sth->execute(array(':airline_name' => $airline_name,':fromsource' => $fromsource)); |
||
| 2283 | } |
||
| 2284 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2285 | if (empty($result) && $fromsource !== NULL) { |
||
| 2286 | $query = 'SELECT COUNT(*) AS nb FROM airlines WHERE forsource = :fromsource'; |
||
| 2287 | $sth = $this->db->prepare($query); |
||
| 2288 | $sth->execute(array(':fromsource' => $fromsource)); |
||
| 2289 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2290 | $sth->closeCursor(); |
||
| 2291 | if ($row['nb'] == 0) $result = $this->getAllAirlineInfoByName($airline_name); |
||
| 2292 | } |
||
| 2293 | return $result; |
||
| 2294 | } |
||
| 2295 | |||
| 2296 | |||
| 2297 | |||
| 2298 | /** |
||
| 2299 | * Gets the aircraft info based on the aircraft type |
||
| 2300 | * |
||
| 2301 | * @param String $aircraft_type the aircraft type |
||
| 2302 | * @return Array aircraft information |
||
| 2303 | * |
||
| 2304 | */ |
||
| 2305 | public function getAllAircraftInfo($aircraft_type) |
||
| 2306 | { |
||
| 2307 | $aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING); |
||
| 2308 | |||
| 2309 | if ($aircraft_type == 'NA') { |
||
| 2310 | return array(array('icao' => 'NA','type' => 'Not Available', 'manufacturer' => 'Not Available', 'aircraft_shadow' => NULL)); |
||
| 2311 | } |
||
| 2312 | $query = "SELECT aircraft.icao, aircraft.type,aircraft.manufacturer,aircraft.aircraft_shadow, aircraft.official_page, aircraft.aircraft_description, aircraft.engine_type, aircraft.engine_count, aircraft.wake_category FROM aircraft WHERE aircraft.icao = :aircraft_type"; |
||
| 2313 | |||
| 2314 | $sth = $this->db->prepare($query); |
||
| 2315 | $sth->execute(array(':aircraft_type' => $aircraft_type)); |
||
| 2316 | /* |
||
| 2317 | $aircraft_array = array(); |
||
| 2318 | $temp_array = array(); |
||
| 2319 | |||
| 2320 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2321 | { |
||
| 2322 | $temp_array = array(); |
||
| 2323 | $temp_array['icao'] = $row['icao']; |
||
| 2324 | $temp_array['type'] = $row['type']; |
||
| 2325 | $temp_array['manufacturer'] = $row['manufacturer']; |
||
| 2326 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
| 2327 | |||
| 2328 | $aircraft_array[] = $temp_array; |
||
| 2329 | } |
||
| 2330 | return $aircraft_array; |
||
| 2331 | */ |
||
| 2332 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2333 | } |
||
| 2334 | |||
| 2335 | /** |
||
| 2336 | * Gets the aircraft icao based on the aircraft name/type |
||
| 2337 | * |
||
| 2338 | * @param String $aircraft_type the aircraft type |
||
| 2339 | * @return String aircraft information |
||
| 2340 | * |
||
| 2341 | */ |
||
| 2342 | public function getAircraftIcao($aircraft_type) |
||
| 2343 | { |
||
| 2344 | $aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING); |
||
| 2345 | $all_aircraft = array('737-300' => 'B733', |
||
| 2346 | '777-200' => 'B772', |
||
| 2347 | '777-200ER' => 'B772', |
||
| 2348 | '777-300ER' => 'B77W', |
||
| 2349 | 'c172p' => 'C172', |
||
| 2350 | 'aerostar' => 'AEST', |
||
| 2351 | 'A320-211' => 'A320', |
||
| 2352 | '747-8i' => 'B748', |
||
| 2353 | 'A380' => 'A388'); |
||
| 2354 | if (isset($all_aircraft[$aircraft_type])) return $all_aircraft[$aircraft_type]; |
||
| 2355 | |||
| 2356 | $query = "SELECT aircraft.icao FROM aircraft WHERE aircraft.type LIKE :saircraft_type OR aircraft.type = :aircraft_type OR aircraft.icao = :aircraft_type LIMIT 1"; |
||
| 2357 | $aircraft_type = strtoupper($aircraft_type); |
||
| 2358 | $sth = $this->db->prepare($query); |
||
| 2359 | $sth->execute(array(':saircraft_type' => '%'.$aircraft_type.'%',':aircraft_type' => $aircraft_type,)); |
||
| 2360 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2361 | if (isset($result[0]['icao'])) return $result[0]['icao']; |
||
| 2362 | else return ''; |
||
| 2363 | } |
||
| 2364 | |||
| 2365 | /** |
||
| 2366 | * Gets the aircraft info based on the aircraft modes |
||
| 2367 | * |
||
| 2368 | * @param String $aircraft_modes the aircraft ident (hex) |
||
| 2369 | * @return String aircraft type |
||
| 2370 | * |
||
| 2371 | */ |
||
| 2372 | public function getAllAircraftType($aircraft_modes) |
||
| 2373 | { |
||
| 2374 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 2375 | |||
| 2376 | $query = "SELECT aircraft_modes.ICAOTypeCode FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes ORDER BY FirstCreated DESC LIMIT 1"; |
||
| 2377 | |||
| 2378 | $sth = $this->db->prepare($query); |
||
| 2379 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 2380 | |||
| 2381 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2382 | $sth->closeCursor(); |
||
| 2383 | if (isset($row['icaotypecode'])) { |
||
| 2384 | $icao = $row['icaotypecode']; |
||
| 2385 | if (isset($this->aircraft_correct_icaotype[$icao])) $icao = $this->aircraft_correct_icaotype[$icao]; |
||
| 2386 | return $icao; |
||
| 2387 | } else return ''; |
||
| 2388 | } |
||
| 2389 | |||
| 2390 | /** |
||
| 2391 | * Gets the aircraft info based on the aircraft registration |
||
| 2392 | * |
||
| 2393 | * @param String $registration the aircraft registration |
||
| 2394 | * @return String aircraft type |
||
| 2395 | * |
||
| 2396 | */ |
||
| 2397 | public function getAllAircraftTypeByRegistration($registration) |
||
| 2398 | { |
||
| 2399 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2400 | |||
| 2401 | $query = "SELECT aircraft_modes.ICAOTypeCode FROM aircraft_modes WHERE aircraft_modes.registration = :registration ORDER BY FirstCreated DESC LIMIT 1"; |
||
| 2402 | |||
| 2403 | $sth = $this->db->prepare($query); |
||
| 2404 | $sth->execute(array(':registration' => $registration)); |
||
| 2405 | |||
| 2406 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2407 | $sth->closeCursor(); |
||
| 2408 | if (isset($row['icaotypecode'])) { |
||
| 2409 | return $row['icaotypecode']; |
||
| 2410 | } else return ''; |
||
| 2411 | } |
||
| 2412 | |||
| 2413 | /** |
||
| 2414 | * Gets the spotter_id and flightaware_id based on the aircraft registration |
||
| 2415 | * |
||
| 2416 | * @param String $registration the aircraft registration |
||
| 2417 | * @return Array spotter_id and flightaware_id |
||
| 2418 | * |
||
| 2419 | */ |
||
| 2420 | public function getAllIDByRegistration($registration) |
||
| 2421 | { |
||
| 2422 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2423 | |||
| 2424 | $query = "SELECT spotter_id,flightaware_id, date FROM spotter_output WHERE spotter_output.registration = :registration"; |
||
| 2425 | |||
| 2426 | $sth = $this->db->prepare($query); |
||
| 2427 | $sth->execute(array(':registration' => $registration)); |
||
| 2428 | |||
| 2429 | $idarray = array(); |
||
| 2430 | while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
||
| 2431 | $date = $row['date']; |
||
| 2432 | $idarray[$date] = array('flightaware_id' => $row['flightaware_id'],'spotter_id' => $row['spotter_id']); |
||
| 2433 | } |
||
| 2434 | return $idarray; |
||
| 2435 | } |
||
| 2436 | |||
| 2437 | /** |
||
| 2438 | * Gets correct aircraft operator code |
||
| 2439 | * |
||
| 2440 | * @param String $operator the aircraft operator code (callsign) |
||
| 2441 | * @return String aircraft operator code |
||
| 2442 | * |
||
| 2443 | */ |
||
| 2444 | public function getOperator($operator) |
||
| 2445 | { |
||
| 2446 | $operator = filter_var($operator,FILTER_SANITIZE_STRING); |
||
| 2447 | $query = "SELECT translation.operator_correct FROM translation WHERE translation.operator = :operator LIMIT 1"; |
||
| 2448 | |||
| 2449 | $sth = $this->db->prepare($query); |
||
| 2450 | $sth->execute(array(':operator' => $operator)); |
||
| 2451 | |||
| 2452 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2453 | $sth->closeCursor(); |
||
| 2454 | if (isset($row['operator_correct'])) { |
||
| 2455 | return $row['operator_correct']; |
||
| 2456 | } else return $operator; |
||
| 2457 | } |
||
| 2458 | |||
| 2459 | /** |
||
| 2460 | * Gets the aircraft route based on the aircraft callsign |
||
| 2461 | * |
||
| 2462 | * @param String $callsign the aircraft callsign |
||
| 2463 | * @return Array aircraft type |
||
| 2464 | * |
||
| 2465 | */ |
||
| 2466 | public function getRouteInfo($callsign) |
||
| 2467 | { |
||
| 2468 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
| 2469 | if ($callsign == '') return array(); |
||
| 2470 | $query = "SELECT routes.Operator_ICAO, routes.FromAirport_ICAO, routes.ToAirport_ICAO, routes.RouteStop, routes.FromAirport_Time, routes.ToAirport_Time FROM routes WHERE CallSign = :callsign LIMIT 1"; |
||
| 2471 | |||
| 2472 | $sth = $this->db->prepare($query); |
||
| 2473 | $sth->execute(array(':callsign' => $callsign)); |
||
| 2474 | |||
| 2475 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2476 | $sth->closeCursor(); |
||
| 2477 | if (count($row) > 0) { |
||
| 2478 | return $row; |
||
| 2479 | } else return array(); |
||
| 2480 | } |
||
| 2481 | |||
| 2482 | /** |
||
| 2483 | * Gets the aircraft info based on the aircraft registration |
||
| 2484 | * |
||
| 2485 | * @param String $registration the aircraft registration |
||
| 2486 | * @return Array aircraft information |
||
| 2487 | * |
||
| 2488 | */ |
||
| 2489 | public function getAircraftInfoByRegistration($registration) |
||
| 2490 | { |
||
| 2491 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2492 | |||
| 2493 | $query = "SELECT spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.airline_icao FROM spotter_output WHERE spotter_output.registration = :registration"; |
||
| 2494 | |||
| 2495 | $sth = $this->db->prepare($query); |
||
| 2496 | $sth->execute(array(':registration' => $registration)); |
||
| 2497 | |||
| 2498 | $aircraft_array = array(); |
||
| 2499 | $temp_array = array(); |
||
| 2500 | |||
| 2501 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2502 | { |
||
| 2503 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 2504 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 2505 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2506 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2507 | |||
| 2508 | $aircraft_array[] = $temp_array; |
||
| 2509 | } |
||
| 2510 | |||
| 2511 | return $aircraft_array; |
||
| 2512 | } |
||
| 2513 | |||
| 2514 | /** |
||
| 2515 | * Gets the aircraft owner & base based on the aircraft registration |
||
| 2516 | * |
||
| 2517 | * @param String $registration the aircraft registration |
||
| 2518 | * @return Array aircraft information |
||
| 2519 | * |
||
| 2520 | */ |
||
| 2521 | public function getAircraftOwnerByRegistration($registration) |
||
| 2522 | { |
||
| 2523 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2524 | $Connection = new Connection($this->db); |
||
| 2525 | if ($Connection->tableExists('aircraft_owner')) { |
||
| 2526 | $query = "SELECT aircraft_owner.base, aircraft_owner.owner, aircraft_owner.date_first_reg FROM aircraft_owner WHERE registration = :registration LIMIT 1"; |
||
| 2527 | $sth = $this->db->prepare($query); |
||
| 2528 | $sth->execute(array(':registration' => $registration)); |
||
| 2529 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2530 | $sth->closeCursor(); |
||
| 2531 | return $result; |
||
| 2532 | } else return array(); |
||
| 2533 | } |
||
| 2534 | |||
| 2535 | |||
| 2536 | /** |
||
| 2537 | * Gets all flights (but with only little info) |
||
| 2538 | * |
||
| 2539 | * @return Array basic flight information |
||
| 2540 | * |
||
| 2541 | */ |
||
| 2542 | public function getAllFlightsforSitemap() |
||
| 2543 | { |
||
| 2544 | //$query = "SELECT spotter_output.spotter_id, spotter_output.ident, spotter_output.airline_name, spotter_output.aircraft_name, spotter_output.aircraft_icao FROM spotter_output ORDER BY LIMIT "; |
||
| 2545 | $query = "SELECT spotter_output.spotter_id FROM spotter_output ORDER BY spotter_id DESC LIMIT 200 OFFSET 0"; |
||
| 2546 | |||
| 2547 | $sth = $this->db->prepare($query); |
||
| 2548 | $sth->execute(); |
||
| 2549 | /* |
||
| 2550 | $flight_array = array(); |
||
| 2551 | $temp_array = array(); |
||
| 2552 | |||
| 2553 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2554 | { |
||
| 2555 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 2556 | // $temp_array['ident'] = $row['ident']; |
||
| 2557 | // $temp_array['airline_name'] = $row['airline_name']; |
||
| 2558 | // $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
| 2559 | // $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2560 | //$temp_array['image'] = $row['image']; |
||
| 2561 | |||
| 2562 | $flight_array[] = $temp_array; |
||
| 2563 | } |
||
| 2564 | |||
| 2565 | return $flight_array; |
||
| 2566 | */ |
||
| 2567 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2568 | } |
||
| 2569 | |||
| 2570 | /** |
||
| 2571 | * Gets a list of all aircraft manufacturers |
||
| 2572 | * |
||
| 2573 | * @return Array list of aircraft types |
||
| 2574 | * |
||
| 2575 | */ |
||
| 2576 | public function getAllManufacturers() |
||
| 2577 | { |
||
| 2578 | /* |
||
| 2579 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer AS aircraft_manufacturer |
||
| 2580 | FROM spotter_output |
||
| 2581 | WHERE spotter_output.aircraft_manufacturer <> '' |
||
| 2582 | ORDER BY spotter_output.aircraft_manufacturer ASC"; |
||
| 2583 | */ |
||
| 2584 | |||
| 2585 | $query = "SELECT DISTINCT manufacturer AS aircraft_manufacturer FROM aircraft WHERE manufacturer <> '' ORDER BY manufacturer ASC"; |
||
| 2586 | $sth = $this->db->prepare($query); |
||
| 2587 | $sth->execute(); |
||
| 2588 | |||
| 2589 | $manufacturer_array = array(); |
||
| 2590 | $temp_array = array(); |
||
| 2591 | |||
| 2592 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2593 | { |
||
| 2594 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2595 | |||
| 2596 | $manufacturer_array[] = $temp_array; |
||
| 2597 | } |
||
| 2598 | |||
| 2599 | return $manufacturer_array; |
||
| 2600 | } |
||
| 2601 | |||
| 2602 | |||
| 2603 | /** |
||
| 2604 | * Gets a list of all aircraft types |
||
| 2605 | * |
||
| 2606 | * @return Array list of aircraft types |
||
| 2607 | * |
||
| 2608 | */ |
||
| 2609 | public function getAllAircraftTypes($filters = array()) |
||
| 2610 | { |
||
| 2611 | /* |
||
| 2612 | $query = "SELECT DISTINCT spotter_output.aircraft_icao AS aircraft_icao, spotter_output.aircraft_name AS aircraft_name |
||
| 2613 | FROM spotter_output |
||
| 2614 | WHERE spotter_output.aircraft_icao <> '' |
||
| 2615 | ORDER BY spotter_output.aircraft_name ASC"; |
||
| 2616 | |||
| 2617 | */ |
||
| 2618 | //$filter_query = $this->getFilter($filters,true,true); |
||
| 2619 | //$query = "SELECT DISTINCT icao AS aircraft_icao, type AS aircraft_name, manufacturer AS aircraft_manufacturer FROM aircraft".$filter_query." icao <> '' ORDER BY aircraft_manufacturer ASC"; |
||
| 2620 | |||
| 2621 | $query = "SELECT DISTINCT icao AS aircraft_icao, type AS aircraft_name, manufacturer AS aircraft_manufacturer FROM aircraft WHERE icao <> '' ORDER BY aircraft_manufacturer ASC"; |
||
| 2622 | |||
| 2623 | $sth = $this->db->prepare($query); |
||
| 2624 | $sth->execute(); |
||
| 2625 | |||
| 2626 | $aircraft_array = array(); |
||
| 2627 | $temp_array = array(); |
||
| 2628 | |||
| 2629 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2630 | { |
||
| 2631 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 2632 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2633 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2634 | |||
| 2635 | $aircraft_array[] = $temp_array; |
||
| 2636 | } |
||
| 2637 | |||
| 2638 | return $aircraft_array; |
||
| 2639 | } |
||
| 2640 | |||
| 2641 | |||
| 2642 | /** |
||
| 2643 | * Gets a list of all aircraft registrations |
||
| 2644 | * |
||
| 2645 | * @return Array list of aircraft registrations |
||
| 2646 | * |
||
| 2647 | */ |
||
| 2648 | public function getAllAircraftRegistrations($filters = array()) |
||
| 2649 | { |
||
| 2650 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2651 | $query = "SELECT DISTINCT spotter_output.registration |
||
| 2652 | FROM spotter_output".$filter_query." spotter_output.registration <> '' |
||
| 2653 | ORDER BY spotter_output.registration ASC"; |
||
| 2654 | |||
| 2655 | $sth = $this->db->prepare($query); |
||
| 2656 | $sth->execute(); |
||
| 2657 | |||
| 2658 | $aircraft_array = array(); |
||
| 2659 | $temp_array = array(); |
||
| 2660 | |||
| 2661 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2662 | { |
||
| 2663 | $temp_array['registration'] = $row['registration']; |
||
| 2664 | |||
| 2665 | $aircraft_array[] = $temp_array; |
||
| 2666 | } |
||
| 2667 | |||
| 2668 | return $aircraft_array; |
||
| 2669 | } |
||
| 2670 | |||
| 2671 | /** |
||
| 2672 | * Gets all source name |
||
| 2673 | * |
||
| 2674 | * @param String type format of source |
||
| 2675 | * @return Array list of source name |
||
| 2676 | * |
||
| 2677 | */ |
||
| 2678 | public function getAllSourceName($type = '',$filters = array()) |
||
| 2679 | { |
||
| 2680 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2681 | $query_values = array(); |
||
| 2682 | $query = "SELECT DISTINCT spotter_output.source_name |
||
| 2683 | FROM spotter_output".$filter_query." spotter_output.source_name <> ''"; |
||
| 2684 | if ($type != '') { |
||
| 2685 | $query_values = array(':type' => $type); |
||
| 2686 | $query .= " AND format_source = :type"; |
||
| 2687 | } |
||
| 2688 | $query .= " ORDER BY spotter_output.source_name ASC"; |
||
| 2689 | |||
| 2690 | $sth = $this->db->prepare($query); |
||
| 2691 | if (!empty($query_values)) $sth->execute($query_values); |
||
| 2692 | else $sth->execute(); |
||
| 2693 | |||
| 2694 | $source_array = array(); |
||
| 2695 | $temp_array = array(); |
||
| 2696 | |||
| 2697 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2698 | { |
||
| 2699 | $temp_array['source_name'] = $row['source_name']; |
||
| 2700 | $source_array[] = $temp_array; |
||
| 2701 | } |
||
| 2702 | return $source_array; |
||
| 2703 | } |
||
| 2704 | |||
| 2705 | |||
| 2706 | |||
| 2707 | /** |
||
| 2708 | * Gets a list of all airline names |
||
| 2709 | * |
||
| 2710 | * @return Array list of airline names |
||
| 2711 | * |
||
| 2712 | */ |
||
| 2713 | public function getAllAirlineNames($airline_type = '',$forsource = NULL,$filters = array()) |
||
| 2714 | { |
||
| 2715 | global $globalAirlinesSource,$globalVATSIM, $globalIVAO; |
||
| 2716 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2717 | $airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING); |
||
| 2718 | if ($airline_type == '' || $airline_type == 'all') { |
||
| 2719 | /* |
||
| 2720 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
| 2721 | FROM spotter_output |
||
| 2722 | WHERE spotter_output.airline_icao <> '' |
||
| 2723 | ORDER BY spotter_output.airline_name ASC"; |
||
| 2724 | */ |
||
| 2725 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $forsource = $globalAirlinesSource; |
||
| 2726 | elseif (isset($globalVATSIM) && $globalVATSIM) $forsource = 'vatsim'; |
||
| 2727 | elseif (isset($globalIVAO) && $globalIVAO) $forsource = 'ivao'; |
||
| 2728 | if ($forsource === NULL) { |
||
| 2729 | $query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines WHERE forsource IS NULL ORDER BY name ASC"; |
||
| 2730 | $query_data = array(); |
||
| 2731 | } else { |
||
| 2732 | $query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines WHERE forsource = :forsource ORDER BY name ASC"; |
||
| 2733 | $query_data = array(':forsource' => $forsource); |
||
| 2734 | } |
||
| 2735 | } else { |
||
| 2736 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
| 2737 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
| 2738 | AND spotter_output.airline_type = :airline_type |
||
| 2739 | ORDER BY spotter_output.airline_icao ASC"; |
||
| 2740 | $query_data = array(':airline_type' => $airline_type); |
||
| 2741 | } |
||
| 2742 | |||
| 2743 | $sth = $this->db->prepare($query); |
||
| 2744 | $sth->execute($query_data); |
||
| 2745 | |||
| 2746 | $airline_array = array(); |
||
| 2747 | $temp_array = array(); |
||
| 2748 | |||
| 2749 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2750 | { |
||
| 2751 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 2752 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 2753 | $temp_array['airline_type'] = $row['airline_type']; |
||
| 2754 | |||
| 2755 | $airline_array[] = $temp_array; |
||
| 2756 | } |
||
| 2757 | return $airline_array; |
||
| 2758 | } |
||
| 2759 | |||
| 2760 | /** |
||
| 2761 | * Gets a list of all alliance names |
||
| 2762 | * |
||
| 2763 | * @return Array list of alliance names |
||
| 2764 | * |
||
| 2765 | */ |
||
| 2766 | public function getAllAllianceNames($forsource = NULL,$filters = array()) |
||
| 2767 | { |
||
| 2768 | global $globalAirlinesSource,$globalVATSIM, $globalIVAO; |
||
| 2769 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2770 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $forsource = $globalAirlinesSource; |
||
| 2771 | elseif (isset($globalVATSIM) && $globalVATSIM) $forsource = 'vatsim'; |
||
| 2772 | elseif (isset($globalIVAO) && $globalIVAO) $forsource = 'ivao'; |
||
| 2773 | if ($forsource === NULL) { |
||
| 2774 | $query = "SELECT DISTINCT alliance FROM airlines WHERE alliance IS NOT NULL AND forsource IS NULL ORDER BY alliance ASC"; |
||
| 2775 | $query_data = array(); |
||
| 2776 | } else { |
||
| 2777 | $query = "SELECT DISTINCT alliance FROM airlines WHERE alliance IS NOT NULL AND forsource = :forsource ORDER BY alliance ASC"; |
||
| 2778 | $query_data = array(':forsource' => $forsource); |
||
| 2779 | } |
||
| 2780 | |||
| 2781 | $sth = $this->db->prepare($query); |
||
| 2782 | $sth->execute($query_data); |
||
| 2783 | |||
| 2784 | $alliance_array = array(); |
||
| 2785 | $alliance_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2786 | return $alliance_array; |
||
| 2787 | } |
||
| 2788 | |||
| 2789 | /** |
||
| 2790 | * Gets a list of all airline countries |
||
| 2791 | * |
||
| 2792 | * @return Array list of airline countries |
||
| 2793 | * |
||
| 2794 | */ |
||
| 2795 | public function getAllAirlineCountries($filters = array()) |
||
| 2796 | { |
||
| 2797 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2798 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
| 2799 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' |
||
| 2800 | ORDER BY spotter_output.airline_country ASC"; |
||
| 2801 | |||
| 2802 | //$query = "SELECT DISTINCT country AS airline_country FROM airlines WHERE country <> '' AND active = 'Y' ORDER BY country ASC"; |
||
| 2803 | $sth = $this->db->prepare($query); |
||
| 2804 | $sth->execute(); |
||
| 2805 | |||
| 2806 | $airline_array = array(); |
||
| 2807 | $temp_array = array(); |
||
| 2808 | |||
| 2809 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2810 | { |
||
| 2811 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 2812 | |||
| 2813 | $airline_array[] = $temp_array; |
||
| 2814 | } |
||
| 2815 | |||
| 2816 | return $airline_array; |
||
| 2817 | } |
||
| 2818 | |||
| 2819 | |||
| 2820 | |||
| 2821 | /** |
||
| 2822 | * Gets a list of all departure & arrival names |
||
| 2823 | * |
||
| 2824 | * @return Array list of airport names |
||
| 2825 | * |
||
| 2826 | */ |
||
| 2827 | public function getAllAirportNames($filters = array()) |
||
| 2828 | { |
||
| 2829 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2830 | $airport_array = array(); |
||
| 2831 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao AS airport_icao, spotter_output.departure_airport_name AS airport_name, spotter_output.departure_airport_city AS airport_city, spotter_output.departure_airport_country AS airport_country |
||
| 2832 | FROM spotter_output".$filter_query." spotter_output.departure_airport_icao <> '' AND spotter_output.departure_airport_icao <> 'NA' |
||
| 2833 | ORDER BY spotter_output.departure_airport_city ASC"; |
||
| 2834 | |||
| 2835 | //$query = "SELECT DISTINCT icao AS airport_icao, name AS airport_name, city AS airport_city, country AS airport_country FROM airport ORDER BY city ASC"; |
||
| 2836 | $sth = $this->db->prepare($query); |
||
| 2837 | $sth->execute(); |
||
| 2838 | |||
| 2839 | $temp_array = array(); |
||
| 2840 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2841 | { |
||
| 2842 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
| 2843 | $temp_array['airport_name'] = $row['airport_name']; |
||
| 2844 | $temp_array['airport_city'] = $row['airport_city']; |
||
| 2845 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2846 | |||
| 2847 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
| 2848 | } |
||
| 2849 | |||
| 2850 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao AS airport_icao, spotter_output.arrival_airport_name AS airport_name, spotter_output.arrival_airport_city AS airport_city, spotter_output.arrival_airport_country AS airport_country |
||
| 2851 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_icao <> '' AND spotter_output.arrival_airport_icao <> 'NA' |
||
| 2852 | ORDER BY spotter_output.arrival_airport_city ASC"; |
||
| 2853 | |||
| 2854 | $sth = $this->db->prepare($query); |
||
| 2855 | $sth->execute(); |
||
| 2856 | |||
| 2857 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2858 | { |
||
| 2859 | // if ($airport_array[$row['airport_city'].",".$row['airport_name']]['airport_icao'] != $row['airport_icao']) |
||
| 2860 | // { |
||
| 2861 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
| 2862 | $temp_array['airport_name'] = $row['airport_name']; |
||
| 2863 | $temp_array['airport_city'] = $row['airport_city']; |
||
| 2864 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2865 | |||
| 2866 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
| 2867 | // } |
||
| 2868 | } |
||
| 2869 | |||
| 2870 | return $airport_array; |
||
| 2871 | } |
||
| 2872 | |||
| 2873 | /** |
||
| 2874 | * Gets a list of all owner names |
||
| 2875 | * |
||
| 2876 | * @return Array list of owner names |
||
| 2877 | * |
||
| 2878 | */ |
||
| 2879 | public function getAllOwnerNames($filters = array()) |
||
| 2880 | { |
||
| 2881 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2882 | $query = "SELECT DISTINCT spotter_output.owner_name |
||
| 2883 | FROM spotter_output".$filter_query." spotter_output.owner_name <> '' |
||
| 2884 | ORDER BY spotter_output.owner_name ASC"; |
||
| 2885 | |||
| 2886 | $sth = $this->db->prepare($query); |
||
| 2887 | $sth->execute(); |
||
| 2888 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2889 | } |
||
| 2890 | |||
| 2891 | /** |
||
| 2892 | * Gets a list of all pilot names and pilot ids |
||
| 2893 | * |
||
| 2894 | * @return Array list of pilot names and pilot ids |
||
| 2895 | * |
||
| 2896 | */ |
||
| 2897 | public function getAllPilotNames($filters = array()) |
||
| 2898 | { |
||
| 2899 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2900 | $query = "SELECT DISTINCT spotter_output.pilot_name, spotter_output.pilot_id |
||
| 2901 | FROM spotter_output".$filter_query." spotter_output.pilot_name <> '' |
||
| 2902 | ORDER BY spotter_output.pilot_name ASC"; |
||
| 2903 | |||
| 2904 | $sth = $this->db->prepare($query); |
||
| 2905 | $sth->execute(); |
||
| 2906 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2907 | } |
||
| 2908 | |||
| 2909 | |||
| 2910 | /** |
||
| 2911 | * Gets a list of all departure & arrival airport countries |
||
| 2912 | * |
||
| 2913 | * @return Array list of airport countries |
||
| 2914 | * |
||
| 2915 | */ |
||
| 2916 | public function getAllAirportCountries($filters = array()) |
||
| 2917 | { |
||
| 2918 | $airport_array = array(); |
||
| 2919 | |||
| 2920 | /* |
||
| 2921 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
| 2922 | FROM spotter_output |
||
| 2923 | WHERE spotter_output.departure_airport_country <> '' |
||
| 2924 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
| 2925 | */ |
||
| 2926 | $query = "SELECT DISTINCT country AS airport_country FROM airport ORDER BY country ASC"; |
||
| 2927 | |||
| 2928 | $sth = $this->db->prepare($query); |
||
| 2929 | $sth->execute(); |
||
| 2930 | |||
| 2931 | $temp_array = array(); |
||
| 2932 | |||
| 2933 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2934 | { |
||
| 2935 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2936 | |||
| 2937 | $airport_array[$row['airport_country']] = $temp_array; |
||
| 2938 | } |
||
| 2939 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2940 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
| 2941 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' |
||
| 2942 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
| 2943 | |||
| 2944 | $sth = $this->db->prepare($query); |
||
| 2945 | $sth->execute(); |
||
| 2946 | |||
| 2947 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2948 | { |
||
| 2949 | if (isset($airport_array[$row['airport_country']]['airport_country']) && $airport_array[$row['airport_country']]['airport_country'] != $row['airport_country']) |
||
| 2950 | { |
||
| 2951 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2952 | $airport_array[$row['airport_country']] = $temp_array; |
||
| 2953 | } |
||
| 2954 | } |
||
| 2955 | |||
| 2956 | return $airport_array; |
||
| 2957 | } |
||
| 2958 | |||
| 2959 | |||
| 2960 | |||
| 2961 | |||
| 2962 | /** |
||
| 2963 | * Gets a list of all countries (airline, departure airport & arrival airport) |
||
| 2964 | * |
||
| 2965 | * @return Array list of countries |
||
| 2966 | * |
||
| 2967 | */ |
||
| 2968 | public function getAllCountries($filters = array()) |
||
| 2969 | { |
||
| 2970 | $Connection= new Connection($this->db); |
||
| 2971 | if ($Connection->tableExists('countries')) { |
||
| 2972 | $query = "SELECT countries.name AS airport_country |
||
| 2973 | FROM countries |
||
| 2974 | ORDER BY countries.name ASC"; |
||
| 2975 | $sth = $this->db->prepare($query); |
||
| 2976 | $sth->execute(); |
||
| 2977 | |||
| 2978 | $temp_array = array(); |
||
| 2979 | $country_array = array(); |
||
| 2980 | |||
| 2981 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2982 | { |
||
| 2983 | $temp_array['country'] = $row['airport_country']; |
||
| 2984 | $country_array[$row['airport_country']] = $temp_array; |
||
| 2985 | } |
||
| 2986 | } else { |
||
| 2987 | $filter_query = $this->getFilter($filters,true,true); |
||
| 2988 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
| 2989 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' |
||
| 2990 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
| 2991 | |||
| 2992 | $sth = $this->db->prepare($query); |
||
| 2993 | $sth->execute(); |
||
| 2994 | |||
| 2995 | $temp_array = array(); |
||
| 2996 | $country_array = array(); |
||
| 2997 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2998 | { |
||
| 2999 | $temp_array['country'] = $row['airport_country']; |
||
| 3000 | $country_array[$row['airport_country']] = $temp_array; |
||
| 3001 | } |
||
| 3002 | |||
| 3003 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
| 3004 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' |
||
| 3005 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
| 3006 | |||
| 3007 | $sth = $this->db->prepare($query); |
||
| 3008 | $sth->execute(); |
||
| 3009 | |||
| 3010 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3011 | { |
||
| 3012 | if ($country_array[$row['airport_country']]['country'] != $row['airport_country']) |
||
| 3013 | { |
||
| 3014 | $temp_array['country'] = $row['airport_country']; |
||
| 3015 | |||
| 3016 | $country_array[$row['country']] = $temp_array; |
||
| 3017 | } |
||
| 3018 | } |
||
| 3019 | |||
| 3020 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
| 3021 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' |
||
| 3022 | ORDER BY spotter_output.airline_country ASC"; |
||
| 3023 | |||
| 3024 | $sth = $this->db->prepare($query); |
||
| 3025 | $sth->execute(); |
||
| 3026 | |||
| 3027 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3028 | { |
||
| 3029 | if (isset($country_array[$row['airline_country']]['country']) && $country_array[$row['airline_country']]['country'] != $row['airline_country']) |
||
| 3030 | { |
||
| 3031 | $temp_array['country'] = $row['airline_country']; |
||
| 3032 | |||
| 3033 | $country_array[$row['country']] = $temp_array; |
||
| 3034 | } |
||
| 3035 | } |
||
| 3036 | } |
||
| 3037 | return $country_array; |
||
| 3038 | } |
||
| 3039 | |||
| 3040 | |||
| 3041 | |||
| 3042 | |||
| 3043 | /** |
||
| 3044 | * Gets a list of all idents/callsigns |
||
| 3045 | * |
||
| 3046 | * @return Array list of ident/callsign names |
||
| 3047 | * |
||
| 3048 | */ |
||
| 3049 | public function getAllIdents($filters = array()) |
||
| 3050 | { |
||
| 3051 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3052 | $query = "SELECT DISTINCT spotter_output.ident |
||
| 3053 | FROM spotter_output".$filter_query." spotter_output.ident <> '' |
||
| 3054 | ORDER BY spotter_output.date ASC LIMIT 700 OFFSET 0"; |
||
| 3055 | |||
| 3056 | $sth = $this->db->prepare($query); |
||
| 3057 | $sth->execute(); |
||
| 3058 | |||
| 3059 | $ident_array = array(); |
||
| 3060 | $temp_array = array(); |
||
| 3061 | |||
| 3062 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3063 | { |
||
| 3064 | $temp_array['ident'] = $row['ident']; |
||
| 3065 | $ident_array[] = $temp_array; |
||
| 3066 | } |
||
| 3067 | |||
| 3068 | return $ident_array; |
||
| 3069 | } |
||
| 3070 | |||
| 3071 | /** |
||
| 3072 | * Get a list of flights from airport since 7 days |
||
| 3073 | * @return Array number, icao, name and city of airports |
||
| 3074 | */ |
||
| 3075 | |||
| 3076 | public function getLast7DaysAirportsDeparture($airport_icao = '',$filters = array()) { |
||
| 3077 | global $globalTimezone, $globalDBdriver; |
||
| 3078 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3079 | if ($globalTimezone != '') { |
||
| 3080 | date_default_timezone_set($globalTimezone); |
||
| 3081 | $datetime = new DateTime(); |
||
| 3082 | $offset = $datetime->format('P'); |
||
| 3083 | } else $offset = '+00:00'; |
||
| 3084 | if ($airport_icao == '') { |
||
| 3085 | if ($globalDBdriver == 'mysql') { |
||
| 3086 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' AND departure_airport_icao <> '' GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3087 | } else { |
||
| 3088 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' AND departure_airport_icao <> '' GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3089 | } |
||
| 3090 | $sth = $this->db->prepare($query); |
||
| 3091 | $sth->execute(array(':offset' => $offset)); |
||
| 3092 | } else { |
||
| 3093 | if ($globalDBdriver == 'mysql') { |
||
| 3094 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3095 | } else { |
||
| 3096 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3097 | } |
||
| 3098 | $sth = $this->db->prepare($query); |
||
| 3099 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3100 | } |
||
| 3101 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3102 | } |
||
| 3103 | |||
| 3104 | /** |
||
| 3105 | * Get a list of flights from airport since 7 days |
||
| 3106 | * @return Array number, icao, name and city of airports |
||
| 3107 | */ |
||
| 3108 | |||
| 3109 | public function getLast7DaysAirportsDepartureByAirlines($airport_icao = '') { |
||
| 3110 | global $globalTimezone, $globalDBdriver; |
||
| 3111 | if ($globalTimezone != '') { |
||
| 3112 | date_default_timezone_set($globalTimezone); |
||
| 3113 | $datetime = new DateTime(); |
||
| 3114 | $offset = $datetime->format('P'); |
||
| 3115 | } else $offset = '+00:00'; |
||
| 3116 | if ($airport_icao == '') { |
||
| 3117 | if ($globalDBdriver == 'mysql') { |
||
| 3118 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' AND departure_airport_icao <> '' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3119 | } else { |
||
| 3120 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' AND departure_airport_icao <> '' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3121 | } |
||
| 3122 | $sth = $this->db->prepare($query); |
||
| 3123 | $sth->execute(array(':offset' => $offset)); |
||
| 3124 | } else { |
||
| 3125 | if ($globalDBdriver == 'mysql') { |
||
| 3126 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3127 | } else { |
||
| 3128 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
| 3129 | } |
||
| 3130 | $sth = $this->db->prepare($query); |
||
| 3131 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3132 | } |
||
| 3133 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3134 | } |
||
| 3135 | |||
| 3136 | /** |
||
| 3137 | * Get a list of flights from detected airport since 7 days |
||
| 3138 | * @return Array number, icao, name and city of airports |
||
| 3139 | */ |
||
| 3140 | |||
| 3141 | public function getLast7DaysDetectedAirportsDeparture($airport_icao = '', $filters = array()) { |
||
| 3142 | global $globalTimezone, $globalDBdriver; |
||
| 3143 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3144 | if ($globalTimezone != '') { |
||
| 3145 | date_default_timezone_set($globalTimezone); |
||
| 3146 | $datetime = new DateTime(); |
||
| 3147 | $offset = $datetime->format('P'); |
||
| 3148 | } else $offset = '+00:00'; |
||
| 3149 | if ($airport_icao == '') { |
||
| 3150 | if ($globalDBdriver == 'mysql') { |
||
| 3151 | $query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3152 | FROM airport, spotter_output".$filter_query." airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao <> 'NA' AND real_departure_airport_icao <> '' |
||
| 3153 | GROUP BY real_departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3154 | } else { |
||
| 3155 | $query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3156 | FROM airport, spotter_output".$filter_query." airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao <> 'NA' AND real_departure_airport_icao <> '' |
||
| 3157 | GROUP BY real_departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3158 | } |
||
| 3159 | $sth = $this->db->prepare($query); |
||
| 3160 | $sth->execute(array(':offset' => $offset)); |
||
| 3161 | } else { |
||
| 3162 | if ($globalDBdriver == 'mysql') { |
||
| 3163 | $query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3164 | FROM airport,spotter_output".$filter_query." airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao = :airport_icao |
||
| 3165 | GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3166 | } else { |
||
| 3167 | $query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3168 | FROM airport,spotter_output".$filter_query." airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3169 | } |
||
| 3170 | $sth = $this->db->prepare($query); |
||
| 3171 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3172 | } |
||
| 3173 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3174 | } |
||
| 3175 | |||
| 3176 | /** |
||
| 3177 | * Get a list of flights from detected airport since 7 days |
||
| 3178 | * @return Array number, icao, name and city of airports |
||
| 3179 | */ |
||
| 3180 | |||
| 3181 | public function getLast7DaysDetectedAirportsDepartureByAirlines($airport_icao = '') { |
||
| 3182 | global $globalTimezone, $globalDBdriver; |
||
| 3183 | if ($globalTimezone != '') { |
||
| 3184 | date_default_timezone_set($globalTimezone); |
||
| 3185 | $datetime = new DateTime(); |
||
| 3186 | $offset = $datetime->format('P'); |
||
| 3187 | } else $offset = '+00:00'; |
||
| 3188 | if ($airport_icao == '') { |
||
| 3189 | if ($globalDBdriver == 'mysql') { |
||
| 3190 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3191 | FROM `spotter_output`, airport |
||
| 3192 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao <> 'NA' AND real_departure_airport_icao <> '' |
||
| 3193 | GROUP BY spotter_output.airline_icao, real_departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3194 | } else { |
||
| 3195 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3196 | FROM spotter_output, airport |
||
| 3197 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao <> 'NA' AND real_departure_airport_icao <> '' |
||
| 3198 | GROUP BY spotter_output.airline_icao, real_departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3199 | } |
||
| 3200 | $sth = $this->db->prepare($query); |
||
| 3201 | $sth->execute(array(':offset' => $offset)); |
||
| 3202 | } else { |
||
| 3203 | if ($globalDBdriver == 'mysql') { |
||
| 3204 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3205 | FROM `spotter_output`, airport |
||
| 3206 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao = :airport_icao |
||
| 3207 | GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3208 | } else { |
||
| 3209 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3210 | FROM spotter_output, airport |
||
| 3211 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao = :airport_icao GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
| 3212 | } |
||
| 3213 | $sth = $this->db->prepare($query); |
||
| 3214 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3215 | } |
||
| 3216 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3217 | } |
||
| 3218 | |||
| 3219 | |||
| 3220 | /** |
||
| 3221 | * Get a list of flights to airport since 7 days |
||
| 3222 | * @return Array number, icao, name and city of airports |
||
| 3223 | */ |
||
| 3224 | |||
| 3225 | public function getLast7DaysAirportsArrival($airport_icao = '', $filters = array()) { |
||
| 3226 | global $globalTimezone, $globalDBdriver; |
||
| 3227 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3228 | if ($globalTimezone != '') { |
||
| 3229 | date_default_timezone_set($globalTimezone); |
||
| 3230 | $datetime = new DateTime(); |
||
| 3231 | $offset = $datetime->format('P'); |
||
| 3232 | } else $offset = '+00:00'; |
||
| 3233 | if ($airport_icao == '') { |
||
| 3234 | if ($globalDBdriver == 'mysql') { |
||
| 3235 | $query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' GROUP BY arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3236 | } else { |
||
| 3237 | $query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' GROUP BY arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3238 | } |
||
| 3239 | $sth = $this->db->prepare($query); |
||
| 3240 | $sth->execute(array(':offset' => $offset)); |
||
| 3241 | } else { |
||
| 3242 | if ($globalDBdriver == 'mysql') { |
||
| 3243 | $query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao GROUP BY arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3244 | } else { |
||
| 3245 | $query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao GROUP BY arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3246 | } |
||
| 3247 | $sth = $this->db->prepare($query); |
||
| 3248 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3249 | } |
||
| 3250 | |||
| 3251 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3252 | } |
||
| 3253 | |||
| 3254 | |||
| 3255 | /** |
||
| 3256 | * Get a list of flights detected to airport since 7 days |
||
| 3257 | * @return Array number, icao, name and city of airports |
||
| 3258 | */ |
||
| 3259 | |||
| 3260 | public function getLast7DaysDetectedAirportsArrival($airport_icao = '',$filters = array()) { |
||
| 3261 | global $globalTimezone, $globalDBdriver; |
||
| 3262 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3263 | if ($globalTimezone != '') { |
||
| 3264 | date_default_timezone_set($globalTimezone); |
||
| 3265 | $datetime = new DateTime(); |
||
| 3266 | $offset = $datetime->format('P'); |
||
| 3267 | } else $offset = '+00:00'; |
||
| 3268 | if ($airport_icao == '') { |
||
| 3269 | if ($globalDBdriver == 'mysql') { |
||
| 3270 | $query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3271 | FROM airport,spotter_output".$filter_query." airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' |
||
| 3272 | GROUP BY real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3273 | } else { |
||
| 3274 | $query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3275 | FROM airport,spotter_output".$filter_query." airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' |
||
| 3276 | GROUP BY real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3277 | } |
||
| 3278 | $sth = $this->db->prepare($query); |
||
| 3279 | $sth->execute(array(':offset' => $offset)); |
||
| 3280 | } else { |
||
| 3281 | if ($globalDBdriver == 'mysql') { |
||
| 3282 | $query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3283 | FROM airport,spotter_output".$filter_query." airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao |
||
| 3284 | GROUP BY real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3285 | } else { |
||
| 3286 | $query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3287 | FROM airport, spotter_output".$filter_query." airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao |
||
| 3288 | GROUP BY real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3289 | } |
||
| 3290 | $sth = $this->db->prepare($query); |
||
| 3291 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3292 | } |
||
| 3293 | |||
| 3294 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3295 | } |
||
| 3296 | |||
| 3297 | |||
| 3298 | /** |
||
| 3299 | * Get a list of flights to airport since 7 days |
||
| 3300 | * @return Array number, icao, name and city of airports |
||
| 3301 | */ |
||
| 3302 | |||
| 3303 | public function getLast7DaysAirportsArrivalByAirlines($airport_icao = '') { |
||
| 3304 | global $globalTimezone, $globalDBdriver; |
||
| 3305 | if ($globalTimezone != '') { |
||
| 3306 | date_default_timezone_set($globalTimezone); |
||
| 3307 | $datetime = new DateTime(); |
||
| 3308 | $offset = $datetime->format('P'); |
||
| 3309 | } else $offset = '+00:00'; |
||
| 3310 | if ($airport_icao == '') { |
||
| 3311 | if ($globalDBdriver == 'mysql') { |
||
| 3312 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3313 | } else { |
||
| 3314 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3315 | } |
||
| 3316 | $sth = $this->db->prepare($query); |
||
| 3317 | $sth->execute(array(':offset' => $offset)); |
||
| 3318 | } else { |
||
| 3319 | if ($globalDBdriver == 'mysql') { |
||
| 3320 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3321 | } else { |
||
| 3322 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
| 3323 | } |
||
| 3324 | $sth = $this->db->prepare($query); |
||
| 3325 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3326 | } |
||
| 3327 | |||
| 3328 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3329 | } |
||
| 3330 | |||
| 3331 | |||
| 3332 | /** |
||
| 3333 | * Get a list of flights detected to airport since 7 days |
||
| 3334 | * @return Array number, icao, name and city of airports |
||
| 3335 | */ |
||
| 3336 | |||
| 3337 | public function getLast7DaysDetectedAirportsArrivalByAirlines($airport_icao = '') { |
||
| 3338 | global $globalTimezone, $globalDBdriver; |
||
| 3339 | if ($globalTimezone != '') { |
||
| 3340 | date_default_timezone_set($globalTimezone); |
||
| 3341 | $datetime = new DateTime(); |
||
| 3342 | $offset = $datetime->format('P'); |
||
| 3343 | } else $offset = '+00:00'; |
||
| 3344 | if ($airport_icao == '') { |
||
| 3345 | if ($globalDBdriver == 'mysql') { |
||
| 3346 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3347 | FROM `spotter_output`, airport |
||
| 3348 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' |
||
| 3349 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3350 | } else { |
||
| 3351 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3352 | FROM spotter_output, airport |
||
| 3353 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' AND arrival_airport_icao <> '' |
||
| 3354 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3355 | } |
||
| 3356 | $sth = $this->db->prepare($query); |
||
| 3357 | $sth->execute(array(':offset' => $offset)); |
||
| 3358 | } else { |
||
| 3359 | if ($globalDBdriver == 'mysql') { |
||
| 3360 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
| 3361 | FROM `spotter_output`, airport |
||
| 3362 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao |
||
| 3363 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3364 | } else { |
||
| 3365 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3366 | FROM spotter_output, airport |
||
| 3367 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao |
||
| 3368 | GROUP BY spotter_output.airline_icao,real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
| 3369 | } |
||
| 3370 | $sth = $this->db->prepare($query); |
||
| 3371 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 3372 | } |
||
| 3373 | |||
| 3374 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 3375 | } |
||
| 3376 | |||
| 3377 | |||
| 3378 | /** |
||
| 3379 | * Gets a list of all dates |
||
| 3380 | * |
||
| 3381 | * @return Array list of date names |
||
| 3382 | * |
||
| 3383 | */ |
||
| 3384 | public function getAllDates() |
||
| 3385 | { |
||
| 3386 | global $globalTimezone, $globalDBdriver; |
||
| 3387 | if ($globalTimezone != '') { |
||
| 3388 | date_default_timezone_set($globalTimezone); |
||
| 3389 | $datetime = new DateTime(); |
||
| 3390 | $offset = $datetime->format('P'); |
||
| 3391 | } else $offset = '+00:00'; |
||
| 3392 | |||
| 3393 | if ($globalDBdriver == 'mysql') { |
||
| 3394 | $query = "SELECT DISTINCT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) as date |
||
| 3395 | FROM spotter_output |
||
| 3396 | WHERE spotter_output.date <> '' |
||
| 3397 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
| 3398 | } else { |
||
| 3399 | $query = "SELECT DISTINCT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 3400 | FROM spotter_output |
||
| 3401 | WHERE spotter_output.date <> '' |
||
| 3402 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
| 3403 | } |
||
| 3404 | |||
| 3405 | $sth = $this->db->prepare($query); |
||
| 3406 | $sth->execute(array(':offset' => $offset)); |
||
| 3407 | |||
| 3408 | $date_array = array(); |
||
| 3409 | $temp_array = array(); |
||
| 3410 | |||
| 3411 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3412 | { |
||
| 3413 | $temp_array['date'] = $row['date']; |
||
| 3414 | |||
| 3415 | $date_array[] = $temp_array; |
||
| 3416 | } |
||
| 3417 | |||
| 3418 | return $date_array; |
||
| 3419 | } |
||
| 3420 | |||
| 3421 | |||
| 3422 | |||
| 3423 | /** |
||
| 3424 | * Gets all route combinations |
||
| 3425 | * |
||
| 3426 | * @return Array the route list |
||
| 3427 | * |
||
| 3428 | */ |
||
| 3429 | public function getAllRoutes() |
||
| 3430 | { |
||
| 3431 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao |
||
| 3432 | FROM spotter_output |
||
| 3433 | WHERE spotter_output.ident <> '' |
||
| 3434 | GROUP BY route |
||
| 3435 | ORDER BY route ASC"; |
||
| 3436 | |||
| 3437 | $sth = $this->db->prepare($query); |
||
| 3438 | $sth->execute(); |
||
| 3439 | |||
| 3440 | $routes_array = array(); |
||
| 3441 | $temp_array = array(); |
||
| 3442 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3443 | { |
||
| 3444 | $temp_array['route'] = $row['route']; |
||
| 3445 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 3446 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 3447 | |||
| 3448 | $routes_array[] = $temp_array; |
||
| 3449 | } |
||
| 3450 | return $routes_array; |
||
| 3451 | } |
||
| 3452 | |||
| 3453 | /** |
||
| 3454 | * Update ident spotter data |
||
| 3455 | * |
||
| 3456 | * @param String $flightaware_id the ID from flightaware |
||
| 3457 | * @param String $ident the flight ident |
||
| 3458 | * @return String success or false |
||
| 3459 | * |
||
| 3460 | */ |
||
| 3461 | public function updateIdentSpotterData($flightaware_id = '', $ident = '',$fromsource = NULL) |
||
| 3462 | { |
||
| 3463 | if (!is_numeric(substr($ident, 0, 3))) |
||
| 3464 | { |
||
| 3465 | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
||
| 3466 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2),$fromsource); |
||
| 3467 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
| 3468 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3),$fromsource); |
||
| 3469 | } else { |
||
| 3470 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3471 | } |
||
| 3472 | if (count($airline_array) == 0) { |
||
| 3473 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3474 | } |
||
| 3475 | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
||
| 3476 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3477 | } |
||
| 3478 | } else { |
||
| 3479 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3480 | } |
||
| 3481 | $airline_name = $airline_array[0]['name']; |
||
| 3482 | $airline_icao = $airline_array[0]['icao']; |
||
| 3483 | $airline_country = $airline_array[0]['country']; |
||
| 3484 | $airline_type = $airline_array[0]['type']; |
||
| 3485 | |||
| 3486 | |||
| 3487 | $query = 'UPDATE spotter_output SET ident = :ident, airline_name = :airline_name, airline_icao = :airline_icao, airline_country = :airline_country, airline_type = :airline_type WHERE flightaware_id = :flightaware_id'; |
||
| 3488 | $query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type); |
||
| 3489 | |||
| 3490 | try { |
||
| 3491 | $sth = $this->db->prepare($query); |
||
| 3492 | $sth->execute($query_values); |
||
| 3493 | } catch (PDOException $e) { |
||
| 3494 | return "error : ".$e->getMessage(); |
||
| 3495 | } |
||
| 3496 | |||
| 3497 | return "success"; |
||
| 3498 | |||
| 3499 | } |
||
| 3500 | /** |
||
| 3501 | * Update latest spotter data |
||
| 3502 | * |
||
| 3503 | * @param String $flightaware_id the ID from flightaware |
||
| 3504 | * @param String $ident the flight ident |
||
| 3505 | * @param String $arrival_airport_icao the arrival airport |
||
| 3506 | * @return String success or false |
||
| 3507 | * |
||
| 3508 | */ |
||
| 3509 | public function updateLatestSpotterData($flightaware_id = '', $ident = '', $latitude = '', $longitude = '', $altitude = '', $ground = false, $groundspeed = NULL, $date = '', $arrival_airport_icao = '',$arrival_airport_time = '') |
||
| 3510 | { |
||
| 3511 | if ($groundspeed == '') $groundspeed = NULL; |
||
| 3512 | $query = 'UPDATE spotter_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_altitude = :last_altitude, last_ground = :last_ground, last_seen = :last_seen, real_arrival_airport_icao = :real_arrival_airport_icao, real_arrival_airport_time = :real_arrival_airport_time, last_ground_speed = :last_ground_speed WHERE flightaware_id = :flightaware_id'; |
||
| 3513 | $query_values = array(':flightaware_id' => $flightaware_id,':real_arrival_airport_icao' => $arrival_airport_icao,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_altitude' => $altitude,':last_ground_speed' => $groundspeed,':last_seen' => $date,':real_arrival_airport_time' => $arrival_airport_time, ':last_ground' => $ground, ':ident' => $ident); |
||
| 3514 | |||
| 3515 | try { |
||
| 3516 | $sth = $this->db->prepare($query); |
||
| 3517 | $sth->execute($query_values); |
||
| 3518 | } catch (PDOException $e) { |
||
| 3519 | return "error : ".$e->getMessage(); |
||
| 3520 | } |
||
| 3521 | |||
| 3522 | return "success"; |
||
| 3523 | |||
| 3524 | } |
||
| 3525 | |||
| 3526 | /** |
||
| 3527 | * Adds a new spotter data |
||
| 3528 | * |
||
| 3529 | * @param String $flightaware_id the ID from flightaware |
||
| 3530 | * @param String $ident the flight ident |
||
| 3531 | * @param String $aircraft_icao the aircraft type |
||
| 3532 | * @param String $departure_airport_icao the departure airport |
||
| 3533 | * @param String $arrival_airport_icao the arrival airport |
||
| 3534 | * @param String $latitude latitude of flight |
||
| 3535 | * @param String $longitude latitude of flight |
||
| 3536 | * @param String $waypoints waypoints of flight |
||
| 3537 | * @param String $altitude altitude of flight |
||
| 3538 | * @param String $heading heading of flight |
||
| 3539 | * @param String $groundspeed speed of flight |
||
| 3540 | * @param String $date date of flight |
||
| 3541 | * @param String $departure_airport_time departure time of flight |
||
| 3542 | * @param String $arrival_airport_time arrival time of flight |
||
| 3543 | * @param String $squawk squawk code of flight |
||
| 3544 | * @param String $route_stop route stop of flight |
||
| 3545 | * @param String $highlight highlight or not |
||
| 3546 | * @param String $ModeS ModesS code of flight |
||
| 3547 | * @param String $registration registration code of flight |
||
| 3548 | * @param String $pilot_id pilot id of flight (for virtual airlines) |
||
| 3549 | * @param String $pilot_name pilot name of flight (for virtual airlines) |
||
| 3550 | * @param String $verticalrate vertival rate of flight |
||
| 3551 | * @return String success or false |
||
| 3552 | */ |
||
| 3553 | public function addSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '', $departure_airport_time = '', $arrival_airport_time = '',$squawk = '', $route_stop = '', $highlight = '', $ModeS = '', $registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $ground = false,$format_source = '', $source_name = '') |
||
| 3554 | { |
||
| 3555 | global $globalURL, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalDebugTimeElapsed, $globalAirlinesSource, $globalVAM; |
||
| 3556 | |||
| 3557 | //if (isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
||
| 3558 | $Image = new Image($this->db); |
||
| 3559 | $Common = new Common(); |
||
| 3560 | |||
| 3561 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
| 3562 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
| 3563 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
| 3564 | if (!isset($globalVAM)) $globalVAM = FALSE; |
||
| 3565 | date_default_timezone_set('UTC'); |
||
| 3566 | |||
| 3567 | //getting the registration |
||
| 3568 | if ($flightaware_id != "" && $registration == '') |
||
| 3569 | { |
||
| 3570 | if (!is_string($flightaware_id)) |
||
| 3571 | { |
||
| 3572 | return false; |
||
| 3573 | } else { |
||
| 3574 | if ($ModeS != '') { |
||
| 3575 | $timeelapsed = microtime(true); |
||
| 3576 | $registration = $this->getAircraftRegistrationBymodeS($ModeS); |
||
| 3577 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3578 | } else { |
||
| 3579 | $myhex = explode('-',$flightaware_id); |
||
| 3580 | if (count($myhex) > 0) { |
||
| 3581 | $timeelapsed = microtime(true); |
||
| 3582 | $registration = $this->getAircraftRegistrationBymodeS($myhex[0]); |
||
| 3583 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3584 | } |
||
| 3585 | } |
||
| 3586 | } |
||
| 3587 | } |
||
| 3588 | $fromsource = NULL; |
||
| 3589 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
||
| 3590 | elseif ($format_source == 'vatsimtxt') $fromsource = 'vatsim'; |
||
| 3591 | elseif ($format_source == 'whazzup') $fromsource = 'ivao'; |
||
| 3592 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
||
| 3593 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
||
| 3594 | //getting the airline information |
||
| 3595 | if ($ident != "") |
||
| 3596 | { |
||
| 3597 | if (!is_string($ident)) |
||
| 3598 | { |
||
| 3599 | return false; |
||
| 3600 | } else { |
||
| 3601 | if (!is_numeric(substr($ident, 0, 3)) && !((substr($ident, 0, 3) == 'OGN' || substr($ident, 0, 3) == 'FLR' || substr($ident, 0, 3) == 'ICA') && $format_source == 'aprs')) |
||
| 3602 | { |
||
| 3603 | $timeelapsed = microtime(true); |
||
| 3604 | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
||
| 3605 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2),$fromsource); |
||
| 3606 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
| 3607 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3),$fromsource); |
||
| 3608 | } else { |
||
| 3609 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3610 | } |
||
| 3611 | if (count($airline_array) == 0) { |
||
| 3612 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3613 | } |
||
| 3614 | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
||
| 3615 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3616 | } |
||
| 3617 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3618 | |||
| 3619 | } else { |
||
| 3620 | $timeelapsed = microtime(true); |
||
| 3621 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 3622 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3623 | } |
||
| 3624 | } |
||
| 3625 | } else $airline_array = array(); |
||
| 3626 | |||
| 3627 | //getting the aircraft information |
||
| 3628 | $aircraft_array = array(); |
||
| 3629 | if ($aircraft_icao != '') |
||
| 3630 | { |
||
| 3631 | if (!is_string($aircraft_icao)) |
||
| 3632 | { |
||
| 3633 | return false; |
||
| 3634 | } else { |
||
| 3635 | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
||
| 3636 | { |
||
| 3637 | $timeelapsed = microtime(true); |
||
| 3638 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
| 3639 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3640 | } else { |
||
| 3641 | $timeelapsed = microtime(true); |
||
| 3642 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
| 3643 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3644 | } |
||
| 3645 | } |
||
| 3646 | } else { |
||
| 3647 | if ($ModeS != '') { |
||
| 3648 | $timeelapsed = microtime(true); |
||
| 3649 | $aircraft_icao = $this->getAllAircraftType($ModeS); |
||
| 3650 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAircraftType : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3651 | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
||
| 3652 | { |
||
| 3653 | $timeelapsed = microtime(true); |
||
| 3654 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
| 3655 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3656 | } else { |
||
| 3657 | $timeelapsed = microtime(true); |
||
| 3658 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
| 3659 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3660 | } |
||
| 3661 | } |
||
| 3662 | } |
||
| 3663 | |||
| 3664 | //getting the departure airport information |
||
| 3665 | $departure_airport_array = array(); |
||
| 3666 | $departure_airport_icao = trim($departure_airport_icao); |
||
| 3667 | if ($departure_airport_icao != '') |
||
| 3668 | { |
||
| 3669 | if (!is_string($departure_airport_icao)) |
||
| 3670 | { |
||
| 3671 | return false; |
||
| 3672 | } else { |
||
| 3673 | $timeelapsed = microtime(true); |
||
| 3674 | $departure_airport_array = $this->getAllAirportInfo($departure_airport_icao); |
||
| 3675 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3676 | } |
||
| 3677 | } |
||
| 3678 | |||
| 3679 | //getting the arrival airport information |
||
| 3680 | $arrival_airport_array = array(); |
||
| 3681 | $arrival_airport_icao = trim($arrival_airport_icao); |
||
| 3682 | if ($arrival_airport_icao != '') |
||
| 3683 | { |
||
| 3684 | if (!is_string($arrival_airport_icao)) |
||
| 3685 | { |
||
| 3686 | return false; |
||
| 3687 | } else { |
||
| 3688 | $timeelapsed = microtime(true); |
||
| 3689 | $arrival_airport_array = $this->getAllAirportInfo($arrival_airport_icao); |
||
| 3690 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3691 | } |
||
| 3692 | } |
||
| 3693 | |||
| 3694 | if ($latitude != "") |
||
| 3695 | { |
||
| 3696 | if (!is_numeric($latitude)) |
||
| 3697 | { |
||
| 3698 | return false; |
||
| 3699 | } |
||
| 3700 | } |
||
| 3701 | |||
| 3702 | if ($longitude != "") |
||
| 3703 | { |
||
| 3704 | if (!is_numeric($longitude)) |
||
| 3705 | { |
||
| 3706 | return false; |
||
| 3707 | } |
||
| 3708 | } |
||
| 3709 | |||
| 3710 | if ($waypoints != "") |
||
| 3711 | { |
||
| 3712 | if (!is_string($waypoints)) |
||
| 3713 | { |
||
| 3714 | return false; |
||
| 3715 | } |
||
| 3716 | } |
||
| 3717 | |||
| 3718 | if ($altitude != "") |
||
| 3719 | { |
||
| 3720 | if (!is_numeric($altitude)) |
||
| 3721 | { |
||
| 3722 | return false; |
||
| 3723 | } |
||
| 3724 | } else $altitude = 0; |
||
| 3725 | |||
| 3726 | if ($heading != "") |
||
| 3727 | { |
||
| 3728 | if (!is_numeric($heading)) |
||
| 3729 | { |
||
| 3730 | return false; |
||
| 3731 | } |
||
| 3732 | } |
||
| 3733 | |||
| 3734 | if ($groundspeed != "") |
||
| 3735 | { |
||
| 3736 | if (!is_numeric($groundspeed)) |
||
| 3737 | { |
||
| 3738 | return false; |
||
| 3739 | } |
||
| 3740 | } |
||
| 3741 | |||
| 3742 | |||
| 3743 | if ($date == "" || strtotime($date) < time()-20*60)) |
||
|
|
|||
| 3744 | { |
||
| 3745 | $date = date("Y-m-d H:i:s", time()); |
||
| 3746 | } |
||
| 3747 | |||
| 3748 | //getting the aircraft image |
||
| 3749 | if (($registration != "" || $registration != 'NA') && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM) |
||
| 3750 | { |
||
| 3751 | $timeelapsed = microtime(true); |
||
| 3752 | $image_array = $Image->getSpotterImage($registration); |
||
| 3753 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getSpotterImage : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3754 | if (!isset($image_array[0]['registration'])) |
||
| 3755 | { |
||
| 3756 | //echo "Add image !!!! \n"; |
||
| 3757 | $Image->addSpotterImage($registration); |
||
| 3758 | } |
||
| 3759 | $timeelapsed = microtime(true); |
||
| 3760 | $owner_info = $this->getAircraftOwnerByRegistration($registration); |
||
| 3761 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftOwnerByRegistration : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3762 | if ($owner_info['owner'] != '') $aircraft_owner = ucwords(strtolower($owner_info['owner'])); |
||
| 3763 | } |
||
| 3764 | |||
| 3765 | if ($globalIVAO && $aircraft_icao != '') |
||
| 3766 | { |
||
| 3767 | if (isset($airline_array[0]['icao'])) $airline_icao = $airline_array[0]['icao']; |
||
| 3768 | else $airline_icao = ''; |
||
| 3769 | $image_array = $Image->getSpotterImage('',$aircraft_icao,$airline_icao); |
||
| 3770 | if (!isset($image_array[0]['registration'])) |
||
| 3771 | { |
||
| 3772 | //echo "Add image !!!! \n"; |
||
| 3773 | $Image->addSpotterImage('',$aircraft_icao,$airline_icao); |
||
| 3774 | } |
||
| 3775 | } |
||
| 3776 | |||
| 3777 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
| 3778 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 3779 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 3780 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 3781 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3782 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3783 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3784 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3785 | $waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
||
| 3786 | $altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3787 | $heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
||
| 3788 | $groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3789 | $squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
||
| 3790 | $route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
||
| 3791 | $ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
||
| 3792 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
||
| 3793 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
| 3794 | $format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
||
| 3795 | $verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
||
| 3796 | |||
| 3797 | if (count($airline_array) == 0) |
||
| 3798 | { |
||
| 3799 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 3800 | } |
||
| 3801 | if (count($aircraft_array) == 0) |
||
| 3802 | { |
||
| 3803 | $aircraft_array = $this->getAllAircraftInfo('NA'); |
||
| 3804 | } |
||
| 3805 | if (count($departure_airport_array) == 0 || $departure_airport_array[0]['icao'] == '' || $departure_airport_icao == '') |
||
| 3806 | { |
||
| 3807 | $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 3808 | } |
||
| 3809 | if (count($arrival_airport_array) == 0 || $arrival_airport_array[0]['icao'] == '' || $arrival_airport_icao == '') |
||
| 3810 | { |
||
| 3811 | $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 3812 | } |
||
| 3813 | if ($registration == '') $registration = 'NA'; |
||
| 3814 | if ($latitude == '' && $longitude == '') { |
||
| 3815 | $latitude = 0; |
||
| 3816 | $longitude = 0; |
||
| 3817 | } |
||
| 3818 | if ($squawk == '' || $Common->isInteger($squawk) === false) $squawk = NULL; |
||
| 3819 | if ($verticalrate == '' || $Common->isInteger($verticalrate) === false) $verticalrate = NULL; |
||
| 3820 | if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; |
||
| 3821 | if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; |
||
| 3822 | if (!isset($aircraft_owner)) $aircraft_owner = NULL; |
||
| 3823 | $query = "INSERT INTO spotter_output (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop,highlight,ModeS, pilot_id, pilot_name, verticalrate, owner_name, ground, format_source, source_name) |
||
| 3824 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name,:departure_airport_city,:departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date, :departure_airport_time, :arrival_airport_time, :squawk, :route_stop, :highlight, :ModeS, :pilot_id, :pilot_name, :verticalrate, :owner_name,:ground, :format_source, :source_name)"; |
||
| 3825 | |||
| 3826 | $airline_name = $airline_array[0]['name']; |
||
| 3827 | $airline_icao = $airline_array[0]['icao']; |
||
| 3828 | $airline_country = $airline_array[0]['country']; |
||
| 3829 | $airline_type = $airline_array[0]['type']; |
||
| 3830 | if ($airline_type == '') { |
||
| 3831 | $timeelapsed = microtime(true); |
||
| 3832 | $airline_type = $this->getAircraftTypeBymodeS($ModeS); |
||
| 3833 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftTypeBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3834 | } |
||
| 3835 | if ($airline_type == null) $airline_type = ''; |
||
| 3836 | $aircraft_type = $aircraft_array[0]['type']; |
||
| 3837 | $aircraft_manufacturer = $aircraft_array[0]['manufacturer']; |
||
| 3838 | $departure_airport_name = $departure_airport_array[0]['name']; |
||
| 3839 | $departure_airport_city = $departure_airport_array[0]['city']; |
||
| 3840 | $departure_airport_country = $departure_airport_array[0]['country']; |
||
| 3841 | |||
| 3842 | $arrival_airport_name = $arrival_airport_array[0]['name']; |
||
| 3843 | $arrival_airport_city = $arrival_airport_array[0]['city']; |
||
| 3844 | $arrival_airport_country = $arrival_airport_array[0]['country']; |
||
| 3845 | $query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,':aircraft_icao' => $aircraft_icao,':aircraft_type' => $aircraft_type,':aircraft_manufacturer' => $aircraft_manufacturer,':departure_airport_icao' => $departure_airport_icao,':departure_airport_name' => $departure_airport_name,':departure_airport_city' => $departure_airport_city,':departure_airport_country' => $departure_airport_country,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date,':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk, ':route_stop' => $route_stop, ':highlight' => $highlight, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':owner_name' => $aircraft_owner, ':format_source' => $format_source, ':ground' => $ground, ':source_name' => $source_name); |
||
| 3846 | |||
| 3847 | try { |
||
| 3848 | |||
| 3849 | $sth = $this->db->prepare($query); |
||
| 3850 | $sth->execute($query_values); |
||
| 3851 | $this->db = null; |
||
| 3852 | } catch (PDOException $e) { |
||
| 3853 | return "error : ".$e->getMessage(); |
||
| 3854 | } |
||
| 3855 | |||
| 3856 | return "success"; |
||
| 3857 | |||
| 3858 | } |
||
| 3859 | |||
| 3860 | |||
| 3861 | /** |
||
| 3862 | * Gets the aircraft ident within the last hour |
||
| 3863 | * |
||
| 3864 | * @return String the ident |
||
| 3865 | * |
||
| 3866 | */ |
||
| 3867 | public function getIdentFromLastHour($ident) |
||
| 3868 | { |
||
| 3869 | global $globalDBdriver, $globalTimezone; |
||
| 3870 | if ($globalDBdriver == 'mysql') { |
||
| 3871 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
| 3872 | WHERE spotter_output.ident = :ident |
||
| 3873 | AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
||
| 3874 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
| 3875 | $query_data = array(':ident' => $ident); |
||
| 3876 | } else { |
||
| 3877 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
| 3878 | WHERE spotter_output.ident = :ident |
||
| 3879 | AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
||
| 3880 | AND spotter_output.date < now() AT TIME ZONE 'UTC'"; |
||
| 3881 | $query_data = array(':ident' => $ident); |
||
| 3882 | } |
||
| 3883 | |||
| 3884 | $sth = $this->db->prepare($query); |
||
| 3885 | $sth->execute($query_data); |
||
| 3886 | $ident_result=''; |
||
| 3887 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3888 | { |
||
| 3889 | $ident_result = $row['ident']; |
||
| 3890 | } |
||
| 3891 | |||
| 3892 | return $ident_result; |
||
| 3893 | } |
||
| 3894 | |||
| 3895 | |||
| 3896 | /** |
||
| 3897 | * Gets the aircraft data from the last 20 seconds |
||
| 3898 | * |
||
| 3899 | * @return Array the spotter data |
||
| 3900 | * |
||
| 3901 | */ |
||
| 3902 | public function getRealTimeData($q = '') |
||
| 3903 | { |
||
| 3904 | global $globalDBdriver; |
||
| 3905 | $additional_query = ''; |
||
| 3906 | if ($q != "") |
||
| 3907 | { |
||
| 3908 | if (!is_string($q)) |
||
| 3909 | { |
||
| 3910 | return false; |
||
| 3911 | } else { |
||
| 3912 | $q_array = explode(" ", $q); |
||
| 3913 | foreach ($q_array as $q_item){ |
||
| 3914 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
| 3915 | $additional_query .= " AND ("; |
||
| 3916 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
| 3917 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
| 3918 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
| 3919 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
| 3920 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
| 3921 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
| 3922 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
| 3923 | $additional_query .= "(spotter_output.ident like '%".$q_item."%')"; |
||
| 3924 | $additional_query .= ")"; |
||
| 3925 | } |
||
| 3926 | } |
||
| 3927 | } |
||
| 3928 | if ($globalDBdriver == 'mysql') { |
||
| 3929 | $query = "SELECT spotter_output.* FROM spotter_output |
||
| 3930 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." |
||
| 3931 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
| 3932 | } else { |
||
| 3933 | $query = "SELECT spotter_output.* FROM spotter_output |
||
| 3934 | WHERE spotter_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." |
||
| 3935 | AND spotter_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
||
| 3936 | } |
||
| 3937 | $spotter_array = $this->getDataFromDB($query, array()); |
||
| 3938 | |||
| 3939 | return $spotter_array; |
||
| 3940 | } |
||
| 3941 | |||
| 3942 | |||
| 3943 | |||
| 3944 | /** |
||
| 3945 | * Gets all airlines that have flown over |
||
| 3946 | * |
||
| 3947 | * @return Array the airline list |
||
| 3948 | * |
||
| 3949 | */ |
||
| 3950 | public function countAllAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(), $year = '', $month = '', $day = '') |
||
| 3951 | { |
||
| 3952 | global $globalDBdriver; |
||
| 3953 | $filter_query = $this->getFilter($filters,true,true); |
||
| 3954 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3955 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND spotter_output.airline_icao <> 'NA'"; |
||
| 3956 | if ($olderthanmonths > 0) { |
||
| 3957 | if ($globalDBdriver == 'mysql') { |
||
| 3958 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 3959 | } else { |
||
| 3960 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 3961 | } |
||
| 3962 | } |
||
| 3963 | if ($sincedate != '') { |
||
| 3964 | if ($globalDBdriver == 'mysql') { |
||
| 3965 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 3966 | } else { |
||
| 3967 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 3968 | } |
||
| 3969 | } |
||
| 3970 | $query_values = array(); |
||
| 3971 | if ($year != '') { |
||
| 3972 | if ($globalDBdriver == 'mysql') { |
||
| 3973 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 3974 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 3975 | } else { |
||
| 3976 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 3977 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 3978 | } |
||
| 3979 | } |
||
| 3980 | if ($month != '') { |
||
| 3981 | if ($globalDBdriver == 'mysql') { |
||
| 3982 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 3983 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 3984 | } else { |
||
| 3985 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 3986 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 3987 | } |
||
| 3988 | } |
||
| 3989 | if ($day != '') { |
||
| 3990 | if ($globalDBdriver == 'mysql') { |
||
| 3991 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 3992 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 3993 | } else { |
||
| 3994 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 3995 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 3996 | } |
||
| 3997 | } |
||
| 3998 | $query .= " GROUP BY spotter_output.airline_name,spotter_output.airline_icao, spotter_output.airline_country ORDER BY airline_count DESC"; |
||
| 3999 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4000 | |||
| 4001 | $sth = $this->db->prepare($query); |
||
| 4002 | $sth->execute($query_values); |
||
| 4003 | $airline_array = array(); |
||
| 4004 | $temp_array = array(); |
||
| 4005 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4006 | { |
||
| 4007 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4008 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4009 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4010 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4011 | $airline_array[] = $temp_array; |
||
| 4012 | } |
||
| 4013 | return $airline_array; |
||
| 4014 | } |
||
| 4015 | |||
| 4016 | /** |
||
| 4017 | * Gets all pilots that have flown over |
||
| 4018 | * |
||
| 4019 | * @return Array the pilots list |
||
| 4020 | * |
||
| 4021 | */ |
||
| 4022 | public function countAllPilots($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '',$day = '') |
||
| 4023 | { |
||
| 4024 | global $globalDBdriver; |
||
| 4025 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4026 | $query = "SELECT DISTINCT spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count, spotter_output.format_source |
||
| 4027 | FROM spotter_output".$filter_query." spotter_output.pilot_id <> ''"; |
||
| 4028 | if ($olderthanmonths > 0) { |
||
| 4029 | if ($globalDBdriver == 'mysql') { |
||
| 4030 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 4031 | } else { |
||
| 4032 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 4033 | } |
||
| 4034 | } |
||
| 4035 | if ($sincedate != '') { |
||
| 4036 | if ($globalDBdriver == 'mysql') { |
||
| 4037 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 4038 | } else { |
||
| 4039 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4040 | } |
||
| 4041 | } |
||
| 4042 | $query_values = array(); |
||
| 4043 | if ($year != '') { |
||
| 4044 | if ($globalDBdriver == 'mysql') { |
||
| 4045 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 4046 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4047 | } else { |
||
| 4048 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 4049 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4050 | } |
||
| 4051 | } |
||
| 4052 | if ($month != '') { |
||
| 4053 | if ($globalDBdriver == 'mysql') { |
||
| 4054 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 4055 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4056 | } else { |
||
| 4057 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 4058 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4059 | } |
||
| 4060 | } |
||
| 4061 | if ($day != '') { |
||
| 4062 | if ($globalDBdriver == 'mysql') { |
||
| 4063 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 4064 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4065 | } else { |
||
| 4066 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 4067 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4068 | } |
||
| 4069 | } |
||
| 4070 | |||
| 4071 | $query .= " GROUP BY spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.format_source ORDER BY pilot_count DESC"; |
||
| 4072 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4073 | |||
| 4074 | |||
| 4075 | $sth = $this->db->prepare($query); |
||
| 4076 | $sth->execute($query_values); |
||
| 4077 | $airline_array = array(); |
||
| 4078 | $temp_array = array(); |
||
| 4079 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4080 | { |
||
| 4081 | $temp_array['pilot_name'] = $row['pilot_name']; |
||
| 4082 | $temp_array['pilot_id'] = $row['pilot_id']; |
||
| 4083 | $temp_array['pilot_count'] = $row['pilot_count']; |
||
| 4084 | $temp_array['format_source'] = $row['format_source']; |
||
| 4085 | $airline_array[] = $temp_array; |
||
| 4086 | } |
||
| 4087 | return $airline_array; |
||
| 4088 | } |
||
| 4089 | |||
| 4090 | /** |
||
| 4091 | * Gets all pilots that have flown over |
||
| 4092 | * |
||
| 4093 | * @return Array the pilots list |
||
| 4094 | * |
||
| 4095 | */ |
||
| 4096 | public function countAllPilotsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '') |
||
| 4097 | { |
||
| 4098 | global $globalDBdriver; |
||
| 4099 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count, spotter_output.format_source |
||
| 4100 | FROM spotter_output WHERE spotter_output.pilot_id <> '' "; |
||
| 4101 | if ($olderthanmonths > 0) { |
||
| 4102 | if ($globalDBdriver == 'mysql') { |
||
| 4103 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4104 | } else { |
||
| 4105 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 4106 | } |
||
| 4107 | } |
||
| 4108 | if ($sincedate != '') { |
||
| 4109 | if ($globalDBdriver == 'mysql') { |
||
| 4110 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 4111 | } else { |
||
| 4112 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4113 | } |
||
| 4114 | } |
||
| 4115 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.format_source ORDER BY pilot_count DESC"; |
||
| 4116 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4117 | |||
| 4118 | |||
| 4119 | $sth = $this->db->prepare($query); |
||
| 4120 | $sth->execute(); |
||
| 4121 | |||
| 4122 | $airline_array = array(); |
||
| 4123 | $temp_array = array(); |
||
| 4124 | |||
| 4125 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4126 | { |
||
| 4127 | $temp_array['pilot_name'] = $row['pilot_name']; |
||
| 4128 | $temp_array['pilot_id'] = $row['pilot_id']; |
||
| 4129 | $temp_array['pilot_count'] = $row['pilot_count']; |
||
| 4130 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4131 | $temp_array['format_source'] = $row['format_source']; |
||
| 4132 | $airline_array[] = $temp_array; |
||
| 4133 | } |
||
| 4134 | return $airline_array; |
||
| 4135 | } |
||
| 4136 | |||
| 4137 | /** |
||
| 4138 | * Gets all owner that have flown over |
||
| 4139 | * |
||
| 4140 | * @return Array the pilots list |
||
| 4141 | * |
||
| 4142 | */ |
||
| 4143 | public function countAllOwners($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '',$month = '',$day = '') |
||
| 4144 | { |
||
| 4145 | global $globalDBdriver; |
||
| 4146 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4147 | $query = "SELECT DISTINCT spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count |
||
| 4148 | FROM spotter_output".$filter_query." spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL"; |
||
| 4149 | if ($olderthanmonths > 0) { |
||
| 4150 | if ($globalDBdriver == 'mysql') { |
||
| 4151 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 4152 | } else { |
||
| 4153 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 4154 | } |
||
| 4155 | } |
||
| 4156 | if ($sincedate != '') { |
||
| 4157 | if ($globalDBdriver == 'mysql') { |
||
| 4158 | $query .= " AND spotter_output.date > '".$sincedate."' "; |
||
| 4159 | } else { |
||
| 4160 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4161 | } |
||
| 4162 | } |
||
| 4163 | $query_values = array(); |
||
| 4164 | if ($year != '') { |
||
| 4165 | if ($globalDBdriver == 'mysql') { |
||
| 4166 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 4167 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4168 | } else { |
||
| 4169 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 4170 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4171 | } |
||
| 4172 | } |
||
| 4173 | if ($month != '') { |
||
| 4174 | if ($globalDBdriver == 'mysql') { |
||
| 4175 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 4176 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4177 | } else { |
||
| 4178 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 4179 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4180 | } |
||
| 4181 | } |
||
| 4182 | if ($day != '') { |
||
| 4183 | if ($globalDBdriver == 'mysql') { |
||
| 4184 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 4185 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4186 | } else { |
||
| 4187 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 4188 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4189 | } |
||
| 4190 | } |
||
| 4191 | $query .= " GROUP BY spotter_output.owner_name ORDER BY owner_count DESC"; |
||
| 4192 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4193 | |||
| 4194 | $sth = $this->db->prepare($query); |
||
| 4195 | $sth->execute($query_values); |
||
| 4196 | $airline_array = array(); |
||
| 4197 | $temp_array = array(); |
||
| 4198 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4199 | { |
||
| 4200 | $temp_array['owner_name'] = $row['owner_name']; |
||
| 4201 | $temp_array['owner_count'] = $row['owner_count']; |
||
| 4202 | $airline_array[] = $temp_array; |
||
| 4203 | } |
||
| 4204 | return $airline_array; |
||
| 4205 | } |
||
| 4206 | |||
| 4207 | /** |
||
| 4208 | * Gets all owner that have flown over |
||
| 4209 | * |
||
| 4210 | * @return Array the pilots list |
||
| 4211 | * |
||
| 4212 | */ |
||
| 4213 | public function countAllOwnersByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
| 4214 | { |
||
| 4215 | global $globalDBdriver; |
||
| 4216 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4217 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count |
||
| 4218 | FROM spotter_output".$filter_query." spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL "; |
||
| 4219 | if ($olderthanmonths > 0) { |
||
| 4220 | if ($globalDBdriver == 'mysql') { |
||
| 4221 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4222 | } else { |
||
| 4223 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 4224 | } |
||
| 4225 | } |
||
| 4226 | if ($sincedate != '') { |
||
| 4227 | if ($globalDBdriver == 'mysql') { |
||
| 4228 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 4229 | } else { |
||
| 4230 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4231 | } |
||
| 4232 | } |
||
| 4233 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.owner_name ORDER BY owner_count DESC"; |
||
| 4234 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4235 | |||
| 4236 | |||
| 4237 | $sth = $this->db->prepare($query); |
||
| 4238 | $sth->execute(); |
||
| 4239 | |||
| 4240 | $airline_array = array(); |
||
| 4241 | $temp_array = array(); |
||
| 4242 | |||
| 4243 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4244 | { |
||
| 4245 | $temp_array['owner_name'] = $row['owner_name']; |
||
| 4246 | $temp_array['owner_count'] = $row['owner_count']; |
||
| 4247 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4248 | $airline_array[] = $temp_array; |
||
| 4249 | } |
||
| 4250 | return $airline_array; |
||
| 4251 | } |
||
| 4252 | |||
| 4253 | /** |
||
| 4254 | * Gets all airlines that have flown over by aircraft |
||
| 4255 | * |
||
| 4256 | * @return Array the airline list |
||
| 4257 | * |
||
| 4258 | */ |
||
| 4259 | public function countAllAirlinesByAircraft($aircraft_icao,$filters = array()) |
||
| 4260 | { |
||
| 4261 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 4262 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4263 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4264 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 4265 | GROUP BY spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country |
||
| 4266 | ORDER BY airline_count DESC"; |
||
| 4267 | |||
| 4268 | |||
| 4269 | $sth = $this->db->prepare($query); |
||
| 4270 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 4271 | |||
| 4272 | $airline_array = array(); |
||
| 4273 | $temp_array = array(); |
||
| 4274 | |||
| 4275 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4276 | { |
||
| 4277 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4278 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4279 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4280 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4281 | |||
| 4282 | $airline_array[] = $temp_array; |
||
| 4283 | } |
||
| 4284 | |||
| 4285 | return $airline_array; |
||
| 4286 | } |
||
| 4287 | |||
| 4288 | |||
| 4289 | /** |
||
| 4290 | * Gets all airline countries that have flown over by aircraft |
||
| 4291 | * |
||
| 4292 | * @return Array the airline country list |
||
| 4293 | * |
||
| 4294 | */ |
||
| 4295 | public function countAllAirlineCountriesByAircraft($aircraft_icao,$filters = array()) |
||
| 4296 | { |
||
| 4297 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 4298 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4299 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4300 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 4301 | GROUP BY spotter_output.airline_country |
||
| 4302 | ORDER BY airline_country_count DESC |
||
| 4303 | LIMIT 10 OFFSET 0"; |
||
| 4304 | |||
| 4305 | |||
| 4306 | $sth = $this->db->prepare($query); |
||
| 4307 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 4308 | |||
| 4309 | $airline_country_array = array(); |
||
| 4310 | $temp_array = array(); |
||
| 4311 | |||
| 4312 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4313 | { |
||
| 4314 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4315 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4316 | |||
| 4317 | $airline_country_array[] = $temp_array; |
||
| 4318 | } |
||
| 4319 | return $airline_country_array; |
||
| 4320 | } |
||
| 4321 | |||
| 4322 | |||
| 4323 | |||
| 4324 | |||
| 4325 | /** |
||
| 4326 | * Gets all airlines that have flown over by airport |
||
| 4327 | * |
||
| 4328 | * @return Array the airline list |
||
| 4329 | * |
||
| 4330 | */ |
||
| 4331 | public function countAllAirlinesByAirport($airport_icao,$filters = array()) |
||
| 4332 | { |
||
| 4333 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 4334 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4335 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4336 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
| 4337 | GROUP BY spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country |
||
| 4338 | ORDER BY airline_count DESC"; |
||
| 4339 | |||
| 4340 | |||
| 4341 | $sth = $this->db->prepare($query); |
||
| 4342 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 4343 | |||
| 4344 | $airline_array = array(); |
||
| 4345 | $temp_array = array(); |
||
| 4346 | |||
| 4347 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4348 | { |
||
| 4349 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4350 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4351 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4352 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4353 | |||
| 4354 | $airline_array[] = $temp_array; |
||
| 4355 | } |
||
| 4356 | return $airline_array; |
||
| 4357 | } |
||
| 4358 | |||
| 4359 | |||
| 4360 | /** |
||
| 4361 | * Gets all airline countries that have flown over by airport icao |
||
| 4362 | * |
||
| 4363 | * @return Array the airline country list |
||
| 4364 | * |
||
| 4365 | */ |
||
| 4366 | public function countAllAirlineCountriesByAirport($airport_icao,$filters = array()) |
||
| 4367 | { |
||
| 4368 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 4369 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4370 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4371 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
| 4372 | GROUP BY spotter_output.airline_country |
||
| 4373 | ORDER BY airline_country_count DESC |
||
| 4374 | LIMIT 10 OFFSET 0"; |
||
| 4375 | |||
| 4376 | |||
| 4377 | $sth = $this->db->prepare($query); |
||
| 4378 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 4379 | |||
| 4380 | $airline_country_array = array(); |
||
| 4381 | $temp_array = array(); |
||
| 4382 | |||
| 4383 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4384 | { |
||
| 4385 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4386 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4387 | |||
| 4388 | $airline_country_array[] = $temp_array; |
||
| 4389 | } |
||
| 4390 | return $airline_country_array; |
||
| 4391 | } |
||
| 4392 | |||
| 4393 | |||
| 4394 | /** |
||
| 4395 | * Gets all airlines that have flown over by aircraft manufacturer |
||
| 4396 | * |
||
| 4397 | * @return Array the airline list |
||
| 4398 | * |
||
| 4399 | */ |
||
| 4400 | public function countAllAirlinesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 4401 | { |
||
| 4402 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 4403 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4404 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4405 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 4406 | GROUP BY spotter_output.airline_name |
||
| 4407 | ORDER BY airline_count DESC"; |
||
| 4408 | |||
| 4409 | $sth = $this->db->prepare($query); |
||
| 4410 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 4411 | |||
| 4412 | $airline_array = array(); |
||
| 4413 | $temp_array = array(); |
||
| 4414 | |||
| 4415 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4416 | { |
||
| 4417 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4418 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4419 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4420 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4421 | |||
| 4422 | $airline_array[] = $temp_array; |
||
| 4423 | } |
||
| 4424 | return $airline_array; |
||
| 4425 | } |
||
| 4426 | |||
| 4427 | |||
| 4428 | |||
| 4429 | /** |
||
| 4430 | * Gets all airline countries that have flown over by aircraft manufacturer |
||
| 4431 | * |
||
| 4432 | * @return Array the airline country list |
||
| 4433 | * |
||
| 4434 | */ |
||
| 4435 | public function countAllAirlineCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 4436 | { |
||
| 4437 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 4438 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4439 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4440 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 4441 | GROUP BY spotter_output.airline_country |
||
| 4442 | ORDER BY airline_country_count DESC |
||
| 4443 | LIMIT 10 OFFSET 0"; |
||
| 4444 | |||
| 4445 | |||
| 4446 | $sth = $this->db->prepare($query); |
||
| 4447 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 4448 | |||
| 4449 | $airline_country_array = array(); |
||
| 4450 | $temp_array = array(); |
||
| 4451 | |||
| 4452 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4453 | { |
||
| 4454 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4455 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4456 | $airline_country_array[] = $temp_array; |
||
| 4457 | } |
||
| 4458 | return $airline_country_array; |
||
| 4459 | } |
||
| 4460 | |||
| 4461 | |||
| 4462 | /** |
||
| 4463 | * Gets all airlines that have flown over by date |
||
| 4464 | * |
||
| 4465 | * @return Array the airline list |
||
| 4466 | * |
||
| 4467 | */ |
||
| 4468 | public function countAllAirlinesByDate($date,$filters = array()) |
||
| 4469 | { |
||
| 4470 | global $globalTimezone, $globalDBdriver; |
||
| 4471 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4472 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 4473 | if ($globalTimezone != '') { |
||
| 4474 | date_default_timezone_set($globalTimezone); |
||
| 4475 | $datetime = new DateTime($date); |
||
| 4476 | $offset = $datetime->format('P'); |
||
| 4477 | } else $offset = '+00:00'; |
||
| 4478 | |||
| 4479 | if ($globalDBdriver == 'mysql') { |
||
| 4480 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4481 | FROM spotter_output".$filter_query." DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 4482 | GROUP BY spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country |
||
| 4483 | ORDER BY airline_count DESC"; |
||
| 4484 | } else { |
||
| 4485 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4486 | FROM spotter_output".$filter_query." to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 4487 | GROUP BY spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country |
||
| 4488 | ORDER BY airline_count DESC"; |
||
| 4489 | } |
||
| 4490 | |||
| 4491 | $sth = $this->db->prepare($query); |
||
| 4492 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 4493 | |||
| 4494 | $airline_array = array(); |
||
| 4495 | $temp_array = array(); |
||
| 4496 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4497 | { |
||
| 4498 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4499 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4500 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4501 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4502 | |||
| 4503 | $airline_array[] = $temp_array; |
||
| 4504 | } |
||
| 4505 | |||
| 4506 | return $airline_array; |
||
| 4507 | } |
||
| 4508 | |||
| 4509 | |||
| 4510 | /** |
||
| 4511 | * Gets all airline countries that have flown over by date |
||
| 4512 | * |
||
| 4513 | * @return Array the airline country list |
||
| 4514 | * |
||
| 4515 | */ |
||
| 4516 | public function countAllAirlineCountriesByDate($date,$filters = array()) |
||
| 4517 | { |
||
| 4518 | global $globalTimezone, $globalDBdriver; |
||
| 4519 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4520 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 4521 | if ($globalTimezone != '') { |
||
| 4522 | date_default_timezone_set($globalTimezone); |
||
| 4523 | $datetime = new DateTime($date); |
||
| 4524 | $offset = $datetime->format('P'); |
||
| 4525 | } else $offset = '+00:00'; |
||
| 4526 | |||
| 4527 | if ($globalDBdriver == 'mysql') { |
||
| 4528 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4529 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 4530 | GROUP BY spotter_output.airline_country |
||
| 4531 | ORDER BY airline_country_count DESC |
||
| 4532 | LIMIT 10 OFFSET 0"; |
||
| 4533 | } else { |
||
| 4534 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4535 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 4536 | GROUP BY spotter_output.airline_country |
||
| 4537 | ORDER BY airline_country_count DESC |
||
| 4538 | LIMIT 10 OFFSET 0"; |
||
| 4539 | } |
||
| 4540 | |||
| 4541 | $sth = $this->db->prepare($query); |
||
| 4542 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 4543 | |||
| 4544 | $airline_country_array = array(); |
||
| 4545 | $temp_array = array(); |
||
| 4546 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4547 | { |
||
| 4548 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4549 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4550 | |||
| 4551 | $airline_country_array[] = $temp_array; |
||
| 4552 | } |
||
| 4553 | return $airline_country_array; |
||
| 4554 | } |
||
| 4555 | |||
| 4556 | |||
| 4557 | /** |
||
| 4558 | * Gets all airlines that have flown over by ident/callsign |
||
| 4559 | * |
||
| 4560 | * @return Array the airline list |
||
| 4561 | * |
||
| 4562 | */ |
||
| 4563 | public function countAllAirlinesByIdent($ident,$filters = array()) |
||
| 4564 | { |
||
| 4565 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 4566 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4567 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4568 | FROM spotter_output".$filter_query." spotter_output.ident = :ident |
||
| 4569 | GROUP BY spotter_output.airline_icao, spotter_output.airline_name, spotter_output.airline_country |
||
| 4570 | ORDER BY airline_count DESC"; |
||
| 4571 | |||
| 4572 | |||
| 4573 | $sth = $this->db->prepare($query); |
||
| 4574 | $sth->execute(array(':ident' => $ident)); |
||
| 4575 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 4576 | } |
||
| 4577 | |||
| 4578 | /** |
||
| 4579 | * Gets all airlines by owner |
||
| 4580 | * |
||
| 4581 | * @return Array the airline list |
||
| 4582 | * |
||
| 4583 | */ |
||
| 4584 | public function countAllAirlinesByOwner($owner,$filters = array()) |
||
| 4585 | { |
||
| 4586 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 4587 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4588 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4589 | FROM spotter_output".$filter_query." spotter_output.owner_name = :owner |
||
| 4590 | GROUP BY spotter_output.airline_icao, spotter_output.airline_name, spotter_output.airline_country |
||
| 4591 | ORDER BY airline_count DESC"; |
||
| 4592 | |||
| 4593 | |||
| 4594 | $sth = $this->db->prepare($query); |
||
| 4595 | $sth->execute(array(':owner' => $owner)); |
||
| 4596 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 4597 | } |
||
| 4598 | |||
| 4599 | /** |
||
| 4600 | * Gets flight duration by owner |
||
| 4601 | * |
||
| 4602 | * @return String Duration of all flights |
||
| 4603 | * |
||
| 4604 | */ |
||
| 4605 | public function getFlightDurationByOwner($owner,$filters = array()) |
||
| 4606 | { |
||
| 4607 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 4608 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4609 | $query = "SELECT SUM(last_seen - date) AS duration |
||
| 4610 | FROM spotter_output".$filter_query." spotter_output.owner_name = :owner"; |
||
| 4611 | $sth = $this->db->prepare($query); |
||
| 4612 | $sth->execute(array(':owner' => $owner)); |
||
| 4613 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 4614 | if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']); |
||
| 4615 | else return $result[0]['duration']; |
||
| 4616 | } |
||
| 4617 | |||
| 4618 | /** |
||
| 4619 | * Gets flight duration by pilot |
||
| 4620 | * |
||
| 4621 | * @return String Duration of all flights |
||
| 4622 | * |
||
| 4623 | */ |
||
| 4624 | public function getFlightDurationByPilot($pilot,$filters = array()) |
||
| 4625 | { |
||
| 4626 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 4627 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4628 | $query = "SELECT SUM(last_seen - date) AS duration |
||
| 4629 | FROM spotter_output".$filter_query." (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot)"; |
||
| 4630 | $sth = $this->db->prepare($query); |
||
| 4631 | $sth->execute(array(':pilot' => $pilot)); |
||
| 4632 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 4633 | if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']); |
||
| 4634 | else return $result[0]['duration']; |
||
| 4635 | } |
||
| 4636 | |||
| 4637 | /** |
||
| 4638 | * Gets all airlines used by pilot |
||
| 4639 | * |
||
| 4640 | * @return Array the airline list |
||
| 4641 | * |
||
| 4642 | */ |
||
| 4643 | public function countAllAirlinesByPilot($pilot,$filters = array()) |
||
| 4644 | { |
||
| 4645 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 4646 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4647 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4648 | FROM spotter_output".$filter_query." (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 4649 | GROUP BY spotter_output.airline_icao, spotter_output.airline_name, spotter_output.airline_country |
||
| 4650 | ORDER BY airline_count DESC"; |
||
| 4651 | |||
| 4652 | |||
| 4653 | $sth = $this->db->prepare($query); |
||
| 4654 | $sth->execute(array(':pilot' => $pilot)); |
||
| 4655 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 4656 | } |
||
| 4657 | |||
| 4658 | /** |
||
| 4659 | * Gets all airlines that have flown over by route |
||
| 4660 | * |
||
| 4661 | * @return Array the airline list |
||
| 4662 | * |
||
| 4663 | */ |
||
| 4664 | public function countAllAirlinesByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
| 4665 | { |
||
| 4666 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4667 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4668 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4669 | |||
| 4670 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4671 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 4672 | GROUP BY spotter_output.airline_name |
||
| 4673 | ORDER BY airline_count DESC"; |
||
| 4674 | |||
| 4675 | |||
| 4676 | $sth = $this->db->prepare($query); |
||
| 4677 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 4678 | |||
| 4679 | $airline_array = array(); |
||
| 4680 | $temp_array = array(); |
||
| 4681 | |||
| 4682 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4683 | { |
||
| 4684 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4685 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4686 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4687 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4688 | |||
| 4689 | $airline_array[] = $temp_array; |
||
| 4690 | } |
||
| 4691 | return $airline_array; |
||
| 4692 | } |
||
| 4693 | |||
| 4694 | /** |
||
| 4695 | * Gets all airline countries that have flown over by route |
||
| 4696 | * |
||
| 4697 | * @return Array the airline country list |
||
| 4698 | * |
||
| 4699 | */ |
||
| 4700 | public function countAllAirlineCountriesByRoute($departure_airport_icao, $arrival_airport_icao,$filters= array()) |
||
| 4701 | { |
||
| 4702 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4703 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4704 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4705 | |||
| 4706 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4707 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 4708 | GROUP BY spotter_output.airline_country |
||
| 4709 | ORDER BY airline_country_count DESC |
||
| 4710 | LIMIT 10 OFFSET 0"; |
||
| 4711 | |||
| 4712 | |||
| 4713 | $sth = $this->db->prepare($query); |
||
| 4714 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 4715 | |||
| 4716 | $airline_country_array = array(); |
||
| 4717 | $temp_array = array(); |
||
| 4718 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4719 | { |
||
| 4720 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4721 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4722 | |||
| 4723 | $airline_country_array[] = $temp_array; |
||
| 4724 | } |
||
| 4725 | |||
| 4726 | return $airline_country_array; |
||
| 4727 | } |
||
| 4728 | |||
| 4729 | |||
| 4730 | /** |
||
| 4731 | * Gets all airlines that have flown over by country |
||
| 4732 | * |
||
| 4733 | * @return Array the airline list |
||
| 4734 | * |
||
| 4735 | */ |
||
| 4736 | public function countAllAirlinesByCountry($country,$filters = array()) |
||
| 4737 | { |
||
| 4738 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 4739 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4740 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 4741 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 4742 | GROUP BY spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country |
||
| 4743 | ORDER BY airline_count DESC"; |
||
| 4744 | |||
| 4745 | |||
| 4746 | $sth = $this->db->prepare($query); |
||
| 4747 | $sth->execute(array(':country' => $country)); |
||
| 4748 | |||
| 4749 | $airline_array = array(); |
||
| 4750 | $temp_array = array(); |
||
| 4751 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4752 | { |
||
| 4753 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4754 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 4755 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 4756 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4757 | |||
| 4758 | $airline_array[] = $temp_array; |
||
| 4759 | } |
||
| 4760 | return $airline_array; |
||
| 4761 | } |
||
| 4762 | |||
| 4763 | |||
| 4764 | /** |
||
| 4765 | * Gets all airline countries that have flown over by country |
||
| 4766 | * |
||
| 4767 | * @return Array the airline country list |
||
| 4768 | * |
||
| 4769 | */ |
||
| 4770 | public function countAllAirlineCountriesByCountry($country,$filters = array()) |
||
| 4771 | { |
||
| 4772 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4773 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 4774 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4775 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 4776 | GROUP BY spotter_output.airline_country |
||
| 4777 | ORDER BY airline_country_count DESC |
||
| 4778 | LIMIT 10 OFFSET 0"; |
||
| 4779 | |||
| 4780 | |||
| 4781 | $sth = $this->db->prepare($query); |
||
| 4782 | $sth->execute(array(':country' => $country)); |
||
| 4783 | |||
| 4784 | $airline_country_array = array(); |
||
| 4785 | $temp_array = array(); |
||
| 4786 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4787 | { |
||
| 4788 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4789 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4790 | |||
| 4791 | $airline_country_array[] = $temp_array; |
||
| 4792 | } |
||
| 4793 | return $airline_country_array; |
||
| 4794 | } |
||
| 4795 | |||
| 4796 | |||
| 4797 | /** |
||
| 4798 | * Gets all airlines countries |
||
| 4799 | * |
||
| 4800 | * @return Array the airline country list |
||
| 4801 | * |
||
| 4802 | */ |
||
| 4803 | public function countAllAirlineCountries($limit = true, $filters = array(), $year = '', $month = '', $day = '') |
||
| 4804 | { |
||
| 4805 | global $globalDBdriver; |
||
| 4806 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4807 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 4808 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.airline_country <> 'NA'"; |
||
| 4809 | $query_values = array(); |
||
| 4810 | if ($year != '') { |
||
| 4811 | if ($globalDBdriver == 'mysql') { |
||
| 4812 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 4813 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4814 | } else { |
||
| 4815 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 4816 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4817 | } |
||
| 4818 | } |
||
| 4819 | if ($month != '') { |
||
| 4820 | if ($globalDBdriver == 'mysql') { |
||
| 4821 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 4822 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4823 | } else { |
||
| 4824 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 4825 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4826 | } |
||
| 4827 | } |
||
| 4828 | if ($day != '') { |
||
| 4829 | if ($globalDBdriver == 'mysql') { |
||
| 4830 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 4831 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4832 | } else { |
||
| 4833 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 4834 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4835 | } |
||
| 4836 | } |
||
| 4837 | $query .= " GROUP BY spotter_output.airline_country |
||
| 4838 | ORDER BY airline_country_count DESC"; |
||
| 4839 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4840 | |||
| 4841 | $sth = $this->db->prepare($query); |
||
| 4842 | $sth->execute($query_values); |
||
| 4843 | |||
| 4844 | $airline_array = array(); |
||
| 4845 | $temp_array = array(); |
||
| 4846 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4847 | { |
||
| 4848 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 4849 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 4850 | |||
| 4851 | $airline_array[] = $temp_array; |
||
| 4852 | } |
||
| 4853 | return $airline_array; |
||
| 4854 | } |
||
| 4855 | |||
| 4856 | /** |
||
| 4857 | * Gets all number of flight over countries |
||
| 4858 | * |
||
| 4859 | * @return Array the airline country list |
||
| 4860 | * |
||
| 4861 | */ |
||
| 4862 | public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
| 4863 | { |
||
| 4864 | global $globalDBdriver; |
||
| 4865 | //$filter_query = $this->getFilter($filters,true,true); |
||
| 4866 | $Connection= new Connection($this->db); |
||
| 4867 | if (!$Connection->tableExists('countries')) return array(); |
||
| 4868 | /* |
||
| 4869 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
| 4870 | FROM countries c, spotter_output s |
||
| 4871 | WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
||
| 4872 | */ |
||
| 4873 | /* |
||
| 4874 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
| 4875 | FROM countries c, spotter_live s |
||
| 4876 | WHERE c.iso2 = s.over_country "; |
||
| 4877 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT flightaware_id,over_country FROM spottrer_live) l ON c.iso2 = l.over_country "; |
||
| 4878 | */ |
||
| 4879 | require_once('class.SpotterLive.php'); |
||
| 4880 | $SpotterLive = new SpotterLive(); |
||
| 4881 | $filter_query = $SpotterLive->getFilter($filters,true,true); |
||
| 4882 | $filter_query .= ' over_country IS NOT NULL'; |
||
| 4883 | if ($olderthanmonths > 0) { |
||
| 4884 | if ($globalDBdriver == 'mysql') { |
||
| 4885 | $filter_query .= ' AND spotter_live.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4886 | } else { |
||
| 4887 | $filter_query .= " AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 4888 | } |
||
| 4889 | } |
||
| 4890 | if ($sincedate != '') { |
||
| 4891 | if ($globalDBdriver == 'mysql') { |
||
| 4892 | $filter_query .= " AND spotter_live.date > '".$sincedate."' "; |
||
| 4893 | } else { |
||
| 4894 | $filter_query .= " AND spotter_live.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4895 | } |
||
| 4896 | } |
||
| 4897 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT flightaware_id,over_country FROM spotter_live".$filter_query.") l ON c.iso2 = l.over_country "; |
||
| 4898 | $query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC"; |
||
| 4899 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4900 | |||
| 4901 | |||
| 4902 | $sth = $this->db->prepare($query); |
||
| 4903 | $sth->execute(); |
||
| 4904 | |||
| 4905 | $flight_array = array(); |
||
| 4906 | $temp_array = array(); |
||
| 4907 | |||
| 4908 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4909 | { |
||
| 4910 | $temp_array['flight_count'] = $row['nb']; |
||
| 4911 | $temp_array['flight_country'] = $row['name']; |
||
| 4912 | $temp_array['flight_country_iso3'] = $row['iso3']; |
||
| 4913 | $temp_array['flight_country_iso2'] = $row['iso2']; |
||
| 4914 | $flight_array[] = $temp_array; |
||
| 4915 | } |
||
| 4916 | return $flight_array; |
||
| 4917 | } |
||
| 4918 | |||
| 4919 | |||
| 4920 | /** |
||
| 4921 | * Gets all aircraft types that have flown over |
||
| 4922 | * |
||
| 4923 | * @return Array the aircraft list |
||
| 4924 | * |
||
| 4925 | */ |
||
| 4926 | public function countAllAircraftTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '') |
||
| 4927 | { |
||
| 4928 | global $globalDBdriver; |
||
| 4929 | $filter_query = $this->getFilter($filters,true,true); |
||
| 4930 | $query = "SELECT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer |
||
| 4931 | FROM spotter_output ".$filter_query." spotter_output.aircraft_name <> '' AND spotter_output.aircraft_icao <> ''"; |
||
| 4932 | if ($olderthanmonths > 0) { |
||
| 4933 | if ($globalDBdriver == 'mysql') { |
||
| 4934 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 4935 | } else { |
||
| 4936 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 4937 | } |
||
| 4938 | } |
||
| 4939 | if ($sincedate != '') { |
||
| 4940 | if ($globalDBdriver == 'mysql') { |
||
| 4941 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 4942 | } else { |
||
| 4943 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4944 | } |
||
| 4945 | } |
||
| 4946 | $query_values = array(); |
||
| 4947 | if ($year != '') { |
||
| 4948 | if ($globalDBdriver == 'mysql') { |
||
| 4949 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 4950 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4951 | } else { |
||
| 4952 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 4953 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 4954 | } |
||
| 4955 | } |
||
| 4956 | if ($month != '') { |
||
| 4957 | if ($globalDBdriver == 'mysql') { |
||
| 4958 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 4959 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4960 | } else { |
||
| 4961 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 4962 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 4963 | } |
||
| 4964 | } |
||
| 4965 | if ($day != '') { |
||
| 4966 | if ($globalDBdriver == 'mysql') { |
||
| 4967 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 4968 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4969 | } else { |
||
| 4970 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 4971 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 4972 | } |
||
| 4973 | } |
||
| 4974 | |||
| 4975 | $query .= " GROUP BY spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer ORDER BY aircraft_icao_count DESC"; |
||
| 4976 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4977 | |||
| 4978 | $sth = $this->db->prepare($query); |
||
| 4979 | $sth->execute($query_values); |
||
| 4980 | |||
| 4981 | $aircraft_array = array(); |
||
| 4982 | $temp_array = array(); |
||
| 4983 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4984 | { |
||
| 4985 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4986 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4987 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4988 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4989 | $aircraft_array[] = $temp_array; |
||
| 4990 | } |
||
| 4991 | return $aircraft_array; |
||
| 4992 | } |
||
| 4993 | |||
| 4994 | /** |
||
| 4995 | * Gets all aircraft types that have flown over by airline |
||
| 4996 | * |
||
| 4997 | * @return Array the aircraft list |
||
| 4998 | * |
||
| 4999 | */ |
||
| 5000 | public function countAllAircraftTypesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '', $day = '') |
||
| 5001 | { |
||
| 5002 | global $globalDBdriver; |
||
| 5003 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5004 | $query = "SELECT spotter_output.airline_icao, spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer |
||
| 5005 | FROM spotter_output".$filter_query." spotter_output.aircraft_name <> '' AND spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao <>'' AND spotter_output.airline_icao <> 'NA'"; |
||
| 5006 | if ($olderthanmonths > 0) { |
||
| 5007 | if ($globalDBdriver == 'mysql') { |
||
| 5008 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 5009 | } else { |
||
| 5010 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 5011 | } |
||
| 5012 | } |
||
| 5013 | if ($sincedate != '') { |
||
| 5014 | if ($globalDBdriver == 'mysql') { |
||
| 5015 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 5016 | } else { |
||
| 5017 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5018 | } |
||
| 5019 | } |
||
| 5020 | $query_values = array(); |
||
| 5021 | if ($year != '') { |
||
| 5022 | if ($globalDBdriver == 'mysql') { |
||
| 5023 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 5024 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 5025 | } else { |
||
| 5026 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 5027 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 5028 | } |
||
| 5029 | } |
||
| 5030 | if ($month != '') { |
||
| 5031 | if ($globalDBdriver == 'mysql') { |
||
| 5032 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 5033 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 5034 | } else { |
||
| 5035 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 5036 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 5037 | } |
||
| 5038 | } |
||
| 5039 | if ($day != '') { |
||
| 5040 | if ($globalDBdriver == 'mysql') { |
||
| 5041 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 5042 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 5043 | } else { |
||
| 5044 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 5045 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 5046 | } |
||
| 5047 | } |
||
| 5048 | |||
| 5049 | $query .= " GROUP BY spotter_output.airline_icao, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer ORDER BY aircraft_icao_count DESC"; |
||
| 5050 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 5051 | |||
| 5052 | $sth = $this->db->prepare($query); |
||
| 5053 | $sth->execute($query_values); |
||
| 5054 | |||
| 5055 | $aircraft_array = array(); |
||
| 5056 | $temp_array = array(); |
||
| 5057 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5058 | { |
||
| 5059 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 5060 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5061 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5062 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5063 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5064 | $aircraft_array[] = $temp_array; |
||
| 5065 | } |
||
| 5066 | return $aircraft_array; |
||
| 5067 | } |
||
| 5068 | |||
| 5069 | /** |
||
| 5070 | * Gets all aircraft types that have flown over by months |
||
| 5071 | * |
||
| 5072 | * @return Array the aircraft list |
||
| 5073 | * |
||
| 5074 | */ |
||
| 5075 | public function countAllAircraftTypesByMonths($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
| 5076 | { |
||
| 5077 | global $globalDBdriver; |
||
| 5078 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5079 | $query = "SELECT EXTRACT(month from spotter_output.date) as month, EXTRACT(year from spotter_output.date) as year,spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer |
||
| 5080 | FROM spotter_output".$filter_query." spotter_output.aircraft_name <> '' AND spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao <>'' AND spotter_output.airline_icao <> 'NA' "; |
||
| 5081 | if ($olderthanmonths > 0) { |
||
| 5082 | if ($globalDBdriver == 'mysql') { |
||
| 5083 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5084 | } else { |
||
| 5085 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 5086 | } |
||
| 5087 | } |
||
| 5088 | if ($sincedate != '') { |
||
| 5089 | if ($globalDBdriver == 'mysql') { |
||
| 5090 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 5091 | } else { |
||
| 5092 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5093 | } |
||
| 5094 | } |
||
| 5095 | |||
| 5096 | $query .= "GROUP BY EXTRACT(month from spotter_output.date), EXTRACT(year from spotter_output.date), spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer ORDER BY aircraft_icao_count DESC"; |
||
| 5097 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 5098 | |||
| 5099 | $sth = $this->db->prepare($query); |
||
| 5100 | $sth->execute(); |
||
| 5101 | |||
| 5102 | $aircraft_array = array(); |
||
| 5103 | $temp_array = array(); |
||
| 5104 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5105 | { |
||
| 5106 | //$temp_array['airline_icao'] = $row['airline_icao']; |
||
| 5107 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5108 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5109 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5110 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5111 | $aircraft_array[] = $temp_array; |
||
| 5112 | } |
||
| 5113 | return $aircraft_array; |
||
| 5114 | } |
||
| 5115 | |||
| 5116 | |||
| 5117 | /** |
||
| 5118 | * Gets all aircraft registration that have flown over by aircaft icao |
||
| 5119 | * |
||
| 5120 | * @return Array the aircraft list |
||
| 5121 | * |
||
| 5122 | */ |
||
| 5123 | public function countAllAircraftRegistrationByAircraft($aircraft_icao,$filters = array()) |
||
| 5124 | { |
||
| 5125 | $Image = new Image($this->db); |
||
| 5126 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5127 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 5128 | |||
| 5129 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5130 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 5131 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5132 | ORDER BY registration_count DESC"; |
||
| 5133 | |||
| 5134 | $sth = $this->db->prepare($query); |
||
| 5135 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 5136 | |||
| 5137 | $aircraft_array = array(); |
||
| 5138 | $temp_array = array(); |
||
| 5139 | |||
| 5140 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5141 | { |
||
| 5142 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5143 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5144 | $temp_array['registration'] = $row['registration']; |
||
| 5145 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5146 | $temp_array['image_thumbnail'] = ""; |
||
| 5147 | if($row['registration'] != "") |
||
| 5148 | { |
||
| 5149 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5150 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5151 | } |
||
| 5152 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5153 | |||
| 5154 | $aircraft_array[] = $temp_array; |
||
| 5155 | } |
||
| 5156 | return $aircraft_array; |
||
| 5157 | } |
||
| 5158 | |||
| 5159 | |||
| 5160 | /** |
||
| 5161 | * Gets all aircraft types that have flown over by airline icao |
||
| 5162 | * |
||
| 5163 | * @return Array the aircraft list |
||
| 5164 | * |
||
| 5165 | */ |
||
| 5166 | public function countAllAircraftTypesByAirline($airline_icao,$filters = array()) |
||
| 5167 | { |
||
| 5168 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5169 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5170 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5171 | FROM spotter_output".$filter_query." spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 5172 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5173 | ORDER BY aircraft_icao_count DESC"; |
||
| 5174 | |||
| 5175 | $sth = $this->db->prepare($query); |
||
| 5176 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5177 | |||
| 5178 | $aircraft_array = array(); |
||
| 5179 | $temp_array = array(); |
||
| 5180 | |||
| 5181 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5182 | { |
||
| 5183 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5184 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5185 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5186 | |||
| 5187 | $aircraft_array[] = $temp_array; |
||
| 5188 | } |
||
| 5189 | return $aircraft_array; |
||
| 5190 | } |
||
| 5191 | |||
| 5192 | |||
| 5193 | /** |
||
| 5194 | * Gets all aircraft registration that have flown over by airline icao |
||
| 5195 | * |
||
| 5196 | * @return Array the aircraft list |
||
| 5197 | * |
||
| 5198 | */ |
||
| 5199 | public function countAllAircraftRegistrationByAirline($airline_icao,$filters = array()) |
||
| 5200 | { |
||
| 5201 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5202 | $Image = new Image($this->db); |
||
| 5203 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5204 | |||
| 5205 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5206 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 5207 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 5208 | ORDER BY registration_count DESC"; |
||
| 5209 | |||
| 5210 | $sth = $this->db->prepare($query); |
||
| 5211 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5212 | |||
| 5213 | $aircraft_array = array(); |
||
| 5214 | $temp_array = array(); |
||
| 5215 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5216 | { |
||
| 5217 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5218 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5219 | $temp_array['registration'] = $row['registration']; |
||
| 5220 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5221 | $temp_array['image_thumbnail'] = ""; |
||
| 5222 | if($row['registration'] != "") |
||
| 5223 | { |
||
| 5224 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5225 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5226 | } |
||
| 5227 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5228 | |||
| 5229 | $aircraft_array[] = $temp_array; |
||
| 5230 | } |
||
| 5231 | return $aircraft_array; |
||
| 5232 | } |
||
| 5233 | |||
| 5234 | |||
| 5235 | /** |
||
| 5236 | * Gets all aircraft manufacturer that have flown over by airline icao |
||
| 5237 | * |
||
| 5238 | * @return Array the aircraft list |
||
| 5239 | * |
||
| 5240 | */ |
||
| 5241 | public function countAllAircraftManufacturerByAirline($airline_icao,$filters = array()) |
||
| 5242 | { |
||
| 5243 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5244 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5245 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5246 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 5247 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5248 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5249 | |||
| 5250 | $sth = $this->db->prepare($query); |
||
| 5251 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5252 | |||
| 5253 | $aircraft_array = array(); |
||
| 5254 | $temp_array = array(); |
||
| 5255 | |||
| 5256 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5257 | { |
||
| 5258 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5259 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 5260 | |||
| 5261 | $aircraft_array[] = $temp_array; |
||
| 5262 | } |
||
| 5263 | return $aircraft_array; |
||
| 5264 | } |
||
| 5265 | |||
| 5266 | |||
| 5267 | /** |
||
| 5268 | * Gets all aircraft types that have flown over by airline icao |
||
| 5269 | * |
||
| 5270 | * @return Array the aircraft list |
||
| 5271 | * |
||
| 5272 | */ |
||
| 5273 | public function countAllAircraftTypesByAirport($airport_icao,$filters = array()) |
||
| 5274 | { |
||
| 5275 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5276 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 5277 | |||
| 5278 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5279 | FROM spotter_output".$filter_query." spotter_output.aircraft_icao <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 5280 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5281 | ORDER BY aircraft_icao_count DESC"; |
||
| 5282 | |||
| 5283 | $sth = $this->db->prepare($query); |
||
| 5284 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 5285 | |||
| 5286 | $aircraft_array = array(); |
||
| 5287 | $temp_array = array(); |
||
| 5288 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5289 | { |
||
| 5290 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5291 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5292 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5293 | |||
| 5294 | $aircraft_array[] = $temp_array; |
||
| 5295 | } |
||
| 5296 | return $aircraft_array; |
||
| 5297 | } |
||
| 5298 | |||
| 5299 | |||
| 5300 | /** |
||
| 5301 | * Gets all aircraft registration that have flown over by airport icao |
||
| 5302 | * |
||
| 5303 | * @return Array the aircraft list |
||
| 5304 | * |
||
| 5305 | */ |
||
| 5306 | public function countAllAircraftRegistrationByAirport($airport_icao,$filters = array()) |
||
| 5307 | { |
||
| 5308 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5309 | $Image = new Image($this->db); |
||
| 5310 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 5311 | |||
| 5312 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5313 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 5314 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 5315 | ORDER BY registration_count DESC"; |
||
| 5316 | |||
| 5317 | $sth = $this->db->prepare($query); |
||
| 5318 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 5319 | |||
| 5320 | $aircraft_array = array(); |
||
| 5321 | $temp_array = array(); |
||
| 5322 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5323 | { |
||
| 5324 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5325 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5326 | $temp_array['registration'] = $row['registration']; |
||
| 5327 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5328 | $temp_array['image_thumbnail'] = ""; |
||
| 5329 | if($row['registration'] != "") |
||
| 5330 | { |
||
| 5331 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5332 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5333 | } |
||
| 5334 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5335 | $aircraft_array[] = $temp_array; |
||
| 5336 | } |
||
| 5337 | return $aircraft_array; |
||
| 5338 | } |
||
| 5339 | |||
| 5340 | |||
| 5341 | /** |
||
| 5342 | * Gets all aircraft manufacturer that have flown over by airport icao |
||
| 5343 | * |
||
| 5344 | * @return Array the aircraft list |
||
| 5345 | * |
||
| 5346 | */ |
||
| 5347 | public function countAllAircraftManufacturerByAirport($airport_icao,$filters = array()) |
||
| 5348 | { |
||
| 5349 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5350 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 5351 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5352 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 5353 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5354 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5355 | |||
| 5356 | |||
| 5357 | $sth = $this->db->prepare($query); |
||
| 5358 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 5359 | |||
| 5360 | $aircraft_array = array(); |
||
| 5361 | $temp_array = array(); |
||
| 5362 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5363 | { |
||
| 5364 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5365 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 5366 | $aircraft_array[] = $temp_array; |
||
| 5367 | } |
||
| 5368 | return $aircraft_array; |
||
| 5369 | } |
||
| 5370 | |||
| 5371 | /** |
||
| 5372 | * Gets all aircraft types that have flown over by aircraft manufacturer |
||
| 5373 | * |
||
| 5374 | * @return Array the aircraft list |
||
| 5375 | * |
||
| 5376 | */ |
||
| 5377 | public function countAllAircraftTypesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 5378 | { |
||
| 5379 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5380 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 5381 | |||
| 5382 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5383 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 5384 | GROUP BY spotter_output.aircraft_name |
||
| 5385 | ORDER BY aircraft_icao_count DESC"; |
||
| 5386 | |||
| 5387 | $sth = $this->db->prepare($query); |
||
| 5388 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 5389 | $aircraft_array = array(); |
||
| 5390 | $temp_array = array(); |
||
| 5391 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5392 | { |
||
| 5393 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5394 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5395 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5396 | $aircraft_array[] = $temp_array; |
||
| 5397 | } |
||
| 5398 | return $aircraft_array; |
||
| 5399 | } |
||
| 5400 | |||
| 5401 | |||
| 5402 | /** |
||
| 5403 | * Gets all aircraft registration that have flown over by aircaft manufacturer |
||
| 5404 | * |
||
| 5405 | * @return Array the aircraft list |
||
| 5406 | * |
||
| 5407 | */ |
||
| 5408 | public function countAllAircraftRegistrationByManufacturer($aircraft_manufacturer, $filters = array()) |
||
| 5409 | { |
||
| 5410 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5411 | $Image = new Image($this->db); |
||
| 5412 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 5413 | |||
| 5414 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5415 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 5416 | GROUP BY spotter_output.registration |
||
| 5417 | ORDER BY registration_count DESC"; |
||
| 5418 | |||
| 5419 | |||
| 5420 | $sth = $this->db->prepare($query); |
||
| 5421 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 5422 | $aircraft_array = array(); |
||
| 5423 | $temp_array = array(); |
||
| 5424 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5425 | { |
||
| 5426 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5427 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5428 | $temp_array['registration'] = $row['registration']; |
||
| 5429 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5430 | $temp_array['image_thumbnail'] = ""; |
||
| 5431 | if($row['registration'] != "") |
||
| 5432 | { |
||
| 5433 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5434 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5435 | } |
||
| 5436 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5437 | $aircraft_array[] = $temp_array; |
||
| 5438 | } |
||
| 5439 | return $aircraft_array; |
||
| 5440 | } |
||
| 5441 | |||
| 5442 | /** |
||
| 5443 | * Gets all aircraft types that have flown over by date |
||
| 5444 | * |
||
| 5445 | * @return Array the aircraft list |
||
| 5446 | * |
||
| 5447 | */ |
||
| 5448 | public function countAllAircraftTypesByDate($date,$filters = array()) |
||
| 5449 | { |
||
| 5450 | global $globalTimezone, $globalDBdriver; |
||
| 5451 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5452 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5453 | if ($globalTimezone != '') { |
||
| 5454 | date_default_timezone_set($globalTimezone); |
||
| 5455 | $datetime = new DateTime($date); |
||
| 5456 | $offset = $datetime->format('P'); |
||
| 5457 | } else $offset = '+00:00'; |
||
| 5458 | |||
| 5459 | if ($globalDBdriver == 'mysql') { |
||
| 5460 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5461 | FROM spotter_output".$filter_query." DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 5462 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5463 | ORDER BY aircraft_icao_count DESC"; |
||
| 5464 | } else { |
||
| 5465 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5466 | FROM spotter_output".$filter_query." to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 5467 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5468 | ORDER BY aircraft_icao_count DESC"; |
||
| 5469 | } |
||
| 5470 | |||
| 5471 | $sth = $this->db->prepare($query); |
||
| 5472 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 5473 | |||
| 5474 | $aircraft_array = array(); |
||
| 5475 | $temp_array = array(); |
||
| 5476 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5477 | { |
||
| 5478 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5479 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5480 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5481 | |||
| 5482 | $aircraft_array[] = $temp_array; |
||
| 5483 | } |
||
| 5484 | return $aircraft_array; |
||
| 5485 | } |
||
| 5486 | |||
| 5487 | |||
| 5488 | /** |
||
| 5489 | * Gets all aircraft registration that have flown over by date |
||
| 5490 | * |
||
| 5491 | * @return Array the aircraft list |
||
| 5492 | * |
||
| 5493 | */ |
||
| 5494 | public function countAllAircraftRegistrationByDate($date,$filters = array()) |
||
| 5495 | { |
||
| 5496 | global $globalTimezone, $globalDBdriver; |
||
| 5497 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5498 | $Image = new Image($this->db); |
||
| 5499 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5500 | if ($globalTimezone != '') { |
||
| 5501 | date_default_timezone_set($globalTimezone); |
||
| 5502 | $datetime = new DateTime($date); |
||
| 5503 | $offset = $datetime->format('P'); |
||
| 5504 | } else $offset = '+00:00'; |
||
| 5505 | |||
| 5506 | if ($globalDBdriver == 'mysql') { |
||
| 5507 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5508 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 5509 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 5510 | ORDER BY registration_count DESC"; |
||
| 5511 | } else { |
||
| 5512 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5513 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 5514 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 5515 | ORDER BY registration_count DESC"; |
||
| 5516 | } |
||
| 5517 | |||
| 5518 | $sth = $this->db->prepare($query); |
||
| 5519 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 5520 | |||
| 5521 | $aircraft_array = array(); |
||
| 5522 | $temp_array = array(); |
||
| 5523 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5524 | { |
||
| 5525 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5526 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5527 | $temp_array['registration'] = $row['registration']; |
||
| 5528 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5529 | $temp_array['image_thumbnail'] = ""; |
||
| 5530 | if($row['registration'] != "") |
||
| 5531 | { |
||
| 5532 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5533 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5534 | } |
||
| 5535 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5536 | |||
| 5537 | $aircraft_array[] = $temp_array; |
||
| 5538 | } |
||
| 5539 | return $aircraft_array; |
||
| 5540 | } |
||
| 5541 | |||
| 5542 | |||
| 5543 | /** |
||
| 5544 | * Gets all aircraft manufacturer that have flown over by date |
||
| 5545 | * |
||
| 5546 | * @return Array the aircraft manufacturer list |
||
| 5547 | * |
||
| 5548 | */ |
||
| 5549 | public function countAllAircraftManufacturerByDate($date,$filters = array()) |
||
| 5550 | { |
||
| 5551 | global $globalTimezone, $globalDBdriver; |
||
| 5552 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5553 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5554 | if ($globalTimezone != '') { |
||
| 5555 | date_default_timezone_set($globalTimezone); |
||
| 5556 | $datetime = new DateTime($date); |
||
| 5557 | $offset = $datetime->format('P'); |
||
| 5558 | } else $offset = '+00:00'; |
||
| 5559 | |||
| 5560 | if ($globalDBdriver == 'mysql') { |
||
| 5561 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5562 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 5563 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5564 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5565 | } else { |
||
| 5566 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5567 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 5568 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5569 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5570 | } |
||
| 5571 | |||
| 5572 | $sth = $this->db->prepare($query); |
||
| 5573 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 5574 | |||
| 5575 | $aircraft_array = array(); |
||
| 5576 | $temp_array = array(); |
||
| 5577 | |||
| 5578 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5579 | { |
||
| 5580 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5581 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 5582 | |||
| 5583 | $aircraft_array[] = $temp_array; |
||
| 5584 | } |
||
| 5585 | return $aircraft_array; |
||
| 5586 | } |
||
| 5587 | |||
| 5588 | |||
| 5589 | /** |
||
| 5590 | * Gets all aircraft types that have flown over by ident/callsign |
||
| 5591 | * |
||
| 5592 | * @return Array the aircraft list |
||
| 5593 | * |
||
| 5594 | */ |
||
| 5595 | public function countAllAircraftTypesByIdent($ident,$filters = array()) |
||
| 5596 | { |
||
| 5597 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5598 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 5599 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5600 | FROM spotter_output".$filter_query." spotter_output.ident = :ident |
||
| 5601 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5602 | ORDER BY aircraft_icao_count DESC"; |
||
| 5603 | |||
| 5604 | $sth = $this->db->prepare($query); |
||
| 5605 | $sth->execute(array(':ident' => $ident)); |
||
| 5606 | |||
| 5607 | $aircraft_array = array(); |
||
| 5608 | $temp_array = array(); |
||
| 5609 | |||
| 5610 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5611 | { |
||
| 5612 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5613 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5614 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5615 | |||
| 5616 | $aircraft_array[] = $temp_array; |
||
| 5617 | } |
||
| 5618 | return $aircraft_array; |
||
| 5619 | } |
||
| 5620 | |||
| 5621 | /** |
||
| 5622 | * Gets all aircraft types that have flown over by pilot |
||
| 5623 | * |
||
| 5624 | * @return Array the aircraft list |
||
| 5625 | * |
||
| 5626 | */ |
||
| 5627 | public function countAllAircraftTypesByPilot($pilot,$filters = array()) |
||
| 5628 | { |
||
| 5629 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5630 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 5631 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5632 | FROM spotter_output".$filter_query." (spotter_output.pilot_id = :pilot OR spotter_output.pilot_name = :pilot) |
||
| 5633 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5634 | ORDER BY aircraft_icao_count DESC"; |
||
| 5635 | |||
| 5636 | $sth = $this->db->prepare($query); |
||
| 5637 | $sth->execute(array(':pilot' => $pilot)); |
||
| 5638 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 5639 | } |
||
| 5640 | |||
| 5641 | /** |
||
| 5642 | * Gets all aircraft types that have flown over by owner |
||
| 5643 | * |
||
| 5644 | * @return Array the aircraft list |
||
| 5645 | * |
||
| 5646 | */ |
||
| 5647 | public function countAllAircraftTypesByOwner($owner,$filters = array()) |
||
| 5648 | { |
||
| 5649 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5650 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 5651 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer |
||
| 5652 | FROM spotter_output".$filter_query." spotter_output.owner_name = :owner |
||
| 5653 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.aircraft_icao |
||
| 5654 | ORDER BY aircraft_icao_count DESC"; |
||
| 5655 | |||
| 5656 | $sth = $this->db->prepare($query); |
||
| 5657 | $sth->execute(array(':owner' => $owner)); |
||
| 5658 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 5659 | } |
||
| 5660 | |||
| 5661 | /** |
||
| 5662 | * Gets all aircraft registration that have flown over by ident/callsign |
||
| 5663 | * |
||
| 5664 | * @return Array the aircraft list |
||
| 5665 | * |
||
| 5666 | */ |
||
| 5667 | public function countAllAircraftRegistrationByIdent($ident,$filters = array()) |
||
| 5668 | { |
||
| 5669 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5670 | $Image = new Image($this->db); |
||
| 5671 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 5672 | |||
| 5673 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5674 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.ident = :ident |
||
| 5675 | GROUP BY spotter_output.registration,spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 5676 | ORDER BY registration_count DESC"; |
||
| 5677 | |||
| 5678 | |||
| 5679 | $sth = $this->db->prepare($query); |
||
| 5680 | $sth->execute(array(':ident' => $ident)); |
||
| 5681 | |||
| 5682 | $aircraft_array = array(); |
||
| 5683 | $temp_array = array(); |
||
| 5684 | |||
| 5685 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5686 | { |
||
| 5687 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5688 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5689 | $temp_array['registration'] = $row['registration']; |
||
| 5690 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5691 | $temp_array['image_thumbnail'] = ""; |
||
| 5692 | if($row['registration'] != "") |
||
| 5693 | { |
||
| 5694 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5695 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5696 | else $temp_array['image_thumbnail'] = ''; |
||
| 5697 | } |
||
| 5698 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5699 | $aircraft_array[] = $temp_array; |
||
| 5700 | } |
||
| 5701 | return $aircraft_array; |
||
| 5702 | } |
||
| 5703 | |||
| 5704 | /** |
||
| 5705 | * Gets all aircraft registration that have flown over by owner |
||
| 5706 | * |
||
| 5707 | * @return Array the aircraft list |
||
| 5708 | * |
||
| 5709 | */ |
||
| 5710 | public function countAllAircraftRegistrationByOwner($owner,$filters = array()) |
||
| 5711 | { |
||
| 5712 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5713 | $Image = new Image($this->db); |
||
| 5714 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 5715 | |||
| 5716 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.registration, spotter_output.airline_name |
||
| 5717 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.owner_name = :owner |
||
| 5718 | GROUP BY spotter_output.registration,spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.airline_name |
||
| 5719 | ORDER BY registration_count DESC"; |
||
| 5720 | |||
| 5721 | |||
| 5722 | $sth = $this->db->prepare($query); |
||
| 5723 | $sth->execute(array(':owner' => $owner)); |
||
| 5724 | |||
| 5725 | $aircraft_array = array(); |
||
| 5726 | $temp_array = array(); |
||
| 5727 | |||
| 5728 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5729 | { |
||
| 5730 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5731 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5732 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5733 | $temp_array['registration'] = $row['registration']; |
||
| 5734 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5735 | $temp_array['image_thumbnail'] = ""; |
||
| 5736 | if($row['registration'] != "") |
||
| 5737 | { |
||
| 5738 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5739 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5740 | else $temp_array['image_thumbnail'] = ''; |
||
| 5741 | } |
||
| 5742 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5743 | $aircraft_array[] = $temp_array; |
||
| 5744 | } |
||
| 5745 | return $aircraft_array; |
||
| 5746 | } |
||
| 5747 | |||
| 5748 | /** |
||
| 5749 | * Gets all aircraft registration that have flown over by pilot |
||
| 5750 | * |
||
| 5751 | * @return Array the aircraft list |
||
| 5752 | * |
||
| 5753 | */ |
||
| 5754 | public function countAllAircraftRegistrationByPilot($pilot,$filters = array()) |
||
| 5755 | { |
||
| 5756 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5757 | $Image = new Image($this->db); |
||
| 5758 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 5759 | |||
| 5760 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.registration, spotter_output.airline_name |
||
| 5761 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 5762 | GROUP BY spotter_output.registration,spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.airline_name |
||
| 5763 | ORDER BY registration_count DESC"; |
||
| 5764 | |||
| 5765 | |||
| 5766 | $sth = $this->db->prepare($query); |
||
| 5767 | $sth->execute(array(':pilot' => $pilot)); |
||
| 5768 | |||
| 5769 | $aircraft_array = array(); |
||
| 5770 | $temp_array = array(); |
||
| 5771 | |||
| 5772 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5773 | { |
||
| 5774 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5775 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5776 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5777 | $temp_array['registration'] = $row['registration']; |
||
| 5778 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5779 | $temp_array['image_thumbnail'] = ""; |
||
| 5780 | if($row['registration'] != "") |
||
| 5781 | { |
||
| 5782 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5783 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5784 | else $temp_array['image_thumbnail'] = ''; |
||
| 5785 | } |
||
| 5786 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5787 | $aircraft_array[] = $temp_array; |
||
| 5788 | } |
||
| 5789 | return $aircraft_array; |
||
| 5790 | } |
||
| 5791 | |||
| 5792 | |||
| 5793 | /** |
||
| 5794 | * Gets all aircraft manufacturer that have flown over by ident/callsign |
||
| 5795 | * |
||
| 5796 | * @return Array the aircraft manufacturer list |
||
| 5797 | * |
||
| 5798 | */ |
||
| 5799 | public function countAllAircraftManufacturerByIdent($ident,$filters = array()) |
||
| 5800 | { |
||
| 5801 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5802 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 5803 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5804 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND spotter_output.ident = :ident |
||
| 5805 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5806 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5807 | |||
| 5808 | |||
| 5809 | $sth = $this->db->prepare($query); |
||
| 5810 | $sth->execute(array(':ident' => $ident)); |
||
| 5811 | $aircraft_array = array(); |
||
| 5812 | $temp_array = array(); |
||
| 5813 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5814 | { |
||
| 5815 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5816 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 5817 | $aircraft_array[] = $temp_array; |
||
| 5818 | } |
||
| 5819 | return $aircraft_array; |
||
| 5820 | } |
||
| 5821 | |||
| 5822 | /** |
||
| 5823 | * Gets all aircraft manufacturer that have flown over by owner |
||
| 5824 | * |
||
| 5825 | * @return Array the aircraft manufacturer list |
||
| 5826 | * |
||
| 5827 | */ |
||
| 5828 | public function countAllAircraftManufacturerByOwner($owner,$filters = array()) |
||
| 5829 | { |
||
| 5830 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5831 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 5832 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5833 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND spotter_output.owner_name = :owner |
||
| 5834 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5835 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5836 | |||
| 5837 | |||
| 5838 | $sth = $this->db->prepare($query); |
||
| 5839 | $sth->execute(array(':owner' => $owner)); |
||
| 5840 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 5841 | } |
||
| 5842 | |||
| 5843 | /** |
||
| 5844 | * Gets all aircraft manufacturer that have flown over by pilot |
||
| 5845 | * |
||
| 5846 | * @return Array the aircraft manufacturer list |
||
| 5847 | * |
||
| 5848 | */ |
||
| 5849 | public function countAllAircraftManufacturerByPilot($pilot,$filters = array()) |
||
| 5850 | { |
||
| 5851 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5852 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 5853 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5854 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 5855 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5856 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5857 | |||
| 5858 | |||
| 5859 | $sth = $this->db->prepare($query); |
||
| 5860 | $sth->execute(array(':pilot' => $pilot)); |
||
| 5861 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 5862 | } |
||
| 5863 | |||
| 5864 | |||
| 5865 | /** |
||
| 5866 | * Gets all aircraft types that have flown over by route |
||
| 5867 | * |
||
| 5868 | * @return Array the aircraft list |
||
| 5869 | * |
||
| 5870 | */ |
||
| 5871 | public function countAllAircraftTypesByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
| 5872 | { |
||
| 5873 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5874 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5875 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5876 | |||
| 5877 | |||
| 5878 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5879 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 5880 | GROUP BY spotter_output.aircraft_name |
||
| 5881 | ORDER BY aircraft_icao_count DESC"; |
||
| 5882 | |||
| 5883 | |||
| 5884 | $sth = $this->db->prepare($query); |
||
| 5885 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 5886 | $aircraft_array = array(); |
||
| 5887 | $temp_array = array(); |
||
| 5888 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5889 | { |
||
| 5890 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5891 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5892 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 5893 | $aircraft_array[] = $temp_array; |
||
| 5894 | } |
||
| 5895 | return $aircraft_array; |
||
| 5896 | } |
||
| 5897 | |||
| 5898 | /** |
||
| 5899 | * Gets all aircraft registration that have flown over by route |
||
| 5900 | * |
||
| 5901 | * @return Array the aircraft list |
||
| 5902 | * |
||
| 5903 | */ |
||
| 5904 | public function countAllAircraftRegistrationByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
| 5905 | { |
||
| 5906 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5907 | $Image = new Image($this->db); |
||
| 5908 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5909 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5910 | |||
| 5911 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 5912 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 5913 | GROUP BY spotter_output.registration |
||
| 5914 | ORDER BY registration_count DESC"; |
||
| 5915 | |||
| 5916 | |||
| 5917 | $sth = $this->db->prepare($query); |
||
| 5918 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 5919 | |||
| 5920 | $aircraft_array = array(); |
||
| 5921 | $temp_array = array(); |
||
| 5922 | |||
| 5923 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5924 | { |
||
| 5925 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 5926 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 5927 | $temp_array['registration'] = $row['registration']; |
||
| 5928 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 5929 | $temp_array['image_thumbnail'] = ""; |
||
| 5930 | if($row['registration'] != "") |
||
| 5931 | { |
||
| 5932 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 5933 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 5934 | } |
||
| 5935 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 5936 | |||
| 5937 | $aircraft_array[] = $temp_array; |
||
| 5938 | } |
||
| 5939 | |||
| 5940 | return $aircraft_array; |
||
| 5941 | } |
||
| 5942 | |||
| 5943 | |||
| 5944 | /** |
||
| 5945 | * Gets all aircraft manufacturer that have flown over by route |
||
| 5946 | * |
||
| 5947 | * @return Array the aircraft manufacturer list |
||
| 5948 | * |
||
| 5949 | */ |
||
| 5950 | public function countAllAircraftManufacturerByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
| 5951 | { |
||
| 5952 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5953 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5954 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 5955 | |||
| 5956 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 5957 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 5958 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 5959 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 5960 | |||
| 5961 | |||
| 5962 | $sth = $this->db->prepare($query); |
||
| 5963 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 5964 | |||
| 5965 | $aircraft_array = array(); |
||
| 5966 | $temp_array = array(); |
||
| 5967 | |||
| 5968 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5969 | { |
||
| 5970 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 5971 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 5972 | |||
| 5973 | $aircraft_array[] = $temp_array; |
||
| 5974 | } |
||
| 5975 | |||
| 5976 | return $aircraft_array; |
||
| 5977 | } |
||
| 5978 | |||
| 5979 | |||
| 5980 | |||
| 5981 | |||
| 5982 | /** |
||
| 5983 | * Gets all aircraft types that have flown over by country |
||
| 5984 | * |
||
| 5985 | * @return Array the aircraft list |
||
| 5986 | * |
||
| 5987 | */ |
||
| 5988 | public function countAllAircraftTypesByCountry($country,$filters = array()) |
||
| 5989 | { |
||
| 5990 | $filter_query = $this->getFilter($filters,true,true); |
||
| 5991 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 5992 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 5993 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 5994 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 5995 | ORDER BY aircraft_icao_count DESC"; |
||
| 5996 | |||
| 5997 | |||
| 5998 | $sth = $this->db->prepare($query); |
||
| 5999 | $sth->execute(array(':country' => $country)); |
||
| 6000 | |||
| 6001 | $aircraft_array = array(); |
||
| 6002 | $temp_array = array(); |
||
| 6003 | |||
| 6004 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6005 | { |
||
| 6006 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 6007 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 6008 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 6009 | |||
| 6010 | $aircraft_array[] = $temp_array; |
||
| 6011 | } |
||
| 6012 | |||
| 6013 | return $aircraft_array; |
||
| 6014 | } |
||
| 6015 | |||
| 6016 | |||
| 6017 | /** |
||
| 6018 | * Gets all aircraft registration that have flown over by country |
||
| 6019 | * |
||
| 6020 | * @return Array the aircraft list |
||
| 6021 | * |
||
| 6022 | */ |
||
| 6023 | public function countAllAircraftRegistrationByCountry($country,$filters = array()) |
||
| 6024 | { |
||
| 6025 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6026 | $Image = new Image($this->db); |
||
| 6027 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 6028 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name |
||
| 6029 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country) |
||
| 6030 | GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 6031 | ORDER BY registration_count DESC"; |
||
| 6032 | |||
| 6033 | |||
| 6034 | $sth = $this->db->prepare($query); |
||
| 6035 | $sth->execute(array(':country' => $country)); |
||
| 6036 | |||
| 6037 | $aircraft_array = array(); |
||
| 6038 | $temp_array = array(); |
||
| 6039 | |||
| 6040 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6041 | { |
||
| 6042 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 6043 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 6044 | $temp_array['registration'] = $row['registration']; |
||
| 6045 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 6046 | $temp_array['image_thumbnail'] = ""; |
||
| 6047 | if($row['registration'] != "") |
||
| 6048 | { |
||
| 6049 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 6050 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 6051 | } |
||
| 6052 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 6053 | |||
| 6054 | $aircraft_array[] = $temp_array; |
||
| 6055 | } |
||
| 6056 | |||
| 6057 | return $aircraft_array; |
||
| 6058 | } |
||
| 6059 | |||
| 6060 | |||
| 6061 | /** |
||
| 6062 | * Gets all aircraft manufacturer that have flown over by country |
||
| 6063 | * |
||
| 6064 | * @return Array the aircraft manufacturer list |
||
| 6065 | * |
||
| 6066 | */ |
||
| 6067 | public function countAllAircraftManufacturerByCountry($country,$filters = array()) |
||
| 6068 | { |
||
| 6069 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6070 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 6071 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 6072 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country) |
||
| 6073 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 6074 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 6075 | |||
| 6076 | |||
| 6077 | $sth = $this->db->prepare($query); |
||
| 6078 | $sth->execute(array(':country' => $country)); |
||
| 6079 | |||
| 6080 | $aircraft_array = array(); |
||
| 6081 | $temp_array = array(); |
||
| 6082 | |||
| 6083 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6084 | { |
||
| 6085 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 6086 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 6087 | |||
| 6088 | $aircraft_array[] = $temp_array; |
||
| 6089 | } |
||
| 6090 | |||
| 6091 | return $aircraft_array; |
||
| 6092 | } |
||
| 6093 | |||
| 6094 | |||
| 6095 | |||
| 6096 | /** |
||
| 6097 | * Gets all aircraft manufacturers that have flown over |
||
| 6098 | * |
||
| 6099 | * @return Array the aircraft list |
||
| 6100 | * |
||
| 6101 | */ |
||
| 6102 | public function countAllAircraftManufacturers($filters = array(),$year = '',$month = '',$day = '') |
||
| 6103 | { |
||
| 6104 | global $globalDBdriver; |
||
| 6105 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6106 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 6107 | FROM spotter_output ".$filter_query." spotter_output.aircraft_manufacturer <> '' AND spotter_output.aircraft_manufacturer <> 'Not Available'"; |
||
| 6108 | $query_values = array(); |
||
| 6109 | if ($year != '') { |
||
| 6110 | if ($globalDBdriver == 'mysql') { |
||
| 6111 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 6112 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6113 | } else { |
||
| 6114 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 6115 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6116 | } |
||
| 6117 | } |
||
| 6118 | if ($month != '') { |
||
| 6119 | if ($globalDBdriver == 'mysql') { |
||
| 6120 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 6121 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6122 | } else { |
||
| 6123 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 6124 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6125 | } |
||
| 6126 | } |
||
| 6127 | if ($day != '') { |
||
| 6128 | if ($globalDBdriver == 'mysql') { |
||
| 6129 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 6130 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6131 | } else { |
||
| 6132 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 6133 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6134 | } |
||
| 6135 | } |
||
| 6136 | $query .= " GROUP BY spotter_output.aircraft_manufacturer |
||
| 6137 | ORDER BY aircraft_manufacturer_count DESC |
||
| 6138 | LIMIT 10"; |
||
| 6139 | |||
| 6140 | |||
| 6141 | $sth = $this->db->prepare($query); |
||
| 6142 | $sth->execute($query_values); |
||
| 6143 | |||
| 6144 | $manufacturer_array = array(); |
||
| 6145 | $temp_array = array(); |
||
| 6146 | |||
| 6147 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6148 | { |
||
| 6149 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 6150 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 6151 | |||
| 6152 | $manufacturer_array[] = $temp_array; |
||
| 6153 | } |
||
| 6154 | |||
| 6155 | return $manufacturer_array; |
||
| 6156 | } |
||
| 6157 | |||
| 6158 | |||
| 6159 | |||
| 6160 | /** |
||
| 6161 | * Gets all aircraft registrations that have flown over |
||
| 6162 | * |
||
| 6163 | * @return Array the aircraft list |
||
| 6164 | * |
||
| 6165 | */ |
||
| 6166 | public function countAllAircraftRegistrations($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '', $month = '', $day = '') |
||
| 6167 | { |
||
| 6168 | global $globalDBdriver; |
||
| 6169 | $Image = new Image($this->db); |
||
| 6170 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6171 | $query = "SELECT DISTINCT spotter_output.registration, COUNT(spotter_output.registration) AS aircraft_registration_count, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 6172 | FROM spotter_output ".$filter_query." spotter_output.registration <> '' AND spotter_output.registration <> 'NA'"; |
||
| 6173 | if ($olderthanmonths > 0) { |
||
| 6174 | if ($globalDBdriver == 'mysql') { |
||
| 6175 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 6176 | } else { |
||
| 6177 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 6178 | } |
||
| 6179 | } |
||
| 6180 | if ($sincedate != '') { |
||
| 6181 | if ($globalDBdriver == 'mysql') { |
||
| 6182 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 6183 | } else { |
||
| 6184 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 6185 | } |
||
| 6186 | } |
||
| 6187 | $query_values = array(); |
||
| 6188 | if ($year != '') { |
||
| 6189 | if ($globalDBdriver == 'mysql') { |
||
| 6190 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 6191 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6192 | } else { |
||
| 6193 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 6194 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6195 | } |
||
| 6196 | } |
||
| 6197 | if ($month != '') { |
||
| 6198 | if ($globalDBdriver == 'mysql') { |
||
| 6199 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 6200 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6201 | } else { |
||
| 6202 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 6203 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6204 | } |
||
| 6205 | } |
||
| 6206 | if ($day != '') { |
||
| 6207 | if ($globalDBdriver == 'mysql') { |
||
| 6208 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 6209 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6210 | } else { |
||
| 6211 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 6212 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6213 | } |
||
| 6214 | } |
||
| 6215 | $query .= " GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name ORDER BY aircraft_registration_count DESC"; |
||
| 6216 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6217 | |||
| 6218 | $sth = $this->db->prepare($query); |
||
| 6219 | $sth->execute($query_values); |
||
| 6220 | |||
| 6221 | $aircraft_array = array(); |
||
| 6222 | $temp_array = array(); |
||
| 6223 | |||
| 6224 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6225 | { |
||
| 6226 | $temp_array['registration'] = $row['registration']; |
||
| 6227 | $temp_array['aircraft_registration_count'] = $row['aircraft_registration_count']; |
||
| 6228 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 6229 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 6230 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 6231 | $temp_array['image_thumbnail'] = ""; |
||
| 6232 | if($row['registration'] != "") |
||
| 6233 | { |
||
| 6234 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 6235 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 6236 | } |
||
| 6237 | |||
| 6238 | $aircraft_array[] = $temp_array; |
||
| 6239 | } |
||
| 6240 | |||
| 6241 | return $aircraft_array; |
||
| 6242 | } |
||
| 6243 | |||
| 6244 | |||
| 6245 | /** |
||
| 6246 | * Gets all aircraft registrations that have flown over |
||
| 6247 | * |
||
| 6248 | * @return Array the aircraft list |
||
| 6249 | * |
||
| 6250 | */ |
||
| 6251 | public function countAllAircraftRegistrationsByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
| 6252 | { |
||
| 6253 | global $globalDBdriver; |
||
| 6254 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6255 | $Image = new Image($this->db); |
||
| 6256 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.registration, COUNT(spotter_output.registration) AS aircraft_registration_count, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 6257 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.registration <> '' AND spotter_output.registration <> 'NA' "; |
||
| 6258 | if ($olderthanmonths > 0) { |
||
| 6259 | if ($globalDBdriver == 'mysql') { |
||
| 6260 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6261 | } else { |
||
| 6262 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 6263 | } |
||
| 6264 | } |
||
| 6265 | if ($sincedate != '') { |
||
| 6266 | if ($globalDBdriver == 'mysql') { |
||
| 6267 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 6268 | } else { |
||
| 6269 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 6270 | } |
||
| 6271 | } |
||
| 6272 | |||
| 6273 | // if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6274 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 6275 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name ORDER BY aircraft_registration_count DESC"; |
||
| 6276 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6277 | |||
| 6278 | $sth = $this->db->prepare($query); |
||
| 6279 | $sth->execute(); |
||
| 6280 | |||
| 6281 | $aircraft_array = array(); |
||
| 6282 | $temp_array = array(); |
||
| 6283 | |||
| 6284 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6285 | { |
||
| 6286 | $temp_array['registration'] = $row['registration']; |
||
| 6287 | $temp_array['aircraft_registration_count'] = $row['aircraft_registration_count']; |
||
| 6288 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 6289 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 6290 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 6291 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 6292 | $temp_array['image_thumbnail'] = ""; |
||
| 6293 | if($row['registration'] != "") |
||
| 6294 | { |
||
| 6295 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 6296 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 6297 | } |
||
| 6298 | |||
| 6299 | $aircraft_array[] = $temp_array; |
||
| 6300 | } |
||
| 6301 | |||
| 6302 | return $aircraft_array; |
||
| 6303 | } |
||
| 6304 | |||
| 6305 | |||
| 6306 | /** |
||
| 6307 | * Gets all departure airports of the airplanes that have flown over |
||
| 6308 | * |
||
| 6309 | * @return Array the airport list |
||
| 6310 | * |
||
| 6311 | */ |
||
| 6312 | public function countAllDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '',$month = '',$day = '') |
||
| 6313 | { |
||
| 6314 | global $globalDBdriver; |
||
| 6315 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6316 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6317 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> ''"; |
||
| 6318 | if ($olderthanmonths > 0) { |
||
| 6319 | if ($globalDBdriver == 'mysql') { |
||
| 6320 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 6321 | } else { |
||
| 6322 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 6323 | } |
||
| 6324 | } |
||
| 6325 | if ($sincedate != '') { |
||
| 6326 | if ($globalDBdriver == 'mysql') { |
||
| 6327 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 6328 | } else { |
||
| 6329 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 6330 | } |
||
| 6331 | } |
||
| 6332 | $query_values = array(); |
||
| 6333 | if ($year != '') { |
||
| 6334 | if ($globalDBdriver == 'mysql') { |
||
| 6335 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 6336 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6337 | } else { |
||
| 6338 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 6339 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6340 | } |
||
| 6341 | } |
||
| 6342 | if ($month != '') { |
||
| 6343 | if ($globalDBdriver == 'mysql') { |
||
| 6344 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 6345 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6346 | } else { |
||
| 6347 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 6348 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6349 | } |
||
| 6350 | } |
||
| 6351 | if ($day != '') { |
||
| 6352 | if ($globalDBdriver == 'mysql') { |
||
| 6353 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 6354 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6355 | } else { |
||
| 6356 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 6357 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6358 | } |
||
| 6359 | } |
||
| 6360 | $query .= " GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6361 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6362 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6363 | |||
| 6364 | $sth = $this->db->prepare($query); |
||
| 6365 | $sth->execute($query_values); |
||
| 6366 | |||
| 6367 | $airport_array = array(); |
||
| 6368 | $temp_array = array(); |
||
| 6369 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6370 | { |
||
| 6371 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6372 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6373 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6374 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6375 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6376 | |||
| 6377 | $airport_array[] = $temp_array; |
||
| 6378 | } |
||
| 6379 | return $airport_array; |
||
| 6380 | } |
||
| 6381 | |||
| 6382 | /** |
||
| 6383 | * Gets all departure airports of the airplanes that have flown over |
||
| 6384 | * |
||
| 6385 | * @return Array the airport list |
||
| 6386 | * |
||
| 6387 | */ |
||
| 6388 | public function countAllDepartureAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
| 6389 | { |
||
| 6390 | global $globalDBdriver; |
||
| 6391 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6392 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6393 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' "; |
||
| 6394 | if ($olderthanmonths > 0) { |
||
| 6395 | if ($globalDBdriver == 'mysql') { |
||
| 6396 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6397 | } else { |
||
| 6398 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 6399 | } |
||
| 6400 | } |
||
| 6401 | if ($sincedate != '') { |
||
| 6402 | if ($globalDBdriver == 'mysql') { |
||
| 6403 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 6404 | } else { |
||
| 6405 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 6406 | } |
||
| 6407 | } |
||
| 6408 | |||
| 6409 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6410 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 6411 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6412 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6413 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6414 | |||
| 6415 | $sth = $this->db->prepare($query); |
||
| 6416 | $sth->execute(); |
||
| 6417 | |||
| 6418 | $airport_array = array(); |
||
| 6419 | $temp_array = array(); |
||
| 6420 | |||
| 6421 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6422 | { |
||
| 6423 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 6424 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6425 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6426 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6427 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6428 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6429 | |||
| 6430 | $airport_array[] = $temp_array; |
||
| 6431 | } |
||
| 6432 | return $airport_array; |
||
| 6433 | } |
||
| 6434 | |||
| 6435 | /** |
||
| 6436 | * Gets all detected departure airports of the airplanes that have flown over |
||
| 6437 | * |
||
| 6438 | * @return Array the airport list |
||
| 6439 | * |
||
| 6440 | */ |
||
| 6441 | public function countAllDetectedDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '',$month = '',$day = '') |
||
| 6442 | { |
||
| 6443 | global $globalDBdriver; |
||
| 6444 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6445 | $query = "SELECT DISTINCT spotter_output.real_departure_airport_icao AS departure_airport_icao, COUNT(spotter_output.real_departure_airport_icao) AS airport_departure_icao_count, airport.name as departure_airport_name, airport.city as departure_airport_city, airport.country as departure_airport_country |
||
| 6446 | FROM airport, spotter_output".$filter_query." spotter_output.real_departure_airport_icao <> '' AND spotter_output.real_departure_airport_icao <> 'NA' AND airport.icao = spotter_output.real_departure_airport_icao"; |
||
| 6447 | if ($olderthanmonths > 0) { |
||
| 6448 | if ($globalDBdriver == 'mysql') { |
||
| 6449 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 6450 | } else { |
||
| 6451 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 6452 | } |
||
| 6453 | } |
||
| 6454 | if ($sincedate != '') { |
||
| 6455 | if ($globalDBdriver == 'mysql') { |
||
| 6456 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 6457 | } else { |
||
| 6458 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 6459 | } |
||
| 6460 | } |
||
| 6461 | $query_values = array(); |
||
| 6462 | if ($year != '') { |
||
| 6463 | if ($globalDBdriver == 'mysql') { |
||
| 6464 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 6465 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6466 | } else { |
||
| 6467 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 6468 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 6469 | } |
||
| 6470 | } |
||
| 6471 | if ($month != '') { |
||
| 6472 | if ($globalDBdriver == 'mysql') { |
||
| 6473 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 6474 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6475 | } else { |
||
| 6476 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 6477 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 6478 | } |
||
| 6479 | } |
||
| 6480 | if ($day != '') { |
||
| 6481 | if ($globalDBdriver == 'mysql') { |
||
| 6482 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 6483 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6484 | } else { |
||
| 6485 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 6486 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 6487 | } |
||
| 6488 | } |
||
| 6489 | $query .= " GROUP BY spotter_output.real_departure_airport_icao, airport.name, airport.city, airport.country |
||
| 6490 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6491 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6492 | //echo $query; |
||
| 6493 | $sth = $this->db->prepare($query); |
||
| 6494 | $sth->execute($query_values); |
||
| 6495 | |||
| 6496 | $airport_array = array(); |
||
| 6497 | $temp_array = array(); |
||
| 6498 | |||
| 6499 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6500 | { |
||
| 6501 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6502 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6503 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6504 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6505 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6506 | |||
| 6507 | $airport_array[] = $temp_array; |
||
| 6508 | } |
||
| 6509 | return $airport_array; |
||
| 6510 | } |
||
| 6511 | |||
| 6512 | /** |
||
| 6513 | * Gets all detected departure airports of the airplanes that have flown over |
||
| 6514 | * |
||
| 6515 | * @return Array the airport list |
||
| 6516 | * |
||
| 6517 | */ |
||
| 6518 | public function countAllDetectedDepartureAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
| 6519 | { |
||
| 6520 | global $globalDBdriver; |
||
| 6521 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6522 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.real_departure_airport_icao AS departure_airport_icao, COUNT(spotter_output.real_departure_airport_icao) AS airport_departure_icao_count, airport.name as departure_airport_name, airport.city as departure_airport_city, airport.country as departure_airport_country |
||
| 6523 | FROM airport, spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.real_departure_airport_icao <> '' AND spotter_output.real_departure_airport_icao <> 'NA' AND airport.icao = spotter_output.real_departure_airport_icao "; |
||
| 6524 | if ($olderthanmonths > 0) { |
||
| 6525 | if ($globalDBdriver == 'mysql') { |
||
| 6526 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6527 | } else { |
||
| 6528 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 6529 | } |
||
| 6530 | } |
||
| 6531 | if ($sincedate != '') { |
||
| 6532 | if ($globalDBdriver == 'mysql') { |
||
| 6533 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 6534 | } else { |
||
| 6535 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP) "; |
||
| 6536 | } |
||
| 6537 | } |
||
| 6538 | |||
| 6539 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6540 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 6541 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.real_departure_airport_icao, airport.name, airport.city, airport.country |
||
| 6542 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6543 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6544 | |||
| 6545 | $sth = $this->db->prepare($query); |
||
| 6546 | $sth->execute(); |
||
| 6547 | |||
| 6548 | $airport_array = array(); |
||
| 6549 | $temp_array = array(); |
||
| 6550 | |||
| 6551 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6552 | { |
||
| 6553 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 6554 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6555 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6556 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6557 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6558 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6559 | |||
| 6560 | $airport_array[] = $temp_array; |
||
| 6561 | } |
||
| 6562 | return $airport_array; |
||
| 6563 | } |
||
| 6564 | |||
| 6565 | /** |
||
| 6566 | * Gets all departure airports of the airplanes that have flown over based on an airline icao |
||
| 6567 | * |
||
| 6568 | * @return Array the airport list |
||
| 6569 | * |
||
| 6570 | */ |
||
| 6571 | public function countAllDepartureAirportsByAirline($airline_icao,$filters = array()) |
||
| 6572 | { |
||
| 6573 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6574 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 6575 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6576 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.airline_icao = :airline_icao AND spotter_output.departure_airport_icao <> '' |
||
| 6577 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6578 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6579 | |||
| 6580 | |||
| 6581 | $sth = $this->db->prepare($query); |
||
| 6582 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 6583 | |||
| 6584 | $airport_array = array(); |
||
| 6585 | $temp_array = array(); |
||
| 6586 | |||
| 6587 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6588 | { |
||
| 6589 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6590 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6591 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6592 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6593 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6594 | |||
| 6595 | $airport_array[] = $temp_array; |
||
| 6596 | } |
||
| 6597 | |||
| 6598 | return $airport_array; |
||
| 6599 | } |
||
| 6600 | |||
| 6601 | |||
| 6602 | |||
| 6603 | /** |
||
| 6604 | * Gets all departure airports by country of the airplanes that have flown over based on an airline icao |
||
| 6605 | * |
||
| 6606 | * @return Array the airport list |
||
| 6607 | * |
||
| 6608 | */ |
||
| 6609 | public function countAllDepartureAirportCountriesByAirline($airline_icao,$filters = array()) |
||
| 6610 | { |
||
| 6611 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6612 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 6613 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6614 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 6615 | GROUP BY spotter_output.departure_airport_country |
||
| 6616 | ORDER BY airport_departure_country_count DESC"; |
||
| 6617 | |||
| 6618 | |||
| 6619 | $sth = $this->db->prepare($query); |
||
| 6620 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 6621 | |||
| 6622 | $airport_array = array(); |
||
| 6623 | $temp_array = array(); |
||
| 6624 | |||
| 6625 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6626 | { |
||
| 6627 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 6628 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6629 | |||
| 6630 | $airport_array[] = $temp_array; |
||
| 6631 | } |
||
| 6632 | |||
| 6633 | return $airport_array; |
||
| 6634 | } |
||
| 6635 | |||
| 6636 | |||
| 6637 | |||
| 6638 | /** |
||
| 6639 | * Gets all departure airports of the airplanes that have flown over based on an aircraft icao |
||
| 6640 | * |
||
| 6641 | * @return Array the airport list |
||
| 6642 | * |
||
| 6643 | */ |
||
| 6644 | public function countAllDepartureAirportsByAircraft($aircraft_icao,$filters = array()) |
||
| 6645 | { |
||
| 6646 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6647 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 6648 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6649 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_icao = :aircraft_icao AND spotter_output.departure_airport_icao <> '' |
||
| 6650 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6651 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6652 | |||
| 6653 | |||
| 6654 | $sth = $this->db->prepare($query); |
||
| 6655 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 6656 | |||
| 6657 | $airport_array = array(); |
||
| 6658 | $temp_array = array(); |
||
| 6659 | |||
| 6660 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6661 | { |
||
| 6662 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6663 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6664 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6665 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6666 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6667 | |||
| 6668 | $airport_array[] = $temp_array; |
||
| 6669 | } |
||
| 6670 | |||
| 6671 | return $airport_array; |
||
| 6672 | } |
||
| 6673 | |||
| 6674 | |||
| 6675 | /** |
||
| 6676 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 6677 | * |
||
| 6678 | * @return Array the airport list |
||
| 6679 | * |
||
| 6680 | */ |
||
| 6681 | public function countAllDepartureAirportCountriesByAircraft($aircraft_icao,$filters = array()) |
||
| 6682 | { |
||
| 6683 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6684 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 6685 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6686 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 6687 | GROUP BY spotter_output.departure_airport_country |
||
| 6688 | ORDER BY airport_departure_country_count DESC"; |
||
| 6689 | |||
| 6690 | |||
| 6691 | $sth = $this->db->prepare($query); |
||
| 6692 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 6693 | |||
| 6694 | $airport_array = array(); |
||
| 6695 | $temp_array = array(); |
||
| 6696 | |||
| 6697 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6698 | { |
||
| 6699 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 6700 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6701 | |||
| 6702 | $airport_array[] = $temp_array; |
||
| 6703 | } |
||
| 6704 | |||
| 6705 | return $airport_array; |
||
| 6706 | } |
||
| 6707 | |||
| 6708 | |||
| 6709 | /** |
||
| 6710 | * Gets all departure airports of the airplanes that have flown over based on an aircraft registration |
||
| 6711 | * |
||
| 6712 | * @return Array the airport list |
||
| 6713 | * |
||
| 6714 | */ |
||
| 6715 | public function countAllDepartureAirportsByRegistration($registration,$filters = array()) |
||
| 6716 | { |
||
| 6717 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6718 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 6719 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6720 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.registration = :registration AND spotter_output.departure_airport_icao <> '' |
||
| 6721 | GROUP BY spotter_output.departure_airport_icao |
||
| 6722 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6723 | |||
| 6724 | |||
| 6725 | $sth = $this->db->prepare($query); |
||
| 6726 | $sth->execute(array(':registration' => $registration)); |
||
| 6727 | |||
| 6728 | $airport_array = array(); |
||
| 6729 | $temp_array = array(); |
||
| 6730 | |||
| 6731 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6732 | { |
||
| 6733 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6734 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6735 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6736 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6737 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6738 | |||
| 6739 | $airport_array[] = $temp_array; |
||
| 6740 | } |
||
| 6741 | |||
| 6742 | return $airport_array; |
||
| 6743 | } |
||
| 6744 | |||
| 6745 | |||
| 6746 | /** |
||
| 6747 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft registration |
||
| 6748 | * |
||
| 6749 | * @return Array the airport list |
||
| 6750 | * |
||
| 6751 | */ |
||
| 6752 | public function countAllDepartureAirportCountriesByRegistration($registration,$filters = array()) |
||
| 6753 | { |
||
| 6754 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6755 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 6756 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6757 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.registration = :registration |
||
| 6758 | GROUP BY spotter_output.departure_airport_country |
||
| 6759 | ORDER BY airport_departure_country_count DESC"; |
||
| 6760 | |||
| 6761 | |||
| 6762 | $sth = $this->db->prepare($query); |
||
| 6763 | $sth->execute(array(':registration' => $registration)); |
||
| 6764 | |||
| 6765 | $airport_array = array(); |
||
| 6766 | $temp_array = array(); |
||
| 6767 | |||
| 6768 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6769 | { |
||
| 6770 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 6771 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6772 | |||
| 6773 | $airport_array[] = $temp_array; |
||
| 6774 | } |
||
| 6775 | |||
| 6776 | return $airport_array; |
||
| 6777 | } |
||
| 6778 | |||
| 6779 | |||
| 6780 | /** |
||
| 6781 | * Gets all departure airports of the airplanes that have flown over based on an arrivl airport icao |
||
| 6782 | * |
||
| 6783 | * @return Array the airport list |
||
| 6784 | * |
||
| 6785 | */ |
||
| 6786 | public function countAllDepartureAirportsByAirport($airport_icao,$filters = array()) |
||
| 6787 | { |
||
| 6788 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6789 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 6790 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6791 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao = :airport_icao AND spotter_output.departure_airport_icao <> '' |
||
| 6792 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6793 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6794 | |||
| 6795 | |||
| 6796 | $sth = $this->db->prepare($query); |
||
| 6797 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 6798 | |||
| 6799 | $airport_array = array(); |
||
| 6800 | $temp_array = array(); |
||
| 6801 | |||
| 6802 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6803 | { |
||
| 6804 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6805 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6806 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6807 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6808 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6809 | |||
| 6810 | $airport_array[] = $temp_array; |
||
| 6811 | } |
||
| 6812 | |||
| 6813 | return $airport_array; |
||
| 6814 | } |
||
| 6815 | |||
| 6816 | |||
| 6817 | /** |
||
| 6818 | * Gets all departure airports by country of the airplanes that have flown over based on an airport icao |
||
| 6819 | * |
||
| 6820 | * @return Array the airport list |
||
| 6821 | * |
||
| 6822 | */ |
||
| 6823 | public function countAllDepartureAirportCountriesByAirport($airport_icao,$filters = array()) |
||
| 6824 | { |
||
| 6825 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6826 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 6827 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6828 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.arrival_airport_icao = :airport_icao |
||
| 6829 | GROUP BY spotter_output.departure_airport_country |
||
| 6830 | ORDER BY airport_departure_country_count DESC"; |
||
| 6831 | |||
| 6832 | |||
| 6833 | $sth = $this->db->prepare($query); |
||
| 6834 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 6835 | |||
| 6836 | $airport_array = array(); |
||
| 6837 | $temp_array = array(); |
||
| 6838 | |||
| 6839 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6840 | { |
||
| 6841 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 6842 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6843 | |||
| 6844 | $airport_array[] = $temp_array; |
||
| 6845 | } |
||
| 6846 | |||
| 6847 | return $airport_array; |
||
| 6848 | } |
||
| 6849 | |||
| 6850 | |||
| 6851 | |||
| 6852 | /** |
||
| 6853 | * Gets all departure airports of the airplanes that have flown over based on an aircraft manufacturer |
||
| 6854 | * |
||
| 6855 | * @return Array the airport list |
||
| 6856 | * |
||
| 6857 | */ |
||
| 6858 | public function countAllDepartureAirportsByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 6859 | { |
||
| 6860 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6861 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 6862 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6863 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer AND spotter_output.departure_airport_icao <> '' |
||
| 6864 | GROUP BY spotter_output.departure_airport_icao |
||
| 6865 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6866 | |||
| 6867 | |||
| 6868 | $sth = $this->db->prepare($query); |
||
| 6869 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 6870 | |||
| 6871 | $airport_array = array(); |
||
| 6872 | $temp_array = array(); |
||
| 6873 | |||
| 6874 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6875 | { |
||
| 6876 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6877 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6878 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6879 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6880 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6881 | |||
| 6882 | $airport_array[] = $temp_array; |
||
| 6883 | } |
||
| 6884 | |||
| 6885 | return $airport_array; |
||
| 6886 | } |
||
| 6887 | |||
| 6888 | |||
| 6889 | /** |
||
| 6890 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft manufacturer |
||
| 6891 | * |
||
| 6892 | * @return Array the airport list |
||
| 6893 | * |
||
| 6894 | */ |
||
| 6895 | public function countAllDepartureAirportCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 6896 | { |
||
| 6897 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6898 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 6899 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6900 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 6901 | GROUP BY spotter_output.departure_airport_country |
||
| 6902 | ORDER BY airport_departure_country_count DESC"; |
||
| 6903 | |||
| 6904 | |||
| 6905 | $sth = $this->db->prepare($query); |
||
| 6906 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 6907 | |||
| 6908 | $airport_array = array(); |
||
| 6909 | $temp_array = array(); |
||
| 6910 | |||
| 6911 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6912 | { |
||
| 6913 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 6914 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6915 | |||
| 6916 | $airport_array[] = $temp_array; |
||
| 6917 | } |
||
| 6918 | |||
| 6919 | return $airport_array; |
||
| 6920 | } |
||
| 6921 | |||
| 6922 | |||
| 6923 | /** |
||
| 6924 | * Gets all departure airports of the airplanes that have flown over based on a date |
||
| 6925 | * |
||
| 6926 | * @return Array the airport list |
||
| 6927 | * |
||
| 6928 | */ |
||
| 6929 | public function countAllDepartureAirportsByDate($date,$filters = array()) |
||
| 6930 | { |
||
| 6931 | global $globalTimezone, $globalDBdriver; |
||
| 6932 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6933 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 6934 | if ($globalTimezone != '') { |
||
| 6935 | date_default_timezone_set($globalTimezone); |
||
| 6936 | $datetime = new DateTime($date); |
||
| 6937 | $offset = $datetime->format('P'); |
||
| 6938 | } else $offset = '+00:00'; |
||
| 6939 | |||
| 6940 | if ($globalDBdriver == 'mysql') { |
||
| 6941 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6942 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 6943 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6944 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6945 | } else { |
||
| 6946 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6947 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 6948 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 6949 | ORDER BY airport_departure_icao_count DESC"; |
||
| 6950 | } |
||
| 6951 | |||
| 6952 | $sth = $this->db->prepare($query); |
||
| 6953 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 6954 | |||
| 6955 | $airport_array = array(); |
||
| 6956 | $temp_array = array(); |
||
| 6957 | |||
| 6958 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6959 | { |
||
| 6960 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6961 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 6962 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 6963 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 6964 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6965 | |||
| 6966 | $airport_array[] = $temp_array; |
||
| 6967 | } |
||
| 6968 | return $airport_array; |
||
| 6969 | } |
||
| 6970 | |||
| 6971 | |||
| 6972 | |||
| 6973 | /** |
||
| 6974 | * Gets all departure airports by country of the airplanes that have flown over based on a date |
||
| 6975 | * |
||
| 6976 | * @return Array the airport list |
||
| 6977 | * |
||
| 6978 | */ |
||
| 6979 | public function countAllDepartureAirportCountriesByDate($date,$filters = array()) |
||
| 6980 | { |
||
| 6981 | global $globalTimezone, $globalDBdriver; |
||
| 6982 | $filter_query = $this->getFilter($filters,true,true); |
||
| 6983 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 6984 | if ($globalTimezone != '') { |
||
| 6985 | date_default_timezone_set($globalTimezone); |
||
| 6986 | $datetime = new DateTime($date); |
||
| 6987 | $offset = $datetime->format('P'); |
||
| 6988 | } else $offset = '+00:00'; |
||
| 6989 | |||
| 6990 | if ($globalDBdriver == 'mysql') { |
||
| 6991 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6992 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 6993 | GROUP BY spotter_output.departure_airport_country |
||
| 6994 | ORDER BY airport_departure_country_count DESC"; |
||
| 6995 | } else { |
||
| 6996 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6997 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 6998 | GROUP BY spotter_output.departure_airport_country |
||
| 6999 | ORDER BY airport_departure_country_count DESC"; |
||
| 7000 | } |
||
| 7001 | |||
| 7002 | $sth = $this->db->prepare($query); |
||
| 7003 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 7004 | |||
| 7005 | $airport_array = array(); |
||
| 7006 | $temp_array = array(); |
||
| 7007 | |||
| 7008 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7009 | { |
||
| 7010 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 7011 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 7012 | |||
| 7013 | $airport_array[] = $temp_array; |
||
| 7014 | } |
||
| 7015 | return $airport_array; |
||
| 7016 | } |
||
| 7017 | |||
| 7018 | |||
| 7019 | |||
| 7020 | /** |
||
| 7021 | * Gets all departure airports of the airplanes that have flown over based on a ident/callsign |
||
| 7022 | * |
||
| 7023 | * @return Array the airport list |
||
| 7024 | * |
||
| 7025 | */ |
||
| 7026 | public function countAllDepartureAirportsByIdent($ident,$filters = array()) |
||
| 7027 | { |
||
| 7028 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7029 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 7030 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7031 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND spotter_output.ident = :ident |
||
| 7032 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7033 | ORDER BY airport_departure_icao_count DESC"; |
||
| 7034 | |||
| 7035 | |||
| 7036 | $sth = $this->db->prepare($query); |
||
| 7037 | $sth->execute(array(':ident' => $ident)); |
||
| 7038 | |||
| 7039 | $airport_array = array(); |
||
| 7040 | $temp_array = array(); |
||
| 7041 | |||
| 7042 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7043 | { |
||
| 7044 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 7045 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 7046 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 7047 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 7048 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 7049 | |||
| 7050 | $airport_array[] = $temp_array; |
||
| 7051 | } |
||
| 7052 | |||
| 7053 | return $airport_array; |
||
| 7054 | } |
||
| 7055 | |||
| 7056 | /** |
||
| 7057 | * Gets all departure airports of the airplanes that have flown over based on a owner |
||
| 7058 | * |
||
| 7059 | * @return Array the airport list |
||
| 7060 | * |
||
| 7061 | */ |
||
| 7062 | public function countAllDepartureAirportsByOwner($owner,$filters = array()) |
||
| 7063 | { |
||
| 7064 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7065 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 7066 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7067 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND spotter_output.owner_name = :owner |
||
| 7068 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7069 | ORDER BY airport_departure_icao_count DESC"; |
||
| 7070 | |||
| 7071 | |||
| 7072 | $sth = $this->db->prepare($query); |
||
| 7073 | $sth->execute(array(':owner' => $owner)); |
||
| 7074 | |||
| 7075 | $airport_array = array(); |
||
| 7076 | $temp_array = array(); |
||
| 7077 | |||
| 7078 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7079 | { |
||
| 7080 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 7081 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 7082 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 7083 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 7084 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 7085 | |||
| 7086 | $airport_array[] = $temp_array; |
||
| 7087 | } |
||
| 7088 | |||
| 7089 | return $airport_array; |
||
| 7090 | } |
||
| 7091 | |||
| 7092 | /** |
||
| 7093 | * Gets all departure airports of the airplanes that have flown over based on a pilot |
||
| 7094 | * |
||
| 7095 | * @return Array the airport list |
||
| 7096 | * |
||
| 7097 | */ |
||
| 7098 | public function countAllDepartureAirportsByPilot($pilot,$filters = array()) |
||
| 7099 | { |
||
| 7100 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7101 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 7102 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7103 | FROM spotter_output".$filter_query." spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 7104 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7105 | ORDER BY airport_departure_icao_count DESC"; |
||
| 7106 | |||
| 7107 | $sth = $this->db->prepare($query); |
||
| 7108 | $sth->execute(array(':pilot' => $pilot)); |
||
| 7109 | |||
| 7110 | $airport_array = array(); |
||
| 7111 | $temp_array = array(); |
||
| 7112 | |||
| 7113 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7114 | { |
||
| 7115 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 7116 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 7117 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 7118 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 7119 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 7120 | |||
| 7121 | $airport_array[] = $temp_array; |
||
| 7122 | } |
||
| 7123 | |||
| 7124 | return $airport_array; |
||
| 7125 | } |
||
| 7126 | |||
| 7127 | |||
| 7128 | |||
| 7129 | /** |
||
| 7130 | * Gets all departure airports by country of the airplanes that have flown over based on a callsign/ident |
||
| 7131 | * |
||
| 7132 | * @return Array the airport list |
||
| 7133 | * |
||
| 7134 | */ |
||
| 7135 | public function countAllDepartureAirportCountriesByIdent($ident,$filters = array()) |
||
| 7136 | { |
||
| 7137 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7138 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 7139 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 7140 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.ident = :ident |
||
| 7141 | GROUP BY spotter_output.departure_airport_country |
||
| 7142 | ORDER BY airport_departure_country_count DESC"; |
||
| 7143 | |||
| 7144 | |||
| 7145 | $sth = $this->db->prepare($query); |
||
| 7146 | $sth->execute(array(':ident' => $ident)); |
||
| 7147 | |||
| 7148 | $airport_array = array(); |
||
| 7149 | $temp_array = array(); |
||
| 7150 | |||
| 7151 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7152 | { |
||
| 7153 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 7154 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 7155 | |||
| 7156 | $airport_array[] = $temp_array; |
||
| 7157 | } |
||
| 7158 | |||
| 7159 | return $airport_array; |
||
| 7160 | } |
||
| 7161 | |||
| 7162 | /** |
||
| 7163 | * Gets all departure airports by country of the airplanes that have flown over based on owner |
||
| 7164 | * |
||
| 7165 | * @return Array the airport list |
||
| 7166 | * |
||
| 7167 | */ |
||
| 7168 | public function countAllDepartureAirportCountriesByOwner($owner,$filters = array()) |
||
| 7169 | { |
||
| 7170 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7171 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 7172 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 7173 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.owner_name = :owner |
||
| 7174 | GROUP BY spotter_output.departure_airport_country |
||
| 7175 | ORDER BY airport_departure_country_count DESC"; |
||
| 7176 | |||
| 7177 | $sth = $this->db->prepare($query); |
||
| 7178 | $sth->execute(array(':owner' => $owner)); |
||
| 7179 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 7180 | } |
||
| 7181 | |||
| 7182 | /** |
||
| 7183 | * Gets all departure airports by country of the airplanes that have flown over based on pilot |
||
| 7184 | * |
||
| 7185 | * @return Array the airport list |
||
| 7186 | * |
||
| 7187 | */ |
||
| 7188 | public function countAllDepartureAirportCountriesByPilot($pilot,$filters = array()) |
||
| 7189 | { |
||
| 7190 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7191 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 7192 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 7193 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 7194 | GROUP BY spotter_output.departure_airport_country |
||
| 7195 | ORDER BY airport_departure_country_count DESC"; |
||
| 7196 | |||
| 7197 | $sth = $this->db->prepare($query); |
||
| 7198 | $sth->execute(array(':pilot' => $pilot)); |
||
| 7199 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 7200 | } |
||
| 7201 | |||
| 7202 | |||
| 7203 | |||
| 7204 | /** |
||
| 7205 | * Gets all departure airports of the airplanes that have flown over based on a country |
||
| 7206 | * |
||
| 7207 | * @return Array the airport list |
||
| 7208 | * |
||
| 7209 | */ |
||
| 7210 | public function countAllDepartureAirportsByCountry($country,$filters = array()) |
||
| 7211 | { |
||
| 7212 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7213 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 7214 | |||
| 7215 | $query = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7216 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 7217 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 7218 | ORDER BY airport_departure_icao_count DESC"; |
||
| 7219 | |||
| 7220 | |||
| 7221 | $sth = $this->db->prepare($query); |
||
| 7222 | $sth->execute(array(':country' => $country)); |
||
| 7223 | |||
| 7224 | $airport_array = array(); |
||
| 7225 | $temp_array = array(); |
||
| 7226 | |||
| 7227 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7228 | { |
||
| 7229 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 7230 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 7231 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 7232 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 7233 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 7234 | |||
| 7235 | $airport_array[] = $temp_array; |
||
| 7236 | } |
||
| 7237 | |||
| 7238 | return $airport_array; |
||
| 7239 | } |
||
| 7240 | |||
| 7241 | |||
| 7242 | /** |
||
| 7243 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 7244 | * |
||
| 7245 | * @return Array the airport list |
||
| 7246 | * |
||
| 7247 | */ |
||
| 7248 | public function countAllDepartureAirportCountriesByCountry($country,$filters = array()) |
||
| 7249 | { |
||
| 7250 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7251 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 7252 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 7253 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 7254 | GROUP BY spotter_output.departure_airport_country |
||
| 7255 | ORDER BY airport_departure_country_count DESC"; |
||
| 7256 | |||
| 7257 | |||
| 7258 | $sth = $this->db->prepare($query); |
||
| 7259 | $sth->execute(array(':country' => $country)); |
||
| 7260 | |||
| 7261 | $airport_array = array(); |
||
| 7262 | $temp_array = array(); |
||
| 7263 | |||
| 7264 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7265 | { |
||
| 7266 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 7267 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 7268 | |||
| 7269 | $airport_array[] = $temp_array; |
||
| 7270 | } |
||
| 7271 | |||
| 7272 | return $airport_array; |
||
| 7273 | } |
||
| 7274 | |||
| 7275 | |||
| 7276 | /** |
||
| 7277 | * Gets all arrival airports of the airplanes that have flown over |
||
| 7278 | * |
||
| 7279 | * @param Boolean $limit Limit result to 10 or not |
||
| 7280 | * @param Integer $olderthanmonths Only show result older than x months |
||
| 7281 | * @param String $sincedate Only show result since x date |
||
| 7282 | * @param Boolean $icaoaskey Show result by ICAO |
||
| 7283 | * @param Array $filters Filter used here |
||
| 7284 | * @return Array the airport list |
||
| 7285 | * |
||
| 7286 | */ |
||
| 7287 | public function countAllArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false,$filters = array(),$year = '',$month = '',$day = '') |
||
| 7288 | { |
||
| 7289 | global $globalDBdriver; |
||
| 7290 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7291 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7292 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> ''"; |
||
| 7293 | if ($olderthanmonths > 0) { |
||
| 7294 | if ($globalDBdriver == 'mysql') { |
||
| 7295 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 7296 | } else { |
||
| 7297 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 7298 | } |
||
| 7299 | } |
||
| 7300 | if ($sincedate != '') { |
||
| 7301 | if ($globalDBdriver == 'mysql') { |
||
| 7302 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 7303 | } else { |
||
| 7304 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 7305 | } |
||
| 7306 | } |
||
| 7307 | $query_values = array(); |
||
| 7308 | if ($year != '') { |
||
| 7309 | if ($globalDBdriver == 'mysql') { |
||
| 7310 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 7311 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 7312 | } else { |
||
| 7313 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 7314 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 7315 | } |
||
| 7316 | } |
||
| 7317 | if ($month != '') { |
||
| 7318 | if ($globalDBdriver == 'mysql') { |
||
| 7319 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 7320 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 7321 | } else { |
||
| 7322 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 7323 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 7324 | } |
||
| 7325 | } |
||
| 7326 | if ($day != '') { |
||
| 7327 | if ($globalDBdriver == 'mysql') { |
||
| 7328 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 7329 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 7330 | } else { |
||
| 7331 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 7332 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 7333 | } |
||
| 7334 | } |
||
| 7335 | $query .= " GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7336 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7337 | if ($limit) $query .= " LIMIT 10"; |
||
| 7338 | |||
| 7339 | |||
| 7340 | $sth = $this->db->prepare($query); |
||
| 7341 | $sth->execute($query_values); |
||
| 7342 | |||
| 7343 | $airport_array = array(); |
||
| 7344 | $temp_array = array(); |
||
| 7345 | |||
| 7346 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7347 | { |
||
| 7348 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7349 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7350 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7351 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7352 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7353 | |||
| 7354 | if ($icaoaskey) { |
||
| 7355 | $icao = $row['arrival_airport_icao']; |
||
| 7356 | $airport_array[$icao] = $temp_array; |
||
| 7357 | } else $airport_array[] = $temp_array; |
||
| 7358 | } |
||
| 7359 | |||
| 7360 | return $airport_array; |
||
| 7361 | } |
||
| 7362 | |||
| 7363 | /** |
||
| 7364 | * Gets all arrival airports of the airplanes that have flown over |
||
| 7365 | * |
||
| 7366 | * @return Array the airport list |
||
| 7367 | * |
||
| 7368 | */ |
||
| 7369 | public function countAllArrivalAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false,$filters = array()) |
||
| 7370 | { |
||
| 7371 | global $globalDBdriver; |
||
| 7372 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7373 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7374 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' "; |
||
| 7375 | if ($olderthanmonths > 0) { |
||
| 7376 | if ($globalDBdriver == 'mysql') { |
||
| 7377 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 7378 | } else { |
||
| 7379 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 7380 | } |
||
| 7381 | } |
||
| 7382 | if ($sincedate != '') { |
||
| 7383 | if ($globalDBdriver == 'mysql') { |
||
| 7384 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 7385 | } else { |
||
| 7386 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 7387 | } |
||
| 7388 | } |
||
| 7389 | |||
| 7390 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 7391 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 7392 | $query .= "GROUP BY spotter_output.airline_icao,spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7393 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7394 | if ($limit) $query .= " LIMIT 10"; |
||
| 7395 | |||
| 7396 | |||
| 7397 | $sth = $this->db->prepare($query); |
||
| 7398 | $sth->execute(); |
||
| 7399 | |||
| 7400 | $airport_array = array(); |
||
| 7401 | $temp_array = array(); |
||
| 7402 | |||
| 7403 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7404 | { |
||
| 7405 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 7406 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7407 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7408 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7409 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7410 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7411 | |||
| 7412 | if ($icaoaskey) { |
||
| 7413 | $icao = $row['arrival_airport_icao']; |
||
| 7414 | $airport_array[$icao] = $temp_array; |
||
| 7415 | } else $airport_array[] = $temp_array; |
||
| 7416 | } |
||
| 7417 | |||
| 7418 | return $airport_array; |
||
| 7419 | } |
||
| 7420 | |||
| 7421 | |||
| 7422 | /** |
||
| 7423 | * Gets all detected arrival airports of the airplanes that have flown over |
||
| 7424 | * |
||
| 7425 | * @return Array the airport list |
||
| 7426 | * |
||
| 7427 | */ |
||
| 7428 | public function countAllDetectedArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false,$filters = array(),$year = '',$month = '',$day = '') |
||
| 7429 | { |
||
| 7430 | global $globalDBdriver; |
||
| 7431 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7432 | $query = "SELECT DISTINCT spotter_output.real_arrival_airport_icao as arrival_airport_icao, COUNT(spotter_output.real_arrival_airport_icao) AS airport_arrival_icao_count, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country |
||
| 7433 | FROM airport,spotter_output".$filter_query." spotter_output.real_arrival_airport_icao <> '' AND spotter_output.real_arrival_airport_icao <> 'NA' AND airport.icao = spotter_output.real_arrival_airport_icao"; |
||
| 7434 | if ($olderthanmonths > 0) { |
||
| 7435 | if ($globalDBdriver == 'mysql') { |
||
| 7436 | $query .= ' AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 7437 | } else { |
||
| 7438 | $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 7439 | } |
||
| 7440 | } |
||
| 7441 | if ($sincedate != '') { |
||
| 7442 | if ($globalDBdriver == 'mysql') { |
||
| 7443 | $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 7444 | } else { |
||
| 7445 | $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 7446 | } |
||
| 7447 | } |
||
| 7448 | $query_values = array(); |
||
| 7449 | if ($year != '') { |
||
| 7450 | if ($globalDBdriver == 'mysql') { |
||
| 7451 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 7452 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 7453 | } else { |
||
| 7454 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 7455 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 7456 | } |
||
| 7457 | } |
||
| 7458 | if ($month != '') { |
||
| 7459 | if ($globalDBdriver == 'mysql') { |
||
| 7460 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 7461 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 7462 | } else { |
||
| 7463 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 7464 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 7465 | } |
||
| 7466 | } |
||
| 7467 | if ($day != '') { |
||
| 7468 | if ($globalDBdriver == 'mysql') { |
||
| 7469 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 7470 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 7471 | } else { |
||
| 7472 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 7473 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 7474 | } |
||
| 7475 | } |
||
| 7476 | $query .= " GROUP BY spotter_output.real_arrival_airport_icao, airport.name, airport.city, airport.country |
||
| 7477 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7478 | if ($limit) $query .= " LIMIT 10"; |
||
| 7479 | |||
| 7480 | |||
| 7481 | $sth = $this->db->prepare($query); |
||
| 7482 | $sth->execute($query_values); |
||
| 7483 | |||
| 7484 | $airport_array = array(); |
||
| 7485 | $temp_array = array(); |
||
| 7486 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7487 | { |
||
| 7488 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7489 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7490 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7491 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7492 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7493 | |||
| 7494 | if ($icaoaskey) { |
||
| 7495 | $icao = $row['arrival_airport_icao']; |
||
| 7496 | $airport_array[$icao] = $temp_array; |
||
| 7497 | } else $airport_array[] = $temp_array; |
||
| 7498 | } |
||
| 7499 | |||
| 7500 | return $airport_array; |
||
| 7501 | } |
||
| 7502 | |||
| 7503 | /** |
||
| 7504 | * Gets all detected arrival airports of the airplanes that have flown over |
||
| 7505 | * |
||
| 7506 | * @return Array the airport list |
||
| 7507 | * |
||
| 7508 | */ |
||
| 7509 | public function countAllDetectedArrivalAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false,$filters = array()) |
||
| 7510 | { |
||
| 7511 | global $globalDBdriver; |
||
| 7512 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7513 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.real_arrival_airport_icao as arrival_airport_icao, COUNT(spotter_output.real_arrival_airport_icao) AS airport_arrival_icao_count, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country |
||
| 7514 | FROM airport,spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.real_arrival_airport_icao <> '' AND spotter_output.real_arrival_airport_icao <> 'NA' AND airport.icao = spotter_output.real_arrival_airport_icao "; |
||
| 7515 | if ($olderthanmonths > 0) { |
||
| 7516 | if ($globalDBdriver == 'mysql') { |
||
| 7517 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 7518 | } else { |
||
| 7519 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 7520 | } |
||
| 7521 | } |
||
| 7522 | if ($sincedate != '') { |
||
| 7523 | if ($globalDBdriver == 'mysql') { |
||
| 7524 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 7525 | } else { |
||
| 7526 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 7527 | } |
||
| 7528 | } |
||
| 7529 | |||
| 7530 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 7531 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 7532 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.real_arrival_airport_icao, airport.name, airport.city, airport.country |
||
| 7533 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7534 | if ($limit) $query .= " LIMIT 10"; |
||
| 7535 | |||
| 7536 | |||
| 7537 | $sth = $this->db->prepare($query); |
||
| 7538 | $sth->execute(); |
||
| 7539 | |||
| 7540 | $airport_array = array(); |
||
| 7541 | $temp_array = array(); |
||
| 7542 | |||
| 7543 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7544 | { |
||
| 7545 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7546 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7547 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7548 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7549 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7550 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 7551 | |||
| 7552 | if ($icaoaskey) { |
||
| 7553 | $icao = $row['arrival_airport_icao']; |
||
| 7554 | $airport_array[$icao] = $temp_array; |
||
| 7555 | } else $airport_array[] = $temp_array; |
||
| 7556 | } |
||
| 7557 | |||
| 7558 | return $airport_array; |
||
| 7559 | } |
||
| 7560 | |||
| 7561 | /** |
||
| 7562 | * Gets all arrival airports of the airplanes that have flown over based on an airline icao |
||
| 7563 | * |
||
| 7564 | * @return Array the airport list |
||
| 7565 | * |
||
| 7566 | */ |
||
| 7567 | public function countAllArrivalAirportsByAirline($airline_icao, $filters = array()) |
||
| 7568 | { |
||
| 7569 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7570 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 7571 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7572 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 7573 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7574 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7575 | |||
| 7576 | $sth = $this->db->prepare($query); |
||
| 7577 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 7578 | |||
| 7579 | $airport_array = array(); |
||
| 7580 | $temp_array = array(); |
||
| 7581 | |||
| 7582 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7583 | { |
||
| 7584 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7585 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7586 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7587 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7588 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7589 | |||
| 7590 | $airport_array[] = $temp_array; |
||
| 7591 | } |
||
| 7592 | |||
| 7593 | return $airport_array; |
||
| 7594 | } |
||
| 7595 | |||
| 7596 | |||
| 7597 | /** |
||
| 7598 | * Gets all arrival airports by country of the airplanes that have flown over based on an airline icao |
||
| 7599 | * |
||
| 7600 | * @return Array the airport list |
||
| 7601 | * |
||
| 7602 | */ |
||
| 7603 | public function countAllArrivalAirportCountriesByAirline($airline_icao,$filters = array()) |
||
| 7604 | { |
||
| 7605 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7606 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 7607 | |||
| 7608 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7609 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 7610 | GROUP BY spotter_output.arrival_airport_country |
||
| 7611 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7612 | |||
| 7613 | |||
| 7614 | $sth = $this->db->prepare($query); |
||
| 7615 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 7616 | |||
| 7617 | $airport_array = array(); |
||
| 7618 | $temp_array = array(); |
||
| 7619 | |||
| 7620 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7621 | { |
||
| 7622 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 7623 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 7624 | |||
| 7625 | $airport_array[] = $temp_array; |
||
| 7626 | } |
||
| 7627 | |||
| 7628 | return $airport_array; |
||
| 7629 | } |
||
| 7630 | |||
| 7631 | |||
| 7632 | /** |
||
| 7633 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft icao |
||
| 7634 | * |
||
| 7635 | * @return Array the airport list |
||
| 7636 | * |
||
| 7637 | */ |
||
| 7638 | public function countAllArrivalAirportsByAircraft($aircraft_icao,$filters = array()) |
||
| 7639 | { |
||
| 7640 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7641 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 7642 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7643 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 7644 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7645 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7646 | |||
| 7647 | |||
| 7648 | $sth = $this->db->prepare($query); |
||
| 7649 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 7650 | |||
| 7651 | $airport_array = array(); |
||
| 7652 | $temp_array = array(); |
||
| 7653 | |||
| 7654 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7655 | { |
||
| 7656 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7657 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7658 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7659 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7660 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7661 | |||
| 7662 | $airport_array[] = $temp_array; |
||
| 7663 | } |
||
| 7664 | |||
| 7665 | return $airport_array; |
||
| 7666 | } |
||
| 7667 | |||
| 7668 | |||
| 7669 | |||
| 7670 | /** |
||
| 7671 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 7672 | * |
||
| 7673 | * @return Array the airport list |
||
| 7674 | * |
||
| 7675 | */ |
||
| 7676 | public function countAllArrivalAirportCountriesByAircraft($aircraft_icao,$filters = array()) |
||
| 7677 | { |
||
| 7678 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7679 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 7680 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7681 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 7682 | GROUP BY spotter_output.arrival_airport_country |
||
| 7683 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7684 | |||
| 7685 | |||
| 7686 | $sth = $this->db->prepare($query); |
||
| 7687 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 7688 | |||
| 7689 | $airport_array = array(); |
||
| 7690 | $temp_array = array(); |
||
| 7691 | |||
| 7692 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7693 | { |
||
| 7694 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 7695 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 7696 | |||
| 7697 | $airport_array[] = $temp_array; |
||
| 7698 | } |
||
| 7699 | |||
| 7700 | return $airport_array; |
||
| 7701 | } |
||
| 7702 | |||
| 7703 | |||
| 7704 | /** |
||
| 7705 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft registration |
||
| 7706 | * |
||
| 7707 | * @return Array the airport list |
||
| 7708 | * |
||
| 7709 | */ |
||
| 7710 | public function countAllArrivalAirportsByRegistration($registration,$filters = array()) |
||
| 7711 | { |
||
| 7712 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7713 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 7714 | |||
| 7715 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7716 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.registration = :registration |
||
| 7717 | GROUP BY spotter_output.arrival_airport_icao |
||
| 7718 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7719 | |||
| 7720 | |||
| 7721 | $sth = $this->db->prepare($query); |
||
| 7722 | $sth->execute(array(':registration' => $registration)); |
||
| 7723 | |||
| 7724 | $airport_array = array(); |
||
| 7725 | $temp_array = array(); |
||
| 7726 | |||
| 7727 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7728 | { |
||
| 7729 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7730 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7731 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7732 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7733 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7734 | |||
| 7735 | $airport_array[] = $temp_array; |
||
| 7736 | } |
||
| 7737 | |||
| 7738 | return $airport_array; |
||
| 7739 | } |
||
| 7740 | |||
| 7741 | |||
| 7742 | /** |
||
| 7743 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft registration |
||
| 7744 | * |
||
| 7745 | * @return Array the airport list |
||
| 7746 | * |
||
| 7747 | */ |
||
| 7748 | public function countAllArrivalAirportCountriesByRegistration($registration,$filters = array()) |
||
| 7749 | { |
||
| 7750 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7751 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 7752 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7753 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.registration = :registration |
||
| 7754 | GROUP BY spotter_output.arrival_airport_country |
||
| 7755 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7756 | |||
| 7757 | |||
| 7758 | $sth = $this->db->prepare($query); |
||
| 7759 | $sth->execute(array(':registration' => $registration)); |
||
| 7760 | |||
| 7761 | $airport_array = array(); |
||
| 7762 | $temp_array = array(); |
||
| 7763 | |||
| 7764 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7765 | { |
||
| 7766 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 7767 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 7768 | |||
| 7769 | $airport_array[] = $temp_array; |
||
| 7770 | } |
||
| 7771 | |||
| 7772 | return $airport_array; |
||
| 7773 | } |
||
| 7774 | |||
| 7775 | |||
| 7776 | |||
| 7777 | /** |
||
| 7778 | * Gets all arrival airports of the airplanes that have flown over based on an departure airport |
||
| 7779 | * |
||
| 7780 | * @return Array the airport list |
||
| 7781 | * |
||
| 7782 | */ |
||
| 7783 | public function countAllArrivalAirportsByAirport($airport_icao,$filters = array()) |
||
| 7784 | { |
||
| 7785 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7786 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 7787 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7788 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.departure_airport_icao = :airport_icao |
||
| 7789 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7790 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7791 | |||
| 7792 | |||
| 7793 | $sth = $this->db->prepare($query); |
||
| 7794 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 7795 | |||
| 7796 | $airport_array = array(); |
||
| 7797 | $temp_array = array(); |
||
| 7798 | |||
| 7799 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7800 | { |
||
| 7801 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7802 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7803 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7804 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7805 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7806 | |||
| 7807 | $airport_array[] = $temp_array; |
||
| 7808 | } |
||
| 7809 | |||
| 7810 | return $airport_array; |
||
| 7811 | } |
||
| 7812 | |||
| 7813 | |||
| 7814 | /** |
||
| 7815 | * Gets all arrival airports by country of the airplanes that have flown over based on an airport icao |
||
| 7816 | * |
||
| 7817 | * @return Array the airport list |
||
| 7818 | * |
||
| 7819 | */ |
||
| 7820 | public function countAllArrivalAirportCountriesByAirport($airport_icao,$filters = array()) |
||
| 7821 | { |
||
| 7822 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7823 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 7824 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7825 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.departure_airport_icao = :airport_icao |
||
| 7826 | GROUP BY spotter_output.arrival_airport_country |
||
| 7827 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7828 | |||
| 7829 | |||
| 7830 | $sth = $this->db->prepare($query); |
||
| 7831 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 7832 | |||
| 7833 | $airport_array = array(); |
||
| 7834 | $temp_array = array(); |
||
| 7835 | |||
| 7836 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7837 | { |
||
| 7838 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 7839 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 7840 | |||
| 7841 | $airport_array[] = $temp_array; |
||
| 7842 | } |
||
| 7843 | |||
| 7844 | return $airport_array; |
||
| 7845 | } |
||
| 7846 | |||
| 7847 | |||
| 7848 | /** |
||
| 7849 | * Gets all arrival airports of the airplanes that have flown over based on a aircraft manufacturer |
||
| 7850 | * |
||
| 7851 | * @return Array the airport list |
||
| 7852 | * |
||
| 7853 | */ |
||
| 7854 | public function countAllArrivalAirportsByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 7855 | { |
||
| 7856 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7857 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 7858 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7859 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 7860 | GROUP BY spotter_output.arrival_airport_icao |
||
| 7861 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7862 | |||
| 7863 | |||
| 7864 | $sth = $this->db->prepare($query); |
||
| 7865 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 7866 | |||
| 7867 | $airport_array = array(); |
||
| 7868 | $temp_array = array(); |
||
| 7869 | |||
| 7870 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7871 | { |
||
| 7872 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7873 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7874 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7875 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7876 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7877 | |||
| 7878 | $airport_array[] = $temp_array; |
||
| 7879 | } |
||
| 7880 | |||
| 7881 | return $airport_array; |
||
| 7882 | } |
||
| 7883 | |||
| 7884 | |||
| 7885 | |||
| 7886 | /** |
||
| 7887 | * Gets all arrival airports by country of the airplanes that have flown over based on a aircraft manufacturer |
||
| 7888 | * |
||
| 7889 | * @return Array the airport list |
||
| 7890 | * |
||
| 7891 | */ |
||
| 7892 | public function countAllArrivalAirportCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
| 7893 | { |
||
| 7894 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7895 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 7896 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7897 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 7898 | GROUP BY spotter_output.arrival_airport_country |
||
| 7899 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7900 | |||
| 7901 | |||
| 7902 | $sth = $this->db->prepare($query); |
||
| 7903 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 7904 | |||
| 7905 | $airport_array = array(); |
||
| 7906 | $temp_array = array(); |
||
| 7907 | |||
| 7908 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7909 | { |
||
| 7910 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 7911 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 7912 | |||
| 7913 | $airport_array[] = $temp_array; |
||
| 7914 | } |
||
| 7915 | |||
| 7916 | return $airport_array; |
||
| 7917 | } |
||
| 7918 | |||
| 7919 | |||
| 7920 | |||
| 7921 | /** |
||
| 7922 | * Gets all arrival airports of the airplanes that have flown over based on a date |
||
| 7923 | * |
||
| 7924 | * @return Array the airport list |
||
| 7925 | * |
||
| 7926 | */ |
||
| 7927 | public function countAllArrivalAirportsByDate($date,$filters = array()) |
||
| 7928 | { |
||
| 7929 | global $globalTimezone, $globalDBdriver; |
||
| 7930 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7931 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 7932 | if ($globalTimezone != '') { |
||
| 7933 | date_default_timezone_set($globalTimezone); |
||
| 7934 | $datetime = new DateTime($date); |
||
| 7935 | $offset = $datetime->format('P'); |
||
| 7936 | } else $offset = '+00:00'; |
||
| 7937 | |||
| 7938 | if ($globalDBdriver == 'mysql') { |
||
| 7939 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7940 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 7941 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7942 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7943 | } else { |
||
| 7944 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7945 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 7946 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 7947 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 7948 | } |
||
| 7949 | |||
| 7950 | $sth = $this->db->prepare($query); |
||
| 7951 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 7952 | |||
| 7953 | $airport_array = array(); |
||
| 7954 | $temp_array = array(); |
||
| 7955 | |||
| 7956 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7957 | { |
||
| 7958 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 7959 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 7960 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 7961 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 7962 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 7963 | |||
| 7964 | $airport_array[] = $temp_array; |
||
| 7965 | } |
||
| 7966 | return $airport_array; |
||
| 7967 | } |
||
| 7968 | |||
| 7969 | |||
| 7970 | |||
| 7971 | /** |
||
| 7972 | * Gets all arrival airports by country of the airplanes that have flown over based on a date |
||
| 7973 | * |
||
| 7974 | * @return Array the airport list |
||
| 7975 | * |
||
| 7976 | */ |
||
| 7977 | public function countAllArrivalAirportCountriesByDate($date, $filters = array()) |
||
| 7978 | { |
||
| 7979 | global $globalTimezone, $globalDBdriver; |
||
| 7980 | $filter_query = $this->getFilter($filters,true,true); |
||
| 7981 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 7982 | if ($globalTimezone != '') { |
||
| 7983 | date_default_timezone_set($globalTimezone); |
||
| 7984 | $datetime = new DateTime($date); |
||
| 7985 | $offset = $datetime->format('P'); |
||
| 7986 | } else $offset = '+00:00'; |
||
| 7987 | |||
| 7988 | if ($globalDBdriver == 'mysql') { |
||
| 7989 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7990 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 7991 | GROUP BY spotter_output.arrival_airport_country |
||
| 7992 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7993 | } else { |
||
| 7994 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 7995 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 7996 | GROUP BY spotter_output.arrival_airport_country |
||
| 7997 | ORDER BY airport_arrival_country_count DESC"; |
||
| 7998 | } |
||
| 7999 | |||
| 8000 | $sth = $this->db->prepare($query); |
||
| 8001 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 8002 | |||
| 8003 | $airport_array = array(); |
||
| 8004 | $temp_array = array(); |
||
| 8005 | |||
| 8006 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8007 | { |
||
| 8008 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 8009 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 8010 | |||
| 8011 | $airport_array[] = $temp_array; |
||
| 8012 | } |
||
| 8013 | return $airport_array; |
||
| 8014 | } |
||
| 8015 | |||
| 8016 | |||
| 8017 | |||
| 8018 | /** |
||
| 8019 | * Gets all arrival airports of the airplanes that have flown over based on a ident/callsign |
||
| 8020 | * |
||
| 8021 | * @return Array the airport list |
||
| 8022 | * |
||
| 8023 | */ |
||
| 8024 | public function countAllArrivalAirportsByIdent($ident,$filters = array()) |
||
| 8025 | { |
||
| 8026 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8027 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 8028 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8029 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.ident = :ident |
||
| 8030 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8031 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 8032 | |||
| 8033 | |||
| 8034 | $sth = $this->db->prepare($query); |
||
| 8035 | $sth->execute(array(':ident' => $ident)); |
||
| 8036 | |||
| 8037 | $airport_array = array(); |
||
| 8038 | $temp_array = array(); |
||
| 8039 | |||
| 8040 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8041 | { |
||
| 8042 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8043 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 8044 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 8045 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 8046 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 8047 | |||
| 8048 | $airport_array[] = $temp_array; |
||
| 8049 | } |
||
| 8050 | |||
| 8051 | return $airport_array; |
||
| 8052 | } |
||
| 8053 | |||
| 8054 | /** |
||
| 8055 | * Gets all arrival airports of the airplanes that have flown over based on a owner |
||
| 8056 | * |
||
| 8057 | * @return Array the airport list |
||
| 8058 | * |
||
| 8059 | */ |
||
| 8060 | public function countAllArrivalAirportsByOwner($owner,$filters = array()) |
||
| 8061 | { |
||
| 8062 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8063 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 8064 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8065 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND spotter_output.owner_name = :owner |
||
| 8066 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8067 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 8068 | |||
| 8069 | |||
| 8070 | $sth = $this->db->prepare($query); |
||
| 8071 | $sth->execute(array(':owner' => $owner)); |
||
| 8072 | $airport_array = array(); |
||
| 8073 | $temp_array = array(); |
||
| 8074 | |||
| 8075 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8076 | { |
||
| 8077 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8078 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 8079 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 8080 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 8081 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 8082 | |||
| 8083 | $airport_array[] = $temp_array; |
||
| 8084 | } |
||
| 8085 | |||
| 8086 | return $airport_array; |
||
| 8087 | } |
||
| 8088 | |||
| 8089 | /** |
||
| 8090 | * Gets all arrival airports of the airplanes that have flown over based on a pilot |
||
| 8091 | * |
||
| 8092 | * @return Array the airport list |
||
| 8093 | * |
||
| 8094 | */ |
||
| 8095 | public function countAllArrivalAirportsByPilot($pilot,$filters = array()) |
||
| 8096 | { |
||
| 8097 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8098 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 8099 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8100 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 8101 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8102 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 8103 | |||
| 8104 | |||
| 8105 | $sth = $this->db->prepare($query); |
||
| 8106 | $sth->execute(array(':pilot' => $pilot)); |
||
| 8107 | $airport_array = array(); |
||
| 8108 | $temp_array = array(); |
||
| 8109 | |||
| 8110 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8111 | { |
||
| 8112 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8113 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 8114 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 8115 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 8116 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 8117 | |||
| 8118 | $airport_array[] = $temp_array; |
||
| 8119 | } |
||
| 8120 | |||
| 8121 | return $airport_array; |
||
| 8122 | } |
||
| 8123 | |||
| 8124 | /** |
||
| 8125 | * Gets all arrival airports by country of the airplanes that have flown over based on a callsign/ident |
||
| 8126 | * |
||
| 8127 | * @return Array the airport list |
||
| 8128 | * |
||
| 8129 | */ |
||
| 8130 | public function countAllArrivalAirportCountriesByIdent($ident, $filters = array()) |
||
| 8131 | { |
||
| 8132 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8133 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 8134 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 8135 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.ident = :ident |
||
| 8136 | GROUP BY spotter_output.arrival_airport_country |
||
| 8137 | ORDER BY airport_arrival_country_count DESC"; |
||
| 8138 | |||
| 8139 | |||
| 8140 | $sth = $this->db->prepare($query); |
||
| 8141 | $sth->execute(array(':ident' => $ident)); |
||
| 8142 | |||
| 8143 | $airport_array = array(); |
||
| 8144 | $temp_array = array(); |
||
| 8145 | |||
| 8146 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8147 | { |
||
| 8148 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 8149 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 8150 | |||
| 8151 | $airport_array[] = $temp_array; |
||
| 8152 | } |
||
| 8153 | |||
| 8154 | return $airport_array; |
||
| 8155 | } |
||
| 8156 | |||
| 8157 | /** |
||
| 8158 | * Gets all arrival airports by country of the airplanes that have flown over based on a owner |
||
| 8159 | * |
||
| 8160 | * @return Array the airport list |
||
| 8161 | * |
||
| 8162 | */ |
||
| 8163 | public function countAllArrivalAirportCountriesByOwner($owner, $filters = array()) |
||
| 8164 | { |
||
| 8165 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8166 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 8167 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 8168 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.owner_name = :owner |
||
| 8169 | GROUP BY spotter_output.arrival_airport_country |
||
| 8170 | ORDER BY airport_arrival_country_count DESC"; |
||
| 8171 | |||
| 8172 | $sth = $this->db->prepare($query); |
||
| 8173 | $sth->execute(array(':owner' => $owner)); |
||
| 8174 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 8175 | } |
||
| 8176 | |||
| 8177 | /** |
||
| 8178 | * Gets all arrival airports by country of the airplanes that have flown over based on a pilot |
||
| 8179 | * |
||
| 8180 | * @return Array the airport list |
||
| 8181 | * |
||
| 8182 | */ |
||
| 8183 | public function countAllArrivalAirportCountriesByPilot($pilot, $filters = array()) |
||
| 8184 | { |
||
| 8185 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8186 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 8187 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 8188 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 8189 | GROUP BY spotter_output.arrival_airport_country |
||
| 8190 | ORDER BY airport_arrival_country_count DESC"; |
||
| 8191 | |||
| 8192 | $sth = $this->db->prepare($query); |
||
| 8193 | $sth->execute(array(':pilot' => $pilot)); |
||
| 8194 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 8195 | } |
||
| 8196 | |||
| 8197 | |||
| 8198 | |||
| 8199 | /** |
||
| 8200 | * Gets all arrival airports of the airplanes that have flown over based on a country |
||
| 8201 | * |
||
| 8202 | * @return Array the airport list |
||
| 8203 | * |
||
| 8204 | */ |
||
| 8205 | public function countAllArrivalAirportsByCountry($country,$filters = array()) |
||
| 8206 | { |
||
| 8207 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8208 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 8209 | $query = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8210 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 8211 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8212 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 8213 | |||
| 8214 | |||
| 8215 | $sth = $this->db->prepare($query); |
||
| 8216 | $sth->execute(array(':country' => $country)); |
||
| 8217 | |||
| 8218 | $airport_array = array(); |
||
| 8219 | $temp_array = array(); |
||
| 8220 | |||
| 8221 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8222 | { |
||
| 8223 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8224 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 8225 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 8226 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 8227 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 8228 | |||
| 8229 | $airport_array[] = $temp_array; |
||
| 8230 | } |
||
| 8231 | |||
| 8232 | return $airport_array; |
||
| 8233 | } |
||
| 8234 | |||
| 8235 | |||
| 8236 | /** |
||
| 8237 | * Gets all arrival airports by country of the airplanes that have flown over based on a country |
||
| 8238 | * |
||
| 8239 | * @return Array the airport list |
||
| 8240 | * |
||
| 8241 | */ |
||
| 8242 | public function countAllArrivalAirportCountriesByCountry($country,$filters = array()) |
||
| 8243 | { |
||
| 8244 | global $globalDBdriver; |
||
| 8245 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8246 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 8247 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 8248 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 8249 | GROUP BY spotter_output.arrival_airport_country |
||
| 8250 | ORDER BY airport_arrival_country_count DESC"; |
||
| 8251 | |||
| 8252 | |||
| 8253 | $sth = $this->db->prepare($query); |
||
| 8254 | $sth->execute(array(':country' => $country)); |
||
| 8255 | |||
| 8256 | $airport_array = array(); |
||
| 8257 | $temp_array = array(); |
||
| 8258 | |||
| 8259 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8260 | { |
||
| 8261 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 8262 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 8263 | |||
| 8264 | $airport_array[] = $temp_array; |
||
| 8265 | } |
||
| 8266 | |||
| 8267 | return $airport_array; |
||
| 8268 | } |
||
| 8269 | |||
| 8270 | |||
| 8271 | |||
| 8272 | /** |
||
| 8273 | * Counts all airport departure countries |
||
| 8274 | * |
||
| 8275 | * @return Array the airport departure list |
||
| 8276 | * |
||
| 8277 | */ |
||
| 8278 | public function countAllDepartureCountries($filters = array(),$year = '',$month = '', $day = '') |
||
| 8279 | { |
||
| 8280 | global $globalDBdriver; |
||
| 8281 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8282 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 8283 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> ''"; |
||
| 8284 | $query_values = array(); |
||
| 8285 | if ($year != '') { |
||
| 8286 | if ($globalDBdriver == 'mysql') { |
||
| 8287 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 8288 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8289 | } else { |
||
| 8290 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 8291 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8292 | } |
||
| 8293 | } |
||
| 8294 | if ($month != '') { |
||
| 8295 | if ($globalDBdriver == 'mysql') { |
||
| 8296 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 8297 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8298 | } else { |
||
| 8299 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 8300 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8301 | } |
||
| 8302 | } |
||
| 8303 | if ($day != '') { |
||
| 8304 | if ($globalDBdriver == 'mysql') { |
||
| 8305 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 8306 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8307 | } else { |
||
| 8308 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 8309 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8310 | } |
||
| 8311 | } |
||
| 8312 | $query .= " GROUP BY spotter_output.departure_airport_country |
||
| 8313 | ORDER BY airport_departure_country_count DESC |
||
| 8314 | LIMIT 10 OFFSET 0"; |
||
| 8315 | |||
| 8316 | |||
| 8317 | $sth = $this->db->prepare($query); |
||
| 8318 | $sth->execute($query_values); |
||
| 8319 | |||
| 8320 | $airport_array = array(); |
||
| 8321 | $temp_array = array(); |
||
| 8322 | |||
| 8323 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8324 | { |
||
| 8325 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 8326 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 8327 | |||
| 8328 | $airport_array[] = $temp_array; |
||
| 8329 | } |
||
| 8330 | |||
| 8331 | return $airport_array; |
||
| 8332 | } |
||
| 8333 | |||
| 8334 | |||
| 8335 | /** |
||
| 8336 | * Counts all airport arrival countries |
||
| 8337 | * |
||
| 8338 | * @return Array the airport arrival list |
||
| 8339 | * |
||
| 8340 | */ |
||
| 8341 | public function countAllArrivalCountries($limit = true,$filters = array(),$year = '',$month = '',$day = '') |
||
| 8342 | { |
||
| 8343 | global $globalDBdriver; |
||
| 8344 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8345 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 8346 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> ''"; |
||
| 8347 | $query_values = array(); |
||
| 8348 | if ($year != '') { |
||
| 8349 | if ($globalDBdriver == 'mysql') { |
||
| 8350 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 8351 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8352 | } else { |
||
| 8353 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 8354 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8355 | } |
||
| 8356 | } |
||
| 8357 | if ($month != '') { |
||
| 8358 | if ($globalDBdriver == 'mysql') { |
||
| 8359 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 8360 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8361 | } else { |
||
| 8362 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 8363 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8364 | } |
||
| 8365 | } |
||
| 8366 | if ($day != '') { |
||
| 8367 | if ($globalDBdriver == 'mysql') { |
||
| 8368 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 8369 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8370 | } else { |
||
| 8371 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 8372 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8373 | } |
||
| 8374 | } |
||
| 8375 | $query .= " GROUP BY spotter_output.arrival_airport_country |
||
| 8376 | ORDER BY airport_arrival_country_count DESC"; |
||
| 8377 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 8378 | |||
| 8379 | |||
| 8380 | $sth = $this->db->prepare($query); |
||
| 8381 | $sth->execute($query_values); |
||
| 8382 | |||
| 8383 | $airport_array = array(); |
||
| 8384 | $temp_array = array(); |
||
| 8385 | |||
| 8386 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8387 | { |
||
| 8388 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 8389 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 8390 | |||
| 8391 | $airport_array[] = $temp_array; |
||
| 8392 | } |
||
| 8393 | |||
| 8394 | return $airport_array; |
||
| 8395 | } |
||
| 8396 | |||
| 8397 | |||
| 8398 | |||
| 8399 | |||
| 8400 | |||
| 8401 | /** |
||
| 8402 | * Gets all route combinations |
||
| 8403 | * |
||
| 8404 | * @return Array the route list |
||
| 8405 | * |
||
| 8406 | */ |
||
| 8407 | public function countAllRoutes($filters = array()) |
||
| 8408 | { |
||
| 8409 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8410 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8411 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.departure_airport_icao <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> '' |
||
| 8412 | GROUP BY route,spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 8413 | ORDER BY route_count DESC |
||
| 8414 | LIMIT 10 OFFSET 0"; |
||
| 8415 | |||
| 8416 | |||
| 8417 | $sth = $this->db->prepare($query); |
||
| 8418 | $sth->execute(); |
||
| 8419 | |||
| 8420 | $routes_array = array(); |
||
| 8421 | $temp_array = array(); |
||
| 8422 | |||
| 8423 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8424 | { |
||
| 8425 | $temp_array['route_count'] = $row['route_count']; |
||
| 8426 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8427 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8428 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8429 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8430 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8431 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8432 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8433 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8434 | |||
| 8435 | $routes_array[] = $temp_array; |
||
| 8436 | } |
||
| 8437 | |||
| 8438 | return $routes_array; |
||
| 8439 | } |
||
| 8440 | |||
| 8441 | |||
| 8442 | |||
| 8443 | |||
| 8444 | /** |
||
| 8445 | * Gets all route combinations based on an aircraft |
||
| 8446 | * |
||
| 8447 | * @return Array the route list |
||
| 8448 | * |
||
| 8449 | */ |
||
| 8450 | public function countAllRoutesByAircraft($aircraft_icao,$filters = array()) |
||
| 8451 | { |
||
| 8452 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8453 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 8454 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8455 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 8456 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8457 | ORDER BY route_count DESC"; |
||
| 8458 | |||
| 8459 | $sth = $this->db->prepare($query); |
||
| 8460 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 8461 | |||
| 8462 | $routes_array = array(); |
||
| 8463 | $temp_array = array(); |
||
| 8464 | |||
| 8465 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8466 | { |
||
| 8467 | $temp_array['route_count'] = $row['route_count']; |
||
| 8468 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8469 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8470 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8471 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8472 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8473 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8474 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8475 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8476 | |||
| 8477 | $routes_array[] = $temp_array; |
||
| 8478 | } |
||
| 8479 | |||
| 8480 | return $routes_array; |
||
| 8481 | } |
||
| 8482 | |||
| 8483 | |||
| 8484 | /** |
||
| 8485 | * Gets all route combinations based on an aircraft registration |
||
| 8486 | * |
||
| 8487 | * @return Array the route list |
||
| 8488 | * |
||
| 8489 | */ |
||
| 8490 | public function countAllRoutesByRegistration($registration, $filters = array()) |
||
| 8491 | { |
||
| 8492 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8493 | $registration = filter_var($registration, FILTER_SANITIZE_STRING); |
||
| 8494 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8495 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.registration = :registration |
||
| 8496 | GROUP BY route |
||
| 8497 | ORDER BY route_count DESC"; |
||
| 8498 | |||
| 8499 | |||
| 8500 | $sth = $this->db->prepare($query); |
||
| 8501 | $sth->execute(array(':registration' => $registration)); |
||
| 8502 | |||
| 8503 | $routes_array = array(); |
||
| 8504 | $temp_array = array(); |
||
| 8505 | |||
| 8506 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8507 | { |
||
| 8508 | $temp_array['route_count'] = $row['route_count']; |
||
| 8509 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8510 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8511 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8512 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8513 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8514 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8515 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8516 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8517 | |||
| 8518 | $routes_array[] = $temp_array; |
||
| 8519 | } |
||
| 8520 | |||
| 8521 | return $routes_array; |
||
| 8522 | } |
||
| 8523 | |||
| 8524 | |||
| 8525 | |||
| 8526 | /** |
||
| 8527 | * Gets all route combinations based on an airline |
||
| 8528 | * |
||
| 8529 | * @return Array the route list |
||
| 8530 | * |
||
| 8531 | */ |
||
| 8532 | public function countAllRoutesByAirline($airline_icao, $filters = array()) |
||
| 8533 | { |
||
| 8534 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8535 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 8536 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8537 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 8538 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8539 | ORDER BY route_count DESC"; |
||
| 8540 | |||
| 8541 | |||
| 8542 | $sth = $this->db->prepare($query); |
||
| 8543 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 8544 | |||
| 8545 | $routes_array = array(); |
||
| 8546 | $temp_array = array(); |
||
| 8547 | |||
| 8548 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8549 | { |
||
| 8550 | $temp_array['route_count'] = $row['route_count']; |
||
| 8551 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8552 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8553 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8554 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8555 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8556 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8557 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8558 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8559 | |||
| 8560 | $routes_array[] = $temp_array; |
||
| 8561 | } |
||
| 8562 | |||
| 8563 | return $routes_array; |
||
| 8564 | } |
||
| 8565 | |||
| 8566 | |||
| 8567 | |||
| 8568 | /** |
||
| 8569 | * Gets all route combinations based on an airport |
||
| 8570 | * |
||
| 8571 | * @return Array the route list |
||
| 8572 | * |
||
| 8573 | */ |
||
| 8574 | public function countAllRoutesByAirport($airport_icao, $filters = array()) |
||
| 8575 | { |
||
| 8576 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8577 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 8578 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8579 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 8580 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8581 | ORDER BY route_count DESC"; |
||
| 8582 | |||
| 8583 | $sth = $this->db->prepare($query); |
||
| 8584 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 8585 | |||
| 8586 | $routes_array = array(); |
||
| 8587 | $temp_array = array(); |
||
| 8588 | |||
| 8589 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8590 | { |
||
| 8591 | $temp_array['route_count'] = $row['route_count']; |
||
| 8592 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8593 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8594 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8595 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8596 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8597 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8598 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8599 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8600 | |||
| 8601 | $routes_array[] = $temp_array; |
||
| 8602 | } |
||
| 8603 | |||
| 8604 | return $routes_array; |
||
| 8605 | } |
||
| 8606 | |||
| 8607 | |||
| 8608 | |||
| 8609 | /** |
||
| 8610 | * Gets all route combinations based on an country |
||
| 8611 | * |
||
| 8612 | * @return Array the route list |
||
| 8613 | * |
||
| 8614 | */ |
||
| 8615 | public function countAllRoutesByCountry($country, $filters = array()) |
||
| 8616 | { |
||
| 8617 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8618 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 8619 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8620 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 8621 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8622 | ORDER BY route_count DESC"; |
||
| 8623 | |||
| 8624 | $sth = $this->db->prepare($query); |
||
| 8625 | $sth->execute(array(':country' => $country)); |
||
| 8626 | |||
| 8627 | $routes_array = array(); |
||
| 8628 | $temp_array = array(); |
||
| 8629 | |||
| 8630 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8631 | { |
||
| 8632 | $temp_array['route_count'] = $row['route_count']; |
||
| 8633 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8634 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8635 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8636 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8637 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8638 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8639 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8640 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8641 | |||
| 8642 | $routes_array[] = $temp_array; |
||
| 8643 | } |
||
| 8644 | |||
| 8645 | return $routes_array; |
||
| 8646 | } |
||
| 8647 | |||
| 8648 | |||
| 8649 | /** |
||
| 8650 | * Gets all route combinations based on an date |
||
| 8651 | * |
||
| 8652 | * @return Array the route list |
||
| 8653 | * |
||
| 8654 | */ |
||
| 8655 | public function countAllRoutesByDate($date, $filters = array()) |
||
| 8656 | { |
||
| 8657 | global $globalTimezone, $globalDBdriver; |
||
| 8658 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8659 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 8660 | if ($globalTimezone != '') { |
||
| 8661 | date_default_timezone_set($globalTimezone); |
||
| 8662 | $datetime = new DateTime($date); |
||
| 8663 | $offset = $datetime->format('P'); |
||
| 8664 | } else $offset = '+00:00'; |
||
| 8665 | |||
| 8666 | if ($globalDBdriver == 'mysql') { |
||
| 8667 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8668 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 8669 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8670 | ORDER BY route_count DESC"; |
||
| 8671 | } else { |
||
| 8672 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8673 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 8674 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8675 | ORDER BY route_count DESC"; |
||
| 8676 | } |
||
| 8677 | |||
| 8678 | $sth = $this->db->prepare($query); |
||
| 8679 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 8680 | |||
| 8681 | $routes_array = array(); |
||
| 8682 | $temp_array = array(); |
||
| 8683 | |||
| 8684 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8685 | { |
||
| 8686 | $temp_array['route_count'] = $row['route_count']; |
||
| 8687 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8688 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8689 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8690 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8691 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8692 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8693 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8694 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8695 | |||
| 8696 | $routes_array[] = $temp_array; |
||
| 8697 | } |
||
| 8698 | |||
| 8699 | return $routes_array; |
||
| 8700 | } |
||
| 8701 | |||
| 8702 | |||
| 8703 | /** |
||
| 8704 | * Gets all route combinations based on an ident/callsign |
||
| 8705 | * |
||
| 8706 | * @return Array the route list |
||
| 8707 | * |
||
| 8708 | */ |
||
| 8709 | public function countAllRoutesByIdent($ident, $filters = array()) |
||
| 8710 | { |
||
| 8711 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8712 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 8713 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8714 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.ident = :ident |
||
| 8715 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8716 | ORDER BY route_count DESC"; |
||
| 8717 | |||
| 8718 | |||
| 8719 | $sth = $this->db->prepare($query); |
||
| 8720 | $sth->execute(array(':ident' => $ident)); |
||
| 8721 | |||
| 8722 | $routes_array = array(); |
||
| 8723 | $temp_array = array(); |
||
| 8724 | |||
| 8725 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8726 | { |
||
| 8727 | $temp_array['route_count'] = $row['route_count']; |
||
| 8728 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8729 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8730 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8731 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8732 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8733 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8734 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8735 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8736 | |||
| 8737 | $routes_array[] = $temp_array; |
||
| 8738 | } |
||
| 8739 | |||
| 8740 | return $routes_array; |
||
| 8741 | } |
||
| 8742 | |||
| 8743 | /** |
||
| 8744 | * Gets all route combinations based on an owner |
||
| 8745 | * |
||
| 8746 | * @return Array the route list |
||
| 8747 | * |
||
| 8748 | */ |
||
| 8749 | public function countAllRoutesByOwner($owner,$filters = array()) |
||
| 8750 | { |
||
| 8751 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8752 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 8753 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8754 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.owner_name = :owner |
||
| 8755 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8756 | ORDER BY route_count DESC"; |
||
| 8757 | |||
| 8758 | |||
| 8759 | $sth = $this->db->prepare($query); |
||
| 8760 | $sth->execute(array(':owner' => $owner)); |
||
| 8761 | |||
| 8762 | $routes_array = array(); |
||
| 8763 | $temp_array = array(); |
||
| 8764 | |||
| 8765 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8766 | { |
||
| 8767 | $temp_array['route_count'] = $row['route_count']; |
||
| 8768 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8769 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8770 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8771 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8772 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8773 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8774 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8775 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8776 | |||
| 8777 | $routes_array[] = $temp_array; |
||
| 8778 | } |
||
| 8779 | |||
| 8780 | return $routes_array; |
||
| 8781 | } |
||
| 8782 | |||
| 8783 | /** |
||
| 8784 | * Gets all route combinations based on a pilot |
||
| 8785 | * |
||
| 8786 | * @return Array the route list |
||
| 8787 | * |
||
| 8788 | */ |
||
| 8789 | public function countAllRoutesByPilot($pilot,$filters = array()) |
||
| 8790 | { |
||
| 8791 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8792 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 8793 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8794 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 8795 | GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8796 | ORDER BY route_count DESC"; |
||
| 8797 | |||
| 8798 | |||
| 8799 | $sth = $this->db->prepare($query); |
||
| 8800 | $sth->execute(array(':pilot' => $pilot)); |
||
| 8801 | |||
| 8802 | $routes_array = array(); |
||
| 8803 | $temp_array = array(); |
||
| 8804 | |||
| 8805 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8806 | { |
||
| 8807 | $temp_array['route_count'] = $row['route_count']; |
||
| 8808 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8809 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8810 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8811 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8812 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8813 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8814 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8815 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8816 | |||
| 8817 | $routes_array[] = $temp_array; |
||
| 8818 | } |
||
| 8819 | |||
| 8820 | return $routes_array; |
||
| 8821 | } |
||
| 8822 | |||
| 8823 | |||
| 8824 | /** |
||
| 8825 | * Gets all route combinations based on an manufacturer |
||
| 8826 | * |
||
| 8827 | * @return Array the route list |
||
| 8828 | * |
||
| 8829 | */ |
||
| 8830 | public function countAllRoutesByManufacturer($aircraft_manufacturer, $filters = array()) |
||
| 8831 | { |
||
| 8832 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8833 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 8834 | $query = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8835 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 8836 | GROUP BY route |
||
| 8837 | ORDER BY route_count DESC"; |
||
| 8838 | |||
| 8839 | |||
| 8840 | $sth = $this->db->prepare($query); |
||
| 8841 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 8842 | |||
| 8843 | $routes_array = array(); |
||
| 8844 | $temp_array = array(); |
||
| 8845 | |||
| 8846 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8847 | { |
||
| 8848 | $temp_array['route_count'] = $row['route_count']; |
||
| 8849 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8850 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8851 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8852 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8853 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8854 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8855 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8856 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8857 | |||
| 8858 | $routes_array[] = $temp_array; |
||
| 8859 | } |
||
| 8860 | |||
| 8861 | return $routes_array; |
||
| 8862 | } |
||
| 8863 | |||
| 8864 | |||
| 8865 | |||
| 8866 | /** |
||
| 8867 | * Gets all route combinations with waypoints |
||
| 8868 | * |
||
| 8869 | * @return Array the route list |
||
| 8870 | * |
||
| 8871 | */ |
||
| 8872 | public function countAllRoutesWithWaypoints($filters = array()) |
||
| 8873 | { |
||
| 8874 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8875 | $query = "SELECT DISTINCT spotter_output.waypoints AS route, count(spotter_output.waypoints) AS route_count, spotter_output.spotter_id, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country |
||
| 8876 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.waypoints <> '' |
||
| 8877 | GROUP BY route, spotter_output.spotter_id, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 8878 | ORDER BY route_count DESC |
||
| 8879 | LIMIT 10 OFFSET 0"; |
||
| 8880 | |||
| 8881 | |||
| 8882 | $sth = $this->db->prepare($query); |
||
| 8883 | $sth->execute(); |
||
| 8884 | |||
| 8885 | $routes_array = array(); |
||
| 8886 | $temp_array = array(); |
||
| 8887 | |||
| 8888 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8889 | { |
||
| 8890 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 8891 | $temp_array['route_count'] = $row['route_count']; |
||
| 8892 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 8893 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 8894 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 8895 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 8896 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 8897 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 8898 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 8899 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 8900 | |||
| 8901 | $routes_array[] = $temp_array; |
||
| 8902 | } |
||
| 8903 | |||
| 8904 | return $routes_array; |
||
| 8905 | } |
||
| 8906 | |||
| 8907 | /** |
||
| 8908 | * Gets all callsigns that have flown over |
||
| 8909 | * |
||
| 8910 | * @return Array the callsign list |
||
| 8911 | * |
||
| 8912 | */ |
||
| 8913 | public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '') |
||
| 8914 | { |
||
| 8915 | global $globalDBdriver; |
||
| 8916 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8917 | $query = "SELECT DISTINCT spotter_output.ident, COUNT(spotter_output.ident) AS callsign_icao_count, spotter_output.airline_name, spotter_output.airline_icao |
||
| 8918 | FROM spotter_output".$filter_query." spotter_output.ident <> ''"; |
||
| 8919 | if ($olderthanmonths > 0) { |
||
| 8920 | if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
||
| 8921 | else $query .= " AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 8922 | } |
||
| 8923 | if ($sincedate != '') { |
||
| 8924 | if ($globalDBdriver == 'mysql') $query .= " AND spotter_output.date > '".$sincedate."'"; |
||
| 8925 | else $query .= " AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 8926 | } |
||
| 8927 | $query_values = array(); |
||
| 8928 | if ($year != '') { |
||
| 8929 | if ($globalDBdriver == 'mysql') { |
||
| 8930 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 8931 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8932 | } else { |
||
| 8933 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 8934 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 8935 | } |
||
| 8936 | } |
||
| 8937 | if ($month != '') { |
||
| 8938 | if ($globalDBdriver == 'mysql') { |
||
| 8939 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 8940 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8941 | } else { |
||
| 8942 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 8943 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 8944 | } |
||
| 8945 | } |
||
| 8946 | if ($day != '') { |
||
| 8947 | if ($globalDBdriver == 'mysql') { |
||
| 8948 | $query .= " AND DAY(spotter_output.date) = :day"; |
||
| 8949 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8950 | } else { |
||
| 8951 | $query .= " AND EXTRACT(DAY FROM spotter_output.date) = :day"; |
||
| 8952 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
| 8953 | } |
||
| 8954 | } |
||
| 8955 | $query .= " GROUP BY spotter_output.ident, spotter_output.airline_name, spotter_output.airline_icao ORDER BY callsign_icao_count DESC"; |
||
| 8956 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 8957 | |||
| 8958 | $sth = $this->db->prepare($query); |
||
| 8959 | $sth->execute($query_values); |
||
| 8960 | |||
| 8961 | $callsign_array = array(); |
||
| 8962 | $temp_array = array(); |
||
| 8963 | |||
| 8964 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8965 | { |
||
| 8966 | $temp_array['callsign_icao'] = $row['ident']; |
||
| 8967 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 8968 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 8969 | $temp_array['callsign_icao_count'] = $row['callsign_icao_count']; |
||
| 8970 | |||
| 8971 | $callsign_array[] = $temp_array; |
||
| 8972 | } |
||
| 8973 | |||
| 8974 | return $callsign_array; |
||
| 8975 | } |
||
| 8976 | |||
| 8977 | /** |
||
| 8978 | * Gets all callsigns that have flown over |
||
| 8979 | * |
||
| 8980 | * @return Array the callsign list |
||
| 8981 | * |
||
| 8982 | */ |
||
| 8983 | public function countAllCallsignsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array()) |
||
| 8984 | { |
||
| 8985 | global $globalDBdriver; |
||
| 8986 | $filter_query = $this->getFilter($filters,true,true); |
||
| 8987 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.ident, COUNT(spotter_output.ident) AS callsign_icao_count, spotter_output.airline_name |
||
| 8988 | FROM spotter_output".$filter_query." spotter_output.ident <> '' AND spotter_output.airline_icao <> '' "; |
||
| 8989 | if ($olderthanmonths > 0) { |
||
| 8990 | if ($globalDBdriver == 'mysql') $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 8991 | else $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 8992 | } |
||
| 8993 | if ($sincedate != '') { |
||
| 8994 | if ($globalDBdriver == 'mysql') $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
| 8995 | else $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP) "; |
||
| 8996 | } |
||
| 8997 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.ident, spotter_output.airline_name, spotter_output.airline_icao ORDER BY callsign_icao_count DESC"; |
||
| 8998 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 8999 | |||
| 9000 | $sth = $this->db->prepare($query); |
||
| 9001 | $sth->execute(); |
||
| 9002 | |||
| 9003 | $callsign_array = array(); |
||
| 9004 | $temp_array = array(); |
||
| 9005 | |||
| 9006 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9007 | { |
||
| 9008 | $temp_array['callsign_icao'] = $row['ident']; |
||
| 9009 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 9010 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9011 | $temp_array['callsign_icao_count'] = $row['callsign_icao_count']; |
||
| 9012 | |||
| 9013 | $callsign_array[] = $temp_array; |
||
| 9014 | } |
||
| 9015 | |||
| 9016 | return $callsign_array; |
||
| 9017 | } |
||
| 9018 | |||
| 9019 | |||
| 9020 | |||
| 9021 | |||
| 9022 | /** |
||
| 9023 | * Counts all dates |
||
| 9024 | * |
||
| 9025 | * @return Array the date list |
||
| 9026 | * |
||
| 9027 | */ |
||
| 9028 | public function countAllDates($filters = array()) |
||
| 9029 | { |
||
| 9030 | global $globalTimezone, $globalDBdriver; |
||
| 9031 | if ($globalTimezone != '') { |
||
| 9032 | date_default_timezone_set($globalTimezone); |
||
| 9033 | $datetime = new DateTime(); |
||
| 9034 | $offset = $datetime->format('P'); |
||
| 9035 | } else $offset = '+00:00'; |
||
| 9036 | |||
| 9037 | if ($globalDBdriver == 'mysql') { |
||
| 9038 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 9039 | FROM spotter_output"; |
||
| 9040 | $query .= $this->getFilter($filters); |
||
| 9041 | $query .= " GROUP BY date_name |
||
| 9042 | ORDER BY date_count DESC |
||
| 9043 | LIMIT 10 OFFSET 0"; |
||
| 9044 | } else { |
||
| 9045 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 9046 | FROM spotter_output"; |
||
| 9047 | $query .= $this->getFilter($filters); |
||
| 9048 | $query .= " GROUP BY date_name |
||
| 9049 | ORDER BY date_count DESC |
||
| 9050 | LIMIT 10 OFFSET 0"; |
||
| 9051 | } |
||
| 9052 | |||
| 9053 | |||
| 9054 | $sth = $this->db->prepare($query); |
||
| 9055 | $sth->execute(array(':offset' => $offset)); |
||
| 9056 | |||
| 9057 | $date_array = array(); |
||
| 9058 | $temp_array = array(); |
||
| 9059 | |||
| 9060 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9061 | { |
||
| 9062 | $temp_array['date_name'] = $row['date_name']; |
||
| 9063 | $temp_array['date_count'] = $row['date_count']; |
||
| 9064 | |||
| 9065 | $date_array[] = $temp_array; |
||
| 9066 | } |
||
| 9067 | |||
| 9068 | return $date_array; |
||
| 9069 | } |
||
| 9070 | |||
| 9071 | /** |
||
| 9072 | * Counts all dates |
||
| 9073 | * |
||
| 9074 | * @return Array the date list |
||
| 9075 | * |
||
| 9076 | */ |
||
| 9077 | public function countAllDatesByAirlines($filters = array()) |
||
| 9078 | { |
||
| 9079 | global $globalTimezone, $globalDBdriver; |
||
| 9080 | if ($globalTimezone != '') { |
||
| 9081 | date_default_timezone_set($globalTimezone); |
||
| 9082 | $datetime = new DateTime(); |
||
| 9083 | $offset = $datetime->format('P'); |
||
| 9084 | } else $offset = '+00:00'; |
||
| 9085 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9086 | if ($globalDBdriver == 'mysql') { |
||
| 9087 | $query = "SELECT spotter_output.airline_icao, DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 9088 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
| 9089 | GROUP BY spotter_output.airline_icao, date_name |
||
| 9090 | ORDER BY date_count DESC |
||
| 9091 | LIMIT 10 OFFSET 0"; |
||
| 9092 | } else { |
||
| 9093 | $query = "SELECT spotter_output.airline_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 9094 | FROM spotter_output |
||
| 9095 | WHERE spotter_output.airline_icao <> '' |
||
| 9096 | GROUP BY spotter_output.airline_icao, date_name |
||
| 9097 | ORDER BY date_count DESC |
||
| 9098 | LIMIT 10 OFFSET 0"; |
||
| 9099 | } |
||
| 9100 | |||
| 9101 | |||
| 9102 | $sth = $this->db->prepare($query); |
||
| 9103 | $sth->execute(array(':offset' => $offset)); |
||
| 9104 | |||
| 9105 | $date_array = array(); |
||
| 9106 | $temp_array = array(); |
||
| 9107 | |||
| 9108 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9109 | { |
||
| 9110 | $temp_array['date_name'] = $row['date_name']; |
||
| 9111 | $temp_array['date_count'] = $row['date_count']; |
||
| 9112 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9113 | |||
| 9114 | $date_array[] = $temp_array; |
||
| 9115 | } |
||
| 9116 | |||
| 9117 | return $date_array; |
||
| 9118 | } |
||
| 9119 | |||
| 9120 | /** |
||
| 9121 | * Counts all dates during the last 7 days |
||
| 9122 | * |
||
| 9123 | * @return Array the date list |
||
| 9124 | * |
||
| 9125 | */ |
||
| 9126 | public function countAllDatesLast7Days($filters = array()) |
||
| 9127 | { |
||
| 9128 | global $globalTimezone, $globalDBdriver; |
||
| 9129 | if ($globalTimezone != '') { |
||
| 9130 | date_default_timezone_set($globalTimezone); |
||
| 9131 | $datetime = new DateTime(); |
||
| 9132 | $offset = $datetime->format('P'); |
||
| 9133 | } else $offset = '+00:00'; |
||
| 9134 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9135 | if ($globalDBdriver == 'mysql') { |
||
| 9136 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 9137 | FROM spotter_output".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)"; |
||
| 9138 | $query .= " GROUP BY date_name |
||
| 9139 | ORDER BY spotter_output.date ASC"; |
||
| 9140 | $query_data = array(':offset' => $offset); |
||
| 9141 | } else { |
||
| 9142 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 9143 | FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '7 DAYS'"; |
||
| 9144 | $query .= " GROUP BY date_name |
||
| 9145 | ORDER BY date_name ASC"; |
||
| 9146 | $query_data = array(':offset' => $offset); |
||
| 9147 | } |
||
| 9148 | |||
| 9149 | $sth = $this->db->prepare($query); |
||
| 9150 | $sth->execute($query_data); |
||
| 9151 | |||
| 9152 | $date_array = array(); |
||
| 9153 | $temp_array = array(); |
||
| 9154 | |||
| 9155 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9156 | { |
||
| 9157 | $temp_array['date_name'] = $row['date_name']; |
||
| 9158 | $temp_array['date_count'] = $row['date_count']; |
||
| 9159 | |||
| 9160 | $date_array[] = $temp_array; |
||
| 9161 | } |
||
| 9162 | |||
| 9163 | return $date_array; |
||
| 9164 | } |
||
| 9165 | |||
| 9166 | /** |
||
| 9167 | * Counts all dates during the last month |
||
| 9168 | * |
||
| 9169 | * @return Array the date list |
||
| 9170 | * |
||
| 9171 | */ |
||
| 9172 | public function countAllDatesLastMonth($filters = array()) |
||
| 9173 | { |
||
| 9174 | global $globalTimezone, $globalDBdriver; |
||
| 9175 | if ($globalTimezone != '') { |
||
| 9176 | date_default_timezone_set($globalTimezone); |
||
| 9177 | $datetime = new DateTime(); |
||
| 9178 | $offset = $datetime->format('P'); |
||
| 9179 | } else $offset = '+00:00'; |
||
| 9180 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9181 | if ($globalDBdriver == 'mysql') { |
||
| 9182 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 9183 | FROM spotter_output".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)"; |
||
| 9184 | $query .= " GROUP BY date_name |
||
| 9185 | ORDER BY spotter_output.date ASC"; |
||
| 9186 | $query_data = array(':offset' => $offset); |
||
| 9187 | } else { |
||
| 9188 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 9189 | FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS'"; |
||
| 9190 | $query .= " GROUP BY date_name |
||
| 9191 | ORDER BY date_name ASC"; |
||
| 9192 | $query_data = array(':offset' => $offset); |
||
| 9193 | } |
||
| 9194 | |||
| 9195 | $sth = $this->db->prepare($query); |
||
| 9196 | $sth->execute($query_data); |
||
| 9197 | |||
| 9198 | $date_array = array(); |
||
| 9199 | $temp_array = array(); |
||
| 9200 | |||
| 9201 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9202 | { |
||
| 9203 | $temp_array['date_name'] = $row['date_name']; |
||
| 9204 | $temp_array['date_count'] = $row['date_count']; |
||
| 9205 | |||
| 9206 | $date_array[] = $temp_array; |
||
| 9207 | } |
||
| 9208 | |||
| 9209 | return $date_array; |
||
| 9210 | } |
||
| 9211 | |||
| 9212 | |||
| 9213 | /** |
||
| 9214 | * Counts all dates during the last month |
||
| 9215 | * |
||
| 9216 | * @return Array the date list |
||
| 9217 | * |
||
| 9218 | */ |
||
| 9219 | public function countAllDatesLastMonthByAirlines($filters = array()) |
||
| 9220 | { |
||
| 9221 | global $globalTimezone, $globalDBdriver; |
||
| 9222 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9223 | if ($globalTimezone != '') { |
||
| 9224 | date_default_timezone_set($globalTimezone); |
||
| 9225 | $datetime = new DateTime(); |
||
| 9226 | $offset = $datetime->format('P'); |
||
| 9227 | } else $offset = '+00:00'; |
||
| 9228 | |||
| 9229 | if ($globalDBdriver == 'mysql') { |
||
| 9230 | $query = "SELECT spotter_output.airline_icao, DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 9231 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH) |
||
| 9232 | GROUP BY spotter_output.airline_icao, date_name |
||
| 9233 | ORDER BY spotter_output.date ASC"; |
||
| 9234 | $query_data = array(':offset' => $offset); |
||
| 9235 | } else { |
||
| 9236 | $query = "SELECT spotter_output.airline_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 9237 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS' |
||
| 9238 | GROUP BY spotter_output.airline_icao, date_name |
||
| 9239 | ORDER BY date_name ASC"; |
||
| 9240 | $query_data = array(':offset' => $offset); |
||
| 9241 | } |
||
| 9242 | |||
| 9243 | $sth = $this->db->prepare($query); |
||
| 9244 | $sth->execute($query_data); |
||
| 9245 | |||
| 9246 | $date_array = array(); |
||
| 9247 | $temp_array = array(); |
||
| 9248 | |||
| 9249 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9250 | { |
||
| 9251 | $temp_array['date_name'] = $row['date_name']; |
||
| 9252 | $temp_array['date_count'] = $row['date_count']; |
||
| 9253 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9254 | |||
| 9255 | $date_array[] = $temp_array; |
||
| 9256 | } |
||
| 9257 | |||
| 9258 | return $date_array; |
||
| 9259 | } |
||
| 9260 | |||
| 9261 | |||
| 9262 | /** |
||
| 9263 | * Counts all month |
||
| 9264 | * |
||
| 9265 | * @return Array the month list |
||
| 9266 | * |
||
| 9267 | */ |
||
| 9268 | public function countAllMonths($filters = array()) |
||
| 9269 | { |
||
| 9270 | global $globalTimezone, $globalDBdriver; |
||
| 9271 | if ($globalTimezone != '') { |
||
| 9272 | date_default_timezone_set($globalTimezone); |
||
| 9273 | $datetime = new DateTime(); |
||
| 9274 | $offset = $datetime->format('P'); |
||
| 9275 | } else $offset = '+00:00'; |
||
| 9276 | |||
| 9277 | if ($globalDBdriver == 'mysql') { |
||
| 9278 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
||
| 9279 | FROM spotter_output"; |
||
| 9280 | $query .= $this->getFilter($filters); |
||
| 9281 | $query .= " GROUP BY year_name, month_name ORDER BY date_count DESC"; |
||
| 9282 | } else { |
||
| 9283 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count |
||
| 9284 | FROM spotter_output"; |
||
| 9285 | $query .= $this->getFilter($filters); |
||
| 9286 | $query .= " GROUP BY year_name, month_name ORDER BY date_count DESC"; |
||
| 9287 | } |
||
| 9288 | |||
| 9289 | |||
| 9290 | $sth = $this->db->prepare($query); |
||
| 9291 | $sth->execute(array(':offset' => $offset)); |
||
| 9292 | |||
| 9293 | $date_array = array(); |
||
| 9294 | $temp_array = array(); |
||
| 9295 | |||
| 9296 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9297 | { |
||
| 9298 | $temp_array['month_name'] = $row['month_name']; |
||
| 9299 | $temp_array['year_name'] = $row['year_name']; |
||
| 9300 | $temp_array['date_count'] = $row['date_count']; |
||
| 9301 | |||
| 9302 | $date_array[] = $temp_array; |
||
| 9303 | } |
||
| 9304 | |||
| 9305 | return $date_array; |
||
| 9306 | } |
||
| 9307 | |||
| 9308 | /** |
||
| 9309 | * Counts all month |
||
| 9310 | * |
||
| 9311 | * @return Array the month list |
||
| 9312 | * |
||
| 9313 | */ |
||
| 9314 | public function countAllMonthsByAirlines($filters = array()) |
||
| 9315 | { |
||
| 9316 | global $globalTimezone, $globalDBdriver; |
||
| 9317 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9318 | if ($globalTimezone != '') { |
||
| 9319 | date_default_timezone_set($globalTimezone); |
||
| 9320 | $datetime = new DateTime(); |
||
| 9321 | $offset = $datetime->format('P'); |
||
| 9322 | } else $offset = '+00:00'; |
||
| 9323 | |||
| 9324 | if ($globalDBdriver == 'mysql') { |
||
| 9325 | $query = "SELECT spotter_output.airline_icao, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
||
| 9326 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
| 9327 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9328 | ORDER BY date_count DESC"; |
||
| 9329 | } else { |
||
| 9330 | $query = "SELECT spotter_output.airline_icao, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count |
||
| 9331 | FROM spotter_output |
||
| 9332 | WHERE spotter_output.airline_icao <> '' |
||
| 9333 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9334 | ORDER BY date_count DESC"; |
||
| 9335 | } |
||
| 9336 | |||
| 9337 | |||
| 9338 | $sth = $this->db->prepare($query); |
||
| 9339 | $sth->execute(array(':offset' => $offset)); |
||
| 9340 | |||
| 9341 | $date_array = array(); |
||
| 9342 | $temp_array = array(); |
||
| 9343 | |||
| 9344 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9345 | { |
||
| 9346 | $temp_array['month_name'] = $row['month_name']; |
||
| 9347 | $temp_array['year_name'] = $row['year_name']; |
||
| 9348 | $temp_array['date_count'] = $row['date_count']; |
||
| 9349 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9350 | |||
| 9351 | $date_array[] = $temp_array; |
||
| 9352 | } |
||
| 9353 | |||
| 9354 | return $date_array; |
||
| 9355 | } |
||
| 9356 | |||
| 9357 | /** |
||
| 9358 | * Counts all military month |
||
| 9359 | * |
||
| 9360 | * @return Array the month list |
||
| 9361 | * |
||
| 9362 | */ |
||
| 9363 | public function countAllMilitaryMonths($filters = array()) |
||
| 9364 | { |
||
| 9365 | global $globalTimezone, $globalDBdriver; |
||
| 9366 | if ($globalTimezone != '') { |
||
| 9367 | date_default_timezone_set($globalTimezone); |
||
| 9368 | $datetime = new DateTime(); |
||
| 9369 | $offset = $datetime->format('P'); |
||
| 9370 | } else $offset = '+00:00'; |
||
| 9371 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9372 | if ($globalDBdriver == 'mysql') { |
||
| 9373 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
||
| 9374 | FROM spotter_output".$filter_query." spotter_output.airline_type = 'military' |
||
| 9375 | GROUP BY year_name, month_name |
||
| 9376 | ORDER BY date_count DESC"; |
||
| 9377 | } else { |
||
| 9378 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count |
||
| 9379 | FROM spotter_output".$filter_query." spotter_output.airline_type = 'military' |
||
| 9380 | GROUP BY year_name, month_name |
||
| 9381 | ORDER BY date_count DESC"; |
||
| 9382 | } |
||
| 9383 | |||
| 9384 | $sth = $this->db->prepare($query); |
||
| 9385 | $sth->execute(array(':offset' => $offset)); |
||
| 9386 | |||
| 9387 | $date_array = array(); |
||
| 9388 | $temp_array = array(); |
||
| 9389 | |||
| 9390 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9391 | { |
||
| 9392 | $temp_array['month_name'] = $row['month_name']; |
||
| 9393 | $temp_array['year_name'] = $row['year_name']; |
||
| 9394 | $temp_array['date_count'] = $row['date_count']; |
||
| 9395 | |||
| 9396 | $date_array[] = $temp_array; |
||
| 9397 | } |
||
| 9398 | |||
| 9399 | return $date_array; |
||
| 9400 | } |
||
| 9401 | |||
| 9402 | /** |
||
| 9403 | * Counts all month owners |
||
| 9404 | * |
||
| 9405 | * @return Array the month list |
||
| 9406 | * |
||
| 9407 | */ |
||
| 9408 | public function countAllMonthsOwners($filters = array()) |
||
| 9409 | { |
||
| 9410 | global $globalTimezone, $globalDBdriver; |
||
| 9411 | if ($globalTimezone != '') { |
||
| 9412 | date_default_timezone_set($globalTimezone); |
||
| 9413 | $datetime = new DateTime(); |
||
| 9414 | $offset = $datetime->format('P'); |
||
| 9415 | } else $offset = '+00:00'; |
||
| 9416 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9417 | |||
| 9418 | if ($globalDBdriver == 'mysql') { |
||
| 9419 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct owner_name) as date_count |
||
| 9420 | FROM spotter_output".$filter_query." owner_name <> '' |
||
| 9421 | GROUP BY year_name, month_name |
||
| 9422 | ORDER BY date_count DESC"; |
||
| 9423 | } else { |
||
| 9424 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct owner_name) as date_count |
||
| 9425 | FROM spotter_output".$filter_query." owner_name <> '' |
||
| 9426 | GROUP BY year_name, month_name |
||
| 9427 | ORDER BY date_count DESC"; |
||
| 9428 | } |
||
| 9429 | |||
| 9430 | $sth = $this->db->prepare($query); |
||
| 9431 | $sth->execute(array(':offset' => $offset)); |
||
| 9432 | |||
| 9433 | $date_array = array(); |
||
| 9434 | $temp_array = array(); |
||
| 9435 | |||
| 9436 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9437 | { |
||
| 9438 | $temp_array['month_name'] = $row['month_name']; |
||
| 9439 | $temp_array['year_name'] = $row['year_name']; |
||
| 9440 | $temp_array['date_count'] = $row['date_count']; |
||
| 9441 | |||
| 9442 | $date_array[] = $temp_array; |
||
| 9443 | } |
||
| 9444 | |||
| 9445 | return $date_array; |
||
| 9446 | } |
||
| 9447 | |||
| 9448 | /** |
||
| 9449 | * Counts all month owners |
||
| 9450 | * |
||
| 9451 | * @return Array the month list |
||
| 9452 | * |
||
| 9453 | */ |
||
| 9454 | public function countAllMonthsOwnersByAirlines($filters = array()) |
||
| 9455 | { |
||
| 9456 | global $globalTimezone, $globalDBdriver; |
||
| 9457 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9458 | if ($globalTimezone != '') { |
||
| 9459 | date_default_timezone_set($globalTimezone); |
||
| 9460 | $datetime = new DateTime(); |
||
| 9461 | $offset = $datetime->format('P'); |
||
| 9462 | } else $offset = '+00:00'; |
||
| 9463 | |||
| 9464 | if ($globalDBdriver == 'mysql') { |
||
| 9465 | $query = "SELECT spotter_output.airline_icao, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct owner_name) as date_count |
||
| 9466 | FROM spotter_output".$filter_query." owner_name <> '' AND spotter_output.airline_icao <> '' |
||
| 9467 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9468 | ORDER BY date_count DESC"; |
||
| 9469 | } else { |
||
| 9470 | $query = "SELECT spotter_output.airline_icao, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct owner_name) as date_count |
||
| 9471 | FROM spotter_output".$filter_query." owner_name <> '' AND spotter_output.airline_icao <> '' |
||
| 9472 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9473 | ORDER BY date_count DESC"; |
||
| 9474 | } |
||
| 9475 | |||
| 9476 | $sth = $this->db->prepare($query); |
||
| 9477 | $sth->execute(array(':offset' => $offset)); |
||
| 9478 | |||
| 9479 | $date_array = array(); |
||
| 9480 | $temp_array = array(); |
||
| 9481 | |||
| 9482 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9483 | { |
||
| 9484 | $temp_array['month_name'] = $row['month_name']; |
||
| 9485 | $temp_array['year_name'] = $row['year_name']; |
||
| 9486 | $temp_array['date_count'] = $row['date_count']; |
||
| 9487 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9488 | |||
| 9489 | $date_array[] = $temp_array; |
||
| 9490 | } |
||
| 9491 | |||
| 9492 | return $date_array; |
||
| 9493 | } |
||
| 9494 | |||
| 9495 | /** |
||
| 9496 | * Counts all month pilot |
||
| 9497 | * |
||
| 9498 | * @return Array the month list |
||
| 9499 | * |
||
| 9500 | */ |
||
| 9501 | public function countAllMonthsPilots($filters = array()) |
||
| 9502 | { |
||
| 9503 | global $globalTimezone, $globalDBdriver; |
||
| 9504 | if ($globalTimezone != '') { |
||
| 9505 | date_default_timezone_set($globalTimezone); |
||
| 9506 | $datetime = new DateTime(); |
||
| 9507 | $offset = $datetime->format('P'); |
||
| 9508 | } else $offset = '+00:00'; |
||
| 9509 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9510 | |||
| 9511 | if ($globalDBdriver == 'mysql') { |
||
| 9512 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct pilot_id) as date_count |
||
| 9513 | FROM spotter_output".$filter_query." pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 9514 | GROUP BY year_name, month_name |
||
| 9515 | ORDER BY date_count DESC"; |
||
| 9516 | } else { |
||
| 9517 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct pilot_id) as date_count |
||
| 9518 | FROM spotter_output".$filter_query." pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 9519 | GROUP BY year_name, month_name |
||
| 9520 | ORDER BY date_count DESC"; |
||
| 9521 | } |
||
| 9522 | |||
| 9523 | $sth = $this->db->prepare($query); |
||
| 9524 | $sth->execute(array(':offset' => $offset)); |
||
| 9525 | |||
| 9526 | $date_array = array(); |
||
| 9527 | $temp_array = array(); |
||
| 9528 | |||
| 9529 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9530 | { |
||
| 9531 | $temp_array['month_name'] = $row['month_name']; |
||
| 9532 | $temp_array['year_name'] = $row['year_name']; |
||
| 9533 | $temp_array['date_count'] = $row['date_count']; |
||
| 9534 | |||
| 9535 | $date_array[] = $temp_array; |
||
| 9536 | } |
||
| 9537 | |||
| 9538 | return $date_array; |
||
| 9539 | } |
||
| 9540 | |||
| 9541 | /** |
||
| 9542 | * Counts all month pilot |
||
| 9543 | * |
||
| 9544 | * @return Array the month list |
||
| 9545 | * |
||
| 9546 | */ |
||
| 9547 | public function countAllMonthsPilotsByAirlines($filters = array()) |
||
| 9548 | { |
||
| 9549 | global $globalTimezone, $globalDBdriver; |
||
| 9550 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9551 | if ($globalTimezone != '') { |
||
| 9552 | date_default_timezone_set($globalTimezone); |
||
| 9553 | $datetime = new DateTime(); |
||
| 9554 | $offset = $datetime->format('P'); |
||
| 9555 | } else $offset = '+00:00'; |
||
| 9556 | |||
| 9557 | if ($globalDBdriver == 'mysql') { |
||
| 9558 | $query = "SELECT spotter_output.airline_icao, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct pilot_id) as date_count |
||
| 9559 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 9560 | GROUP BY spotter_output.airline_icao,year_name, month_name |
||
| 9561 | ORDER BY date_count DESC"; |
||
| 9562 | } else { |
||
| 9563 | $query = "SELECT spotter_output.airline_icao, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct pilot_id) as date_count |
||
| 9564 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' AND pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 9565 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9566 | ORDER BY date_count DESC"; |
||
| 9567 | } |
||
| 9568 | |||
| 9569 | $sth = $this->db->prepare($query); |
||
| 9570 | $sth->execute(array(':offset' => $offset)); |
||
| 9571 | |||
| 9572 | $date_array = array(); |
||
| 9573 | $temp_array = array(); |
||
| 9574 | |||
| 9575 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9576 | { |
||
| 9577 | $temp_array['month_name'] = $row['month_name']; |
||
| 9578 | $temp_array['year_name'] = $row['year_name']; |
||
| 9579 | $temp_array['date_count'] = $row['date_count']; |
||
| 9580 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9581 | |||
| 9582 | $date_array[] = $temp_array; |
||
| 9583 | } |
||
| 9584 | |||
| 9585 | return $date_array; |
||
| 9586 | } |
||
| 9587 | |||
| 9588 | /** |
||
| 9589 | * Counts all month airline |
||
| 9590 | * |
||
| 9591 | * @return Array the month list |
||
| 9592 | * |
||
| 9593 | */ |
||
| 9594 | public function countAllMonthsAirlines($filters = array()) |
||
| 9595 | { |
||
| 9596 | global $globalTimezone, $globalDBdriver; |
||
| 9597 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9598 | if ($globalTimezone != '') { |
||
| 9599 | date_default_timezone_set($globalTimezone); |
||
| 9600 | $datetime = new DateTime(); |
||
| 9601 | $offset = $datetime->format('P'); |
||
| 9602 | } else $offset = '+00:00'; |
||
| 9603 | |||
| 9604 | if ($globalDBdriver == 'mysql') { |
||
| 9605 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct airline_icao) as date_count |
||
| 9606 | FROM spotter_output".$filter_query." airline_icao <> '' |
||
| 9607 | GROUP BY year_name, month_name |
||
| 9608 | ORDER BY date_count DESC"; |
||
| 9609 | } else { |
||
| 9610 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct airline_icao) as date_count |
||
| 9611 | FROM spotter_output".$filter_query." airline_icao <> '' |
||
| 9612 | GROUP BY year_name, month_name |
||
| 9613 | ORDER BY date_count DESC"; |
||
| 9614 | } |
||
| 9615 | |||
| 9616 | $sth = $this->db->prepare($query); |
||
| 9617 | $sth->execute(array(':offset' => $offset)); |
||
| 9618 | |||
| 9619 | $date_array = array(); |
||
| 9620 | $temp_array = array(); |
||
| 9621 | |||
| 9622 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9623 | { |
||
| 9624 | $temp_array['month_name'] = $row['month_name']; |
||
| 9625 | $temp_array['year_name'] = $row['year_name']; |
||
| 9626 | $temp_array['date_count'] = $row['date_count']; |
||
| 9627 | |||
| 9628 | $date_array[] = $temp_array; |
||
| 9629 | } |
||
| 9630 | |||
| 9631 | return $date_array; |
||
| 9632 | } |
||
| 9633 | |||
| 9634 | /** |
||
| 9635 | * Counts all month aircraft |
||
| 9636 | * |
||
| 9637 | * @return Array the month list |
||
| 9638 | * |
||
| 9639 | */ |
||
| 9640 | public function countAllMonthsAircrafts($filters = array()) |
||
| 9641 | { |
||
| 9642 | global $globalTimezone, $globalDBdriver; |
||
| 9643 | if ($globalTimezone != '') { |
||
| 9644 | date_default_timezone_set($globalTimezone); |
||
| 9645 | $datetime = new DateTime(); |
||
| 9646 | $offset = $datetime->format('P'); |
||
| 9647 | } else $offset = '+00:00'; |
||
| 9648 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9649 | |||
| 9650 | if ($globalDBdriver == 'mysql') { |
||
| 9651 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct aircraft_icao) as date_count |
||
| 9652 | FROM spotter_output".$filter_query." aircraft_icao <> '' |
||
| 9653 | GROUP BY year_name, month_name |
||
| 9654 | ORDER BY date_count DESC"; |
||
| 9655 | } else { |
||
| 9656 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct aircraft_icao) as date_count |
||
| 9657 | FROM spotter_output".$filter_query." aircraft_icao <> '' |
||
| 9658 | GROUP BY year_name, month_name |
||
| 9659 | ORDER BY date_count DESC"; |
||
| 9660 | } |
||
| 9661 | |||
| 9662 | $sth = $this->db->prepare($query); |
||
| 9663 | $sth->execute(array(':offset' => $offset)); |
||
| 9664 | |||
| 9665 | $date_array = array(); |
||
| 9666 | $temp_array = array(); |
||
| 9667 | |||
| 9668 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9669 | { |
||
| 9670 | $temp_array['month_name'] = $row['month_name']; |
||
| 9671 | $temp_array['year_name'] = $row['year_name']; |
||
| 9672 | $temp_array['date_count'] = $row['date_count']; |
||
| 9673 | |||
| 9674 | $date_array[] = $temp_array; |
||
| 9675 | } |
||
| 9676 | |||
| 9677 | return $date_array; |
||
| 9678 | } |
||
| 9679 | |||
| 9680 | |||
| 9681 | /** |
||
| 9682 | * Counts all month aircraft |
||
| 9683 | * |
||
| 9684 | * @return Array the month list |
||
| 9685 | * |
||
| 9686 | */ |
||
| 9687 | public function countAllMonthsAircraftsByAirlines($filters = array()) |
||
| 9688 | { |
||
| 9689 | global $globalTimezone, $globalDBdriver; |
||
| 9690 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9691 | if ($globalTimezone != '') { |
||
| 9692 | date_default_timezone_set($globalTimezone); |
||
| 9693 | $datetime = new DateTime(); |
||
| 9694 | $offset = $datetime->format('P'); |
||
| 9695 | } else $offset = '+00:00'; |
||
| 9696 | |||
| 9697 | if ($globalDBdriver == 'mysql') { |
||
| 9698 | $query = "SELECT spotter_output.airline_icao,YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct aircraft_icao) as date_count |
||
| 9699 | FROM spotter_output".$filter_query." aircraft_icao <> '' AND spotter_output.airline_icao <> '' |
||
| 9700 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9701 | ORDER BY date_count DESC"; |
||
| 9702 | } else { |
||
| 9703 | $query = "SELECT spotter_output.airline_icao, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct aircraft_icao) as date_count |
||
| 9704 | FROM spotter_output".$filter_query." aircraft_icao <> '' AND spotter_output.airline_icao <> '' |
||
| 9705 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9706 | ORDER BY date_count DESC"; |
||
| 9707 | } |
||
| 9708 | |||
| 9709 | $sth = $this->db->prepare($query); |
||
| 9710 | $sth->execute(array(':offset' => $offset)); |
||
| 9711 | |||
| 9712 | $date_array = array(); |
||
| 9713 | $temp_array = array(); |
||
| 9714 | |||
| 9715 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9716 | { |
||
| 9717 | $temp_array['month_name'] = $row['month_name']; |
||
| 9718 | $temp_array['year_name'] = $row['year_name']; |
||
| 9719 | $temp_array['date_count'] = $row['date_count']; |
||
| 9720 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9721 | |||
| 9722 | $date_array[] = $temp_array; |
||
| 9723 | } |
||
| 9724 | |||
| 9725 | return $date_array; |
||
| 9726 | } |
||
| 9727 | |||
| 9728 | /** |
||
| 9729 | * Counts all month real arrival |
||
| 9730 | * |
||
| 9731 | * @return Array the month list |
||
| 9732 | * |
||
| 9733 | */ |
||
| 9734 | public function countAllMonthsRealArrivals($filters = array()) |
||
| 9735 | { |
||
| 9736 | global $globalTimezone, $globalDBdriver; |
||
| 9737 | if ($globalTimezone != '') { |
||
| 9738 | date_default_timezone_set($globalTimezone); |
||
| 9739 | $datetime = new DateTime(); |
||
| 9740 | $offset = $datetime->format('P'); |
||
| 9741 | } else $offset = '+00:00'; |
||
| 9742 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9743 | |||
| 9744 | if ($globalDBdriver == 'mysql') { |
||
| 9745 | $query = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(real_arrival_airport_icao) as date_count |
||
| 9746 | FROM spotter_output".$filter_query." real_arrival_airport_icao <> '' |
||
| 9747 | GROUP BY year_name, month_name |
||
| 9748 | ORDER BY date_count DESC"; |
||
| 9749 | } else { |
||
| 9750 | $query = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(real_arrival_airport_icao) as date_count |
||
| 9751 | FROM spotter_output".$filter_query." real_arrival_airport_icao <> '' |
||
| 9752 | GROUP BY year_name, month_name |
||
| 9753 | ORDER BY date_count DESC"; |
||
| 9754 | } |
||
| 9755 | |||
| 9756 | $sth = $this->db->prepare($query); |
||
| 9757 | $sth->execute(array(':offset' => $offset)); |
||
| 9758 | |||
| 9759 | $date_array = array(); |
||
| 9760 | $temp_array = array(); |
||
| 9761 | |||
| 9762 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9763 | { |
||
| 9764 | $temp_array['month_name'] = $row['month_name']; |
||
| 9765 | $temp_array['year_name'] = $row['year_name']; |
||
| 9766 | $temp_array['date_count'] = $row['date_count']; |
||
| 9767 | |||
| 9768 | $date_array[] = $temp_array; |
||
| 9769 | } |
||
| 9770 | |||
| 9771 | return $date_array; |
||
| 9772 | } |
||
| 9773 | |||
| 9774 | |||
| 9775 | /** |
||
| 9776 | * Counts all month real arrival |
||
| 9777 | * |
||
| 9778 | * @return Array the month list |
||
| 9779 | * |
||
| 9780 | */ |
||
| 9781 | public function countAllMonthsRealArrivalsByAirlines($filters = array()) |
||
| 9782 | { |
||
| 9783 | global $globalTimezone, $globalDBdriver; |
||
| 9784 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9785 | if ($globalTimezone != '') { |
||
| 9786 | date_default_timezone_set($globalTimezone); |
||
| 9787 | $datetime = new DateTime(); |
||
| 9788 | $offset = $datetime->format('P'); |
||
| 9789 | } else $offset = '+00:00'; |
||
| 9790 | |||
| 9791 | if ($globalDBdriver == 'mysql') { |
||
| 9792 | $query = "SELECT spotter_output.airline_icao, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(real_arrival_airport_icao) as date_count |
||
| 9793 | FROM spotter_output".$filter_query." real_arrival_airport_icao <> '' AND spotter_output.airline_icao <> '' |
||
| 9794 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9795 | ORDER BY date_count DESC"; |
||
| 9796 | } else { |
||
| 9797 | $query = "SELECT spotter_output.airline_icao, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(real_arrival_airport_icao) as date_count |
||
| 9798 | FROM spotter_output".$filter_query." real_arrival_airport_icao <> '' AND spotter_output.airline_icao <> '' |
||
| 9799 | GROUP BY spotter_output.airline_icao, year_name, month_name |
||
| 9800 | ORDER BY date_count DESC"; |
||
| 9801 | } |
||
| 9802 | |||
| 9803 | $sth = $this->db->prepare($query); |
||
| 9804 | $sth->execute(array(':offset' => $offset)); |
||
| 9805 | |||
| 9806 | $date_array = array(); |
||
| 9807 | $temp_array = array(); |
||
| 9808 | |||
| 9809 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9810 | { |
||
| 9811 | $temp_array['month_name'] = $row['month_name']; |
||
| 9812 | $temp_array['year_name'] = $row['year_name']; |
||
| 9813 | $temp_array['date_count'] = $row['date_count']; |
||
| 9814 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9815 | |||
| 9816 | $date_array[] = $temp_array; |
||
| 9817 | } |
||
| 9818 | |||
| 9819 | return $date_array; |
||
| 9820 | } |
||
| 9821 | |||
| 9822 | |||
| 9823 | /** |
||
| 9824 | * Counts all dates during the last year |
||
| 9825 | * |
||
| 9826 | * @return Array the date list |
||
| 9827 | * |
||
| 9828 | */ |
||
| 9829 | public function countAllMonthsLastYear($filters) |
||
| 9830 | { |
||
| 9831 | global $globalTimezone, $globalDBdriver; |
||
| 9832 | if ($globalTimezone != '') { |
||
| 9833 | date_default_timezone_set($globalTimezone); |
||
| 9834 | $datetime = new DateTime(); |
||
| 9835 | $offset = $datetime->format('P'); |
||
| 9836 | } else $offset = '+00:00'; |
||
| 9837 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9838 | if ($globalDBdriver == 'mysql') { |
||
| 9839 | $query = "SELECT MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count |
||
| 9840 | FROM spotter_output".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)"; |
||
| 9841 | $query .= " GROUP BY year_name, month_name |
||
| 9842 | ORDER BY year_name, month_name ASC"; |
||
| 9843 | $query_data = array(':offset' => $offset); |
||
| 9844 | } else { |
||
| 9845 | $query = "SELECT EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name, count(*) as date_count |
||
| 9846 | FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 YEARS'"; |
||
| 9847 | $query .= " GROUP BY year_name, month_name |
||
| 9848 | ORDER BY year_name, month_name ASC"; |
||
| 9849 | $query_data = array(':offset' => $offset); |
||
| 9850 | } |
||
| 9851 | |||
| 9852 | $sth = $this->db->prepare($query); |
||
| 9853 | $sth->execute($query_data); |
||
| 9854 | |||
| 9855 | $date_array = array(); |
||
| 9856 | $temp_array = array(); |
||
| 9857 | |||
| 9858 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9859 | { |
||
| 9860 | $temp_array['year_name'] = $row['year_name']; |
||
| 9861 | $temp_array['month_name'] = $row['month_name']; |
||
| 9862 | $temp_array['date_count'] = $row['date_count']; |
||
| 9863 | |||
| 9864 | $date_array[] = $temp_array; |
||
| 9865 | } |
||
| 9866 | |||
| 9867 | return $date_array; |
||
| 9868 | } |
||
| 9869 | |||
| 9870 | |||
| 9871 | |||
| 9872 | /** |
||
| 9873 | * Counts all hours |
||
| 9874 | * |
||
| 9875 | * @return Array the hour list |
||
| 9876 | * |
||
| 9877 | */ |
||
| 9878 | public function countAllHours($orderby,$filters = array()) |
||
| 9879 | { |
||
| 9880 | global $globalTimezone, $globalDBdriver; |
||
| 9881 | if ($globalTimezone != '') { |
||
| 9882 | date_default_timezone_set($globalTimezone); |
||
| 9883 | $datetime = new DateTime(); |
||
| 9884 | $offset = $datetime->format('P'); |
||
| 9885 | } else $offset = '+00:00'; |
||
| 9886 | |||
| 9887 | $orderby_sql = ''; |
||
| 9888 | if ($orderby == "hour") |
||
| 9889 | { |
||
| 9890 | $orderby_sql = "ORDER BY hour_name ASC"; |
||
| 9891 | } |
||
| 9892 | if ($orderby == "count") |
||
| 9893 | { |
||
| 9894 | $orderby_sql = "ORDER BY hour_count DESC"; |
||
| 9895 | } |
||
| 9896 | |||
| 9897 | if ($globalDBdriver == 'mysql') { |
||
| 9898 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 9899 | FROM spotter_output"; |
||
| 9900 | $query .= $this->getFilter($filters); |
||
| 9901 | $query .= " GROUP BY hour_name |
||
| 9902 | ".$orderby_sql; |
||
| 9903 | |||
| 9904 | /* $query = "SELECT HOUR(spotter_output.date) AS hour_name, count(*) as hour_count |
||
| 9905 | FROM spotter_output |
||
| 9906 | GROUP BY hour_name |
||
| 9907 | ".$orderby_sql." |
||
| 9908 | LIMIT 10 OFFSET 00"; |
||
| 9909 | */ |
||
| 9910 | $query_data = array(':offset' => $offset); |
||
| 9911 | } else { |
||
| 9912 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 9913 | FROM spotter_output"; |
||
| 9914 | $query .= $this->getFilter($filters); |
||
| 9915 | $query .= " GROUP BY hour_name |
||
| 9916 | ".$orderby_sql; |
||
| 9917 | $query_data = array(':offset' => $offset); |
||
| 9918 | } |
||
| 9919 | |||
| 9920 | $sth = $this->db->prepare($query); |
||
| 9921 | $sth->execute($query_data); |
||
| 9922 | |||
| 9923 | $hour_array = array(); |
||
| 9924 | $temp_array = array(); |
||
| 9925 | |||
| 9926 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9927 | { |
||
| 9928 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 9929 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 9930 | |||
| 9931 | $hour_array[] = $temp_array; |
||
| 9932 | } |
||
| 9933 | |||
| 9934 | return $hour_array; |
||
| 9935 | } |
||
| 9936 | |||
| 9937 | /** |
||
| 9938 | * Counts all hours |
||
| 9939 | * |
||
| 9940 | * @return Array the hour list |
||
| 9941 | * |
||
| 9942 | */ |
||
| 9943 | public function countAllHoursByAirlines($orderby, $filters = array()) |
||
| 9944 | { |
||
| 9945 | global $globalTimezone, $globalDBdriver; |
||
| 9946 | $filter_query = $this->getFilter($filters,true,true); |
||
| 9947 | if ($globalTimezone != '') { |
||
| 9948 | date_default_timezone_set($globalTimezone); |
||
| 9949 | $datetime = new DateTime(); |
||
| 9950 | $offset = $datetime->format('P'); |
||
| 9951 | } else $offset = '+00:00'; |
||
| 9952 | |||
| 9953 | $orderby_sql = ''; |
||
| 9954 | if ($orderby == "hour") |
||
| 9955 | { |
||
| 9956 | $orderby_sql = "ORDER BY hour_name ASC"; |
||
| 9957 | } |
||
| 9958 | if ($orderby == "count") |
||
| 9959 | { |
||
| 9960 | $orderby_sql = "ORDER BY hour_count DESC"; |
||
| 9961 | } |
||
| 9962 | |||
| 9963 | if ($globalDBdriver == 'mysql') { |
||
| 9964 | $query = "SELECT spotter_output.airline_icao, HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 9965 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
| 9966 | GROUP BY spotter_output.airline_icao, hour_name |
||
| 9967 | ".$orderby_sql; |
||
| 9968 | |||
| 9969 | /* $query = "SELECT HOUR(spotter_output.date) AS hour_name, count(*) as hour_count |
||
| 9970 | FROM spotter_output |
||
| 9971 | GROUP BY hour_name |
||
| 9972 | ".$orderby_sql." |
||
| 9973 | LIMIT 10 OFFSET 00"; |
||
| 9974 | */ |
||
| 9975 | $query_data = array(':offset' => $offset); |
||
| 9976 | } else { |
||
| 9977 | $query = "SELECT spotter_output.airline_icao, EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 9978 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
| 9979 | GROUP BY spotter_output.airline_icao, hour_name |
||
| 9980 | ".$orderby_sql; |
||
| 9981 | $query_data = array(':offset' => $offset); |
||
| 9982 | } |
||
| 9983 | |||
| 9984 | $sth = $this->db->prepare($query); |
||
| 9985 | $sth->execute($query_data); |
||
| 9986 | |||
| 9987 | $hour_array = array(); |
||
| 9988 | $temp_array = array(); |
||
| 9989 | |||
| 9990 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 9991 | { |
||
| 9992 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 9993 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 9994 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 9995 | |||
| 9996 | $hour_array[] = $temp_array; |
||
| 9997 | } |
||
| 9998 | |||
| 9999 | return $hour_array; |
||
| 10000 | } |
||
| 10001 | |||
| 10002 | |||
| 10003 | |||
| 10004 | /** |
||
| 10005 | * Counts all hours by airline |
||
| 10006 | * |
||
| 10007 | * @return Array the hour list |
||
| 10008 | * |
||
| 10009 | */ |
||
| 10010 | public function countAllHoursByAirline($airline_icao, $filters = array()) |
||
| 10011 | { |
||
| 10012 | global $globalTimezone, $globalDBdriver; |
||
| 10013 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10014 | if ($globalTimezone != '') { |
||
| 10015 | date_default_timezone_set($globalTimezone); |
||
| 10016 | $datetime = new DateTime(); |
||
| 10017 | $offset = $datetime->format('P'); |
||
| 10018 | } else $offset = '+00:00'; |
||
| 10019 | |||
| 10020 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 10021 | |||
| 10022 | if ($globalDBdriver == 'mysql') { |
||
| 10023 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10024 | FROM spotter_output".$filter_query." spotter_output.airline_icao = :airline_icao |
||
| 10025 | GROUP BY hour_name |
||
| 10026 | ORDER BY hour_name ASC"; |
||
| 10027 | } else { |
||
| 10028 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10029 | FROM spotter_output".$filter_query." spotter_output.airline_icao = :airline_icao |
||
| 10030 | GROUP BY hour_name |
||
| 10031 | ORDER BY hour_name ASC"; |
||
| 10032 | } |
||
| 10033 | |||
| 10034 | $sth = $this->db->prepare($query); |
||
| 10035 | $sth->execute(array(':airline_icao' => $airline_icao,':offset' => $offset)); |
||
| 10036 | |||
| 10037 | $hour_array = array(); |
||
| 10038 | $temp_array = array(); |
||
| 10039 | |||
| 10040 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10041 | { |
||
| 10042 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10043 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10044 | |||
| 10045 | $hour_array[] = $temp_array; |
||
| 10046 | } |
||
| 10047 | |||
| 10048 | return $hour_array; |
||
| 10049 | } |
||
| 10050 | |||
| 10051 | |||
| 10052 | |||
| 10053 | |||
| 10054 | /** |
||
| 10055 | * Counts all hours by aircraft |
||
| 10056 | * |
||
| 10057 | * @return Array the hour list |
||
| 10058 | * |
||
| 10059 | */ |
||
| 10060 | public function countAllHoursByAircraft($aircraft_icao, $filters = array()) |
||
| 10061 | { |
||
| 10062 | global $globalTimezone, $globalDBdriver; |
||
| 10063 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10064 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 10065 | if ($globalTimezone != '') { |
||
| 10066 | date_default_timezone_set($globalTimezone); |
||
| 10067 | $datetime = new DateTime(); |
||
| 10068 | $offset = $datetime->format('P'); |
||
| 10069 | } else $offset = '+00:00'; |
||
| 10070 | |||
| 10071 | if ($globalDBdriver == 'mysql') { |
||
| 10072 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10073 | FROM spotter_output".$filter_query." spotter_output.aircraft_icao = :aircraft_icao |
||
| 10074 | GROUP BY hour_name |
||
| 10075 | ORDER BY hour_name ASC"; |
||
| 10076 | } else { |
||
| 10077 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10078 | FROM spotter_output".$filter_query." spotter_output.aircraft_icao = :aircraft_icao |
||
| 10079 | GROUP BY hour_name |
||
| 10080 | ORDER BY hour_name ASC"; |
||
| 10081 | } |
||
| 10082 | |||
| 10083 | $sth = $this->db->prepare($query); |
||
| 10084 | $sth->execute(array(':aircraft_icao' => $aircraft_icao,':offset' => $offset)); |
||
| 10085 | |||
| 10086 | $hour_array = array(); |
||
| 10087 | $temp_array = array(); |
||
| 10088 | |||
| 10089 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10090 | { |
||
| 10091 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10092 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10093 | |||
| 10094 | $hour_array[] = $temp_array; |
||
| 10095 | } |
||
| 10096 | |||
| 10097 | return $hour_array; |
||
| 10098 | } |
||
| 10099 | |||
| 10100 | |||
| 10101 | /** |
||
| 10102 | * Counts all hours by aircraft registration |
||
| 10103 | * |
||
| 10104 | * @return Array the hour list |
||
| 10105 | * |
||
| 10106 | */ |
||
| 10107 | public function countAllHoursByRegistration($registration, $filters = array()) |
||
| 10108 | { |
||
| 10109 | global $globalTimezone, $globalDBdriver; |
||
| 10110 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10111 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 10112 | if ($globalTimezone != '') { |
||
| 10113 | date_default_timezone_set($globalTimezone); |
||
| 10114 | $datetime = new DateTime(); |
||
| 10115 | $offset = $datetime->format('P'); |
||
| 10116 | } else $offset = '+00:00'; |
||
| 10117 | |||
| 10118 | if ($globalDBdriver == 'mysql') { |
||
| 10119 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10120 | FROM spotter_output".$filter_query." spotter_output.registration = :registration |
||
| 10121 | GROUP BY hour_name |
||
| 10122 | ORDER BY hour_name ASC"; |
||
| 10123 | } else { |
||
| 10124 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10125 | FROM spotter_output".$filter_query." spotter_output.registration = :registration |
||
| 10126 | GROUP BY hour_name |
||
| 10127 | ORDER BY hour_name ASC"; |
||
| 10128 | } |
||
| 10129 | |||
| 10130 | $sth = $this->db->prepare($query); |
||
| 10131 | $sth->execute(array(':registration' => $registration,':offset' => $offset)); |
||
| 10132 | |||
| 10133 | $hour_array = array(); |
||
| 10134 | $temp_array = array(); |
||
| 10135 | |||
| 10136 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10137 | { |
||
| 10138 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10139 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10140 | |||
| 10141 | $hour_array[] = $temp_array; |
||
| 10142 | } |
||
| 10143 | |||
| 10144 | return $hour_array; |
||
| 10145 | } |
||
| 10146 | |||
| 10147 | |||
| 10148 | /** |
||
| 10149 | * Counts all hours by airport |
||
| 10150 | * |
||
| 10151 | * @return Array the hour list |
||
| 10152 | * |
||
| 10153 | */ |
||
| 10154 | public function countAllHoursByAirport($airport_icao, $filters = array()) |
||
| 10155 | { |
||
| 10156 | global $globalTimezone, $globalDBdriver; |
||
| 10157 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10158 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 10159 | if ($globalTimezone != '') { |
||
| 10160 | date_default_timezone_set($globalTimezone); |
||
| 10161 | $datetime = new DateTime(); |
||
| 10162 | $offset = $datetime->format('P'); |
||
| 10163 | } else $offset = '+00:00'; |
||
| 10164 | |||
| 10165 | if ($globalDBdriver == 'mysql') { |
||
| 10166 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10167 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 10168 | GROUP BY hour_name |
||
| 10169 | ORDER BY hour_name ASC"; |
||
| 10170 | } else { |
||
| 10171 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10172 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 10173 | GROUP BY hour_name |
||
| 10174 | ORDER BY hour_name ASC"; |
||
| 10175 | } |
||
| 10176 | |||
| 10177 | $sth = $this->db->prepare($query); |
||
| 10178 | $sth->execute(array(':airport_icao' => $airport_icao,':offset' => $offset)); |
||
| 10179 | |||
| 10180 | $hour_array = array(); |
||
| 10181 | $temp_array = array(); |
||
| 10182 | |||
| 10183 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10184 | { |
||
| 10185 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10186 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10187 | |||
| 10188 | $hour_array[] = $temp_array; |
||
| 10189 | } |
||
| 10190 | |||
| 10191 | return $hour_array; |
||
| 10192 | } |
||
| 10193 | |||
| 10194 | |||
| 10195 | |||
| 10196 | /** |
||
| 10197 | * Counts all hours by manufacturer |
||
| 10198 | * |
||
| 10199 | * @return Array the hour list |
||
| 10200 | * |
||
| 10201 | */ |
||
| 10202 | public function countAllHoursByManufacturer($aircraft_manufacturer,$filters =array()) |
||
| 10203 | { |
||
| 10204 | global $globalTimezone, $globalDBdriver; |
||
| 10205 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10206 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 10207 | if ($globalTimezone != '') { |
||
| 10208 | date_default_timezone_set($globalTimezone); |
||
| 10209 | $datetime = new DateTime(); |
||
| 10210 | $offset = $datetime->format('P'); |
||
| 10211 | } else $offset = '+00:00'; |
||
| 10212 | |||
| 10213 | if ($globalDBdriver == 'mysql') { |
||
| 10214 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10215 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 10216 | GROUP BY hour_name |
||
| 10217 | ORDER BY hour_name ASC"; |
||
| 10218 | } else { |
||
| 10219 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10220 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 10221 | GROUP BY hour_name |
||
| 10222 | ORDER BY hour_name ASC"; |
||
| 10223 | } |
||
| 10224 | |||
| 10225 | $sth = $this->db->prepare($query); |
||
| 10226 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer,':offset' => $offset)); |
||
| 10227 | |||
| 10228 | $hour_array = array(); |
||
| 10229 | $temp_array = array(); |
||
| 10230 | |||
| 10231 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10232 | { |
||
| 10233 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10234 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10235 | |||
| 10236 | $hour_array[] = $temp_array; |
||
| 10237 | } |
||
| 10238 | |||
| 10239 | return $hour_array; |
||
| 10240 | } |
||
| 10241 | |||
| 10242 | |||
| 10243 | |||
| 10244 | /** |
||
| 10245 | * Counts all hours by date |
||
| 10246 | * |
||
| 10247 | * @return Array the hour list |
||
| 10248 | * |
||
| 10249 | */ |
||
| 10250 | public function countAllHoursByDate($date, $filters = array()) |
||
| 10251 | { |
||
| 10252 | global $globalTimezone, $globalDBdriver; |
||
| 10253 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10254 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 10255 | if ($globalTimezone != '') { |
||
| 10256 | date_default_timezone_set($globalTimezone); |
||
| 10257 | $datetime = new DateTime($date); |
||
| 10258 | $offset = $datetime->format('P'); |
||
| 10259 | } else $offset = '+00:00'; |
||
| 10260 | |||
| 10261 | if ($globalDBdriver == 'mysql') { |
||
| 10262 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10263 | FROM spotter_output".$filter_query." DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 10264 | GROUP BY hour_name |
||
| 10265 | ORDER BY hour_name ASC"; |
||
| 10266 | } else { |
||
| 10267 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10268 | FROM spotter_output".$filter_query." to_char(spotter_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date |
||
| 10269 | GROUP BY hour_name |
||
| 10270 | ORDER BY hour_name ASC"; |
||
| 10271 | } |
||
| 10272 | |||
| 10273 | $sth = $this->db->prepare($query); |
||
| 10274 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 10275 | |||
| 10276 | $hour_array = array(); |
||
| 10277 | $temp_array = array(); |
||
| 10278 | |||
| 10279 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10280 | { |
||
| 10281 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10282 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10283 | |||
| 10284 | $hour_array[] = $temp_array; |
||
| 10285 | } |
||
| 10286 | |||
| 10287 | return $hour_array; |
||
| 10288 | } |
||
| 10289 | |||
| 10290 | |||
| 10291 | |||
| 10292 | /** |
||
| 10293 | * Counts all hours by a ident/callsign |
||
| 10294 | * |
||
| 10295 | * @return Array the hour list |
||
| 10296 | * |
||
| 10297 | */ |
||
| 10298 | public function countAllHoursByIdent($ident, $filters = array()) |
||
| 10299 | { |
||
| 10300 | global $globalTimezone, $globalDBdriver; |
||
| 10301 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10302 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 10303 | if ($globalTimezone != '') { |
||
| 10304 | date_default_timezone_set($globalTimezone); |
||
| 10305 | $datetime = new DateTime(); |
||
| 10306 | $offset = $datetime->format('P'); |
||
| 10307 | } else $offset = '+00:00'; |
||
| 10308 | |||
| 10309 | if ($globalDBdriver == 'mysql') { |
||
| 10310 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10311 | FROM spotter_output".$filter_query." spotter_output.ident = :ident |
||
| 10312 | GROUP BY hour_name |
||
| 10313 | ORDER BY hour_name ASC"; |
||
| 10314 | } else { |
||
| 10315 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10316 | FROM spotter_output".$filter_query." spotter_output.ident = :ident |
||
| 10317 | GROUP BY hour_name |
||
| 10318 | ORDER BY hour_name ASC"; |
||
| 10319 | } |
||
| 10320 | |||
| 10321 | |||
| 10322 | $sth = $this->db->prepare($query); |
||
| 10323 | $sth->execute(array(':ident' => $ident,':offset' => $offset)); |
||
| 10324 | |||
| 10325 | $hour_array = array(); |
||
| 10326 | $temp_array = array(); |
||
| 10327 | |||
| 10328 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10329 | { |
||
| 10330 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10331 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10332 | |||
| 10333 | $hour_array[] = $temp_array; |
||
| 10334 | } |
||
| 10335 | |||
| 10336 | return $hour_array; |
||
| 10337 | } |
||
| 10338 | |||
| 10339 | /** |
||
| 10340 | * Counts all hours by a owner |
||
| 10341 | * |
||
| 10342 | * @return Array the hour list |
||
| 10343 | * |
||
| 10344 | */ |
||
| 10345 | public function countAllHoursByOwner($owner, $filters = array()) |
||
| 10346 | { |
||
| 10347 | global $globalTimezone, $globalDBdriver; |
||
| 10348 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10349 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 10350 | if ($globalTimezone != '') { |
||
| 10351 | date_default_timezone_set($globalTimezone); |
||
| 10352 | $datetime = new DateTime(); |
||
| 10353 | $offset = $datetime->format('P'); |
||
| 10354 | } else $offset = '+00:00'; |
||
| 10355 | |||
| 10356 | if ($globalDBdriver == 'mysql') { |
||
| 10357 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10358 | FROM spotter_output".$filter_query." spotter_output.owner_name = :owner |
||
| 10359 | GROUP BY hour_name |
||
| 10360 | ORDER BY hour_name ASC"; |
||
| 10361 | } else { |
||
| 10362 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10363 | FROM spotter_output".$filter_query." spotter_output.owner_name = :owner |
||
| 10364 | GROUP BY hour_name |
||
| 10365 | ORDER BY hour_name ASC"; |
||
| 10366 | } |
||
| 10367 | |||
| 10368 | |||
| 10369 | $sth = $this->db->prepare($query); |
||
| 10370 | $sth->execute(array(':owner' => $owner,':offset' => $offset)); |
||
| 10371 | |||
| 10372 | $hour_array = array(); |
||
| 10373 | $temp_array = array(); |
||
| 10374 | |||
| 10375 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10376 | { |
||
| 10377 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10378 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10379 | |||
| 10380 | $hour_array[] = $temp_array; |
||
| 10381 | } |
||
| 10382 | |||
| 10383 | return $hour_array; |
||
| 10384 | } |
||
| 10385 | |||
| 10386 | /** |
||
| 10387 | * Counts all hours by a pilot |
||
| 10388 | * |
||
| 10389 | * @return Array the hour list |
||
| 10390 | * |
||
| 10391 | */ |
||
| 10392 | public function countAllHoursByPilot($pilot, $filters = array()) |
||
| 10393 | { |
||
| 10394 | global $globalTimezone, $globalDBdriver; |
||
| 10395 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10396 | $pilot = filter_var($pilot,FILTER_SANITIZE_STRING); |
||
| 10397 | if ($globalTimezone != '') { |
||
| 10398 | date_default_timezone_set($globalTimezone); |
||
| 10399 | $datetime = new DateTime(); |
||
| 10400 | $offset = $datetime->format('P'); |
||
| 10401 | } else $offset = '+00:00'; |
||
| 10402 | |||
| 10403 | if ($globalDBdriver == 'mysql') { |
||
| 10404 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10405 | FROM spotter_output".$filter_query." (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 10406 | GROUP BY hour_name |
||
| 10407 | ORDER BY hour_name ASC"; |
||
| 10408 | } else { |
||
| 10409 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10410 | FROM spotter_output".$filter_query." (spotter_output.pilot_name = :pilot OR spotter_output.pilot_id = :pilot) |
||
| 10411 | GROUP BY hour_name |
||
| 10412 | ORDER BY hour_name ASC"; |
||
| 10413 | } |
||
| 10414 | |||
| 10415 | |||
| 10416 | $sth = $this->db->prepare($query); |
||
| 10417 | $sth->execute(array(':pilot' => $pilot,':offset' => $offset)); |
||
| 10418 | |||
| 10419 | $hour_array = array(); |
||
| 10420 | $temp_array = array(); |
||
| 10421 | |||
| 10422 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10423 | { |
||
| 10424 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10425 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10426 | |||
| 10427 | $hour_array[] = $temp_array; |
||
| 10428 | } |
||
| 10429 | |||
| 10430 | return $hour_array; |
||
| 10431 | } |
||
| 10432 | |||
| 10433 | |||
| 10434 | |||
| 10435 | /** |
||
| 10436 | * Counts all hours by route |
||
| 10437 | * |
||
| 10438 | * @return Array the hour list |
||
| 10439 | * |
||
| 10440 | */ |
||
| 10441 | public function countAllHoursByRoute($departure_airport_icao, $arrival_airport_icao, $filters =array()) |
||
| 10442 | { |
||
| 10443 | global $globalTimezone, $globalDBdriver; |
||
| 10444 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10445 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 10446 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 10447 | if ($globalTimezone != '') { |
||
| 10448 | date_default_timezone_set($globalTimezone); |
||
| 10449 | $datetime = new DateTime(); |
||
| 10450 | $offset = $datetime->format('P'); |
||
| 10451 | } else $offset = '+00:00'; |
||
| 10452 | |||
| 10453 | if ($globalDBdriver == 'mysql') { |
||
| 10454 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10455 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 10456 | GROUP BY hour_name |
||
| 10457 | ORDER BY hour_name ASC"; |
||
| 10458 | } else { |
||
| 10459 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10460 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 10461 | GROUP BY hour_name |
||
| 10462 | ORDER BY hour_name ASC"; |
||
| 10463 | } |
||
| 10464 | |||
| 10465 | $sth = $this->db->prepare($query); |
||
| 10466 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':offset' => $offset)); |
||
| 10467 | |||
| 10468 | $hour_array = array(); |
||
| 10469 | $temp_array = array(); |
||
| 10470 | |||
| 10471 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10472 | { |
||
| 10473 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10474 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10475 | |||
| 10476 | $hour_array[] = $temp_array; |
||
| 10477 | } |
||
| 10478 | |||
| 10479 | return $hour_array; |
||
| 10480 | } |
||
| 10481 | |||
| 10482 | |||
| 10483 | /** |
||
| 10484 | * Counts all hours by country |
||
| 10485 | * |
||
| 10486 | * @return Array the hour list |
||
| 10487 | * |
||
| 10488 | */ |
||
| 10489 | public function countAllHoursByCountry($country, $filters = array()) |
||
| 10490 | { |
||
| 10491 | global $globalTimezone, $globalDBdriver; |
||
| 10492 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10493 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 10494 | if ($globalTimezone != '') { |
||
| 10495 | date_default_timezone_set($globalTimezone); |
||
| 10496 | $datetime = new DateTime(); |
||
| 10497 | $offset = $datetime->format('P'); |
||
| 10498 | } else $offset = '+00:00'; |
||
| 10499 | |||
| 10500 | if ($globalDBdriver == 'mysql') { |
||
| 10501 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10502 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 10503 | GROUP BY hour_name |
||
| 10504 | ORDER BY hour_name ASC"; |
||
| 10505 | } else { |
||
| 10506 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10507 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 10508 | GROUP BY hour_name |
||
| 10509 | ORDER BY hour_name ASC"; |
||
| 10510 | } |
||
| 10511 | |||
| 10512 | $sth = $this->db->prepare($query); |
||
| 10513 | $sth->execute(array(':country' => $country,':offset' => $offset)); |
||
| 10514 | |||
| 10515 | $hour_array = array(); |
||
| 10516 | $temp_array = array(); |
||
| 10517 | |||
| 10518 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10519 | { |
||
| 10520 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10521 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10522 | |||
| 10523 | $hour_array[] = $temp_array; |
||
| 10524 | } |
||
| 10525 | |||
| 10526 | return $hour_array; |
||
| 10527 | } |
||
| 10528 | |||
| 10529 | |||
| 10530 | |||
| 10531 | |||
| 10532 | /** |
||
| 10533 | * Counts all aircraft that have flown over |
||
| 10534 | * |
||
| 10535 | * @return Integer the number of aircrafts |
||
| 10536 | * |
||
| 10537 | */ |
||
| 10538 | public function countOverallAircrafts($filters = array(),$year = '',$month = '') |
||
| 10539 | { |
||
| 10540 | global $globalDBdriver; |
||
| 10541 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10542 | $query = "SELECT COUNT(DISTINCT spotter_output.aircraft_icao) AS aircraft_count |
||
| 10543 | FROM spotter_output".$filter_query." spotter_output.ident <> ''"; |
||
| 10544 | $query_values = array(); |
||
| 10545 | if ($year != '') { |
||
| 10546 | if ($globalDBdriver == 'mysql') { |
||
| 10547 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10548 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10549 | } else { |
||
| 10550 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10551 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10552 | } |
||
| 10553 | } |
||
| 10554 | if ($month != '') { |
||
| 10555 | if ($globalDBdriver == 'mysql') { |
||
| 10556 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10557 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10558 | } else { |
||
| 10559 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10560 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10561 | } |
||
| 10562 | } |
||
| 10563 | |||
| 10564 | $sth = $this->db->prepare($query); |
||
| 10565 | $sth->execute($query_values); |
||
| 10566 | return $sth->fetchColumn(); |
||
| 10567 | } |
||
| 10568 | |||
| 10569 | /** |
||
| 10570 | * Counts all flight that really arrival |
||
| 10571 | * |
||
| 10572 | * @return Integer the number of aircrafts |
||
| 10573 | * |
||
| 10574 | */ |
||
| 10575 | public function countOverallArrival($filters = array(),$year = '',$month = '') |
||
| 10576 | { |
||
| 10577 | global $globalDBdriver; |
||
| 10578 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10579 | $query = "SELECT COUNT(spotter_output.real_arrival_airport_icao) AS arrival_count |
||
| 10580 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_icao <> ''"; |
||
| 10581 | $query_values = array(); |
||
| 10582 | if ($year != '') { |
||
| 10583 | if ($globalDBdriver == 'mysql') { |
||
| 10584 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10585 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10586 | } else { |
||
| 10587 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10588 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10589 | } |
||
| 10590 | } |
||
| 10591 | if ($month != '') { |
||
| 10592 | if ($globalDBdriver == 'mysql') { |
||
| 10593 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10594 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10595 | } else { |
||
| 10596 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10597 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10598 | } |
||
| 10599 | } |
||
| 10600 | |||
| 10601 | $sth = $this->db->prepare($query); |
||
| 10602 | $sth->execute($query_values); |
||
| 10603 | return $sth->fetchColumn(); |
||
| 10604 | } |
||
| 10605 | |||
| 10606 | /** |
||
| 10607 | * Counts all pilots that have flown over |
||
| 10608 | * |
||
| 10609 | * @return Integer the number of pilots |
||
| 10610 | * |
||
| 10611 | */ |
||
| 10612 | public function countOverallPilots($filters = array(),$year = '',$month = '') |
||
| 10613 | { |
||
| 10614 | global $globalDBdriver; |
||
| 10615 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10616 | $query = "SELECT COUNT(DISTINCT spotter_output.pilot_id) AS pilot_count |
||
| 10617 | FROM spotter_output".$filter_query." spotter_output.pilot_id <> ''"; |
||
| 10618 | $query_values = array(); |
||
| 10619 | if ($year != '') { |
||
| 10620 | if ($globalDBdriver == 'mysql') { |
||
| 10621 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10622 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10623 | } else { |
||
| 10624 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10625 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10626 | } |
||
| 10627 | } |
||
| 10628 | if ($month != '') { |
||
| 10629 | if ($globalDBdriver == 'mysql') { |
||
| 10630 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10631 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10632 | } else { |
||
| 10633 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10634 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10635 | } |
||
| 10636 | } |
||
| 10637 | $sth = $this->db->prepare($query); |
||
| 10638 | $sth->execute($query_values); |
||
| 10639 | return $sth->fetchColumn(); |
||
| 10640 | } |
||
| 10641 | |||
| 10642 | /** |
||
| 10643 | * Counts all owners that have flown over |
||
| 10644 | * |
||
| 10645 | * @return Integer the number of owners |
||
| 10646 | * |
||
| 10647 | */ |
||
| 10648 | public function countOverallOwners($filters = array(),$year = '',$month = '') |
||
| 10649 | { |
||
| 10650 | global $globalDBdriver; |
||
| 10651 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10652 | $query = "SELECT COUNT(DISTINCT spotter_output.owner_name) AS owner_count |
||
| 10653 | FROM spotter_output".$filter_query." spotter_output.owner_name <> ''"; |
||
| 10654 | $query_values = array(); |
||
| 10655 | if ($year != '') { |
||
| 10656 | if ($globalDBdriver == 'mysql') { |
||
| 10657 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10658 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10659 | } else { |
||
| 10660 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10661 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10662 | } |
||
| 10663 | } |
||
| 10664 | if ($month != '') { |
||
| 10665 | if ($globalDBdriver == 'mysql') { |
||
| 10666 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10667 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10668 | } else { |
||
| 10669 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10670 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10671 | } |
||
| 10672 | } |
||
| 10673 | $sth = $this->db->prepare($query); |
||
| 10674 | $sth->execute($query_values); |
||
| 10675 | return $sth->fetchColumn(); |
||
| 10676 | } |
||
| 10677 | |||
| 10678 | |||
| 10679 | /** |
||
| 10680 | * Counts all flights that have flown over |
||
| 10681 | * |
||
| 10682 | * @return Integer the number of flights |
||
| 10683 | * |
||
| 10684 | */ |
||
| 10685 | public function countOverallFlights($filters = array(),$year = '',$month = '') |
||
| 10686 | { |
||
| 10687 | global $globalDBdriver; |
||
| 10688 | $queryi = "SELECT COUNT(spotter_output.spotter_id) AS flight_count FROM spotter_output"; |
||
| 10689 | $query_values = array(); |
||
| 10690 | $query = ''; |
||
| 10691 | if ($year != '') { |
||
| 10692 | if ($globalDBdriver == 'mysql') { |
||
| 10693 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10694 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10695 | } else { |
||
| 10696 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10697 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10698 | } |
||
| 10699 | } |
||
| 10700 | if ($month != '') { |
||
| 10701 | if ($globalDBdriver == 'mysql') { |
||
| 10702 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10703 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10704 | } else { |
||
| 10705 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10706 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10707 | } |
||
| 10708 | } |
||
| 10709 | if (empty($query_values)) $queryi .= $this->getFilter($filters); |
||
| 10710 | else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
||
| 10711 | |||
| 10712 | //echo $query; |
||
| 10713 | $sth = $this->db->prepare($queryi); |
||
| 10714 | $sth->execute($query_values); |
||
| 10715 | return $sth->fetchColumn(); |
||
| 10716 | } |
||
| 10717 | |||
| 10718 | /** |
||
| 10719 | * Counts all military flights that have flown over |
||
| 10720 | * |
||
| 10721 | * @return Integer the number of flights |
||
| 10722 | * |
||
| 10723 | */ |
||
| 10724 | public function countOverallMilitaryFlights($filters = array(),$year = '',$month = '') |
||
| 10725 | { |
||
| 10726 | global $globalDBdriver; |
||
| 10727 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10728 | $query = "SELECT COUNT(spotter_output.spotter_id) AS flight_count |
||
| 10729 | FROM airlines,spotter_output".$filter_query." spotter_output.airline_icao = airlines.icao AND airlines.type = 'military'"; |
||
| 10730 | $query_values = array(); |
||
| 10731 | if ($year != '') { |
||
| 10732 | if ($globalDBdriver == 'mysql') { |
||
| 10733 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10734 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10735 | } else { |
||
| 10736 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10737 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10738 | } |
||
| 10739 | } |
||
| 10740 | if ($month != '') { |
||
| 10741 | if ($globalDBdriver == 'mysql') { |
||
| 10742 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10743 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10744 | } else { |
||
| 10745 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10746 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10747 | } |
||
| 10748 | } |
||
| 10749 | |||
| 10750 | $sth = $this->db->prepare($query); |
||
| 10751 | $sth->execute($query_values); |
||
| 10752 | return $sth->fetchColumn(); |
||
| 10753 | } |
||
| 10754 | |||
| 10755 | |||
| 10756 | |||
| 10757 | /** |
||
| 10758 | * Counts all airlines that have flown over |
||
| 10759 | * |
||
| 10760 | * @return Integer the number of airlines |
||
| 10761 | * |
||
| 10762 | */ |
||
| 10763 | public function countOverallAirlines($filters = array(),$year = '',$month = '') |
||
| 10764 | { |
||
| 10765 | global $globalDBdriver; |
||
| 10766 | $queryi = "SELECT COUNT(DISTINCT spotter_output.airline_name) AS airline_count |
||
| 10767 | FROM spotter_output"; |
||
| 10768 | |||
| 10769 | $query_values = array(); |
||
| 10770 | $query = ''; |
||
| 10771 | if ($year != '') { |
||
| 10772 | if ($globalDBdriver == 'mysql') { |
||
| 10773 | $query .= " AND YEAR(spotter_output.date) = :year"; |
||
| 10774 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10775 | } else { |
||
| 10776 | $query .= " AND EXTRACT(YEAR FROM spotter_output.date) = :year"; |
||
| 10777 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
| 10778 | } |
||
| 10779 | } |
||
| 10780 | if ($month != '') { |
||
| 10781 | if ($globalDBdriver == 'mysql') { |
||
| 10782 | $query .= " AND MONTH(spotter_output.date) = :month"; |
||
| 10783 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10784 | } else { |
||
| 10785 | $query .= " AND EXTRACT(MONTH FROM spotter_output.date) = :month"; |
||
| 10786 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
| 10787 | } |
||
| 10788 | } |
||
| 10789 | if ($query == '') $queryi .= $this->getFilter($filters); |
||
| 10790 | else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
||
| 10791 | |||
| 10792 | |||
| 10793 | $sth = $this->db->prepare($queryi); |
||
| 10794 | $sth->execute($query_values); |
||
| 10795 | return $sth->fetchColumn(); |
||
| 10796 | } |
||
| 10797 | |||
| 10798 | |||
| 10799 | /** |
||
| 10800 | * Counts all hours of today |
||
| 10801 | * |
||
| 10802 | * @return Array the hour list |
||
| 10803 | * |
||
| 10804 | */ |
||
| 10805 | public function countAllHoursFromToday($filters = array()) |
||
| 10806 | { |
||
| 10807 | global $globalTimezone, $globalDBdriver; |
||
| 10808 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10809 | if ($globalTimezone != '') { |
||
| 10810 | date_default_timezone_set($globalTimezone); |
||
| 10811 | $datetime = new DateTime(); |
||
| 10812 | $offset = $datetime->format('P'); |
||
| 10813 | } else $offset = '+00:00'; |
||
| 10814 | |||
| 10815 | if ($globalDBdriver == 'mysql') { |
||
| 10816 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 10817 | FROM spotter_output".$filter_query." DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = CURDATE() |
||
| 10818 | GROUP BY hour_name |
||
| 10819 | ORDER BY hour_name ASC"; |
||
| 10820 | } else { |
||
| 10821 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 10822 | FROM spotter_output".$filter_query." to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date) |
||
| 10823 | GROUP BY hour_name |
||
| 10824 | ORDER BY hour_name ASC"; |
||
| 10825 | } |
||
| 10826 | |||
| 10827 | $sth = $this->db->prepare($query); |
||
| 10828 | $sth->execute(array(':offset' => $offset)); |
||
| 10829 | |||
| 10830 | $hour_array = array(); |
||
| 10831 | $temp_array = array(); |
||
| 10832 | |||
| 10833 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10834 | { |
||
| 10835 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 10836 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 10837 | $hour_array[] = $temp_array; |
||
| 10838 | } |
||
| 10839 | |||
| 10840 | return $hour_array; |
||
| 10841 | } |
||
| 10842 | |||
| 10843 | /** |
||
| 10844 | * Gets all the spotter information based on calculated upcoming flights |
||
| 10845 | * |
||
| 10846 | * @return Array the spotter information |
||
| 10847 | * |
||
| 10848 | */ |
||
| 10849 | public function getUpcomingFlights($limit = '', $sort = '', $filters = array()) |
||
| 10850 | { |
||
| 10851 | global $global_query, $globalDBdriver, $globalTimezone; |
||
| 10852 | $filter_query = $this->getFilter($filters,true,true); |
||
| 10853 | date_default_timezone_set('UTC'); |
||
| 10854 | $limit_query = ''; |
||
| 10855 | if ($limit != "") |
||
| 10856 | { |
||
| 10857 | $limit_array = explode(",", $limit); |
||
| 10858 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 10859 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 10860 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 10861 | { |
||
| 10862 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 10863 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 10864 | } |
||
| 10865 | } |
||
| 10866 | $currentHour = date("G"); |
||
| 10867 | $next3Hours = date("G", strtotime("+3 hour")); |
||
| 10868 | //if the next 3 hours is already equal to/past midnight, we limit it to stay there, otherwise the query will fail |
||
| 10869 | if ($currentHour >= 21 && $next3Hours >= 00) |
||
| 10870 | { |
||
| 10871 | $next3Hours = 24; |
||
| 10872 | } |
||
| 10873 | $currentDayofWeek = date("l"); |
||
| 10874 | if ($globalDBdriver == 'mysql') { |
||
| 10875 | if ($sort != "") |
||
| 10876 | { |
||
| 10877 | $search_orderby_array = $this->getOrderBy(); |
||
| 10878 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 10879 | } else { |
||
| 10880 | $orderby_query = " ORDER BY HOUR(spotter_output.date) ASC"; |
||
| 10881 | } |
||
| 10882 | /* |
||
| 10883 | $query = "SELECT spotter_output.*, count(spotter_output.ident) as ident_count |
||
| 10884 | FROM spotter_output |
||
| 10885 | WHERE DAYNAME(spotter_output.date) = '$currentDayofWeek' AND HOUR(spotter_output.date) >= '$currentHour' AND HOUR(spotter_output.date) <= '$next3Hours' AND spotter_output.ident <> '' AND format_source <> 'aprs' |
||
| 10886 | GROUP BY spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time HAVING count(spotter_output.ident) > 10 $orderby_query"; |
||
| 10887 | */ |
||
| 10888 | /* $query = "SELECT spotter_output.ident, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time, count(spotter_output.ident) as ident_count |
||
| 10889 | FROM spotter_output |
||
| 10890 | WHERE DAYNAME(spotter_output.date) = '$currentDayofWeek' AND HOUR(spotter_output.date) >= '$currentHour' AND HOUR(spotter_output.date) <= '$next3Hours' AND spotter_output.ident <> '' AND format_source <> 'aprs' |
||
| 10891 | GROUP BY spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time HAVING count(spotter_output.ident) > 10 $orderby_query"; |
||
| 10892 | */ |
||
| 10893 | $query = "SELECT spotter_output.ident, spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time, count(spotter_output.ident) as ident_count |
||
| 10894 | FROM spotter_output".$filter_query." DAYNAME(spotter_output.date) = '$currentDayofWeek' AND HOUR(spotter_output.date) >= '$currentHour' AND HOUR(spotter_output.date) <= '$next3Hours' AND spotter_output.ident <> '' AND format_source <> 'aprs' |
||
| 10895 | GROUP BY spotter_output.ident,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time |
||
| 10896 | HAVING count(spotter_output.ident) > 5$orderby_query"; |
||
| 10897 | |||
| 10898 | $spotter_array = $this->getDataFromDB($query.$limit_query); |
||
| 10899 | } else { |
||
| 10900 | if ($sort != "") |
||
| 10901 | { |
||
| 10902 | $search_orderby_array = $this->getOrderBy(); |
||
| 10903 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 10904 | } else { |
||
| 10905 | $orderby_query = " ORDER BY to_char(spotter_output.date,'HH') ASC"; |
||
| 10906 | } |
||
| 10907 | $query = "SELECT spotter_output.ident, spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time, count(spotter_output.ident) as ident_count, to_char(spotter_output.date,'HH') |
||
| 10908 | FROM spotter_output".$filter_query." DATE_PART('dow', spotter_output.date) = DATE_PART('dow', date 'now' AT TIME ZONE :timezone) AND EXTRACT (HOUR FROM spotter_output.date AT TIME ZONE :timezone) >= '$currentHour' AND EXTRACT (HOUR FROM spotter_output.date AT TIME ZONE :timezone) <= '$next3Hours' AND ident <> '' |
||
| 10909 | GROUP BY spotter_output.ident,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time, to_char(spotter_output.date,'HH') |
||
| 10910 | HAVING count(spotter_output.ident) > 5$orderby_query"; |
||
| 10911 | //echo $query; |
||
| 10912 | $spotter_array = $this->getDataFromDB($query.$limit_query,array(':timezone' => $globalTimezone)); |
||
| 10913 | /* |
||
| 10914 | $sth = $this->db->prepare($query); |
||
| 10915 | $sth->execute(array(':timezone' => $globalTimezone)); |
||
| 10916 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 10917 | */ |
||
| 10918 | } |
||
| 10919 | return $spotter_array; |
||
| 10920 | } |
||
| 10921 | |||
| 10922 | |||
| 10923 | /** |
||
| 10924 | * Gets the Barrie Spotter ID based on the FlightAware ID |
||
| 10925 | * |
||
| 10926 | * @return Integer the Barrie Spotter ID |
||
| 10927 | q * |
||
| 10928 | */ |
||
| 10929 | public function getSpotterIDBasedOnFlightAwareID($flightaware_id) |
||
| 10930 | { |
||
| 10931 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
| 10932 | |||
| 10933 | $query = "SELECT spotter_output.spotter_id |
||
| 10934 | FROM spotter_output |
||
| 10935 | WHERE spotter_output.flightaware_id = '".$flightaware_id."'"; |
||
| 10936 | |||
| 10937 | |||
| 10938 | $sth = $this->db->prepare($query); |
||
| 10939 | $sth->execute(); |
||
| 10940 | |||
| 10941 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 10942 | { |
||
| 10943 | return $row['spotter_id']; |
||
| 10944 | } |
||
| 10945 | } |
||
| 10946 | |||
| 10947 | |||
| 10948 | /** |
||
| 10949 | * Parses a date string |
||
| 10950 | * |
||
| 10951 | * @param String $dateString the date string |
||
| 10952 | * @param String $timezone the timezone of a user |
||
| 10953 | * @return Array the time information |
||
| 10954 | * |
||
| 10955 | */ |
||
| 10956 | public function parseDateString($dateString, $timezone = '') |
||
| 10957 | { |
||
| 10958 | $time_array = array(); |
||
| 10959 | |||
| 10960 | if ($timezone != "") |
||
| 10961 | { |
||
| 10962 | date_default_timezone_set($timezone); |
||
| 10963 | } |
||
| 10964 | |||
| 10965 | $current_date = date("Y-m-d H:i:s"); |
||
| 10966 | $date = date("Y-m-d H:i:s",strtotime($dateString." UTC")); |
||
| 10967 | |||
| 10968 | $diff = abs(strtotime($current_date) - strtotime($date)); |
||
| 10969 | |||
| 10970 | $time_array['years'] = floor($diff / (365*60*60*24)); |
||
| 10971 | $years = $time_array['years']; |
||
| 10972 | |||
| 10973 | $time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); |
||
| 10974 | $months = $time_array['months']; |
||
| 10975 | |||
| 10976 | $time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); |
||
| 10977 | $days = $time_array['days']; |
||
| 10978 | $time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); |
||
| 10979 | $hours = $time_array['hours']; |
||
| 10980 | $time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); |
||
| 10981 | $minutes = $time_array['minutes']; |
||
| 10982 | $time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60)); |
||
| 10983 | |||
| 10984 | return $time_array; |
||
| 10985 | } |
||
| 10986 | |||
| 10987 | |||
| 10988 | |||
| 10989 | |||
| 10990 | /** |
||
| 10991 | * Parses the direction degrees to working |
||
| 10992 | * |
||
| 10993 | * @param Float $direction the direction in degrees |
||
| 10994 | * @return Array the direction information |
||
| 10995 | * |
||
| 10996 | */ |
||
| 10997 | public function parseDirection($direction = 0) |
||
| 10998 | { |
||
| 10999 | if ($direction == '') $direction = 0; |
||
| 11000 | $direction_array = array(); |
||
| 11001 | $temp_array = array(); |
||
| 11002 | |||
| 11003 | if ($direction == 360 || ($direction >= 0 && $direction < 22.5)) |
||
| 11004 | { |
||
| 11005 | $temp_array['direction_degree'] = $direction; |
||
| 11006 | $temp_array['direction_shortname'] = "N"; |
||
| 11007 | $temp_array['direction_fullname'] = "North"; |
||
| 11008 | } elseif ($direction >= 22.5 && $direction < 45){ |
||
| 11009 | $temp_array['direction_degree'] = $direction; |
||
| 11010 | $temp_array['direction_shortname'] = "NNE"; |
||
| 11011 | $temp_array['direction_fullname'] = "North-Northeast"; |
||
| 11012 | } elseif ($direction >= 45 && $direction < 67.5){ |
||
| 11013 | $temp_array['direction_degree'] = $direction; |
||
| 11014 | $temp_array['direction_shortname'] = "NE"; |
||
| 11015 | $temp_array['direction_fullname'] = "Northeast"; |
||
| 11016 | } elseif ($direction >= 67.5 && $direction < 90){ |
||
| 11017 | $temp_array['direction_degree'] = $direction; |
||
| 11018 | $temp_array['direction_shortname'] = "ENE"; |
||
| 11019 | $temp_array['direction_fullname'] = "East-Northeast"; |
||
| 11020 | } elseif ($direction >= 90 && $direction < 112.5){ |
||
| 11021 | $temp_array['direction_degree'] = $direction; |
||
| 11022 | $temp_array['direction_shortname'] = "E"; |
||
| 11023 | $temp_array['direction_fullname'] = "East"; |
||
| 11024 | } elseif ($direction >= 112.5 && $direction < 135){ |
||
| 11025 | $temp_array['direction_degree'] = $direction; |
||
| 11026 | $temp_array['direction_shortname'] = "ESE"; |
||
| 11027 | $temp_array['direction_fullname'] = "East-Southeast"; |
||
| 11028 | } elseif ($direction >= 135 && $direction < 157.5){ |
||
| 11029 | $temp_array['direction_degree'] = $direction; |
||
| 11030 | $temp_array['direction_shortname'] = "SE"; |
||
| 11031 | $temp_array['direction_fullname'] = "Southeast"; |
||
| 11032 | } elseif ($direction >= 157.5 && $direction < 180){ |
||
| 11033 | $temp_array['direction_degree'] = $direction; |
||
| 11034 | $temp_array['direction_shortname'] = "SSE"; |
||
| 11035 | $temp_array['direction_fullname'] = "South-Southeast"; |
||
| 11036 | } elseif ($direction >= 180 && $direction < 202.5){ |
||
| 11037 | $temp_array['direction_degree'] = $direction; |
||
| 11038 | $temp_array['direction_shortname'] = "S"; |
||
| 11039 | $temp_array['direction_fullname'] = "South"; |
||
| 11040 | } elseif ($direction >= 202.5 && $direction < 225){ |
||
| 11041 | $temp_array['direction_degree'] = $direction; |
||
| 11042 | $temp_array['direction_shortname'] = "SSW"; |
||
| 11043 | $temp_array['direction_fullname'] = "South-Southwest"; |
||
| 11044 | } elseif ($direction >= 225 && $direction < 247.5){ |
||
| 11045 | $temp_array['direction_degree'] = $direction; |
||
| 11046 | $temp_array['direction_shortname'] = "SW"; |
||
| 11047 | $temp_array['direction_fullname'] = "Southwest"; |
||
| 11048 | } elseif ($direction >= 247.5 && $direction < 270){ |
||
| 11049 | $temp_array['direction_degree'] = $direction; |
||
| 11050 | $temp_array['direction_shortname'] = "WSW"; |
||
| 11051 | $temp_array['direction_fullname'] = "West-Southwest"; |
||
| 11052 | } elseif ($direction >= 270 && $direction < 292.5){ |
||
| 11053 | $temp_array['direction_degree'] = $direction; |
||
| 11054 | $temp_array['direction_shortname'] = "W"; |
||
| 11055 | $temp_array['direction_fullname'] = "West"; |
||
| 11056 | } elseif ($direction >= 292.5 && $direction < 315){ |
||
| 11057 | $temp_array['direction_degree'] = $direction; |
||
| 11058 | $temp_array['direction_shortname'] = "WNW"; |
||
| 11059 | $temp_array['direction_fullname'] = "West-Northwest"; |
||
| 11060 | } elseif ($direction >= 315 && $direction < 337.5){ |
||
| 11061 | $temp_array['direction_degree'] = $direction; |
||
| 11062 | $temp_array['direction_shortname'] = "NW"; |
||
| 11063 | $temp_array['direction_fullname'] = "Northwest"; |
||
| 11064 | } elseif ($direction >= 337.5 && $direction < 360){ |
||
| 11065 | $temp_array['direction_degree'] = $direction; |
||
| 11066 | $temp_array['direction_shortname'] = "NNW"; |
||
| 11067 | $temp_array['direction_fullname'] = "North-Northwest"; |
||
| 11068 | } |
||
| 11069 | $direction_array[] = $temp_array; |
||
| 11070 | return $direction_array; |
||
| 11071 | } |
||
| 11072 | |||
| 11073 | |||
| 11074 | /** |
||
| 11075 | * Gets the aircraft registration |
||
| 11076 | * |
||
| 11077 | * @param String $flightaware_id the flight aware id |
||
| 11078 | * @return String the aircraft registration |
||
| 11079 | * |
||
| 11080 | */ |
||
| 11081 | |||
| 11082 | public function getAircraftRegistration($flightaware_id) |
||
| 11083 | { |
||
| 11084 | global $globalFlightAwareUsername, $globalFlightAwarePassword; |
||
| 11085 | |||
| 11086 | $options = array( |
||
| 11087 | 'trace' => true, |
||
| 11088 | 'exceptions' => 0, |
||
| 11089 | 'login' => $globalFlightAwareUsername, |
||
| 11090 | 'password' => $globalFlightAwarePassword, |
||
| 11091 | ); |
||
| 11092 | $client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options); |
||
| 11093 | |||
| 11094 | $params = array('faFlightID' => $flightaware_id); |
||
| 11095 | $result = $client->AirlineFlightInfo($params); |
||
| 11096 | |||
| 11097 | if (isset($result->AirlineFlightInfoResult)) |
||
| 11098 | { |
||
| 11099 | $registration = $result->AirlineFlightInfoResult->tailnumber; |
||
| 11100 | } else return ''; |
||
| 11101 | |||
| 11102 | $registration = $this->convertAircraftRegistration($registration); |
||
| 11103 | |||
| 11104 | return $registration; |
||
| 11105 | } |
||
| 11106 | |||
| 11107 | |||
| 11108 | /** |
||
| 11109 | * Gets the aircraft registration from ModeS |
||
| 11110 | * |
||
| 11111 | * @param String $aircraft_modes the flight ModeS in hex |
||
| 11112 | * @return String the aircraft registration |
||
| 11113 | * |
||
| 11114 | */ |
||
| 11115 | public function getAircraftRegistrationBymodeS($aircraft_modes) |
||
| 11116 | { |
||
| 11117 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 11118 | |||
| 11119 | $query = "SELECT aircraft_modes.Registration FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes ORDER BY FirstCreated DESC LIMIT 1"; |
||
| 11120 | |||
| 11121 | $sth = $this->db->prepare($query); |
||
| 11122 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 11123 | |||
| 11124 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 11125 | $sth->closeCursor(); |
||
| 11126 | if (count($row) > 0) { |
||
| 11127 | //return $row['Registration']; |
||
| 11128 | return $row['registration']; |
||
| 11129 | } else return ''; |
||
| 11130 | |||
| 11131 | } |
||
| 11132 | |||
| 11133 | /** |
||
| 11134 | * Gets the aircraft type from ModeS |
||
| 11135 | * |
||
| 11136 | * @param String $aircraft_modes the flight ModeS in hex |
||
| 11137 | * @return String the aircraft type |
||
| 11138 | * |
||
| 11139 | */ |
||
| 11140 | public function getAircraftTypeBymodeS($aircraft_modes) |
||
| 11141 | { |
||
| 11142 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 11143 | |||
| 11144 | $query = "SELECT aircraft_modes.type_flight FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes ORDER BY FirstCreated DESC LIMIT 1"; |
||
| 11145 | |||
| 11146 | $sth = $this->db->prepare($query); |
||
| 11147 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 11148 | |||
| 11149 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 11150 | $sth->closeCursor(); |
||
| 11151 | if (count($row) > 0) { |
||
| 11152 | if ($row['type_flight'] == null) return ''; |
||
| 11153 | else return $row['type_flight']; |
||
| 11154 | } else return ''; |
||
| 11155 | |||
| 11156 | } |
||
| 11157 | |||
| 11158 | /** |
||
| 11159 | * Gets Country from latitude/longitude |
||
| 11160 | * |
||
| 11161 | * @param Float $latitude latitute of the flight |
||
| 11162 | * @param Float $longitude longitute of the flight |
||
| 11163 | * @return String the countrie |
||
| 11164 | */ |
||
| 11165 | public function getCountryFromLatitudeLongitude($latitude,$longitude) |
||
| 11166 | { |
||
| 11167 | global $globalDBdriver, $globalDebug; |
||
| 11168 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 11169 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 11170 | |||
| 11171 | $Connection = new Connection($this->db); |
||
| 11172 | if (!$Connection->tableExists('countries')) return ''; |
||
| 11173 | |||
| 11174 | try { |
||
| 11175 | /* |
||
| 11176 | if ($globalDBdriver == 'mysql') { |
||
| 11177 | //$query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(:latitude :longitude)'), ogc_geom) LIMIT 1"; |
||
| 11178 | $query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(".$longitude.' '.$latitude.")'), ogc_geom) LIMIT 1"; |
||
| 11179 | } |
||
| 11180 | */ |
||
| 11181 | // This query seems to work both for MariaDB and PostgreSQL |
||
| 11182 | $query = "SELECT name,iso2,iso3 FROM countries WHERE ST_Within(ST_GeomFromText('POINT(".$longitude." ".$latitude.")',4326), ogc_geom) LIMIT 1"; |
||
| 11183 | |||
| 11184 | $sth = $this->db->prepare($query); |
||
| 11185 | //$sth->execute(array(':latitude' => $latitude,':longitude' => $longitude)); |
||
| 11186 | $sth->execute(); |
||
| 11187 | |||
| 11188 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 11189 | $sth->closeCursor(); |
||
| 11190 | if (count($row) > 0) { |
||
| 11191 | return $row; |
||
| 11192 | } else return ''; |
||
| 11193 | } catch (PDOException $e) { |
||
| 11194 | if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
||
| 11195 | return ''; |
||
| 11196 | } |
||
| 11197 | |||
| 11198 | } |
||
| 11199 | |||
| 11200 | /** |
||
| 11201 | * Gets Country from iso2 |
||
| 11202 | * |
||
| 11203 | * @param String $iso2 ISO2 country code |
||
| 11204 | * @return String the countrie |
||
| 11205 | */ |
||
| 11206 | public function getCountryFromISO2($iso2) |
||
| 11207 | { |
||
| 11208 | global $globalDBdriver, $globalDebug; |
||
| 11209 | $iso2 = filter_var($iso2,FILTER_SANITIZE_STRING); |
||
| 11210 | |||
| 11211 | $Connection = new Connection($this->db); |
||
| 11212 | if (!$Connection->tableExists('countries')) return ''; |
||
| 11213 | |||
| 11214 | try { |
||
| 11215 | $query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1"; |
||
| 11216 | |||
| 11217 | $sth = $this->db->prepare($query); |
||
| 11218 | $sth->execute(array(':iso2' => $iso2)); |
||
| 11219 | |||
| 11220 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 11221 | $sth->closeCursor(); |
||
| 11222 | if (count($row) > 0) { |
||
| 11223 | return $row; |
||
| 11224 | } else return ''; |
||
| 11225 | } catch (PDOException $e) { |
||
| 11226 | if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
||
| 11227 | return ''; |
||
| 11228 | } |
||
| 11229 | |||
| 11230 | } |
||
| 11231 | |||
| 11232 | /** |
||
| 11233 | * converts the registration code using the country prefix |
||
| 11234 | * |
||
| 11235 | * @param String $registration the aircraft registration |
||
| 11236 | * @return String the aircraft registration |
||
| 11237 | * |
||
| 11238 | */ |
||
| 11239 | public function convertAircraftRegistration($registration) |
||
| 11240 | { |
||
| 11241 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 11242 | $registration_prefix = ''; |
||
| 11243 | $registration_1 = substr($registration, 0, 1); |
||
| 11244 | $registration_2 = substr($registration, 0, 2); |
||
| 11245 | |||
| 11246 | //first get the prefix based on two characters |
||
| 11247 | $query = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_2"; |
||
| 11248 | |||
| 11249 | |||
| 11250 | $sth = $this->db->prepare($query); |
||
| 11251 | $sth->execute(array(':registration_2' => $registration_2)); |
||
| 11252 | |||
| 11253 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11254 | { |
||
| 11255 | $registration_prefix = $row['registration_prefix']; |
||
| 11256 | } |
||
| 11257 | |||
| 11258 | //if we didn't find a two chracter prefix lets just search the one with one character |
||
| 11259 | if ($registration_prefix == '') |
||
| 11260 | { |
||
| 11261 | $query = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_1"; |
||
| 11262 | $sth = $this->db->prepare($query); |
||
| 11263 | $sth->execute(array(':registration_1' => $registration_1)); |
||
| 11264 | |||
| 11265 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11266 | { |
||
| 11267 | $registration_prefix = $row['registration_prefix']; |
||
| 11268 | } |
||
| 11269 | } |
||
| 11270 | |||
| 11271 | //determine which characters are being used and convert the registration code appropiately |
||
| 11272 | if (strlen($registration_prefix) == 1) |
||
| 11273 | { |
||
| 11274 | if (0 === strpos($registration, 'N')) { |
||
| 11275 | $registration = preg_replace("/^(.{1})/", "$1", $registration); |
||
| 11276 | } else { |
||
| 11277 | $registration = preg_replace("/^(.{1})/", "$1-", $registration); |
||
| 11278 | } |
||
| 11279 | } else if(strlen($registration_prefix) == 2){ |
||
| 11280 | if (0 === strpos($registration, 'N')) { |
||
| 11281 | $registration = preg_replace("/^(.{2})/", "$1", $registration); |
||
| 11282 | } else { |
||
| 11283 | $registration = preg_replace("/^(.{2})/", "$1-", $registration); |
||
| 11284 | } |
||
| 11285 | } |
||
| 11286 | return $registration; |
||
| 11287 | } |
||
| 11288 | |||
| 11289 | /** |
||
| 11290 | * Country from the registration code |
||
| 11291 | * |
||
| 11292 | * @param String $registration the aircraft registration |
||
| 11293 | * @return String the country |
||
| 11294 | * |
||
| 11295 | */ |
||
| 11296 | public function countryFromAircraftRegistration($registration) |
||
| 11297 | { |
||
| 11298 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 11299 | |||
| 11300 | $registration_prefix = ''; |
||
| 11301 | $registration_test = explode('-',$registration); |
||
| 11302 | $country = ''; |
||
| 11303 | if ($registration_test[0] != $registration) { |
||
| 11304 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 11305 | |||
| 11306 | $sth = $this->db->prepare($query); |
||
| 11307 | $sth->execute(array(':registration_1' => $registration_test[0])); |
||
| 11308 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11309 | { |
||
| 11310 | //$registration_prefix = $row['registration_prefix']; |
||
| 11311 | $country = $row['country']; |
||
| 11312 | } |
||
| 11313 | } else { |
||
| 11314 | $registration_1 = substr($registration, 0, 1); |
||
| 11315 | $registration_2 = substr($registration, 0, 2); |
||
| 11316 | |||
| 11317 | $country = ''; |
||
| 11318 | //first get the prefix based on two characters |
||
| 11319 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_2 LIMIT 1"; |
||
| 11320 | |||
| 11321 | |||
| 11322 | $sth = $this->db->prepare($query); |
||
| 11323 | $sth->execute(array(':registration_2' => $registration_2)); |
||
| 11324 | |||
| 11325 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11326 | { |
||
| 11327 | $registration_prefix = $row['registration_prefix']; |
||
| 11328 | $country = $row['country']; |
||
| 11329 | } |
||
| 11330 | |||
| 11331 | //if we didn't find a two chracter prefix lets just search the one with one character |
||
| 11332 | if ($registration_prefix == "") |
||
| 11333 | { |
||
| 11334 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 11335 | |||
| 11336 | $sth = $this->db->prepare($query); |
||
| 11337 | $sth->execute(array(':registration_1' => $registration_1)); |
||
| 11338 | |||
| 11339 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11340 | { |
||
| 11341 | //$registration_prefix = $row['registration_prefix']; |
||
| 11342 | $country = $row['country']; |
||
| 11343 | } |
||
| 11344 | } |
||
| 11345 | } |
||
| 11346 | |||
| 11347 | return $country; |
||
| 11348 | } |
||
| 11349 | |||
| 11350 | /** |
||
| 11351 | * Registration prefix from the registration code |
||
| 11352 | * |
||
| 11353 | * @param String $registration the aircraft registration |
||
| 11354 | * @return String the registration prefix |
||
| 11355 | * |
||
| 11356 | */ |
||
| 11357 | public function registrationPrefixFromAircraftRegistration($registration) |
||
| 11358 | { |
||
| 11359 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 11360 | |||
| 11361 | $registration_prefix = ''; |
||
| 11362 | $registration_test = explode('-',$registration); |
||
| 11363 | //$country = ''; |
||
| 11364 | if ($registration_test[0] != $registration) { |
||
| 11365 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 11366 | |||
| 11367 | $sth = $this->db->prepare($query); |
||
| 11368 | $sth->execute(array(':registration_1' => $registration_test[0])); |
||
| 11369 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11370 | { |
||
| 11371 | $registration_prefix = $row['registration_prefix']; |
||
| 11372 | //$country = $row['country']; |
||
| 11373 | } |
||
| 11374 | } else { |
||
| 11375 | $registration_1 = substr($registration, 0, 1); |
||
| 11376 | $registration_2 = substr($registration, 0, 2); |
||
| 11377 | |||
| 11378 | //first get the prefix based on two characters |
||
| 11379 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_2 LIMIT 1"; |
||
| 11380 | |||
| 11381 | |||
| 11382 | $sth = $this->db->prepare($query); |
||
| 11383 | $sth->execute(array(':registration_2' => $registration_2)); |
||
| 11384 | |||
| 11385 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11386 | { |
||
| 11387 | $registration_prefix = $row['registration_prefix']; |
||
| 11388 | //$country = $row['country']; |
||
| 11389 | } |
||
| 11390 | |||
| 11391 | //if we didn't find a two chracter prefix lets just search the one with one character |
||
| 11392 | if ($registration_prefix == "") |
||
| 11393 | { |
||
| 11394 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 11395 | |||
| 11396 | $sth = $this->db->prepare($query); |
||
| 11397 | $sth->execute(array(':registration_1' => $registration_1)); |
||
| 11398 | |||
| 11399 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11400 | { |
||
| 11401 | $registration_prefix = $row['registration_prefix']; |
||
| 11402 | //$country = $row['country']; |
||
| 11403 | } |
||
| 11404 | } |
||
| 11405 | } |
||
| 11406 | |||
| 11407 | return $registration_prefix; |
||
| 11408 | } |
||
| 11409 | |||
| 11410 | |||
| 11411 | /** |
||
| 11412 | * Country from the registration code |
||
| 11413 | * |
||
| 11414 | * @param String $registration the aircraft registration |
||
| 11415 | * @return String the country |
||
| 11416 | * |
||
| 11417 | */ |
||
| 11418 | public function countryFromAircraftRegistrationCode($registration) |
||
| 11419 | { |
||
| 11420 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 11421 | |||
| 11422 | $country = ''; |
||
| 11423 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration LIMIT 1"; |
||
| 11424 | $sth = $this->db->prepare($query); |
||
| 11425 | $sth->execute(array(':registration' => $registration)); |
||
| 11426 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11427 | { |
||
| 11428 | $country = $row['country']; |
||
| 11429 | } |
||
| 11430 | return $country; |
||
| 11431 | } |
||
| 11432 | |||
| 11433 | /** |
||
| 11434 | * Set a new highlight value for a flight |
||
| 11435 | * |
||
| 11436 | * @param String $flightaware_id flightaware_id from spotter_output table |
||
| 11437 | * @param String $highlight New highlight value |
||
| 11438 | */ |
||
| 11439 | public function setHighlightFlight($flightaware_id,$highlight) { |
||
| 11440 | |||
| 11441 | $query = "UPDATE spotter_output SET highlight = :highlight WHERE flightaware_id = :flightaware_id"; |
||
| 11442 | $sth = $this->db->prepare($query); |
||
| 11443 | $sth->execute(array(':flightaware_id' => $flightaware_id, ':highlight' => $highlight)); |
||
| 11444 | } |
||
| 11445 | |||
| 11446 | /** |
||
| 11447 | * Set a new highlight value for a flight by Registration |
||
| 11448 | * |
||
| 11449 | * @param String $registration Registration of the aircraft |
||
| 11450 | * @param String $date Date of spotted aircraft |
||
| 11451 | * @param String $highlight New highlight value |
||
| 11452 | */ |
||
| 11453 | public function setHighlightFlightByRegistration($registration,$highlight, $date = '') { |
||
| 11454 | if ($date == '') { |
||
| 11455 | $query = "UPDATE spotter_output SET highlight = :highlight WHERE spotter_id IN (SELECT MAX(spotter_id) FROM spotter_output WHERE registration = :registration)"; |
||
| 11456 | $query_values = array(':registration' => $registration, ':highlight' => $highlight); |
||
| 11457 | } else { |
||
| 11458 | $query = "UPDATE spotter_output SET highlight = :highlight WHERE registration = :registration AND date(date) = :date"; |
||
| 11459 | $query_values = array(':registration' => $registration, ':highlight' => $highlight,':date' => $date); |
||
| 11460 | } |
||
| 11461 | $sth = $this->db->prepare($query); |
||
| 11462 | $sth->execute($query_values); |
||
| 11463 | } |
||
| 11464 | |||
| 11465 | /** |
||
| 11466 | * Gets the short url from bit.ly |
||
| 11467 | * |
||
| 11468 | * @param String $url the full url |
||
| 11469 | * @return String the bit.ly url |
||
| 11470 | * |
||
| 11471 | */ |
||
| 11472 | public function getBitlyURL($url) |
||
| 11473 | { |
||
| 11474 | global $globalBitlyAccessToken; |
||
| 11475 | |||
| 11476 | if ($globalBitlyAccessToken == '') return $url; |
||
| 11477 | |||
| 11478 | $google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; |
||
| 11479 | |||
| 11480 | $ch = curl_init(); |
||
| 11481 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
| 11482 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 11483 | curl_setopt($ch, CURLOPT_URL, $google_url); |
||
| 11484 | $bitly_data = curl_exec($ch); |
||
| 11485 | curl_close($ch); |
||
| 11486 | |||
| 11487 | $bitly_data = json_decode($bitly_data); |
||
| 11488 | $bitly_url = ''; |
||
| 11489 | if ($bitly_data->status_txt = "OK"){ |
||
| 11490 | $bitly_url = $bitly_data->data->url; |
||
| 11491 | } |
||
| 11492 | |||
| 11493 | return $bitly_url; |
||
| 11494 | } |
||
| 11495 | |||
| 11496 | |||
| 11497 | public function getOrderBy() |
||
| 11498 | { |
||
| 11499 | $orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_output.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC")); |
||
| 11500 | |||
| 11501 | return $orderby; |
||
| 11502 | |||
| 11503 | } |
||
| 11504 | |||
| 11505 | /* |
||
| 11506 | public function importFromFlightAware() |
||
| 11507 | { |
||
| 11508 | global $globalFlightAwareUsername, $globalFlightAwarePassword, $globalLatitudeMax, $globalLatitudeMin, $globalLongitudeMax, $globalLongitudeMin, $globalAirportIgnore; |
||
| 11509 | $Spotter = new Spotter($this->db); |
||
| 11510 | $SpotterLive = new SpotterLive($this->db); |
||
| 11511 | $options = array( |
||
| 11512 | 'trace' => true, |
||
| 11513 | 'exceptions' => 0, |
||
| 11514 | 'login' => $globalFlightAwareUsername, |
||
| 11515 | 'password' => $globalFlightAwarePassword, |
||
| 11516 | ); |
||
| 11517 | $client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options); |
||
| 11518 | $params = array('query' => '{range lat '.$globalLatitudeMin.' '.$globalLatitudeMax.'} {range lon '.$globalLongitudeMax.' '.$globalLongitudeMin.'} {true inAir}', 'howMany' => '15', 'offset' => '0'); |
||
| 11519 | $result = $client->SearchBirdseyeInFlight($params); |
||
| 11520 | $dataFound = false; |
||
| 11521 | $ignoreImport = false; |
||
| 11522 | if (isset($result->SearchBirdseyeInFlightResult)) |
||
| 11523 | { |
||
| 11524 | if (is_array($result->SearchBirdseyeInFlightResult->aircraft)) |
||
| 11525 | { |
||
| 11526 | foreach($result->SearchBirdseyeInFlightResult->aircraft as $aircraft) |
||
| 11527 | { |
||
| 11528 | if (!strstr($aircraft->origin, 'L ') && !strstr($aircraft->destination, 'L ')) |
||
| 11529 | { |
||
| 11530 | foreach($globalAirportIgnore as $airportIgnore) |
||
| 11531 | { |
||
| 11532 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
| 11533 | { |
||
| 11534 | $ignoreImport = true; |
||
| 11535 | } |
||
| 11536 | } |
||
| 11537 | if ($ignoreImport == false) |
||
| 11538 | { |
||
| 11539 | $flightaware_id = $aircraft->faFlightID; |
||
| 11540 | $ident = $aircraft->ident; |
||
| 11541 | $aircraft_type = $aircraft->type; |
||
| 11542 | $departure_airport = $aircraft->origin; |
||
| 11543 | $arrival_airport = $aircraft->destination; |
||
| 11544 | $latitude = $aircraft->latitude; |
||
| 11545 | $longitude = $aircraft->longitude; |
||
| 11546 | $waypoints = $aircraft->waypoints; |
||
| 11547 | $altitude = $aircraft->altitude; |
||
| 11548 | $heading = $aircraft->heading; |
||
| 11549 | $groundspeed = $aircraft->groundspeed; |
||
| 11550 | $dataFound = true; |
||
| 11551 | //gets the callsign from the last hour |
||
| 11552 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
| 11553 | //change the departure/arrival airport to NA if its not available |
||
| 11554 | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
||
| 11555 | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
||
| 11556 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
| 11557 | if($last_hour_ident == "") |
||
| 11558 | { |
||
| 11559 | //adds the spotter data for the archive |
||
| 11560 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 11561 | } |
||
| 11562 | |||
| 11563 | //adds the spotter LIVE data |
||
| 11564 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 11565 | } |
||
| 11566 | } |
||
| 11567 | $ignoreImport = false; |
||
| 11568 | } |
||
| 11569 | } else { |
||
| 11570 | if (!strstr($result->SearchBirdseyeInFlightResult->aircraft->origin, 'L ') && !strstr($result->SearchBirdseyeInFlightResult->aircraft->destination, 'L ')) |
||
| 11571 | { |
||
| 11572 | foreach($globalAirportIgnore as $airportIgnore) |
||
| 11573 | { |
||
| 11574 | foreach($globalAirportIgnore as $airportIgnore) |
||
| 11575 | { |
||
| 11576 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
| 11577 | { |
||
| 11578 | $ignoreImport = true; |
||
| 11579 | } |
||
| 11580 | } |
||
| 11581 | if ($ignoreImport == false) |
||
| 11582 | { |
||
| 11583 | $flightaware_id = $result->SearchBirdseyeInFlightResult->aircraft->faFlightID; |
||
| 11584 | $ident = $result->SearchBirdseyeInFlightResult->aircraft->ident; |
||
| 11585 | $aircraft_type = $result->SearchBirdseyeInFlightResult->aircraft->type; |
||
| 11586 | $departure_airport = $result->SearchBirdseyeInFlightResult->aircraft->origin; |
||
| 11587 | $arrival_airport = $result->SearchBirdseyeInFlightResult->aircraft->destination; |
||
| 11588 | $latitude = $result->SearchBirdseyeInFlightResult->aircraft->latitude; |
||
| 11589 | $longitude = $result->SearchBirdseyeInFlightResult->aircraft->longitude; |
||
| 11590 | $waypoints = $result->SearchBirdseyeInFlightResult->aircraft->waypoints; |
||
| 11591 | $altitude = $result->SearchBirdseyeInFlightResult->aircraft->altitude; |
||
| 11592 | $heading = $result->SearchBirdseyeInFlightResult->aircraft->heading; |
||
| 11593 | $groundspeed = $result->SearchBirdseyeInFlightResult->aircraft->groundspeed; |
||
| 11594 | $dataFound = true; |
||
| 11595 | //gets the callsign from the last hour |
||
| 11596 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
| 11597 | //change the departure/arrival airport to NA if its not available |
||
| 11598 | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
||
| 11599 | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
||
| 11600 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
| 11601 | if($last_hour_ident == "") |
||
| 11602 | { |
||
| 11603 | //adds the spotter data for the archive |
||
| 11604 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 11605 | } |
||
| 11606 | //adds the spotter LIVE data |
||
| 11607 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 11608 | } |
||
| 11609 | $ignoreImport = false; |
||
| 11610 | } |
||
| 11611 | } |
||
| 11612 | } |
||
| 11613 | } |
||
| 11614 | } |
||
| 11615 | */ |
||
| 11616 | |||
| 11617 | // Update flights data when new data in DB |
||
| 11618 | public function updateFieldsFromOtherTables() |
||
| 11619 | { |
||
| 11620 | global $globalDebug, $globalDBdriver; |
||
| 11621 | $Image = new Image($this->db); |
||
| 11622 | |||
| 11623 | |||
| 11624 | // routes |
||
| 11625 | if ($globalDebug) print "Routes...\n"; |
||
| 11626 | if ($globalDBdriver == 'mysql') { |
||
| 11627 | $query = "SELECT spotter_output.spotter_id, routes.FromAirport_ICAO, routes.ToAirport_ICAO FROM spotter_output, routes WHERE spotter_output.ident = routes.CallSign AND ( spotter_output.departure_airport_icao != routes.FromAirport_ICAO OR spotter_output.arrival_airport_icao != routes.ToAirport_ICAO) AND routes.FromAirport_ICAO != '' AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 DAY)"; |
||
| 11628 | } else { |
||
| 11629 | $query = "SELECT spotter_output.spotter_id, routes.FromAirport_ICAO, routes.ToAirport_ICAO FROM spotter_output, routes WHERE spotter_output.ident = routes.CallSign AND ( spotter_output.departure_airport_icao != routes.FromAirport_ICAO OR spotter_output.arrival_airport_icao != routes.ToAirport_ICAO) AND routes.FromAirport_ICAO != '' AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '15 DAYS'"; |
||
| 11630 | } |
||
| 11631 | $sth = $this->db->prepare($query); |
||
| 11632 | $sth->execute(); |
||
| 11633 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11634 | { |
||
| 11635 | $departure_airport_array = $this->getAllAirportInfo($row['fromairport_icao']); |
||
| 11636 | $arrival_airport_array = $this->getAllAirportInfo($row['toairport_icao']); |
||
| 11637 | if (count($departure_airport_array) > 0 && count($arrival_airport_array) > 0) { |
||
| 11638 | $update_query="UPDATE spotter_output SET departure_airport_icao = :fromicao, arrival_airport_icao = :toicao, departure_airport_name = :departure_airport_name, departure_airport_city = :departure_airport_city, departure_airport_country = :departure_airport_country, arrival_airport_name = :arrival_airport_name, arrival_airport_city = :arrival_airport_city, arrival_airport_country = :arrival_airport_country WHERE spotter_id = :spotter_id"; |
||
| 11639 | $sthu = $this->db->prepare($update_query); |
||
| 11640 | $sthu->execute(array(':fromicao' => $row['fromairport_icao'],':toicao' => $row['toairport_icao'],':spotter_id' => $row['spotter_id'],':departure_airport_name' => $departure_airport_array[0]['name'],':departure_airport_city' => $departure_airport_array[0]['city'],':departure_airport_country' => $departure_airport_array[0]['country'],':arrival_airport_name' => $arrival_airport_array[0]['name'],':arrival_airport_city' => $arrival_airport_array[0]['city'],':arrival_airport_country' => $arrival_airport_array[0]['country'])); |
||
| 11641 | } |
||
| 11642 | } |
||
| 11643 | |||
| 11644 | if ($globalDebug) print "Airlines...\n"; |
||
| 11645 | //airlines |
||
| 11646 | if ($globalDBdriver == 'mysql') { |
||
| 11647 | $query = "SELECT spotter_output.spotter_id, spotter_output.ident FROM spotter_output WHERE (spotter_output.airline_name = '' OR spotter_output.airline_name = 'Not Available') AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 DAY)"; |
||
| 11648 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 11649 | $query = "SELECT spotter_output.spotter_id, spotter_output.ident FROM spotter_output WHERE (spotter_output.airline_name = '' OR spotter_output.airline_name = 'Not Available') AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '15 DAYS'"; |
||
| 11650 | } |
||
| 11651 | $sth = $this->db->prepare($query); |
||
| 11652 | $sth->execute(); |
||
| 11653 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11654 | { |
||
| 11655 | if (is_numeric(substr($row['ident'], -1, 1))) |
||
| 11656 | { |
||
| 11657 | $fromsource = NULL; |
||
| 11658 | if (isset($row['format_source']) && $row['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
||
| 11659 | elseif (isset($row['format_source']) && $row['format_source'] == 'whazzup') $fromsource = 'ivao'; |
||
| 11660 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
||
| 11661 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
||
| 11662 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3),$fromsource); |
||
| 11663 | if (isset($airline_array[0]['name'])) { |
||
| 11664 | $update_query = "UPDATE spotter_output SET spotter_output.airline_name = :airline_name, spotter_output.airline_icao = :airline_icao, spotter_output.airline_country = :airline_country, spotter_output.airline_type = :airline_type WHERE spotter_output.spotter_id = :spotter_id"; |
||
| 11665 | $sthu = $this->db->prepare($update_query); |
||
| 11666 | $sthu->execute(array(':airline_name' => $airline_array[0]['name'],':airline_icao' => $airline_array[0]['icao'], ':airline_country' => $airline_array[0]['country'], ':airline_type' => $airline_array[0]['type'], ':spotter_id' => $row['spotter_id'])); |
||
| 11667 | } |
||
| 11668 | } |
||
| 11669 | } |
||
| 11670 | |||
| 11671 | if ($globalDebug) print "Remove Duplicate in aircraft_modes...\n"; |
||
| 11672 | //duplicate modes |
||
| 11673 | $query = "DELETE aircraft_modes FROM aircraft_modes LEFT OUTER JOIN (SELECT max(`AircraftID`) as `AircraftID`,`ModeS` FROM `aircraft_modes` group by ModeS) as KeepRows ON aircraft_modes.AircraftID = KeepRows.AircraftID WHERE KeepRows.AircraftID IS NULL"; |
||
| 11674 | $sth = $this->db->prepare($query); |
||
| 11675 | $sth->execute(); |
||
| 11676 | |||
| 11677 | if ($globalDebug) print "Aircraft...\n"; |
||
| 11678 | //aircraft |
||
| 11679 | if ($globalDBdriver == 'mysql') { |
||
| 11680 | $query = "SELECT spotter_output.spotter_id, spotter_output.aircraft_icao, spotter_output.registration FROM spotter_output WHERE (spotter_output.aircraft_name = '' OR spotter_output.aircraft_name = 'Not Available') AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)"; |
||
| 11681 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 11682 | $query = "SELECT spotter_output.spotter_id, spotter_output.aircraft_icao, spotter_output.registration FROM spotter_output WHERE (spotter_output.aircraft_name = '' OR spotter_output.aircraft_name = 'Not Available') AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INERVAL '15 DAYS'"; |
||
| 11683 | } |
||
| 11684 | $sth = $this->db->prepare($query); |
||
| 11685 | $sth->execute(); |
||
| 11686 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11687 | { |
||
| 11688 | if ($row['aircraft_icao'] != '') { |
||
| 11689 | $aircraft_name = $this->getAllAircraftInfo($row['aircraft_icao']); |
||
| 11690 | if ($row['registration'] != ""){ |
||
| 11691 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 11692 | if (!isset($image_array[0]['registration'])) { |
||
| 11693 | $Image->addSpotterImage($row['registration']); |
||
| 11694 | } |
||
| 11695 | } |
||
| 11696 | if (count($aircraft_name) > 0) { |
||
| 11697 | $update_query = "UPDATE spotter_output SET spotter_output.aircraft_name = :aircraft_name, spotter_output.aircraft_manufacturer = :aircraft_manufacturer WHERE spotter_output.spotter_id = :spotter_id"; |
||
| 11698 | $sthu = $this->db->prepare($update_query); |
||
| 11699 | $sthu->execute(array(':aircraft_name' => $aircraft_name[0]['type'], ':aircraft_manufacturer' => $aircraft_name[0]['manufacturer'], ':spotter_id' => $row['spotter_id'])); |
||
| 11700 | } |
||
| 11701 | } |
||
| 11702 | } |
||
| 11703 | } |
||
| 11704 | |||
| 11705 | // Update arrival airports for data already in DB |
||
| 11706 | public function updateArrivalAirports() |
||
| 11707 | { |
||
| 11708 | global $globalDebug, $globalDBdriver, $globalClosestMinDist; |
||
| 11709 | $query = "SELECT spotter_output.spotter_id, spotter_output.last_latitude, spotter_output.last_longitude, spotter_output.last_altitude, spotter_output.arrival_airport_icao, spotter_output.real_arrival_airport_icao FROM spotter_output"; |
||
| 11710 | $sth = $this->db->prepare($query); |
||
| 11711 | $sth->execute(); |
||
| 11712 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 11713 | { |
||
| 11714 | if ($row['last_latitude'] != '' && $row['last_longitude'] != '') { |
||
| 11715 | $closestAirports = $this->closestAirports($row['last_latitude'],$row['last_longitude'],$globalClosestMinDist); |
||
| 11716 | $airport_icao = ''; |
||
| 11717 | if (isset($closestAirports[0])) { |
||
| 11718 | if ($row['arrival_airport_icao'] == $closestAirports[0]['icao']) { |
||
| 11719 | $airport_icao = $closestAirports[0]['icao']; |
||
| 11720 | if ($globalDebug) echo "\o/ 1st ---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
||
| 11721 | } elseif (count($closestAirports > 1) && $row['arrival_airport_icao'] != '' && $row['arrival_airport_icao'] != 'NA') { |
||
| 11722 | foreach ($closestAirports as $airport) { |
||
| 11723 | if ($row['arrival_airport_icao'] == $airport['icao']) { |
||
| 11724 | $airport_icao = $airport['icao']; |
||
| 11725 | if ($globalDebug) echo "\o/ try --++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
||
| 11726 | break; |
||
| 11727 | } |
||
| 11728 | } |
||
| 11729 | } elseif ($row['last_altitude'] == 0 || ($row['last_altitude'] != '' && ($closestAirports[0]['altitude'] <= $row['last_altitude']*100+1000 && $row['last_altitude']*100 < $closestAirports[0]['altitude']+5000))) { |
||
| 11730 | $airport_icao = $closestAirports[0]['icao']; |
||
| 11731 | if ($globalDebug) echo "\o/ NP --++ Find arrival airport. Airport ICAO : ".$airport_icao." ! Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist." - Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.($row['last_altitude']*100)."\n"; |
||
| 11732 | } else { |
||
| 11733 | if ($globalDebug) echo "----- Can't find arrival airport. Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist." - Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.($row['last_altitude']*100)."\n"; |
||
| 11734 | } |
||
| 11735 | } else { |
||
| 11736 | if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
||
| 11737 | } |
||
| 11738 | if ($row['real_arrival_airport_icao'] != $airport_icao) { |
||
| 11739 | if ($globalDebug) echo "Updating airport to ".$airport_icao."...\n"; |
||
| 11740 | $update_query="UPDATE spotter_output SET real_arrival_airport_icao = :airport_icao WHERE spotter_id = :spotter_id"; |
||
| 11741 | $sthu = $this->db->prepare($update_query); |
||
| 11742 | $sthu->execute(array(':airport_icao' => $airport_icao,':spotter_id' => $row['spotter_id'])); |
||
| 11743 | } |
||
| 11744 | } |
||
| 11745 | } |
||
| 11746 | } |
||
| 11747 | |||
| 11748 | public function closestAirports($origLat,$origLon,$dist = 10) { |
||
| 11749 | global $globalDBdriver; |
||
| 11750 | $dist = number_format($dist*0.621371,2,'.',''); // convert km to mile |
||
| 11751 | /* |
||
| 11752 | $query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - abs(latitude))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(abs(latitude)*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2))) as distance |
||
| 11753 | FROM airport WHERE longitude between ($origLon-$dist/abs(cos(radians($origLat))*69)) and ($origLon+$dist/abs(cos(radians($origLat))*69)) and latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
| 11754 | having distance < $dist ORDER BY distance limit 100;"; |
||
| 11755 | */ |
||
| 11756 | if ($globalDBdriver == 'mysql') { |
||
| 11757 | $query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(latitude*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2))) as distance |
||
| 11758 | FROM airport WHERE longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
| 11759 | AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(latitude*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2)))) < $dist ORDER BY distance limit 100;"; |
||
| 11760 | } else { |
||
| 11761 | $query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(longitude as double precision))*pi()/180/2),2))) as distance |
||
| 11762 | FROM airport WHERE CAST(longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
| 11763 | AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(longitude as double precision))*pi()/180/2),2)))) < $dist ORDER BY distance limit 100;"; |
||
| 11764 | } |
||
| 11765 | $sth = $this->db->prepare($query); |
||
| 11766 | $sth->execute(); |
||
| 11767 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 11768 | } |
||
| 11769 | } |
||
| 11770 | /* |
||
| 11782 | ?> |