Ysurac /
FlightAirMap
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | require_once(dirname(__FILE__).'/class.Scheduler.php'); |
||
| 3 | require_once(dirname(__FILE__).'/class.ACARS.php'); |
||
| 4 | require_once(dirname(__FILE__).'/class.Image.php'); |
||
| 5 | $global_query = "SELECT spotter_output.* FROM spotter_output"; |
||
| 6 | |||
| 7 | class Spotter{ |
||
| 8 | public $db; |
||
| 9 | |||
| 10 | function __construct($dbc = null) { |
||
| 11 | $Connection = new Connection($dbc); |
||
| 12 | $this->db = $Connection->db; |
||
| 13 | } |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Executes the SQL statements to get the spotter information |
||
| 17 | * |
||
| 18 | * @param String $query the SQL query |
||
| 19 | * @param String $limit the limit query |
||
| 20 | * @return Array the spotter information |
||
| 21 | * |
||
| 22 | */ |
||
| 23 | public function getDataFromDB($query, $params = array(), $limitQuery = '') |
||
| 24 | { |
||
| 25 | global $globalSquawkCountry, $globalIVAO, $globalVATSIM, $globalphpVMS; |
||
| 26 | $Image = new Image($this->db); |
||
| 27 | $Schedule = new Schedule($this->db); |
||
| 28 | $ACARS = new ACARS($this->db); |
||
| 29 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
| 30 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
| 31 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
| 32 | date_default_timezone_set('UTC'); |
||
| 33 | |||
| 34 | if (!is_string($query)) |
||
| 35 | { |
||
| 36 | return false; |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($limitQuery != "") |
||
| 40 | { |
||
| 41 | if (!is_string($limitQuery)) |
||
| 42 | { |
||
| 43 | return false; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | |||
| 48 | try { |
||
| 49 | $sth = $this->db->prepare($query.$limitQuery); |
||
| 50 | $sth->execute($params); |
||
| 51 | } catch (PDOException $e) { |
||
| 52 | printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery); |
||
| 53 | exit(); |
||
| 54 | } |
||
| 55 | |||
| 56 | // $num_rows = count($sth->fetchAll()); |
||
| 57 | $num_rows = 0; |
||
| 58 | |||
| 59 | $spotter_array = array(); |
||
| 60 | $temp_array = array(); |
||
| 61 | |||
| 62 | |||
| 63 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 64 | { |
||
| 65 | $num_rows++; |
||
| 66 | $temp_array = array(); |
||
| 67 | if (isset($row['spotter_live_id'])) { |
||
| 68 | //$temp_array['spotter_id'] = $row['spotter_live_id']; |
||
| 69 | $temp_array['spotter_id'] = $this->getSpotterIDBasedOnFlightAwareID($row['flightaware_id']); |
||
| 70 | } elseif (isset($row['spotter_archive_id'])) { |
||
| 71 | $temp_array['spotter_id'] = $row['spotter_archive_id']; |
||
| 72 | } elseif (isset($row['spotter_archive_output_id'])) { |
||
| 73 | $temp_array['spotter_id'] = $row['spotter_archive_output_id']; |
||
| 74 | } elseif (isset($row['spotter_id'])) { |
||
| 75 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 76 | } else { |
||
| 77 | $temp_array['spotter_id'] = ''; |
||
| 78 | } |
||
| 79 | $temp_array['flightaware_id'] = $row['flightaware_id']; |
||
| 80 | if (isset($row['modes'])) $temp_array['modes'] = $row['modes']; |
||
| 81 | $temp_array['ident'] = $row['ident']; |
||
| 82 | if (isset($row['registration']) && $row['registration'] != '') { |
||
| 83 | $temp_array['registration'] = $row['registration']; |
||
| 84 | } elseif (isset($temp_array['modes'])) { |
||
| 85 | $temp_array['registration'] = $this->getAircraftRegistrationBymodeS($temp_array['modes']); |
||
| 86 | } else $temp_array['registration'] = ''; |
||
| 87 | $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
| 88 | |||
| 89 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
| 90 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
| 91 | if (isset($row['real_arrival_airport_icao']) && $row['real_arrival_airport_icao'] != NULL) $temp_array['real_arrival_airport'] = $row['real_arrival_airport_icao']; |
||
| 92 | $temp_array['latitude'] = $row['latitude']; |
||
| 93 | $temp_array['longitude'] = $row['longitude']; |
||
| 94 | /* |
||
| 95 | if (Connection->tableExists('countries')) { |
||
| 96 | $country_info = $this->getCountryFromLatitudeLongitude($temp_array['latitude'],$temp_array['longitude']); |
||
| 97 | if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) { |
||
| 98 | $temp_array['country'] = $country_info['name']; |
||
| 99 | $temp_array['country_iso2'] = $country_info['iso2']; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | */ |
||
| 103 | $temp_array['waypoints'] = $row['waypoints']; |
||
| 104 | $temp_array['format_source'] = $row['format_source']; |
||
| 105 | if (isset($row['route_stop'])) { |
||
| 106 | $temp_array['route_stop'] = $row['route_stop']; |
||
| 107 | if ($row['route_stop'] != '') { |
||
| 108 | $allroute = explode(' ',$row['route_stop']); |
||
| 109 | |||
| 110 | foreach ($allroute as $route) { |
||
| 111 | $route_airport_array = $this->getAllAirportInfo($route); |
||
| 112 | if (isset($route_airport_array[0]['name'])) { |
||
| 113 | $route_stop_details['airport_name'] = $route_airport_array[0]['name']; |
||
| 114 | $route_stop_details['airport_city'] = $route_airport_array[0]['city']; |
||
| 115 | $route_stop_details['airport_country'] = $route_airport_array[0]['country']; |
||
| 116 | $route_stop_details['airport_icao'] = $route_airport_array[0]['icao']; |
||
| 117 | $temp_array['route_stop_details'][] = $route_stop_details; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | $temp_array['altitude'] = $row['altitude']; |
||
| 123 | $temp_array['heading'] = $row['heading']; |
||
| 124 | $heading_direction = $this->parseDirection($row['heading']); |
||
| 125 | if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
||
| 126 | $temp_array['ground_speed'] = $row['ground_speed']; |
||
| 127 | $temp_array['image'] = ""; |
||
| 128 | $temp_array['image_thumbnail'] = ""; |
||
| 129 | $temp_array['image_source'] = ""; |
||
| 130 | $temp_array['image_copyright'] = ""; |
||
| 131 | |||
| 132 | if (isset($row['highlight'])) { |
||
| 133 | $temp_array['highlight'] = $row['highlight']; |
||
| 134 | } else $temp_array['highlight'] = ''; |
||
| 135 | |||
| 136 | $dateArray = $this->parseDateString($row['date']); |
||
| 137 | if ($dateArray['seconds'] < 10) |
||
| 138 | { |
||
| 139 | $temp_array['date'] = "a few seconds ago"; |
||
| 140 | } elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) |
||
| 141 | { |
||
| 142 | $temp_array['date'] = "half a minute ago"; |
||
| 143 | } elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) |
||
| 144 | { |
||
| 145 | $temp_array['date'] = "about a minute ago"; |
||
| 146 | } elseif ($dateArray['minutes'] < 5) |
||
| 147 | { |
||
| 148 | $temp_array['date'] = "a few minutes ago"; |
||
| 149 | View Code Duplication | } elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) |
|
| 150 | { |
||
| 151 | $temp_array['date'] = "about ".$dateArray['minutes']." minutes ago"; |
||
| 152 | } elseif ($dateArray['hours'] < 2) |
||
| 153 | { |
||
| 154 | $temp_array['date'] = "about an hour ago"; |
||
| 155 | View Code Duplication | } elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) |
|
| 156 | { |
||
| 157 | $temp_array['date'] = "about ".$dateArray['hours']." hours ago"; |
||
| 158 | } else { |
||
| 159 | $temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC")); |
||
| 160 | } |
||
| 161 | $temp_array['date_minutes_past'] = $dateArray['minutes']; |
||
| 162 | $temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC")); |
||
| 163 | $temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC")); |
||
| 164 | $temp_array['date_unix'] = strtotime($row['date']." UTC"); |
||
| 165 | |||
| 166 | if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') { |
||
| 167 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 168 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 169 | if (isset($row['aircraft_shadow'])) { |
||
| 170 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
| 171 | } |
||
| 172 | } else { |
||
| 173 | $aircraft_array = $this->getAllAircraftInfo($row['aircraft_icao']); |
||
| 174 | if (count($aircraft_array) > 0) { |
||
| 175 | $temp_array['aircraft_name'] = $aircraft_array[0]['type']; |
||
| 176 | $temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer']; |
||
| 177 | |||
| 178 | if ($aircraft_array[0]['aircraft_shadow'] != NULL) { |
||
| 179 | $temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow']; |
||
| 180 | } else $temp_array['aircraft_shadow'] = 'default.png'; |
||
| 181 | } else { |
||
| 182 | $temp_array['aircraft_shadow'] = 'default.png'; |
||
| 183 | $temp_array['aircraft_name'] = 'N/A'; |
||
| 184 | $temp_array['aircraft_manufacturer'] = 'N/A'; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | if (!isset($row['airline_name']) || $row['airline_name'] == '') { |
||
| 188 | $airline_array = array(); |
||
| 189 | if (!is_numeric(substr($row['ident'], 0, 3))) { |
||
| 190 | if (is_numeric(substr($row['ident'], 2, 1))) { |
||
| 191 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 2)); |
||
| 192 | } elseif (is_numeric(substr($row['ident'], 3, 1))) { |
||
| 193 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3)); |
||
| 194 | } else { |
||
| 195 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 199 | } |
||
| 200 | if (count($airline_array) > 0) { |
||
| 201 | $temp_array['airline_icao'] = $airline_array[0]['icao']; |
||
| 202 | $temp_array['airline_iata'] = $airline_array[0]['iata']; |
||
| 203 | $temp_array['airline_name'] = $airline_array[0]['name']; |
||
| 204 | $temp_array['airline_country'] = $airline_array[0]['country']; |
||
| 205 | $temp_array['airline_callsign'] = $airline_array[0]['callsign']; |
||
| 206 | $temp_array['airline_type'] = $airline_array[0]['type']; |
||
| 207 | } |
||
| 208 | } else { |
||
| 209 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 210 | if (isset($row['airline_iata'])) $temp_array['airline_iata'] = $row['airline_iata']; |
||
| 211 | else $temp_array['airline_iata'] = ''; |
||
| 212 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 213 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 214 | if (isset($row['airline_callsign'])) $temp_array['airline_callsign'] = $row['airline_callsign']; |
||
| 215 | else $temp_array['airline_callsign'] = 'N/A'; |
||
| 216 | $temp_array['airline_type'] = $row['airline_type']; |
||
| 217 | } |
||
| 218 | if (isset($temp_array['airline_iata']) && $temp_array['airline_iata'] != '') { |
||
| 219 | $acars_array = $ACARS->getLiveAcarsData($temp_array['airline_iata'].substr($temp_array['ident'],3)); |
||
| 220 | //$acars_array = ACARS->getLiveAcarsData('BA40YL'); |
||
| 221 | if (count($acars_array) > 0) { |
||
| 222 | $temp_array['acars'] = $acars_array; |
||
| 223 | //print_r($acars_array); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | if (isset($row['owner_name']) && $row['owner_name'] != '' && $row['owner_name'] != NULL) { |
||
| 227 | $temp_array['aircraft_owner'] = $row['owner_name']; |
||
| 228 | } |
||
| 229 | if ($temp_array['registration'] != "" && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !isset($temp_array['aircraft_owner'])) { |
||
| 230 | $owner_info = $this->getAircraftOwnerByRegistration($temp_array['registration']); |
||
| 231 | if ($owner_info['owner'] != '') $temp_array['aircraft_owner'] = ucwords(strtolower($owner_info['owner'])); |
||
| 232 | $temp_array['aircraft_base'] = $owner_info['base']; |
||
| 233 | $temp_array['aircraft_date_first_reg'] = $owner_info['date_first_reg']; |
||
| 234 | } |
||
| 235 | |||
| 236 | if($temp_array['registration'] != "" || ($globalIVAO && $temp_array['aircraft_type'] != '')) |
||
| 237 | { |
||
| 238 | if ($globalIVAO) { |
||
| 239 | if (isset($temp_array['airline_icao'])) $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type'],$temp_array['airline_icao']); |
||
| 240 | else $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type']); |
||
| 241 | } else $image_array = $Image->getSpotterImage($temp_array['registration']); |
||
| 242 | if (count($image_array) > 0) { |
||
| 243 | $temp_array['image'] = $image_array[0]['image']; |
||
| 244 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 245 | $temp_array['image_source'] = $image_array[0]['image_source']; |
||
| 246 | $temp_array['image_source_website'] = $image_array[0]['image_source_website']; |
||
| 247 | if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') { |
||
| 248 | $planespotter_url_array = explode("_", $temp_array['image']); |
||
| 249 | $planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]); |
||
| 250 | $temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id; |
||
| 251 | } |
||
| 252 | $temp_array['image_copyright'] = $image_array[0]['image_copyright']; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | |||
| 257 | if (isset($row['departure_airport_time']) && $row['departure_airport_time'] != '') { |
||
| 258 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
| 259 | } |
||
| 260 | if (isset($row['arrival_airport_time']) && $row['arrival_airport_time'] != '') { |
||
| 261 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
| 262 | } |
||
| 263 | if ((!isset($globalIVAO) || ! $globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
||
| 264 | $schedule_array = $Schedule->getSchedule($temp_array['ident']); |
||
| 265 | //print_r($schedule_array); |
||
| 266 | if (count($schedule_array) > 0) { |
||
| 267 | if ($schedule_array['departure_airport_icao'] != '') { |
||
| 268 | $row['departure_airport_icao'] = $schedule_array['departure_airport_icao']; |
||
| 269 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
| 270 | } |
||
| 271 | if ($schedule_array['arrival_airport_icao'] != '') { |
||
| 272 | $row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao']; |
||
| 273 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
| 274 | } |
||
| 275 | |||
| 276 | $temp_array['departure_airport_time'] = $schedule_array['departure_airport_time']; |
||
| 277 | $temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time']; |
||
| 278 | } |
||
| 279 | } else { |
||
| 280 | if (isset($row['real_departure_airport_time']) && $row['real_departure_airport_time'] != '') { |
||
| 281 | $temp_array['departure_airport_time'] = $row['real_departure_airport_time']; |
||
| 282 | } |
||
| 283 | if (isset($row['real_arrival_airport_time']) && $row['real_arrival_airport_time'] != '') { |
||
| 284 | $temp_array['real_arrival_airport_time'] = $row['real_arrival_airport_time']; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | //if ($row['departure_airport_icao'] != '' && $row['departure_airport_name'] == '') { |
||
| 289 | if ($row['departure_airport_icao'] != '') { |
||
| 290 | $departure_airport_array = $this->getAllAirportInfo($row['departure_airport_icao']); |
||
| 291 | if (!isset($departure_airport_array[0]['name'])) $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 292 | /* |
||
| 293 | } elseif ($row['departure_airport_name'] != '') { |
||
| 294 | $temp_array['departure_airport_name'] = $row['departure_airport_name']; |
||
| 295 | $temp_array['departure_airport_city'] = $row['departure_airport_city']; |
||
| 296 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 297 | $temp_array['departure_airport_icao'] = $row['departure_airport_icao']; |
||
| 298 | */ |
||
| 299 | } else $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 300 | if (isset($departure_airport_array[0]['name'])) { |
||
| 301 | $temp_array['departure_airport_name'] = $departure_airport_array[0]['name']; |
||
| 302 | $temp_array['departure_airport_city'] = $departure_airport_array[0]['city']; |
||
| 303 | $temp_array['departure_airport_country'] = $departure_airport_array[0]['country']; |
||
| 304 | $temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata']; |
||
| 305 | $temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao']; |
||
| 306 | $temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude']; |
||
| 307 | $temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude']; |
||
| 308 | $temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude']; |
||
| 309 | } |
||
| 310 | |||
| 311 | /* |
||
| 312 | if (isset($row['departure_airport_time'])) { |
||
| 313 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
| 314 | } |
||
| 315 | */ |
||
| 316 | |||
| 317 | if ($row['arrival_airport_icao'] != '') { |
||
| 318 | $arrival_airport_array = $this->getAllAirportInfo($row['arrival_airport_icao']); |
||
| 319 | if (count($arrival_airport_array) == 0) $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 320 | } else $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 321 | if (isset($arrival_airport_array[0]['name'])) { |
||
| 322 | $temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name']; |
||
| 323 | $temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city']; |
||
| 324 | $temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country']; |
||
| 325 | $temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata']; |
||
| 326 | $temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao']; |
||
| 327 | $temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude']; |
||
| 328 | $temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude']; |
||
| 329 | $temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude']; |
||
| 330 | } |
||
| 331 | /* |
||
| 332 | if (isset($row['arrival_airport_time'])) { |
||
| 333 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
| 334 | } |
||
| 335 | */ |
||
| 336 | if (isset($row['pilot_id']) && $row['pilot_id'] != '') $temp_array['pilot_id'] = $row['pilot_id']; |
||
| 337 | if (isset($row['pilot_name']) && $row['pilot_name'] != '') $temp_array['pilot_name'] = $row['pilot_name']; |
||
| 338 | if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; |
||
| 339 | View Code Duplication | if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; |
|
| 340 | if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
||
| 341 | if (isset($row['squawk'])) { |
||
| 342 | $temp_array['squawk'] = $row['squawk']; |
||
| 343 | if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) { |
||
| 344 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['country_iso2']); |
||
| 345 | View Code Duplication | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
|
| 346 | } elseif ($row['squawk'] != '' && isset($temp_array['over_country'])) { |
||
| 347 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['over_country']); |
||
| 348 | View Code Duplication | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
|
| 349 | View Code Duplication | } elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
|
| 350 | } |
||
| 351 | |||
| 352 | $temp_array['query_number_rows'] = $num_rows; |
||
| 353 | |||
| 354 | $spotter_array[] = $temp_array; |
||
| 355 | } |
||
| 356 | if ($num_rows == 0) return array(); |
||
| 357 | $spotter_array[0]['query_number_rows'] = $num_rows; |
||
| 358 | return $spotter_array; |
||
| 359 | } |
||
| 360 | |||
| 361 | |||
| 362 | /** |
||
| 363 | * Gets all the spotter information |
||
| 364 | * |
||
| 365 | * @return Array the spotter information |
||
| 366 | * |
||
| 367 | */ |
||
| 368 | 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 = '') |
||
| 369 | { |
||
| 370 | global $globalTimezone, $globalDBdriver; |
||
| 371 | require_once(dirname(__FILE__).'/class.Translation.php'); |
||
| 372 | $Translation = new Translation(); |
||
| 373 | |||
| 374 | date_default_timezone_set('UTC'); |
||
| 375 | |||
| 376 | $query_values = array(); |
||
| 377 | $additional_query = ''; |
||
| 378 | if ($q != "") |
||
| 379 | { |
||
| 380 | if (!is_string($q)) |
||
| 381 | { |
||
| 382 | return false; |
||
| 383 | } else { |
||
| 384 | $q_array = explode(" ", $q); |
||
| 385 | foreach ($q_array as $q_item){ |
||
| 386 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
| 387 | $additional_query .= " AND ("; |
||
| 388 | if (is_int($q_item)) $additional_query .= "(spotter_output.spotter_id like '%".$q_item."%') OR "; |
||
| 389 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
| 390 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
| 391 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
| 392 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
| 393 | $additional_query .= "(spotter_output.airline_name like '%".$q_item."%') OR "; |
||
| 394 | $additional_query .= "(spotter_output.airline_country like '%".$q_item."%') OR "; |
||
| 395 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
| 396 | $additional_query .= "(spotter_output.departure_airport_name like '%".$q_item."%') OR "; |
||
| 397 | $additional_query .= "(spotter_output.departure_airport_city like '%".$q_item."%') OR "; |
||
| 398 | $additional_query .= "(spotter_output.departure_airport_country like '%".$q_item."%') OR "; |
||
| 399 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
| 400 | $additional_query .= "(spotter_output.arrival_airport_name like '%".$q_item."%') OR "; |
||
| 401 | $additional_query .= "(spotter_output.arrival_airport_city like '%".$q_item."%') OR "; |
||
| 402 | $additional_query .= "(spotter_output.arrival_airport_country like '%".$q_item."%') OR "; |
||
| 403 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
| 404 | $additional_query .= "(spotter_output.owner_name like '%".$q_item."%') OR "; |
||
| 405 | $additional_query .= "(spotter_output.pilot_id like '%".$q_item."%') OR "; |
||
| 406 | $additional_query .= "(spotter_output.pilot_name like '%".$q_item."%') OR "; |
||
| 407 | $additional_query .= "(spotter_output.ident like '%".$q_item."%') OR "; |
||
| 408 | $translate = $Translation->ident2icao($q_item); |
||
| 409 | if ($translate != $q_item) $additional_query .= "(spotter_output.ident like '%".$translate."%') OR "; |
||
| 410 | $additional_query .= "(spotter_output.highlight like '%".$q_item."%')"; |
||
| 411 | $additional_query .= ")"; |
||
| 412 | } |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | View Code Duplication | if ($registration != "") |
|
| 417 | { |
||
| 418 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 419 | if (!is_string($registration)) |
||
| 420 | { |
||
| 421 | return false; |
||
| 422 | } else { |
||
| 423 | $additional_query .= " AND spotter_output.registration = :registration"; |
||
| 424 | $query_values = array_merge($query_values,array(':registration' => $registration)); |
||
| 425 | } |
||
| 426 | } |
||
| 427 | |||
| 428 | View Code Duplication | if ($aircraft_icao != "") |
|
| 429 | { |
||
| 430 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 431 | if (!is_string($aircraft_icao)) |
||
| 432 | { |
||
| 433 | return false; |
||
| 434 | } else { |
||
| 435 | $additional_query .= " AND spotter_output.aircraft_icao = :aircraft_icao"; |
||
| 436 | $query_values = array_merge($query_values,array(':aircraft_icao' => $aircraft_icao)); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | View Code Duplication | if ($aircraft_manufacturer != "") |
|
| 441 | { |
||
| 442 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 443 | if (!is_string($aircraft_manufacturer)) |
||
| 444 | { |
||
| 445 | return false; |
||
| 446 | } else { |
||
| 447 | $additional_query .= " AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer"; |
||
| 448 | $query_values = array_merge($query_values,array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 449 | } |
||
| 450 | } |
||
| 451 | |||
| 452 | View Code Duplication | if ($highlights == "true") |
|
| 453 | { |
||
| 454 | if (!is_string($highlights)) |
||
| 455 | { |
||
| 456 | return false; |
||
| 457 | } else { |
||
| 458 | $additional_query .= " AND (spotter_output.highlight <> '')"; |
||
| 459 | } |
||
| 460 | } |
||
| 461 | |||
| 462 | View Code Duplication | if ($airline_icao != "") |
|
| 463 | { |
||
| 464 | $registration = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 465 | if (!is_string($airline_icao)) |
||
| 466 | { |
||
| 467 | return false; |
||
| 468 | } else { |
||
| 469 | $additional_query .= " AND spotter_output.airline_icao = :airline_icao"; |
||
| 470 | $query_values = array_merge($query_values,array(':airline_icao' => $airline_icao)); |
||
| 471 | } |
||
| 472 | } |
||
| 473 | |||
| 474 | View Code Duplication | if ($airline_country != "") |
|
| 475 | { |
||
| 476 | $airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING); |
||
| 477 | if (!is_string($airline_country)) |
||
| 478 | { |
||
| 479 | return false; |
||
| 480 | } else { |
||
| 481 | $additional_query .= " AND spotter_output.airline_country = :airline_country"; |
||
| 482 | $query_values = array_merge($query_values,array(':airline_country' => $airline_country)); |
||
| 483 | } |
||
| 484 | } |
||
| 485 | |||
| 486 | View Code Duplication | if ($airline_type != "") |
|
| 487 | { |
||
| 488 | if (!is_string($airline_type)) |
||
| 489 | { |
||
| 490 | return false; |
||
| 491 | } else { |
||
| 492 | if ($airline_type == "passenger") |
||
| 493 | { |
||
| 494 | $additional_query .= " AND (spotter_output.airline_type = 'passenger')"; |
||
| 495 | } |
||
| 496 | if ($airline_type == "cargo") |
||
| 497 | { |
||
| 498 | $additional_query .= " AND (spotter_output.airline_type = 'cargo')"; |
||
| 499 | } |
||
| 500 | if ($airline_type == "military") |
||
| 501 | { |
||
| 502 | $additional_query .= " AND (spotter_output.airline_type = 'military')"; |
||
| 503 | } |
||
| 504 | } |
||
| 505 | } |
||
| 506 | |||
| 507 | View Code Duplication | if ($airport != "") |
|
| 508 | { |
||
| 509 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
| 510 | if (!is_string($airport)) |
||
| 511 | { |
||
| 512 | return false; |
||
| 513 | } else { |
||
| 514 | $additional_query .= " AND (spotter_output.departure_airport_icao = :airport OR spotter_output.arrival_airport_icao = :airport)"; |
||
| 515 | $query_values = array_merge($query_values,array(':airport' => $airport)); |
||
| 516 | } |
||
| 517 | } |
||
| 518 | |||
| 519 | View Code Duplication | if ($airport_country != "") |
|
| 520 | { |
||
| 521 | $airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING); |
||
| 522 | if (!is_string($airport_country)) |
||
| 523 | { |
||
| 524 | return false; |
||
| 525 | } else { |
||
| 526 | $additional_query .= " AND (spotter_output.departure_airport_country = :airport_country OR spotter_output.arrival_airport_country = :airport_country)"; |
||
| 527 | $query_values = array_merge($query_values,array(':airport_country' => $airport_country)); |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | if ($callsign != "") |
||
| 532 | { |
||
| 533 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
| 534 | if (!is_string($callsign)) |
||
| 535 | { |
||
| 536 | return false; |
||
| 537 | } else { |
||
| 538 | $translate = $Translation->ident2icao($callsign); |
||
| 539 | if ($translate != $callsign) { |
||
| 540 | $additional_query .= " AND (spotter_output.ident = :callsign OR spotter_output.ident = :translate)"; |
||
| 541 | $query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate)); |
||
| 542 | } else { |
||
| 543 | $additional_query .= " AND spotter_output.ident = :callsign"; |
||
| 544 | $query_values = array_merge($query_values,array(':callsign' => $callsign)); |
||
| 545 | } |
||
| 546 | } |
||
| 547 | } |
||
| 548 | |||
| 549 | View Code Duplication | if ($owner != "") |
|
| 550 | { |
||
| 551 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
| 552 | if (!is_string($owner)) |
||
| 553 | { |
||
| 554 | return false; |
||
| 555 | } else { |
||
| 556 | $additional_query .= " AND spotter_output.owner_name = :owner"; |
||
| 557 | $query_values = array_merge($query_values,array(':owner' => $owner)); |
||
| 558 | } |
||
| 559 | } |
||
| 560 | |||
| 561 | View Code Duplication | if ($pilot_name != "") |
|
| 562 | { |
||
| 563 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
| 564 | if (!is_string($pilot_name)) |
||
| 565 | { |
||
| 566 | return false; |
||
| 567 | } else { |
||
| 568 | $additional_query .= " AND spotter_output.pilot_name = :pilot_name"; |
||
| 569 | $query_values = array_merge($query_values,array(':pilot_name' => $pilot_name)); |
||
| 570 | } |
||
| 571 | } |
||
| 572 | |||
| 573 | View Code Duplication | if ($pilot_id != "") |
|
| 574 | { |
||
| 575 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT); |
||
| 576 | if (!is_string($pilot_id)) |
||
| 577 | { |
||
| 578 | return false; |
||
| 579 | } else { |
||
| 580 | $additional_query .= " AND spotter_output.pilot_id = :pilot_id"; |
||
| 581 | $query_values = array_merge($query_values,array(':pilot_id' => $pilot_id)); |
||
| 582 | } |
||
| 583 | } |
||
| 584 | |||
| 585 | View Code Duplication | if ($departure_airport_route != "") |
|
| 586 | { |
||
| 587 | $departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING); |
||
| 588 | if (!is_string($departure_airport_route)) |
||
| 589 | { |
||
| 590 | return false; |
||
| 591 | } else { |
||
| 592 | $additional_query .= " AND spotter_output.departure_airport_icao = :departure_airport_route"; |
||
| 593 | $query_values = array_merge($query_values,array(':departure_airport_route' => $departure_airport_route)); |
||
| 594 | } |
||
| 595 | } |
||
| 596 | |||
| 597 | View Code Duplication | if ($arrival_airport_route != "") |
|
| 598 | { |
||
| 599 | $arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING); |
||
| 600 | if (!is_string($arrival_airport_route)) |
||
| 601 | { |
||
| 602 | return false; |
||
| 603 | } else { |
||
| 604 | $additional_query .= " AND spotter_output.arrival_airport_icao = :arrival_airport_route"; |
||
| 605 | $query_values = array_merge($query_values,array(':arrival_airport_route' => $arrival_airport_route)); |
||
| 606 | } |
||
| 607 | } |
||
| 608 | |||
| 609 | View Code Duplication | if ($altitude != "") |
|
| 610 | { |
||
| 611 | $altitude_array = explode(",", $altitude); |
||
| 612 | $altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 613 | $altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 614 | |||
| 615 | if ($altitude_array[1] != "") |
||
| 616 | { |
||
| 617 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
| 618 | $altitude_array[1] = substr($altitude_array[1], 0, -2); |
||
| 619 | $additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' "; |
||
| 620 | } else { |
||
| 621 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
| 622 | $additional_query .= " AND altitude <= '".$altitude_array[0]."' "; |
||
| 623 | } |
||
| 624 | } |
||
| 625 | |||
| 626 | View Code Duplication | if ($date_posted != "") |
|
| 627 | { |
||
| 628 | $date_array = explode(",", $date_posted); |
||
| 629 | $date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); |
||
| 630 | $date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); |
||
| 631 | |||
| 632 | if ($globalTimezone != '') { |
||
| 633 | date_default_timezone_set($globalTimezone); |
||
| 634 | $datetime = new DateTime(); |
||
| 635 | $offset = $datetime->format('P'); |
||
| 636 | } else $offset = '+00:00'; |
||
| 637 | |||
| 638 | if ($date_array[1] != "") |
||
| 639 | { |
||
| 640 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
| 641 | $date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
||
| 642 | if ($globalDBdriver == 'mysql') { |
||
| 643 | $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]."' "; |
||
| 644 | } else { |
||
| 645 | $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]."' "; |
||
| 646 | } |
||
| 647 | } else { |
||
| 648 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
| 649 | if ($globalDBdriver == 'mysql') { |
||
| 650 | $additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; |
||
| 651 | } else { |
||
| 652 | $additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' "; |
||
| 653 | } |
||
| 654 | } |
||
| 655 | } |
||
| 656 | |||
| 657 | if ($limit != "") |
||
| 658 | { |
||
| 659 | $limit_array = explode(",", $limit); |
||
| 660 | |||
| 661 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 662 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 663 | |||
| 664 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 665 | { |
||
| 666 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 667 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 668 | } |
||
| 669 | } else $limit_query = ""; |
||
| 670 | |||
| 671 | |||
| 672 | if ($sort != "") |
||
| 673 | { |
||
| 674 | $search_orderby_array = $this->getOrderBy(); |
||
| 675 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 676 | } else { |
||
| 677 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
| 678 | $orderby_query = " ORDER BY distance ASC"; |
||
| 679 | } else { |
||
| 680 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | if ($includegeodata == "true") |
||
| 685 | { |
||
| 686 | $additional_query .= " AND spotter_output.waypoints <> ''"; |
||
| 687 | } |
||
| 688 | |||
| 689 | |||
| 690 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
| 691 | $dist = number_format($dist*0.621371,2,'.',''); // convert km to mile |
||
| 692 | |||
| 693 | if ($globalDBdriver == 'mysql') { |
||
| 694 | $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 |
||
| 695 | FROM spotter_output, spotter_archive WHERE 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)) |
||
| 696 | 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; |
||
| 697 | } else { |
||
| 698 | $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 |
||
| 699 | FROM spotter_output, spotter_archive WHERE 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)) |
||
| 700 | 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".$orderby_query; |
||
| 701 | } |
||
| 702 | } else { |
||
| 703 | $query = "SELECT spotter_output.* FROM spotter_output |
||
| 704 | WHERE spotter_output.ident <> '' |
||
| 705 | ".$additional_query." |
||
| 706 | ".$orderby_query; |
||
| 707 | } |
||
| 708 | $spotter_array = $this->getDataFromDB($query, $query_values,$limit_query); |
||
| 709 | return $spotter_array; |
||
| 710 | } |
||
| 711 | |||
| 712 | |||
| 713 | /** |
||
| 714 | * Gets all the spotter information based on the latest data entry |
||
| 715 | * |
||
| 716 | * @return Array the spotter information |
||
| 717 | * |
||
| 718 | */ |
||
| 719 | View Code Duplication | public function getLatestSpotterData($limit = '', $sort = '') |
|
| 720 | { |
||
| 721 | global $global_query; |
||
| 722 | |||
| 723 | date_default_timezone_set('UTC'); |
||
| 724 | |||
| 725 | if ($limit != "") |
||
| 726 | { |
||
| 727 | $limit_array = explode(",", $limit); |
||
| 728 | |||
| 729 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 730 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 731 | |||
| 732 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 733 | { |
||
| 734 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 735 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 736 | } |
||
| 737 | } |
||
| 738 | |||
| 739 | if ($sort != "") |
||
| 740 | { |
||
| 741 | $search_orderby_array = $this->getOrderBy(); |
||
| 742 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 743 | } else { |
||
| 744 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 745 | } |
||
| 746 | |||
| 747 | $query = $global_query." ".$orderby_query; |
||
| 748 | |||
| 749 | $spotter_array = $this->getDataFromDB($query, array(),$limit_query); |
||
| 750 | |||
| 751 | return $spotter_array; |
||
| 752 | } |
||
| 753 | |||
| 754 | |||
| 755 | /** |
||
| 756 | * Gets all the spotter information based on a user's latitude and longitude |
||
| 757 | * |
||
| 758 | * @return Array the spotter information |
||
| 759 | * |
||
| 760 | */ |
||
| 761 | public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
||
| 762 | { |
||
| 763 | date_default_timezone_set('UTC'); |
||
| 764 | |||
| 765 | if ($lat != "") |
||
| 766 | { |
||
| 767 | if (!is_numeric($lat)) |
||
| 768 | { |
||
| 769 | return false; |
||
| 770 | } |
||
| 771 | } |
||
| 772 | |||
| 773 | if ($lng != "") |
||
| 774 | { |
||
| 775 | if (!is_numeric($lng)) |
||
| 776 | { |
||
| 777 | return false; |
||
| 778 | } |
||
| 779 | } |
||
| 780 | |||
| 781 | if ($radius != "") |
||
| 782 | { |
||
| 783 | if (!is_numeric($radius)) |
||
| 784 | { |
||
| 785 | return false; |
||
| 786 | } |
||
| 787 | } |
||
| 788 | |||
| 789 | if ($interval != "") |
||
| 790 | { |
||
| 791 | if (!is_string($interval)) |
||
| 792 | { |
||
| 793 | return false; |
||
| 794 | } else { |
||
| 795 | if ($interval == "30m"){ |
||
| 796 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) <= $this_output.date '; |
||
| 797 | } else if ($interval == "1h"){ |
||
| 798 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) <= $this_output.date '; |
||
| 799 | } else if ($interval == "3h"){ |
||
| 800 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 3 HOUR) <= $this_output.date '; |
||
| 801 | } else if ($interval == "6h"){ |
||
| 802 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 6 HOUR) <= $this_output.date '; |
||
| 803 | } else if ($interval == "12h"){ |
||
| 804 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 HOUR) <= $this_output.date '; |
||
| 805 | } else if ($interval == "24h"){ |
||
| 806 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) <= $this_output.date '; |
||
| 807 | } else if ($interval == "7d"){ |
||
| 808 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) <= $this_output.date '; |
||
| 809 | } else if ($interval == "30d"){ |
||
| 810 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 DAY) <= $this_output.date '; |
||
| 811 | } |
||
| 812 | } |
||
| 813 | } |
||
| 814 | |||
| 815 | $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 |
||
| 816 | WHERE spotter_output.latitude <> '' |
||
| 817 | AND spotter_output.longitude <> '' |
||
| 818 | ".$additional_query." |
||
| 819 | HAVING distance < :radius |
||
| 820 | ORDER BY distance"; |
||
| 821 | |||
| 822 | $spotter_array = $this->getDataFromDB($query, array(':radius' => $radius),$limit_query); |
||
| 823 | |||
| 824 | return $spotter_array; |
||
| 825 | } |
||
| 826 | |||
| 827 | |||
| 828 | /** |
||
| 829 | * Gets all the spotter information sorted by the newest aircraft type |
||
| 830 | * |
||
| 831 | * @return Array the spotter information |
||
| 832 | * |
||
| 833 | */ |
||
| 834 | View Code Duplication | public function getNewestSpotterDataSortedByAircraftType($limit = '', $sort = '') |
|
| 835 | { |
||
| 836 | global $global_query; |
||
| 837 | |||
| 838 | date_default_timezone_set('UTC'); |
||
| 839 | |||
| 840 | if ($limit != "") |
||
| 841 | { |
||
| 842 | $limit_array = explode(",", $limit); |
||
| 843 | |||
| 844 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 845 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 846 | |||
| 847 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 848 | { |
||
| 849 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 850 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 851 | } |
||
| 852 | } |
||
| 853 | |||
| 854 | if ($sort != "") |
||
| 855 | { |
||
| 856 | $search_orderby_array = $this->getOrderBy(); |
||
| 857 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 858 | } else { |
||
| 859 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 860 | } |
||
| 861 | |||
| 862 | $query = $global_query." WHERE 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; |
||
| 863 | |||
| 864 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 865 | |||
| 866 | return $spotter_array; |
||
| 867 | } |
||
| 868 | |||
| 869 | |||
| 870 | /** |
||
| 871 | * Gets all the spotter information sorted by the newest aircraft registration |
||
| 872 | * |
||
| 873 | * @return Array the spotter information |
||
| 874 | * |
||
| 875 | */ |
||
| 876 | View Code Duplication | public function getNewestSpotterDataSortedByAircraftRegistration($limit = '', $sort = '') |
|
| 877 | { |
||
| 878 | global $global_query; |
||
| 879 | |||
| 880 | date_default_timezone_set('UTC'); |
||
| 881 | |||
| 882 | if ($limit != "") |
||
| 883 | { |
||
| 884 | $limit_array = explode(",", $limit); |
||
| 885 | |||
| 886 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 887 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 888 | |||
| 889 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 890 | { |
||
| 891 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 892 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 893 | } |
||
| 894 | } |
||
| 895 | |||
| 896 | if ($sort != "") |
||
| 897 | { |
||
| 898 | $search_orderby_array = $this->getOrderBy(); |
||
| 899 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 900 | } else { |
||
| 901 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 902 | } |
||
| 903 | |||
| 904 | $query = $global_query." WHERE 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; |
||
| 905 | |||
| 906 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 907 | |||
| 908 | return $spotter_array; |
||
| 909 | } |
||
| 910 | |||
| 911 | |||
| 912 | /** |
||
| 913 | * Gets all the spotter information sorted by the newest airline |
||
| 914 | * |
||
| 915 | * @return Array the spotter information |
||
| 916 | * |
||
| 917 | */ |
||
| 918 | View Code Duplication | public function getNewestSpotterDataSortedByAirline($limit = '', $sort = '') |
|
| 919 | { |
||
| 920 | global $global_query; |
||
| 921 | |||
| 922 | date_default_timezone_set('UTC'); |
||
| 923 | |||
| 924 | if ($limit != "") |
||
| 925 | { |
||
| 926 | $limit_array = explode(",", $limit); |
||
| 927 | |||
| 928 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 929 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 930 | |||
| 931 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 932 | { |
||
| 933 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 934 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 935 | } |
||
| 936 | } |
||
| 937 | |||
| 938 | if ($sort != "") |
||
| 939 | { |
||
| 940 | $search_orderby_array = $this->getOrderBy(); |
||
| 941 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 942 | } else { |
||
| 943 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 944 | } |
||
| 945 | |||
| 946 | $query = $global_query." WHERE 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; |
||
| 947 | |||
| 948 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 949 | |||
| 950 | return $spotter_array; |
||
| 951 | } |
||
| 952 | |||
| 953 | |||
| 954 | /** |
||
| 955 | * Gets all the spotter information sorted by the newest departure airport |
||
| 956 | * |
||
| 957 | * @return Array the spotter information |
||
| 958 | * |
||
| 959 | */ |
||
| 960 | View Code Duplication | public function getNewestSpotterDataSortedByDepartureAirport($limit = '', $sort = '') |
|
| 961 | { |
||
| 962 | global $global_query; |
||
| 963 | |||
| 964 | date_default_timezone_set('UTC'); |
||
| 965 | |||
| 966 | if ($limit != "") |
||
| 967 | { |
||
| 968 | $limit_array = explode(",", $limit); |
||
| 969 | |||
| 970 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 971 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 972 | |||
| 973 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 974 | { |
||
| 975 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 976 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 977 | } |
||
| 978 | } |
||
| 979 | |||
| 980 | if ($sort != "") |
||
| 981 | { |
||
| 982 | $search_orderby_array = $this->getOrderBy(); |
||
| 983 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 984 | } else { |
||
| 985 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 986 | } |
||
| 987 | |||
| 988 | $query = $global_query." WHERE 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; |
||
| 989 | |||
| 990 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 991 | |||
| 992 | return $spotter_array; |
||
| 993 | } |
||
| 994 | |||
| 995 | |||
| 996 | /** |
||
| 997 | * Gets all the spotter information sorted by the newest arrival airport |
||
| 998 | * |
||
| 999 | * @return Array the spotter information |
||
| 1000 | * |
||
| 1001 | */ |
||
| 1002 | View Code Duplication | public function getNewestSpotterDataSortedByArrivalAirport($limit = '', $sort = '') |
|
| 1003 | { |
||
| 1004 | global $global_query; |
||
| 1005 | |||
| 1006 | date_default_timezone_set('UTC'); |
||
| 1007 | |||
| 1008 | if ($limit != "") |
||
| 1009 | { |
||
| 1010 | $limit_array = explode(",", $limit); |
||
| 1011 | |||
| 1012 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1013 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1014 | |||
| 1015 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1016 | { |
||
| 1017 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1018 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1019 | } |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | if ($sort != "") |
||
| 1023 | { |
||
| 1024 | $search_orderby_array = $this->getOrderBy(); |
||
| 1025 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1026 | } else { |
||
| 1027 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
| 1028 | } |
||
| 1029 | |||
| 1030 | $query = $global_query." WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' 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; |
||
| 1031 | |||
| 1032 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1033 | |||
| 1034 | return $spotter_array; |
||
| 1035 | } |
||
| 1036 | |||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Gets all the spotter information based on the spotter id |
||
| 1040 | * |
||
| 1041 | * @return Array the spotter information |
||
| 1042 | * |
||
| 1043 | */ |
||
| 1044 | public function getSpotterDataByID($id = '') |
||
| 1045 | { |
||
| 1046 | global $global_query; |
||
| 1047 | |||
| 1048 | date_default_timezone_set('UTC'); |
||
| 1049 | |||
| 1050 | $query_values = array(); |
||
| 1051 | $additional_query = ''; |
||
| 1052 | if ($id != "") |
||
| 1053 | { |
||
| 1054 | if (!is_string($id)) |
||
| 1055 | { |
||
| 1056 | return false; |
||
| 1057 | } else { |
||
| 1058 | $additional_query = " AND (spotter_output.spotter_id = :id)"; |
||
| 1059 | $query_values = array(':id' => $id); |
||
| 1060 | } |
||
| 1061 | } |
||
| 1062 | |||
| 1063 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." "; |
||
| 1064 | |||
| 1065 | $spotter_array = $this->getDataFromDB($query,$query_values); |
||
| 1066 | |||
| 1067 | return $spotter_array; |
||
| 1068 | } |
||
| 1069 | |||
| 1070 | |||
| 1071 | |||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Gets all the spotter information based on the callsign |
||
| 1075 | * |
||
| 1076 | * @return Array the spotter information |
||
| 1077 | * |
||
| 1078 | */ |
||
| 1079 | public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') |
||
| 1080 | { |
||
| 1081 | global $global_query; |
||
| 1082 | |||
| 1083 | date_default_timezone_set('UTC'); |
||
| 1084 | |||
| 1085 | $query_values = array(); |
||
| 1086 | |||
| 1087 | if ($ident != "") |
||
| 1088 | { |
||
| 1089 | if (!is_string($ident)) |
||
| 1090 | { |
||
| 1091 | return false; |
||
| 1092 | } else { |
||
| 1093 | $additional_query = " AND (spotter_output.ident = :ident)"; |
||
| 1094 | $query_values = array(':ident' => $ident); |
||
| 1095 | } |
||
| 1096 | } |
||
| 1097 | |||
| 1098 | if ($limit != "") |
||
| 1099 | { |
||
| 1100 | $limit_array = explode(",", $limit); |
||
| 1101 | |||
| 1102 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1103 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1104 | |||
| 1105 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1106 | { |
||
| 1107 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1108 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1109 | } |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | if ($sort != "") |
||
| 1113 | { |
||
| 1114 | $search_orderby_array = $this->getOrderBy(); |
||
| 1115 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1116 | } else { |
||
| 1117 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1121 | |||
| 1122 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1123 | |||
| 1124 | return $spotter_array; |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | |||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Gets all the spotter information based on the aircraft type |
||
| 1131 | * |
||
| 1132 | * @return Array the spotter information |
||
| 1133 | * |
||
| 1134 | */ |
||
| 1135 | public function getSpotterDataByAircraft($aircraft_type = '', $limit = '', $sort = '') |
||
| 1136 | { |
||
| 1137 | global $global_query; |
||
| 1138 | |||
| 1139 | date_default_timezone_set('UTC'); |
||
| 1140 | |||
| 1141 | $query_values = array(); |
||
| 1142 | |||
| 1143 | if ($aircraft_type != "") |
||
| 1144 | { |
||
| 1145 | if (!is_string($aircraft_type)) |
||
| 1146 | { |
||
| 1147 | return false; |
||
| 1148 | } else { |
||
| 1149 | $additional_query = " AND (spotter_output.aircraft_icao = :aircraft_type)"; |
||
| 1150 | $query_values = array(':aircraft_type' => $aircraft_type); |
||
| 1151 | } |
||
| 1152 | } |
||
| 1153 | |||
| 1154 | if ($limit != "") |
||
| 1155 | { |
||
| 1156 | $limit_array = explode(",", $limit); |
||
| 1157 | |||
| 1158 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1159 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1160 | |||
| 1161 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1162 | { |
||
| 1163 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1164 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1165 | } |
||
| 1166 | } |
||
| 1167 | |||
| 1168 | if ($sort != "") |
||
| 1169 | { |
||
| 1170 | $search_orderby_array = $this->getOrderBy(); |
||
| 1171 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1172 | } else { |
||
| 1173 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1174 | } |
||
| 1175 | |||
| 1176 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1177 | |||
| 1178 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1179 | |||
| 1180 | return $spotter_array; |
||
| 1181 | } |
||
| 1182 | |||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * Gets all the spotter information based on the aircraft registration |
||
| 1186 | * |
||
| 1187 | * @return Array the spotter information |
||
| 1188 | * |
||
| 1189 | */ |
||
| 1190 | public function getSpotterDataByRegistration($registration = '', $limit = '', $sort = '') |
||
| 1191 | { |
||
| 1192 | global $global_query; |
||
| 1193 | |||
| 1194 | date_default_timezone_set('UTC'); |
||
| 1195 | |||
| 1196 | $query_values = array(); |
||
| 1197 | |||
| 1198 | if ($registration != "") |
||
| 1199 | { |
||
| 1200 | if (!is_string($registration)) |
||
| 1201 | { |
||
| 1202 | return false; |
||
| 1203 | } else { |
||
| 1204 | $additional_query = " AND (spotter_output.registration = :registration)"; |
||
| 1205 | $query_values = array(':registration' => $registration); |
||
| 1206 | } |
||
| 1207 | } |
||
| 1208 | |||
| 1209 | if ($limit != "") |
||
| 1210 | { |
||
| 1211 | $limit_array = explode(",", $limit); |
||
| 1212 | |||
| 1213 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1214 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1215 | |||
| 1216 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1217 | { |
||
| 1218 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1219 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1220 | } |
||
| 1221 | } |
||
| 1222 | |||
| 1223 | if ($sort != "") |
||
| 1224 | { |
||
| 1225 | $search_orderby_array = $this->getOrderBy(); |
||
| 1226 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1227 | } else { |
||
| 1228 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1229 | } |
||
| 1230 | |||
| 1231 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1232 | |||
| 1233 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1234 | |||
| 1235 | return $spotter_array; |
||
| 1236 | } |
||
| 1237 | |||
| 1238 | |||
| 1239 | |||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Gets all the spotter information based on the airline |
||
| 1243 | * |
||
| 1244 | * @return Array the spotter information |
||
| 1245 | * |
||
| 1246 | */ |
||
| 1247 | public function getSpotterDataByAirline($airline = '', $limit = '', $sort = '') |
||
| 1248 | { |
||
| 1249 | global $global_query; |
||
| 1250 | |||
| 1251 | date_default_timezone_set('UTC'); |
||
| 1252 | |||
| 1253 | $query_values = array(); |
||
| 1254 | |||
| 1255 | if ($airline != "") |
||
| 1256 | { |
||
| 1257 | if (!is_string($airline)) |
||
| 1258 | { |
||
| 1259 | return false; |
||
| 1260 | } else { |
||
| 1261 | $additional_query = " AND (spotter_output.airline_icao = :airline)"; |
||
| 1262 | $query_values = array(':airline' => $airline); |
||
| 1263 | } |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | if ($limit != "") |
||
| 1267 | { |
||
| 1268 | $limit_array = explode(",", $limit); |
||
| 1269 | |||
| 1270 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1271 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1272 | |||
| 1273 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1274 | { |
||
| 1275 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1276 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1277 | } |
||
| 1278 | } |
||
| 1279 | |||
| 1280 | if ($sort != "") |
||
| 1281 | { |
||
| 1282 | $search_orderby_array = $this->getOrderBy(); |
||
| 1283 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1284 | } else { |
||
| 1285 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1286 | } |
||
| 1287 | |||
| 1288 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1289 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1290 | |||
| 1291 | return $spotter_array; |
||
| 1292 | } |
||
| 1293 | |||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Gets all the spotter information based on the airport |
||
| 1297 | * |
||
| 1298 | * @return Array the spotter information |
||
| 1299 | * |
||
| 1300 | */ |
||
| 1301 | View Code Duplication | public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '') |
|
| 1302 | { |
||
| 1303 | global $global_query; |
||
| 1304 | |||
| 1305 | date_default_timezone_set('UTC'); |
||
| 1306 | $additional_query = ''; |
||
| 1307 | $query_values = array(); |
||
| 1308 | |||
| 1309 | if ($airport != "") |
||
| 1310 | { |
||
| 1311 | if (!is_string($airport)) |
||
| 1312 | { |
||
| 1313 | return false; |
||
| 1314 | } else { |
||
| 1315 | $additional_query .= " AND ((spotter_output.departure_airport_icao = :airport) OR (spotter_output.arrival_airport_icao = :airport))"; |
||
| 1316 | $query_values = array(':airport' => $airport); |
||
| 1317 | } |
||
| 1318 | } |
||
| 1319 | |||
| 1320 | if ($limit != "") |
||
| 1321 | { |
||
| 1322 | $limit_array = explode(",", $limit); |
||
| 1323 | |||
| 1324 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1325 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1326 | |||
| 1327 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1328 | { |
||
| 1329 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1330 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1331 | } |
||
| 1332 | } |
||
| 1333 | |||
| 1334 | if ($sort != "") |
||
| 1335 | { |
||
| 1336 | $search_orderby_array = $this->getOrderBy(); |
||
| 1337 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1338 | } else { |
||
| 1339 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1340 | } |
||
| 1341 | |||
| 1342 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." AND ((spotter_output.departure_airport_icao <> 'NA') AND (spotter_output.arrival_airport_icao <> 'NA')) ".$orderby_query; |
||
| 1343 | |||
| 1344 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1345 | |||
| 1346 | return $spotter_array; |
||
| 1347 | } |
||
| 1348 | |||
| 1349 | |||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Gets all the spotter information based on the date |
||
| 1353 | * |
||
| 1354 | * @return Array the spotter information |
||
| 1355 | * |
||
| 1356 | */ |
||
| 1357 | public function getSpotterDataByDate($date = '', $limit = '', $sort = '') |
||
| 1358 | { |
||
| 1359 | global $global_query, $globalTimezone, $globalDBdriver; |
||
| 1360 | |||
| 1361 | $query_values = array(); |
||
| 1362 | |||
| 1363 | if ($date != "") |
||
| 1364 | { |
||
| 1365 | if ($globalTimezone != '') { |
||
| 1366 | date_default_timezone_set($globalTimezone); |
||
| 1367 | $datetime = new DateTime($date); |
||
| 1368 | $offset = $datetime->format('P'); |
||
| 1369 | } else $offset = '+00:00'; |
||
| 1370 | if ($globalDBdriver == 'mysql') { |
||
| 1371 | $additional_query = " AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date "; |
||
| 1372 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset); |
||
| 1373 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 1374 | $additional_query = " AND spotter_output.date AT TIME ZONE :timezone = :date "; |
||
| 1375 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone); |
||
| 1376 | } |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | if ($limit != "") |
||
| 1380 | { |
||
| 1381 | $limit_array = explode(",", $limit); |
||
| 1382 | |||
| 1383 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1384 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1385 | |||
| 1386 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1387 | { |
||
| 1388 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1389 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1390 | } |
||
| 1391 | } |
||
| 1392 | |||
| 1393 | if ($sort != "") |
||
| 1394 | { |
||
| 1395 | $search_orderby_array = $this->getOrderBy(); |
||
| 1396 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1397 | } else { |
||
| 1398 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1399 | } |
||
| 1400 | |||
| 1401 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1402 | |||
| 1403 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1404 | |||
| 1405 | return $spotter_array; |
||
| 1406 | } |
||
| 1407 | |||
| 1408 | |||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Gets all the spotter information based on the country name |
||
| 1412 | * |
||
| 1413 | * @return Array the spotter information |
||
| 1414 | * |
||
| 1415 | */ |
||
| 1416 | View Code Duplication | public function getSpotterDataByCountry($country = '', $limit = '', $sort = '') |
|
| 1417 | { |
||
| 1418 | global $global_query; |
||
| 1419 | |||
| 1420 | date_default_timezone_set('UTC'); |
||
| 1421 | |||
| 1422 | $query_values = array(); |
||
| 1423 | $additional_query = ''; |
||
| 1424 | if ($country != "") |
||
| 1425 | { |
||
| 1426 | if (!is_string($country)) |
||
| 1427 | { |
||
| 1428 | return false; |
||
| 1429 | } else { |
||
| 1430 | $additional_query .= " AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country))"; |
||
| 1431 | $additional_query .= " OR spotter_output.airline_country = :country"; |
||
| 1432 | $query_values = array(':country' => $country); |
||
| 1433 | } |
||
| 1434 | } |
||
| 1435 | |||
| 1436 | if ($limit != "") |
||
| 1437 | { |
||
| 1438 | $limit_array = explode(",", $limit); |
||
| 1439 | |||
| 1440 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1441 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1442 | |||
| 1443 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1444 | { |
||
| 1445 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1446 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1447 | } |
||
| 1448 | } |
||
| 1449 | |||
| 1450 | if ($sort != "") |
||
| 1451 | { |
||
| 1452 | $search_orderby_array = $this->getOrderBy(); |
||
| 1453 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1454 | } else { |
||
| 1455 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1456 | } |
||
| 1457 | |||
| 1458 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1459 | |||
| 1460 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1461 | |||
| 1462 | return $spotter_array; |
||
| 1463 | } |
||
| 1464 | |||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Gets all the spotter information based on the manufacturer name |
||
| 1468 | * |
||
| 1469 | * @return Array the spotter information |
||
| 1470 | * |
||
| 1471 | */ |
||
| 1472 | View Code Duplication | public function getSpotterDataByManufacturer($aircraft_manufacturer = '', $limit = '', $sort = '') |
|
| 1473 | { |
||
| 1474 | global $global_query; |
||
| 1475 | |||
| 1476 | date_default_timezone_set('UTC'); |
||
| 1477 | |||
| 1478 | $query_values = array(); |
||
| 1479 | $additional_query = ''; |
||
| 1480 | |||
| 1481 | if ($aircraft_manufacturer != "") |
||
| 1482 | { |
||
| 1483 | if (!is_string($aircraft_manufacturer)) |
||
| 1484 | { |
||
| 1485 | return false; |
||
| 1486 | } else { |
||
| 1487 | $additional_query .= " AND (spotter_output.aircraft_manufacturer = :aircraft_manufacturer)"; |
||
| 1488 | $query_values = array(':aircraft_manufacturer' => $aircraft_manufacturer); |
||
| 1489 | } |
||
| 1490 | } |
||
| 1491 | |||
| 1492 | if ($limit != "") |
||
| 1493 | { |
||
| 1494 | $limit_array = explode(",", $limit); |
||
| 1495 | |||
| 1496 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1497 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1498 | |||
| 1499 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1500 | { |
||
| 1501 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1502 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1503 | } |
||
| 1504 | } |
||
| 1505 | |||
| 1506 | if ($sort != "") |
||
| 1507 | { |
||
| 1508 | $search_orderby_array = $this->getOrderBy(); |
||
| 1509 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1510 | } else { |
||
| 1511 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1512 | } |
||
| 1513 | |||
| 1514 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1515 | |||
| 1516 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1517 | |||
| 1518 | return $spotter_array; |
||
| 1519 | } |
||
| 1520 | |||
| 1521 | |||
| 1522 | |||
| 1523 | |||
| 1524 | /** |
||
| 1525 | * Gets a list of all aircraft with a special highlight text |
||
| 1526 | * |
||
| 1527 | * @param String $aircraft_registration the aircraft registration |
||
| 1528 | * @param String $airport_departure the departure airport |
||
| 1529 | * @return Array the spotter information |
||
| 1530 | * |
||
| 1531 | */ |
||
| 1532 | public function getSpotterDataByRoute($departure_airport_icao = '', $arrival_airport_icao = '', $limit = '', $sort = '') |
||
| 1533 | { |
||
| 1534 | global $global_query; |
||
| 1535 | |||
| 1536 | $query_values = array(); |
||
| 1537 | $additional_query = ''; |
||
| 1538 | if ($departure_airport_icao != "") |
||
| 1539 | { |
||
| 1540 | if (!is_string($departure_airport_icao)) |
||
| 1541 | { |
||
| 1542 | return false; |
||
| 1543 | } else { |
||
| 1544 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1545 | $additional_query .= " AND (spotter_output.departure_airport_icao = :departure_airport_icao)"; |
||
| 1546 | $query_values = array(':departure_airport_icao' => $departure_airport_icao); |
||
| 1547 | } |
||
| 1548 | } |
||
| 1549 | |||
| 1550 | View Code Duplication | if ($arrival_airport_icao != "") |
|
| 1551 | { |
||
| 1552 | if (!is_string($arrival_airport_icao)) |
||
| 1553 | { |
||
| 1554 | return false; |
||
| 1555 | } else { |
||
| 1556 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1557 | $additional_query .= " AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)"; |
||
| 1558 | $query_values = array_merge($query_values,array(':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 1559 | } |
||
| 1560 | } |
||
| 1561 | |||
| 1562 | if ($limit != "") |
||
| 1563 | { |
||
| 1564 | $limit_array = explode(",", $limit); |
||
| 1565 | |||
| 1566 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1567 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1568 | |||
| 1569 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1570 | { |
||
| 1571 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1572 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1573 | } |
||
| 1574 | } |
||
| 1575 | |||
| 1576 | if ($sort != "") |
||
| 1577 | { |
||
| 1578 | $search_orderby_array = $this->getOrderBy(); |
||
| 1579 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1580 | } else { |
||
| 1581 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1582 | } |
||
| 1583 | |||
| 1584 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
| 1585 | |||
| 1586 | //$result = mysqli_query($GLOBALS["___mysqli_ston"], $query); |
||
| 1587 | |||
| 1588 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
| 1589 | |||
| 1590 | return $spotter_array; |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | |||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Gets all the spotter information based on the special column in the table |
||
| 1597 | * |
||
| 1598 | * @return Array the spotter information |
||
| 1599 | * |
||
| 1600 | */ |
||
| 1601 | View Code Duplication | public function getSpotterDataByHighlight($limit = '', $sort = '') |
|
| 1602 | { |
||
| 1603 | global $global_query; |
||
| 1604 | |||
| 1605 | date_default_timezone_set('UTC'); |
||
| 1606 | |||
| 1607 | if ($limit != "") |
||
| 1608 | { |
||
| 1609 | $limit_array = explode(",", $limit); |
||
| 1610 | |||
| 1611 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 1612 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 1613 | |||
| 1614 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 1615 | { |
||
| 1616 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 1617 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 1618 | } |
||
| 1619 | } |
||
| 1620 | |||
| 1621 | if ($sort != "") |
||
| 1622 | { |
||
| 1623 | $search_orderby_array = $this->getOrderBy(); |
||
| 1624 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 1625 | } else { |
||
| 1626 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
| 1627 | } |
||
| 1628 | |||
| 1629 | $query = $global_query." WHERE spotter_output.highlight <> '' ".$orderby_query; |
||
| 1630 | |||
| 1631 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
| 1632 | |||
| 1633 | return $spotter_array; |
||
| 1634 | } |
||
| 1635 | |||
| 1636 | |||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Gets all the highlight based on a aircraft registration |
||
| 1640 | * |
||
| 1641 | * @return String the highlight text |
||
| 1642 | * |
||
| 1643 | */ |
||
| 1644 | public function getHighlightByRegistration($registration) |
||
| 1645 | { |
||
| 1646 | global $global_query; |
||
| 1647 | |||
| 1648 | date_default_timezone_set('UTC'); |
||
| 1649 | |||
| 1650 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 1651 | |||
| 1652 | |||
| 1653 | $query = $global_query." WHERE spotter_output.highlight <> '' AND spotter_output.registration = :registration"; |
||
| 1654 | $sth = $this->db->prepare($query); |
||
| 1655 | $sth->execute(array(':registration' => $registration)); |
||
| 1656 | |||
| 1657 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1658 | { |
||
| 1659 | $highlight = $row['highlight']; |
||
| 1660 | } |
||
| 1661 | if (isset($highlight)) return $highlight; |
||
| 1662 | } |
||
| 1663 | |||
| 1664 | |||
| 1665 | /** |
||
| 1666 | * Gets the squawk usage from squawk code |
||
| 1667 | * |
||
| 1668 | * @param String $squawk squawk code |
||
| 1669 | * @param String $country country |
||
| 1670 | * @return String usage |
||
| 1671 | * |
||
| 1672 | */ |
||
| 1673 | public function getSquawkUsage($squawk = '',$country = 'FR') |
||
| 1674 | { |
||
| 1675 | |||
| 1676 | $squawk = filter_var($squawk,FILTER_SANITIZE_STRING); |
||
| 1677 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 1678 | |||
| 1679 | $query_values = array(); |
||
| 1680 | |||
| 1681 | $query = "SELECT squawk.* FROM squawk WHERE squawk.code = :squawk AND squawk.country = :country LIMIT 1"; |
||
| 1682 | $query_values = array(':squawk' => ltrim($squawk,'0'), ':country' => $country); |
||
| 1683 | |||
| 1684 | $sth = $this->db->prepare($query); |
||
| 1685 | $sth->execute($query_values); |
||
| 1686 | |||
| 1687 | $temp_array = array(); |
||
| 1688 | |||
| 1689 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 1690 | if (count($row) > 0) { |
||
| 1691 | return $row['usage']; |
||
| 1692 | } else return ''; |
||
| 1693 | } |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * Gets the airport icao from the iata |
||
| 1697 | * |
||
| 1698 | * @param String $airport_iata the iata code of the airport |
||
| 1699 | * @return String airport iata |
||
| 1700 | * |
||
| 1701 | */ |
||
| 1702 | public function getAirportIcao($airport_iata = '') |
||
| 1703 | { |
||
| 1704 | |||
| 1705 | $airport_iata = filter_var($airport_iata,FILTER_SANITIZE_STRING); |
||
| 1706 | |||
| 1707 | $query_values = array(); |
||
| 1708 | |||
| 1709 | $query = "SELECT airport.* FROM airport WHERE airport.iata = :airport LIMIT 1"; |
||
| 1710 | $query_values = array(':airport' => $airport_iata); |
||
| 1711 | |||
| 1712 | |||
| 1713 | $sth = $this->db->prepare($query); |
||
| 1714 | $sth->execute($query_values); |
||
| 1715 | |||
| 1716 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 1717 | if (count($row) > 0) { |
||
| 1718 | return $row['icao']; |
||
| 1719 | } else return ''; |
||
| 1720 | } |
||
| 1721 | |||
| 1722 | /** |
||
| 1723 | * Gets the airport distance |
||
| 1724 | * |
||
| 1725 | * @param String $airport_icao the icao code of the airport |
||
| 1726 | * @param Float $latitude the latitude |
||
| 1727 | * @param Float $longitude the longitude |
||
| 1728 | * @return Float distance to the airport |
||
| 1729 | * |
||
| 1730 | */ |
||
| 1731 | public function getAirportDistance($airport_icao,$latitude,$longitude) |
||
| 1732 | { |
||
| 1733 | |||
| 1734 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 1735 | |||
| 1736 | $query_values = array(); |
||
| 1737 | |||
| 1738 | $query = "SELECT airport.latitude, airport.longitude FROM airport WHERE airport.icao = :airport LIMIT 1"; |
||
| 1739 | $query_values = array(':airport' => $airport_icao); |
||
| 1740 | $sth = $this->db->prepare($query); |
||
| 1741 | $sth->execute($query_values); |
||
| 1742 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 1743 | if (count($row) > 0) { |
||
| 1744 | $airport_latitude = $row['latitude']; |
||
| 1745 | $airport_longitude = $row['longitude']; |
||
| 1746 | $Common = new Common(); |
||
| 1747 | return $Common->distance($latitude,$longitude,$airport_latitude,$airport_longitude); |
||
| 1748 | } else return ''; |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * Gets the airport info based on the icao |
||
| 1753 | * |
||
| 1754 | * @param String $airport_iata the icao code of the airport |
||
| 1755 | * @return Array airport information |
||
| 1756 | * |
||
| 1757 | */ |
||
| 1758 | public function getAllAirportInfo($airport = '') |
||
| 1759 | { |
||
| 1760 | |||
| 1761 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
| 1762 | |||
| 1763 | $query_values = array(); |
||
| 1764 | if ($airport == 'NA') { |
||
| 1765 | 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' => '')); |
||
| 1766 | } elseif ($airport == '') { |
||
| 1767 | $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"; |
||
| 1768 | } else { |
||
| 1769 | $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"; |
||
| 1770 | $query_values = array(':airport' => $airport); |
||
| 1771 | } |
||
| 1772 | |||
| 1773 | $sth = $this->db->prepare($query); |
||
| 1774 | $sth->execute($query_values); |
||
| 1775 | /* |
||
| 1776 | $airport_array = array(); |
||
| 1777 | $temp_array = array(); |
||
| 1778 | |||
| 1779 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1780 | { |
||
| 1781 | $temp_array['name'] = $row['name']; |
||
| 1782 | $temp_array['city'] = $row['city']; |
||
| 1783 | $temp_array['country'] = $row['country']; |
||
| 1784 | $temp_array['iata'] = $row['iata']; |
||
| 1785 | $temp_array['icao'] = $row['icao']; |
||
| 1786 | $temp_array['latitude'] = $row['latitude']; |
||
| 1787 | $temp_array['longitude'] = $row['longitude']; |
||
| 1788 | $temp_array['altitude'] = $row['altitude']; |
||
| 1789 | $temp_array['home_link'] = $row['home_link']; |
||
| 1790 | $temp_array['wikipedia_link'] = $row['wikipedia_link']; |
||
| 1791 | $temp_array['image'] = $row['image']; |
||
| 1792 | $temp_array['image_thumb'] = $row['image_thumb']; |
||
| 1793 | |||
| 1794 | $airport_array[] = $temp_array; |
||
| 1795 | } |
||
| 1796 | |||
| 1797 | return $airport_array; |
||
| 1798 | */ |
||
| 1799 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 1800 | } |
||
| 1801 | |||
| 1802 | /** |
||
| 1803 | * Gets the airport info based on the country |
||
| 1804 | * |
||
| 1805 | * @param Array $countries Airports countries |
||
| 1806 | * @return Array airport information |
||
| 1807 | * |
||
| 1808 | */ |
||
| 1809 | public function getAllAirportInfobyCountry($countries) |
||
| 1810 | { |
||
| 1811 | $lst_countries = ''; |
||
| 1812 | foreach ($countries as $country) { |
||
| 1813 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 1814 | if ($lst_countries == '') { |
||
| 1815 | $lst_countries = "'".$country."'"; |
||
| 1816 | } else { |
||
| 1817 | $lst_countries .= ",'".$country."'"; |
||
| 1818 | } |
||
| 1819 | } |
||
| 1820 | $query = "SELECT airport.* FROM airport WHERE airport.country IN (".$lst_countries.")"; |
||
| 1821 | |||
| 1822 | $sth = $this->db->prepare($query); |
||
| 1823 | $sth->execute(); |
||
| 1824 | |||
| 1825 | $airport_array = array(); |
||
| 1826 | $temp_array = array(); |
||
| 1827 | |||
| 1828 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1829 | { |
||
| 1830 | $temp_array['name'] = $row['name']; |
||
| 1831 | $temp_array['city'] = $row['city']; |
||
| 1832 | $temp_array['country'] = $row['country']; |
||
| 1833 | $temp_array['iata'] = $row['iata']; |
||
| 1834 | $temp_array['icao'] = $row['icao']; |
||
| 1835 | $temp_array['latitude'] = $row['latitude']; |
||
| 1836 | $temp_array['longitude'] = $row['longitude']; |
||
| 1837 | $temp_array['altitude'] = $row['altitude']; |
||
| 1838 | |||
| 1839 | $airport_array[] = $temp_array; |
||
| 1840 | } |
||
| 1841 | |||
| 1842 | return $airport_array; |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * Gets airports info based on the coord |
||
| 1847 | * |
||
| 1848 | * @param Array $coord Airports longitude min,latitude min, longitude max, latitude max |
||
| 1849 | * @return Array airport information |
||
| 1850 | * |
||
| 1851 | */ |
||
| 1852 | public function getAllAirportInfobyCoord($coord) |
||
| 1853 | { |
||
| 1854 | global $globalDBdriver; |
||
| 1855 | $lst_countries = ''; |
||
| 1856 | View Code Duplication | if (is_array($coord)) { |
|
| 1857 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1858 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1859 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1860 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1861 | } |
||
| 1862 | if ($globalDBdriver == 'mysql') { |
||
| 1863 | $query = "SELECT airport.* FROM airport WHERE airport.latitude BETWEEN ".$minlat." AND ".$maxlat." AND airport.longitude BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'"; |
||
| 1864 | } else { |
||
| 1865 | $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'"; |
||
| 1866 | } |
||
| 1867 | $sth = $this->db->prepare($query); |
||
| 1868 | $sth->execute(); |
||
| 1869 | |||
| 1870 | $airport_array = array(); |
||
| 1871 | $temp_array = array(); |
||
| 1872 | |||
| 1873 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1874 | { |
||
| 1875 | $temp_array = $row; |
||
| 1876 | |||
| 1877 | $airport_array[] = $temp_array; |
||
| 1878 | } |
||
| 1879 | |||
| 1880 | return $airport_array; |
||
| 1881 | } |
||
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Gets waypoints info based on the coord |
||
| 1885 | * |
||
| 1886 | * @param Array $coord waypoints coord |
||
| 1887 | * @return Array airport information |
||
| 1888 | * |
||
| 1889 | */ |
||
| 1890 | public function getAllWaypointsInfobyCoord($coord) |
||
| 1891 | { |
||
| 1892 | $lst_countries = ''; |
||
| 1893 | View Code Duplication | if (is_array($coord)) { |
|
| 1894 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1895 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1896 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1897 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1898 | } |
||
| 1899 | //$query = "SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong; |
||
| 1900 | $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.")"; |
||
| 1901 | //$query = "SELECT waypoints.* FROM waypoints"; |
||
| 1902 | //$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"; |
||
| 1903 | //$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; |
||
| 1904 | //$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; |
||
| 1905 | //echo $query; |
||
| 1906 | |||
| 1907 | $sth = $this->db->prepare($query); |
||
| 1908 | $sth->execute(); |
||
| 1909 | |||
| 1910 | $waypoints_array = array(); |
||
| 1911 | $temp_array = array(); |
||
| 1912 | |||
| 1913 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1914 | { |
||
| 1915 | $temp_array = $row; |
||
| 1916 | |||
| 1917 | $waypoints_array[] = $temp_array; |
||
| 1918 | } |
||
| 1919 | |||
| 1920 | return $waypoints_array; |
||
| 1921 | } |
||
| 1922 | |||
| 1923 | |||
| 1924 | /** |
||
| 1925 | * Gets the airline info based on the icao code or iata code |
||
| 1926 | * |
||
| 1927 | * @param String $airline_icao the iata code of the airport |
||
| 1928 | * @return Array airport information |
||
| 1929 | * |
||
| 1930 | */ |
||
| 1931 | public function getAllAirlineInfo($airline_icao) |
||
| 1932 | { |
||
| 1933 | $airline_icao = strtoupper(filter_var($airline_icao,FILTER_SANITIZE_STRING)); |
||
| 1934 | if ($airline_icao == 'NA') { |
||
| 1935 | $airline_array[] = array('name' => 'Not Available','iata' => 'NA', 'icao' => 'NA', 'callsign' => '', 'country' => 'NA', 'type' =>''); |
||
| 1936 | return $airline_array; |
||
| 1937 | } else { |
||
| 1938 | if (strlen($airline_icao) == 2) { |
||
| 1939 | $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' LIMIT 1"; |
||
| 1940 | } else { |
||
| 1941 | $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' LIMIT 1"; |
||
| 1942 | } |
||
| 1943 | |||
| 1944 | $sth = $this->db->prepare($query); |
||
| 1945 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 1946 | /* |
||
| 1947 | $airline_array = array(); |
||
| 1948 | $temp_array = array(); |
||
| 1949 | |||
| 1950 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1951 | { |
||
| 1952 | $temp_array['name'] = $row['name']; |
||
| 1953 | $temp_array['iata'] = $row['iata']; |
||
| 1954 | $temp_array['icao'] = $row['icao']; |
||
| 1955 | $temp_array['callsign'] = $row['callsign']; |
||
| 1956 | $temp_array['country'] = $row['country']; |
||
| 1957 | $temp_array['type'] = $row['type']; |
||
| 1958 | $airline_array[] = $temp_array; |
||
| 1959 | } |
||
| 1960 | return $airline_array; |
||
| 1961 | */ |
||
| 1962 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 1963 | } |
||
| 1964 | } |
||
| 1965 | |||
| 1966 | |||
| 1967 | |||
| 1968 | /** |
||
| 1969 | * Gets the aircraft info based on the aircraft type |
||
| 1970 | * |
||
| 1971 | * @param String $aircraft_type the aircraft type |
||
| 1972 | * @return Array aircraft information |
||
| 1973 | * |
||
| 1974 | */ |
||
| 1975 | public function getAllAircraftInfo($aircraft_type) |
||
| 1976 | { |
||
| 1977 | $aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING); |
||
| 1978 | |||
| 1979 | if ($aircraft_type == 'NA') { |
||
| 1980 | return array(array('icao' => 'NA','type' => 'Not Available', 'manufacturer' => 'Not Available', 'aircraft_shadow' => NULL)); |
||
| 1981 | } |
||
| 1982 | $query = "SELECT aircraft.icao, aircraft.type,aircraft.manufacturer,aircraft.aircraft_shadow FROM aircraft WHERE aircraft.icao = :aircraft_type"; |
||
| 1983 | |||
| 1984 | $sth = $this->db->prepare($query); |
||
| 1985 | $sth->execute(array(':aircraft_type' => $aircraft_type)); |
||
| 1986 | /* |
||
| 1987 | $aircraft_array = array(); |
||
| 1988 | $temp_array = array(); |
||
| 1989 | |||
| 1990 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 1991 | { |
||
| 1992 | $temp_array = array(); |
||
| 1993 | $temp_array['icao'] = $row['icao']; |
||
| 1994 | $temp_array['type'] = $row['type']; |
||
| 1995 | $temp_array['manufacturer'] = $row['manufacturer']; |
||
| 1996 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
| 1997 | |||
| 1998 | $aircraft_array[] = $temp_array; |
||
| 1999 | } |
||
| 2000 | return $aircraft_array; |
||
| 2001 | */ |
||
| 2002 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2003 | } |
||
| 2004 | |||
| 2005 | /** |
||
| 2006 | * Gets the aircraft info based on the aircraft ident |
||
| 2007 | * |
||
| 2008 | * @param String $aircraft_ident the aircraft ident (hex) |
||
| 2009 | * @return String aircraft type |
||
| 2010 | * |
||
| 2011 | */ |
||
| 2012 | View Code Duplication | public function getAllAircraftType($aircraft_modes) |
|
| 2013 | { |
||
| 2014 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 2015 | |||
| 2016 | $query = "SELECT aircraft_modes.ICAOTypeCode FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1"; |
||
| 2017 | |||
| 2018 | $sth = $this->db->prepare($query); |
||
| 2019 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 2020 | |||
| 2021 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2022 | if (isset($row['icaotypecode'])) { |
||
| 2023 | return $row['icaotypecode']; |
||
| 2024 | } else return ''; |
||
| 2025 | } |
||
| 2026 | |||
| 2027 | /** |
||
| 2028 | * Gets correct aircraft operator corde |
||
| 2029 | * |
||
| 2030 | * @param String $operator the aircraft operator code (callsign) |
||
| 2031 | * @return String aircraft operator code |
||
| 2032 | * |
||
| 2033 | */ |
||
| 2034 | View Code Duplication | public function getOperator($operator) |
|
| 2035 | { |
||
| 2036 | $operator = filter_var($operator,FILTER_SANITIZE_STRING); |
||
| 2037 | $query = "SELECT translation.operator_correct FROM translation WHERE translation.operator = :operator LIMIT 1"; |
||
| 2038 | |||
| 2039 | $sth = $this->db->prepare($query); |
||
| 2040 | $sth->execute(array(':operator' => $operator)); |
||
| 2041 | |||
| 2042 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2043 | if (isset($row['operator_correct'])) { |
||
| 2044 | return $row['operator_correct']; |
||
| 2045 | } else return $operator; |
||
| 2046 | } |
||
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Gets the aircraft route based on the aircraft callsign |
||
| 2050 | * |
||
| 2051 | * @param String $callsign the aircraft callsign |
||
| 2052 | * @return Array aircraft type |
||
| 2053 | * |
||
| 2054 | */ |
||
| 2055 | public function getRouteInfo($callsign) |
||
| 2056 | { |
||
| 2057 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
| 2058 | if ($callsign == '') return array(); |
||
| 2059 | $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"; |
||
| 2060 | |||
| 2061 | $sth = $this->db->prepare($query); |
||
| 2062 | $sth->execute(array(':callsign' => $callsign)); |
||
| 2063 | |||
| 2064 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2065 | if (count($row) > 0) { |
||
| 2066 | return $row; |
||
| 2067 | } else return array(); |
||
| 2068 | } |
||
| 2069 | |||
| 2070 | /** |
||
| 2071 | * Gets the aircraft info based on the aircraft registration |
||
| 2072 | * |
||
| 2073 | * @param String $aircraft_registration the aircraft registration |
||
| 2074 | * @return Array aircraft information |
||
| 2075 | * |
||
| 2076 | */ |
||
| 2077 | View Code Duplication | public function getAircraftInfoByRegistration($registration) |
|
| 2078 | { |
||
| 2079 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2080 | |||
| 2081 | $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"; |
||
| 2082 | |||
| 2083 | $sth = $this->db->prepare($query); |
||
| 2084 | $sth->execute(array(':registration' => $registration)); |
||
| 2085 | |||
| 2086 | $aircraft_array = array(); |
||
| 2087 | $temp_array = array(); |
||
| 2088 | |||
| 2089 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2090 | { |
||
| 2091 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 2092 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 2093 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2094 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2095 | |||
| 2096 | $aircraft_array[] = $temp_array; |
||
| 2097 | } |
||
| 2098 | |||
| 2099 | return $aircraft_array; |
||
| 2100 | } |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Gets the aircraft owner & base based on the aircraft registration |
||
| 2104 | * |
||
| 2105 | * @param String $aircraft_registration the aircraft registration |
||
| 2106 | * @return Array aircraft information |
||
| 2107 | * |
||
| 2108 | */ |
||
| 2109 | public function getAircraftOwnerByRegistration($registration) |
||
| 2110 | { |
||
| 2111 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 2112 | $Connection = new Connection($this->db); |
||
| 2113 | if ($Connection->tableExists('aircraft_owner')) { |
||
| 2114 | $query = "SELECT aircraft_owner.base, aircraft_owner.owner, aircraft_owner.date_first_reg FROM aircraft_owner WHERE registration = :registration LIMIT 1"; |
||
| 2115 | $sth = $this->db->prepare($query); |
||
| 2116 | $sth->execute(array(':registration' => $registration)); |
||
| 2117 | |||
| 2118 | return $sth->fetch(PDO::FETCH_ASSOC); |
||
| 2119 | } else return array(); |
||
| 2120 | } |
||
| 2121 | |||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Gets all flights (but with only little info) |
||
| 2125 | * |
||
| 2126 | * @return Array basic flight information |
||
| 2127 | * |
||
| 2128 | */ |
||
| 2129 | public function getAllFlightsforSitemap() |
||
| 2130 | { |
||
| 2131 | //$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 "; |
||
| 2132 | $query = "SELECT spotter_output.spotter_id FROM spotter_output ORDER BY spotter_id DESC LIMIT 200 OFFSET 0"; |
||
| 2133 | |||
| 2134 | $sth = $this->db->prepare($query); |
||
| 2135 | $sth->execute(); |
||
| 2136 | /* |
||
| 2137 | $flight_array = array(); |
||
| 2138 | $temp_array = array(); |
||
| 2139 | |||
| 2140 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2141 | { |
||
| 2142 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 2143 | // $temp_array['ident'] = $row['ident']; |
||
| 2144 | // $temp_array['airline_name'] = $row['airline_name']; |
||
| 2145 | // $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
| 2146 | // $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2147 | //$temp_array['image'] = $row['image']; |
||
| 2148 | |||
| 2149 | $flight_array[] = $temp_array; |
||
| 2150 | } |
||
| 2151 | |||
| 2152 | return $flight_array; |
||
| 2153 | */ |
||
| 2154 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2155 | } |
||
| 2156 | |||
| 2157 | /** |
||
| 2158 | * Gets a list of all aircraft manufacturers |
||
| 2159 | * |
||
| 2160 | * @return Array list of aircraft types |
||
| 2161 | * |
||
| 2162 | */ |
||
| 2163 | View Code Duplication | public function getAllManufacturers() |
|
| 2164 | { |
||
| 2165 | /* |
||
| 2166 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer AS aircraft_manufacturer |
||
| 2167 | FROM spotter_output |
||
| 2168 | WHERE spotter_output.aircraft_manufacturer <> '' |
||
| 2169 | ORDER BY spotter_output.aircraft_manufacturer ASC"; |
||
| 2170 | */ |
||
| 2171 | |||
| 2172 | $query = "SELECT DISTINCT manufacturer AS aircraft_manufacturer FROM aircraft WHERE manufacturer <> '' ORDER BY manufacturer ASC"; |
||
| 2173 | $sth = $this->db->prepare($query); |
||
| 2174 | $sth->execute(); |
||
| 2175 | |||
| 2176 | $manufacturer_array = array(); |
||
| 2177 | $temp_array = array(); |
||
| 2178 | |||
| 2179 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2180 | { |
||
| 2181 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2182 | |||
| 2183 | $manufacturer_array[] = $temp_array; |
||
| 2184 | } |
||
| 2185 | |||
| 2186 | return $manufacturer_array; |
||
| 2187 | } |
||
| 2188 | |||
| 2189 | |||
| 2190 | /** |
||
| 2191 | * Gets a list of all aircraft types |
||
| 2192 | * |
||
| 2193 | * @return Array list of aircraft types |
||
| 2194 | * |
||
| 2195 | */ |
||
| 2196 | View Code Duplication | public function getAllAircraftTypes() |
|
| 2197 | { |
||
| 2198 | /* |
||
| 2199 | $query = "SELECT DISTINCT spotter_output.aircraft_icao AS aircraft_icao, spotter_output.aircraft_name AS aircraft_name |
||
| 2200 | FROM spotter_output |
||
| 2201 | WHERE spotter_output.aircraft_icao <> '' |
||
| 2202 | ORDER BY spotter_output.aircraft_name ASC"; |
||
| 2203 | |||
| 2204 | */ |
||
| 2205 | $query = "SELECT DISTINCT icao AS aircraft_icao, type AS aircraft_name, manufacturer AS aircraft_manufacturer FROM aircraft WHERE icao <> '' ORDER BY aircraft_name ASC"; |
||
| 2206 | |||
| 2207 | $sth = $this->db->prepare($query); |
||
| 2208 | $sth->execute(); |
||
| 2209 | |||
| 2210 | $aircraft_array = array(); |
||
| 2211 | $temp_array = array(); |
||
| 2212 | |||
| 2213 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2214 | { |
||
| 2215 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 2216 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 2217 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 2218 | |||
| 2219 | $aircraft_array[] = $temp_array; |
||
| 2220 | } |
||
| 2221 | |||
| 2222 | return $aircraft_array; |
||
| 2223 | } |
||
| 2224 | |||
| 2225 | |||
| 2226 | /** |
||
| 2227 | * Gets a list of all aircraft registrations |
||
| 2228 | * |
||
| 2229 | * @return Array list of aircraft registrations |
||
| 2230 | * |
||
| 2231 | */ |
||
| 2232 | View Code Duplication | public function getAllAircraftRegistrations() |
|
| 2233 | { |
||
| 2234 | $query = "SELECT DISTINCT spotter_output.registration |
||
| 2235 | FROM spotter_output |
||
| 2236 | WHERE spotter_output.registration <> '' |
||
| 2237 | ORDER BY spotter_output.registration ASC"; |
||
| 2238 | |||
| 2239 | $sth = $this->db->prepare($query); |
||
| 2240 | $sth->execute(); |
||
| 2241 | |||
| 2242 | $aircraft_array = array(); |
||
| 2243 | $temp_array = array(); |
||
| 2244 | |||
| 2245 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2246 | { |
||
| 2247 | $temp_array['registration'] = $row['registration']; |
||
| 2248 | |||
| 2249 | $aircraft_array[] = $temp_array; |
||
| 2250 | } |
||
| 2251 | |||
| 2252 | return $aircraft_array; |
||
| 2253 | } |
||
| 2254 | |||
| 2255 | /** |
||
| 2256 | * Gets all source name |
||
| 2257 | * |
||
| 2258 | * @param String type format of source |
||
| 2259 | * @return Array list of source name |
||
| 2260 | * |
||
| 2261 | */ |
||
| 2262 | public function getAllSourceName($type = '') |
||
| 2263 | { |
||
| 2264 | $query_values = array(); |
||
| 2265 | $query = "SELECT DISTINCT spotter_output.source_name |
||
| 2266 | FROM spotter_output |
||
| 2267 | WHERE spotter_output.source_name <> ''"; |
||
| 2268 | if ($type != '') { |
||
| 2269 | $query_values = array(':type' => $type); |
||
| 2270 | $query .= " AND format_source = :type"; |
||
| 2271 | } |
||
| 2272 | $query .= " ORDER BY spotter_output.source_name ASC"; |
||
| 2273 | |||
| 2274 | $sth = $this->db->prepare($query); |
||
| 2275 | if (!empty($query_values)) $sth->execute($query_values); |
||
| 2276 | else $sth->execute(); |
||
| 2277 | |||
| 2278 | $source_array = array(); |
||
| 2279 | $temp_array = array(); |
||
| 2280 | |||
| 2281 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2282 | { |
||
| 2283 | $temp_array['source_name'] = $row['source_name']; |
||
| 2284 | $source_array[] = $temp_array; |
||
| 2285 | } |
||
| 2286 | return $source_array; |
||
| 2287 | } |
||
| 2288 | |||
| 2289 | |||
| 2290 | |||
| 2291 | /** |
||
| 2292 | * Gets a list of all airline names |
||
| 2293 | * |
||
| 2294 | * @return Array list of airline names |
||
| 2295 | * |
||
| 2296 | */ |
||
| 2297 | public function getAllAirlineNames($airline_type = '') |
||
| 2298 | { |
||
| 2299 | $airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING); |
||
| 2300 | if ($airline_type == '' || $airline_type == 'all') { |
||
| 2301 | /* |
||
| 2302 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
| 2303 | FROM spotter_output |
||
| 2304 | WHERE spotter_output.airline_icao <> '' |
||
| 2305 | ORDER BY spotter_output.airline_name ASC"; |
||
| 2306 | */ |
||
| 2307 | $query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines ORDER BY name ASC"; |
||
| 2308 | } else { |
||
| 2309 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
| 2310 | FROM spotter_output |
||
| 2311 | WHERE spotter_output.airline_icao <> '' |
||
| 2312 | AND spotter_output.airline_type = :airline_type |
||
| 2313 | ORDER BY spotter_output.airline_icao ASC"; |
||
| 2314 | } |
||
| 2315 | |||
| 2316 | $sth = $this->db->prepare($query); |
||
| 2317 | if ($airline_type != '' || $airline_type == 'all') { |
||
| 2318 | $sth->execute(array(':airline_type' => $airline_type)); |
||
| 2319 | } else { |
||
| 2320 | $sth->execute(); |
||
| 2321 | } |
||
| 2322 | |||
| 2323 | $airline_array = array(); |
||
| 2324 | $temp_array = array(); |
||
| 2325 | |||
| 2326 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2327 | { |
||
| 2328 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 2329 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 2330 | $temp_array['airline_type'] = $row['airline_type']; |
||
| 2331 | |||
| 2332 | $airline_array[] = $temp_array; |
||
| 2333 | } |
||
| 2334 | return $airline_array; |
||
| 2335 | } |
||
| 2336 | |||
| 2337 | |||
| 2338 | /** |
||
| 2339 | * Gets a list of all airline countries |
||
| 2340 | * |
||
| 2341 | * @return Array list of airline countries |
||
| 2342 | * |
||
| 2343 | */ |
||
| 2344 | View Code Duplication | public function getAllAirlineCountries() |
|
| 2345 | { |
||
| 2346 | |||
| 2347 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
| 2348 | FROM spotter_output |
||
| 2349 | WHERE spotter_output.airline_country <> '' |
||
| 2350 | ORDER BY spotter_output.airline_country ASC"; |
||
| 2351 | |||
| 2352 | //$query = "SELECT DISTINCT country AS airline_country FROM airlines WHERE country <> '' AND active = 'Y' ORDER BY country ASC"; |
||
| 2353 | $sth = $this->db->prepare($query); |
||
| 2354 | $sth->execute(); |
||
| 2355 | |||
| 2356 | $airline_array = array(); |
||
| 2357 | $temp_array = array(); |
||
| 2358 | |||
| 2359 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2360 | { |
||
| 2361 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 2362 | |||
| 2363 | $airline_array[] = $temp_array; |
||
| 2364 | } |
||
| 2365 | |||
| 2366 | return $airline_array; |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | |||
| 2370 | |||
| 2371 | /** |
||
| 2372 | * Gets a list of all departure & arrival names |
||
| 2373 | * |
||
| 2374 | * @return Array list of airport names |
||
| 2375 | * |
||
| 2376 | */ |
||
| 2377 | public function getAllAirportNames() |
||
| 2378 | { |
||
| 2379 | $airport_array = array(); |
||
| 2380 | |||
| 2381 | $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 |
||
| 2382 | FROM spotter_output |
||
| 2383 | WHERE spotter_output.departure_airport_icao <> '' AND spotter_output.departure_airport_icao <> 'NA' |
||
| 2384 | ORDER BY spotter_output.departure_airport_city ASC"; |
||
| 2385 | |||
| 2386 | //$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"; |
||
| 2387 | $sth = $this->db->prepare($query); |
||
| 2388 | $sth->execute(); |
||
| 2389 | |||
| 2390 | $temp_array = array(); |
||
| 2391 | View Code Duplication | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 2392 | { |
||
| 2393 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
| 2394 | $temp_array['airport_name'] = $row['airport_name']; |
||
| 2395 | $temp_array['airport_city'] = $row['airport_city']; |
||
| 2396 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2397 | |||
| 2398 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
| 2399 | } |
||
| 2400 | |||
| 2401 | $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 |
||
| 2402 | FROM spotter_output |
||
| 2403 | WHERE spotter_output.arrival_airport_icao <> '' AND spotter_output.arrival_airport_icao <> 'NA' |
||
| 2404 | ORDER BY spotter_output.arrival_airport_city ASC"; |
||
| 2405 | |||
| 2406 | $sth = $this->db->prepare($query); |
||
| 2407 | $sth->execute(); |
||
| 2408 | |||
| 2409 | View Code Duplication | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 2410 | { |
||
| 2411 | // if ($airport_array[$row['airport_city'].",".$row['airport_name']]['airport_icao'] != $row['airport_icao']) |
||
| 2412 | // { |
||
| 2413 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
| 2414 | $temp_array['airport_name'] = $row['airport_name']; |
||
| 2415 | $temp_array['airport_city'] = $row['airport_city']; |
||
| 2416 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2417 | |||
| 2418 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
| 2419 | // } |
||
| 2420 | } |
||
| 2421 | |||
| 2422 | return $airport_array; |
||
| 2423 | } |
||
| 2424 | |||
| 2425 | |||
| 2426 | /** |
||
| 2427 | * Gets a list of all departure & arrival airport countries |
||
| 2428 | * |
||
| 2429 | * @return Array list of airport countries |
||
| 2430 | * |
||
| 2431 | */ |
||
| 2432 | public function getAllAirportCountries() |
||
| 2433 | { |
||
| 2434 | $airport_array = array(); |
||
| 2435 | |||
| 2436 | /* |
||
| 2437 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
| 2438 | FROM spotter_output |
||
| 2439 | WHERE spotter_output.departure_airport_country <> '' |
||
| 2440 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
| 2441 | */ |
||
| 2442 | $query = "SELECT DISTINCT country AS airport_country FROM airport ORDER BY country ASC"; |
||
| 2443 | |||
| 2444 | $sth = $this->db->prepare($query); |
||
| 2445 | $sth->execute(); |
||
| 2446 | |||
| 2447 | $temp_array = array(); |
||
| 2448 | |||
| 2449 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2450 | { |
||
| 2451 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2452 | |||
| 2453 | $airport_array[$row['airport_country']] = $temp_array; |
||
| 2454 | } |
||
| 2455 | |||
| 2456 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
| 2457 | FROM spotter_output |
||
| 2458 | WHERE spotter_output.arrival_airport_country <> '' |
||
| 2459 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
| 2460 | |||
| 2461 | $sth = $this->db->prepare($query); |
||
| 2462 | $sth->execute(); |
||
| 2463 | |||
| 2464 | View Code Duplication | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 2465 | { |
||
| 2466 | if (isset($airport_array[$row['airport_country']]['airport_country']) && $airport_array[$row['airport_country']]['airport_country'] != $row['airport_country']) |
||
| 2467 | { |
||
| 2468 | $temp_array['airport_country'] = $row['airport_country']; |
||
| 2469 | |||
| 2470 | $airport_array[$row['airport_country']] = $temp_array; |
||
| 2471 | } |
||
| 2472 | } |
||
| 2473 | |||
| 2474 | return $airport_array; |
||
| 2475 | } |
||
| 2476 | |||
| 2477 | |||
| 2478 | |||
| 2479 | |||
| 2480 | /** |
||
| 2481 | * Gets a list of all countries (airline, departure airport & arrival airport) |
||
| 2482 | * |
||
| 2483 | * @return Array list of countries |
||
| 2484 | * |
||
| 2485 | */ |
||
| 2486 | public function getAllCountries() |
||
| 2487 | { |
||
| 2488 | $Connection= new Connection($this->db); |
||
| 2489 | if ($Connection->tableExists('countries')) { |
||
| 2490 | |||
| 2491 | $country_array = array(); |
||
| 2492 | |||
| 2493 | $query = "SELECT countries.name AS airport_country |
||
| 2494 | FROM countries |
||
| 2495 | ORDER BY countries.name ASC"; |
||
| 2496 | $sth = $this->db->prepare($query); |
||
| 2497 | $sth->execute(); |
||
| 2498 | |||
| 2499 | $temp_array = array(); |
||
| 2500 | |||
| 2501 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2502 | { |
||
| 2503 | $temp_array['country'] = $row['airport_country']; |
||
| 2504 | |||
| 2505 | $country_array[$row['airport_country']] = $temp_array; |
||
| 2506 | } |
||
| 2507 | } else { |
||
| 2508 | |||
| 2509 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
| 2510 | FROM spotter_output |
||
| 2511 | WHERE spotter_output.departure_airport_country <> '' |
||
| 2512 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
| 2513 | |||
| 2514 | $sth = $this->db->prepare($query); |
||
| 2515 | $sth->execute(); |
||
| 2516 | |||
| 2517 | $temp_array = array(); |
||
| 2518 | |||
| 2519 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2520 | { |
||
| 2521 | $temp_array['country'] = $row['airport_country']; |
||
| 2522 | |||
| 2523 | $country_array[$row['airport_country']] = $temp_array; |
||
| 2524 | } |
||
| 2525 | |||
| 2526 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
| 2527 | FROM spotter_output |
||
| 2528 | WHERE spotter_output.arrival_airport_country <> '' |
||
| 2529 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
| 2530 | |||
| 2531 | $sth = $this->db->prepare($query); |
||
| 2532 | $sth->execute(); |
||
| 2533 | |||
| 2534 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2535 | { |
||
| 2536 | if ($country_array[$row['airport_country']]['country'] != $row['airport_country']) |
||
| 2537 | { |
||
| 2538 | $temp_array['country'] = $row['airport_country']; |
||
| 2539 | |||
| 2540 | $country_array[$row['country']] = $temp_array; |
||
| 2541 | } |
||
| 2542 | } |
||
| 2543 | |||
| 2544 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
| 2545 | FROM spotter_output |
||
| 2546 | WHERE spotter_output.airline_country <> '' |
||
| 2547 | ORDER BY spotter_output.airline_country ASC"; |
||
| 2548 | |||
| 2549 | $sth = $this->db->prepare($query); |
||
| 2550 | $sth->execute(); |
||
| 2551 | |||
| 2552 | View Code Duplication | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 2553 | { |
||
| 2554 | if (isset($country_array[$row['airline_country']]['country']) && $country_array[$row['airline_country']]['country'] != $row['airline_country']) |
||
| 2555 | { |
||
| 2556 | $temp_array['country'] = $row['airline_country']; |
||
| 2557 | |||
| 2558 | $country_array[$row['country']] = $temp_array; |
||
| 2559 | } |
||
| 2560 | } |
||
| 2561 | } |
||
| 2562 | return $country_array; |
||
| 2563 | } |
||
| 2564 | |||
| 2565 | |||
| 2566 | |||
| 2567 | |||
| 2568 | /** |
||
| 2569 | * Gets a list of all idents/callsigns |
||
| 2570 | * |
||
| 2571 | * @return Array list of ident/callsign names |
||
| 2572 | * |
||
| 2573 | */ |
||
| 2574 | View Code Duplication | public function getAllIdents() |
|
| 2575 | { |
||
| 2576 | $query = "SELECT DISTINCT spotter_output.ident |
||
| 2577 | FROM spotter_output |
||
| 2578 | WHERE spotter_output.ident <> '' |
||
| 2579 | ORDER BY spotter_output.date ASC LIMIT 700 OFFSET 0"; |
||
| 2580 | |||
| 2581 | $sth = $this->db->prepare($query); |
||
| 2582 | $sth->execute(); |
||
| 2583 | |||
| 2584 | $ident_array = array(); |
||
| 2585 | $temp_array = array(); |
||
| 2586 | |||
| 2587 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2588 | { |
||
| 2589 | $temp_array['ident'] = $row['ident']; |
||
| 2590 | $ident_array[] = $temp_array; |
||
| 2591 | } |
||
| 2592 | |||
| 2593 | return $ident_array; |
||
| 2594 | } |
||
| 2595 | |||
| 2596 | /** |
||
| 2597 | * Get a list of flights from airport since 7 days |
||
| 2598 | * @return Array number, icao, name and city of airports |
||
| 2599 | */ |
||
| 2600 | |||
| 2601 | View Code Duplication | public function getLast7DaysAirportsDeparture($airport_icao = '') { |
|
| 2602 | global $globalTimezone, $globalDBdriver; |
||
| 2603 | if ($globalTimezone != '') { |
||
| 2604 | date_default_timezone_set($globalTimezone); |
||
| 2605 | $datetime = new DateTime(); |
||
| 2606 | $offset = $datetime->format('P'); |
||
| 2607 | } else $offset = '+00:00'; |
||
| 2608 | if ($airport_icao == '') { |
||
| 2609 | if ($globalDBdriver == 'mysql') { |
||
| 2610 | $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` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' 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"; |
||
| 2611 | } else { |
||
| 2612 | $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 WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' 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"; |
||
| 2613 | } |
||
| 2614 | $sth = $this->db->prepare($query); |
||
| 2615 | $sth->execute(array(':offset' => $offset)); |
||
| 2616 | } else { |
||
| 2617 | if ($globalDBdriver == 'mysql') { |
||
| 2618 | $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` WHERE 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"; |
||
| 2619 | } else { |
||
| 2620 | $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 WHERE 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"; |
||
| 2621 | } |
||
| 2622 | $sth = $this->db->prepare($query); |
||
| 2623 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 2624 | } |
||
| 2625 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2626 | } |
||
| 2627 | |||
| 2628 | /** |
||
| 2629 | * Get a list of flights from detected airport since 7 days |
||
| 2630 | * @return Array number, icao, name and city of airports |
||
| 2631 | */ |
||
| 2632 | |||
| 2633 | View Code Duplication | public function getLast7DaysDetectedAirportsDeparture($airport_icao = '') { |
|
| 2634 | global $globalTimezone, $globalDBdriver; |
||
| 2635 | if ($globalTimezone != '') { |
||
| 2636 | date_default_timezone_set($globalTimezone); |
||
| 2637 | $datetime = new DateTime(); |
||
| 2638 | $offset = $datetime->format('P'); |
||
| 2639 | } else $offset = '+00:00'; |
||
| 2640 | if ($airport_icao == '') { |
||
| 2641 | if ($globalDBdriver == 'mysql') { |
||
| 2642 | $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 |
||
| 2643 | FROM `spotter_output`, airport |
||
| 2644 | WHERE 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' |
||
| 2645 | 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"; |
||
| 2646 | } else { |
||
| 2647 | $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 |
||
| 2648 | FROM spotter_output, airport |
||
| 2649 | WHERE 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' |
||
| 2650 | 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"; |
||
| 2651 | } |
||
| 2652 | $sth = $this->db->prepare($query); |
||
| 2653 | $sth->execute(array(':offset' => $offset)); |
||
| 2654 | } else { |
||
| 2655 | if ($globalDBdriver == 'mysql') { |
||
| 2656 | $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 |
||
| 2657 | FROM `spotter_output`, airport |
||
| 2658 | WHERE 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 |
||
| 2659 | 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"; |
||
| 2660 | } else { |
||
| 2661 | $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 |
||
| 2662 | FROM spotter_output, airport |
||
| 2663 | WHERE 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"; |
||
| 2664 | } |
||
| 2665 | $sth = $this->db->prepare($query); |
||
| 2666 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 2667 | } |
||
| 2668 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2669 | } |
||
| 2670 | |||
| 2671 | /** |
||
| 2672 | * Get a list of flights to airport since 7 days |
||
| 2673 | * @return Array number, icao, name and city of airports |
||
| 2674 | */ |
||
| 2675 | |||
| 2676 | View Code Duplication | public function getLast7DaysAirportsArrival($airport_icao = '') { |
|
| 2677 | global $globalTimezone, $globalDBdriver; |
||
| 2678 | if ($globalTimezone != '') { |
||
| 2679 | date_default_timezone_set($globalTimezone); |
||
| 2680 | $datetime = new DateTime(); |
||
| 2681 | $offset = $datetime->format('P'); |
||
| 2682 | } else $offset = '+00:00'; |
||
| 2683 | if ($airport_icao == '') { |
||
| 2684 | if ($globalDBdriver == 'mysql') { |
||
| 2685 | $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` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' 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"; |
||
| 2686 | } else { |
||
| 2687 | $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 WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' 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"; |
||
| 2688 | } |
||
| 2689 | $sth = $this->db->prepare($query); |
||
| 2690 | $sth->execute(array(':offset' => $offset)); |
||
| 2691 | } else { |
||
| 2692 | if ($globalDBdriver == 'mysql') { |
||
| 2693 | $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` WHERE 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"; |
||
| 2694 | } else { |
||
| 2695 | $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 WHERE 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"; |
||
| 2696 | } |
||
| 2697 | $sth = $this->db->prepare($query); |
||
| 2698 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 2699 | } |
||
| 2700 | |||
| 2701 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2702 | } |
||
| 2703 | |||
| 2704 | |||
| 2705 | /** |
||
| 2706 | * Get a list of flights detected to airport since 7 days |
||
| 2707 | * @return Array number, icao, name and city of airports |
||
| 2708 | */ |
||
| 2709 | |||
| 2710 | View Code Duplication | public function getLast7DaysDetectedAirportsArrival($airport_icao = '') { |
|
| 2711 | global $globalTimezone, $globalDBdriver; |
||
| 2712 | if ($globalTimezone != '') { |
||
| 2713 | date_default_timezone_set($globalTimezone); |
||
| 2714 | $datetime = new DateTime(); |
||
| 2715 | $offset = $datetime->format('P'); |
||
| 2716 | } else $offset = '+00:00'; |
||
| 2717 | if ($airport_icao == '') { |
||
| 2718 | if ($globalDBdriver == 'mysql') { |
||
| 2719 | $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 |
||
| 2720 | FROM `spotter_output`, airport |
||
| 2721 | WHERE airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' |
||
| 2722 | 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"; |
||
| 2723 | } else { |
||
| 2724 | $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 |
||
| 2725 | FROM spotter_output, airport |
||
| 2726 | WHERE 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' |
||
| 2727 | 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"; |
||
| 2728 | } |
||
| 2729 | $sth = $this->db->prepare($query); |
||
| 2730 | $sth->execute(array(':offset' => $offset)); |
||
| 2731 | } else { |
||
| 2732 | if ($globalDBdriver == 'mysql') { |
||
| 2733 | $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 |
||
| 2734 | FROM `spotter_output`, airport |
||
| 2735 | WHERE 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 |
||
| 2736 | 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"; |
||
| 2737 | } else { |
||
| 2738 | $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 |
||
| 2739 | FROM spotter_output, airport |
||
| 2740 | WHERE 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 |
||
| 2741 | 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"; |
||
| 2742 | } |
||
| 2743 | $sth = $this->db->prepare($query); |
||
| 2744 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
| 2745 | } |
||
| 2746 | |||
| 2747 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 2748 | } |
||
| 2749 | |||
| 2750 | |||
| 2751 | /** |
||
| 2752 | * Gets a list of all dates |
||
| 2753 | * |
||
| 2754 | * @return Array list of date names |
||
| 2755 | * |
||
| 2756 | */ |
||
| 2757 | public function getAllDates() |
||
| 2758 | { |
||
| 2759 | global $globalTimezone, $globalDBdriver; |
||
| 2760 | if ($globalTimezone != '') { |
||
| 2761 | date_default_timezone_set($globalTimezone); |
||
| 2762 | $datetime = new DateTime(); |
||
| 2763 | $offset = $datetime->format('P'); |
||
| 2764 | } else $offset = '+00:00'; |
||
| 2765 | |||
| 2766 | if ($globalDBdriver == 'mysql') { |
||
| 2767 | $query = "SELECT DISTINCT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) as date |
||
| 2768 | FROM spotter_output |
||
| 2769 | WHERE spotter_output.date <> '' |
||
| 2770 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
| 2771 | } else { |
||
| 2772 | $query = "SELECT DISTINCT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
| 2773 | FROM spotter_output |
||
| 2774 | WHERE spotter_output.date <> '' |
||
| 2775 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
| 2776 | } |
||
| 2777 | |||
| 2778 | $sth = $this->db->prepare($query); |
||
| 2779 | $sth->execute(array(':offset' => $offset)); |
||
| 2780 | |||
| 2781 | $date_array = array(); |
||
| 2782 | $temp_array = array(); |
||
| 2783 | |||
| 2784 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2785 | { |
||
| 2786 | $temp_array['date'] = $row['date']; |
||
| 2787 | |||
| 2788 | $date_array[] = $temp_array; |
||
| 2789 | } |
||
| 2790 | |||
| 2791 | return $date_array; |
||
| 2792 | } |
||
| 2793 | |||
| 2794 | |||
| 2795 | |||
| 2796 | /** |
||
| 2797 | * Gets all route combinations |
||
| 2798 | * |
||
| 2799 | * @return Array the route list |
||
| 2800 | * |
||
| 2801 | */ |
||
| 2802 | View Code Duplication | public function getAllRoutes() |
|
| 2803 | { |
||
| 2804 | $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 |
||
| 2805 | FROM spotter_output |
||
| 2806 | WHERE spotter_output.ident <> '' |
||
| 2807 | GROUP BY route |
||
| 2808 | ORDER BY route ASC"; |
||
| 2809 | |||
| 2810 | $sth = $this->db->prepare($query); |
||
| 2811 | $sth->execute(); |
||
| 2812 | |||
| 2813 | $routes_array = array(); |
||
| 2814 | $temp_array = array(); |
||
| 2815 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 2816 | { |
||
| 2817 | $temp_array['route'] = $row['route']; |
||
| 2818 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 2819 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 2820 | |||
| 2821 | $routes_array[] = $temp_array; |
||
| 2822 | } |
||
| 2823 | return $routes_array; |
||
| 2824 | } |
||
| 2825 | |||
| 2826 | /** |
||
| 2827 | * Update ident spotter data |
||
| 2828 | * |
||
| 2829 | * @param String $flightaware_id the ID from flightaware |
||
| 2830 | * @param String $ident the flight ident |
||
| 2831 | * @return String success or false |
||
| 2832 | * |
||
| 2833 | */ |
||
| 2834 | public function updateIdentSpotterData($flightaware_id = '', $ident = '') |
||
| 2835 | { |
||
| 2836 | if (!is_numeric(substr($ident, 0, 3))) |
||
| 2837 | { |
||
| 2838 | View Code Duplication | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
| 2839 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2)); |
||
| 2840 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
| 2841 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3)); |
||
| 2842 | } else { |
||
| 2843 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2844 | } |
||
| 2845 | if (count($airline_array) == 0) { |
||
| 2846 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2847 | } |
||
| 2848 | View Code Duplication | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
|
| 2849 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2850 | } |
||
| 2851 | } else { |
||
| 2852 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2853 | } |
||
| 2854 | $airline_name = $airline_array[0]['name']; |
||
| 2855 | $airline_icao = $airline_array[0]['icao']; |
||
| 2856 | $airline_country = $airline_array[0]['country']; |
||
| 2857 | $airline_type = $airline_array[0]['type']; |
||
| 2858 | |||
| 2859 | |||
| 2860 | $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'; |
||
| 2861 | $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); |
||
| 2862 | |||
| 2863 | try { |
||
| 2864 | $sth = $this->db->prepare($query); |
||
| 2865 | $sth->execute($query_values); |
||
| 2866 | } catch (PDOException $e) { |
||
| 2867 | return "error : ".$e->getMessage(); |
||
| 2868 | } |
||
| 2869 | |||
| 2870 | return "success"; |
||
| 2871 | |||
| 2872 | } |
||
| 2873 | /** |
||
| 2874 | * Update latest spotter data |
||
| 2875 | * |
||
| 2876 | * @param String $flightaware_id the ID from flightaware |
||
| 2877 | * @param String $ident the flight ident |
||
| 2878 | * @param String $aircraft_icao the aircraft type |
||
| 2879 | * @param String $departure_airport_icao the departure airport |
||
| 2880 | * @param String $arrival_airport_icao the arrival airport |
||
| 2881 | * @return String success or false |
||
| 2882 | * |
||
| 2883 | */ |
||
| 2884 | public function updateLatestSpotterData($flightaware_id = '', $ident = '', $latitude = '', $longitude = '', $altitude = '', $ground = false, $groundspeed = NULL, $date = '', $arrival_airport_icao = '',$arrival_airport_time = '') |
||
| 2885 | { |
||
| 2886 | if ($groundspeed == '') $groundspeed = NULL; |
||
| 2887 | $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'; |
||
| 2888 | $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); |
||
| 2889 | |||
| 2890 | try { |
||
| 2891 | $sth = $this->db->prepare($query); |
||
| 2892 | $sth->execute($query_values); |
||
| 2893 | } catch (PDOException $e) { |
||
| 2894 | return "error : ".$e->getMessage(); |
||
| 2895 | } |
||
| 2896 | |||
| 2897 | return "success"; |
||
| 2898 | |||
| 2899 | } |
||
| 2900 | |||
| 2901 | /** |
||
| 2902 | * Adds a new spotter data |
||
| 2903 | * |
||
| 2904 | * @param String $flightaware_id the ID from flightaware |
||
| 2905 | * @param String $ident the flight ident |
||
| 2906 | * @param String $aircraft_icao the aircraft type |
||
| 2907 | * @param String $departure_airport_icao the departure airport |
||
| 2908 | * @param String $arrival_airport_icao the arrival airport |
||
| 2909 | * @return String success or false |
||
| 2910 | * |
||
| 2911 | */ |
||
| 2912 | 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 = '') |
||
| 2913 | { |
||
| 2914 | global $globalURL, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalDebugTimeElapsed; |
||
| 2915 | |||
| 2916 | //if (isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
||
| 2917 | $Image = new Image($this->db); |
||
| 2918 | $Common = new Common(); |
||
| 2919 | |||
| 2920 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
| 2921 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
| 2922 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
| 2923 | date_default_timezone_set('UTC'); |
||
| 2924 | |||
| 2925 | //getting the registration |
||
| 2926 | if ($flightaware_id != "" && $registration == '') |
||
| 2927 | { |
||
| 2928 | if (!is_string($flightaware_id)) |
||
| 2929 | { |
||
| 2930 | return false; |
||
| 2931 | } else { |
||
| 2932 | if ($ModeS != '') { |
||
| 2933 | $timeelapsed = microtime(true); |
||
| 2934 | $registration = $this->getAircraftRegistrationBymodeS($ModeS); |
||
| 2935 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2936 | View Code Duplication | } else { |
|
| 2937 | $myhex = explode('-',$flightaware_id); |
||
| 2938 | if (count($myhex) > 0) { |
||
| 2939 | $timeelapsed = microtime(true); |
||
| 2940 | $registration = $this->getAircraftRegistrationBymodeS($myhex[0]); |
||
| 2941 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2942 | } |
||
| 2943 | } |
||
| 2944 | } |
||
| 2945 | } |
||
| 2946 | |||
| 2947 | //getting the airline information |
||
| 2948 | if ($ident != "") |
||
| 2949 | { |
||
| 2950 | if (!is_string($ident)) |
||
| 2951 | { |
||
| 2952 | return false; |
||
| 2953 | } else { |
||
| 2954 | if (!is_numeric(substr($ident, 0, 3))) |
||
| 2955 | { |
||
| 2956 | $timeelapsed = microtime(true); |
||
| 2957 | View Code Duplication | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
| 2958 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2)); |
||
| 2959 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
| 2960 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3)); |
||
| 2961 | } else { |
||
| 2962 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2963 | } |
||
| 2964 | if (count($airline_array) == 0) { |
||
| 2965 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2966 | } |
||
| 2967 | View Code Duplication | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
|
| 2968 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2969 | } |
||
| 2970 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2971 | |||
| 2972 | } else { |
||
| 2973 | $timeelapsed = microtime(true); |
||
| 2974 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
| 2975 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2976 | } |
||
| 2977 | } |
||
| 2978 | } else $airline_array = array(); |
||
| 2979 | |||
| 2980 | //getting the aircraft information |
||
| 2981 | if ($aircraft_icao != "") |
||
| 2982 | { |
||
| 2983 | if (!is_string($aircraft_icao)) |
||
| 2984 | { |
||
| 2985 | return false; |
||
| 2986 | View Code Duplication | } else { |
|
| 2987 | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
||
| 2988 | { |
||
| 2989 | $timeelapsed = microtime(true); |
||
| 2990 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
| 2991 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2992 | } else { |
||
| 2993 | $timeelapsed = microtime(true); |
||
| 2994 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
| 2995 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 2996 | } |
||
| 2997 | } |
||
| 2998 | } else { |
||
| 2999 | if ($ModeS != '') { |
||
| 3000 | $timeelapsed = microtime(true); |
||
| 3001 | $aircraft_icao = $this->getAllAircraftType($ModeS); |
||
| 3002 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAircraftType : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3003 | View Code Duplication | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
|
| 3004 | { |
||
| 3005 | $timeelapsed = microtime(true); |
||
| 3006 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
| 3007 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3008 | } else { |
||
| 3009 | $timeelapsed = microtime(true); |
||
| 3010 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
| 3011 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3012 | } |
||
| 3013 | } |
||
| 3014 | } |
||
| 3015 | |||
| 3016 | //getting the departure airport information |
||
| 3017 | View Code Duplication | if ($departure_airport_icao != "") |
|
| 3018 | { |
||
| 3019 | if (!is_string($departure_airport_icao)) |
||
| 3020 | { |
||
| 3021 | return false; |
||
| 3022 | } else { |
||
| 3023 | $timeelapsed = microtime(true); |
||
| 3024 | $departure_airport_array = $this->getAllAirportInfo($departure_airport_icao); |
||
| 3025 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3026 | } |
||
| 3027 | } |
||
| 3028 | |||
| 3029 | //getting the arrival airport information |
||
| 3030 | View Code Duplication | if ($arrival_airport_icao != "") |
|
| 3031 | { |
||
| 3032 | if (!is_string($arrival_airport_icao)) |
||
| 3033 | { |
||
| 3034 | return false; |
||
| 3035 | } else { |
||
| 3036 | $timeelapsed = microtime(true); |
||
| 3037 | $arrival_airport_array = $this->getAllAirportInfo($arrival_airport_icao); |
||
| 3038 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3039 | } |
||
| 3040 | } |
||
| 3041 | |||
| 3042 | |||
| 3043 | if ($latitude != "") |
||
| 3044 | { |
||
| 3045 | if (!is_numeric($latitude)) |
||
| 3046 | { |
||
| 3047 | return false; |
||
| 3048 | } |
||
| 3049 | } |
||
| 3050 | |||
| 3051 | if ($longitude != "") |
||
| 3052 | { |
||
| 3053 | if (!is_numeric($longitude)) |
||
| 3054 | { |
||
| 3055 | return false; |
||
| 3056 | } |
||
| 3057 | } |
||
| 3058 | |||
| 3059 | if ($waypoints != "") |
||
| 3060 | { |
||
| 3061 | if (!is_string($waypoints)) |
||
| 3062 | { |
||
| 3063 | return false; |
||
| 3064 | } |
||
| 3065 | } |
||
| 3066 | |||
| 3067 | View Code Duplication | if ($altitude != "") |
|
| 3068 | { |
||
| 3069 | if (!is_numeric($altitude)) |
||
| 3070 | { |
||
| 3071 | return false; |
||
| 3072 | } |
||
| 3073 | } else $altitude = 0; |
||
| 3074 | |||
| 3075 | if ($heading != "") |
||
| 3076 | { |
||
| 3077 | if (!is_numeric($heading)) |
||
| 3078 | { |
||
| 3079 | return false; |
||
| 3080 | } |
||
| 3081 | } |
||
| 3082 | |||
| 3083 | if ($groundspeed != "") |
||
| 3084 | { |
||
| 3085 | if (!is_numeric($groundspeed)) |
||
| 3086 | { |
||
| 3087 | return false; |
||
| 3088 | } |
||
| 3089 | } |
||
| 3090 | |||
| 3091 | |||
| 3092 | if ($date == "") |
||
| 3093 | { |
||
| 3094 | $date = date("Y-m-d H:i:s", time()); |
||
| 3095 | } |
||
| 3096 | |||
| 3097 | //getting the aircraft image |
||
| 3098 | if (($registration != "" || $registration != 'NA') && !$globalIVAO && !$globalVATSIM && !$globalphpVMS) |
||
| 3099 | { |
||
| 3100 | $timeelapsed = microtime(true); |
||
| 3101 | $image_array = $Image->getSpotterImage($registration); |
||
| 3102 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getSpotterImage : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3103 | if (!isset($image_array[0]['registration'])) |
||
| 3104 | { |
||
| 3105 | //echo "Add image !!!! \n"; |
||
| 3106 | $Image->addSpotterImage($registration); |
||
| 3107 | } |
||
| 3108 | $timeelapsed = microtime(true); |
||
| 3109 | $owner_info = $this->getAircraftOwnerByRegistration($registration); |
||
| 3110 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftOwnerByRegistration : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3111 | if ($owner_info['owner'] != '') $aircraft_owner = ucwords(strtolower($owner_info['owner'])); |
||
| 3112 | } |
||
| 3113 | |||
| 3114 | if ($globalIVAO && $aircraft_icao != '') |
||
| 3115 | { |
||
| 3116 | if (isset($airline_array[0]['icao'])) $airline_icao = $airline_array[0]['icao']; |
||
| 3117 | else $airline_icao = ''; |
||
| 3118 | $image_array = $Image->getSpotterImage('',$aircraft_icao,$airline_icao); |
||
| 3119 | if (!isset($image_array[0]['registration'])) |
||
| 3120 | { |
||
| 3121 | //echo "Add image !!!! \n"; |
||
| 3122 | $Image->addSpotterImage('',$aircraft_icao,$airline_icao); |
||
| 3123 | } |
||
| 3124 | } |
||
| 3125 | |||
| 3126 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
| 3127 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 3128 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 3129 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 3130 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3131 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3132 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3133 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3134 | $waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
||
| 3135 | $altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3136 | $heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
||
| 3137 | $groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 3138 | $squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
||
| 3139 | $route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
||
| 3140 | $ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
||
| 3141 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
||
| 3142 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
| 3143 | $format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
||
| 3144 | $verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
||
| 3145 | |||
| 3146 | if (count($airline_array) == 0) |
||
| 3147 | { |
||
| 3148 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
| 3149 | } |
||
| 3150 | if (count($aircraft_array) == 0) |
||
| 3151 | { |
||
| 3152 | $aircraft_array = $this->getAllAircraftInfo('NA'); |
||
| 3153 | } |
||
| 3154 | if (count($departure_airport_array) == 0) |
||
| 3155 | { |
||
| 3156 | $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
| 3157 | } |
||
| 3158 | if (count($arrival_airport_array) == 0) |
||
| 3159 | { |
||
| 3160 | $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
| 3161 | } |
||
| 3162 | if ($registration == '') $registration = 'NA'; |
||
| 3163 | if ($squawk == '' || $Common->isInteger($squawk) == false) $squawk = NULL; |
||
| 3164 | if ($verticalrate == '' || $Common->isInteger($verticalrate) == false) $verticalrate = NULL; |
||
| 3165 | if ($heading == '' || $Common->isInteger($heading) == false) $heading = 0; |
||
| 3166 | if ($groundspeed == '' || $Common->isInteger($groundspeed) == false) $groundspeed = 0; |
||
| 3167 | if (!isset($aircraft_owner)) $aircraft_owner = NULL; |
||
| 3168 | $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) |
||
| 3169 | 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)"; |
||
| 3170 | |||
| 3171 | $airline_name = $airline_array[0]['name']; |
||
| 3172 | $airline_icao = $airline_array[0]['icao']; |
||
| 3173 | $airline_country = $airline_array[0]['country']; |
||
| 3174 | $airline_type = $airline_array[0]['type']; |
||
| 3175 | View Code Duplication | if ($airline_type == '') { |
|
| 3176 | $timeelapsed = microtime(true); |
||
| 3177 | $airline_type = $this->getAircraftTypeBymodeS($ModeS); |
||
| 3178 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftTypeBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 3179 | } |
||
| 3180 | if ($airline_type == null) $airline_type = ''; |
||
| 3181 | $aircraft_type = $aircraft_array[0]['type']; |
||
| 3182 | $aircraft_manufacturer = $aircraft_array[0]['manufacturer']; |
||
| 3183 | $departure_airport_name = $departure_airport_array[0]['name']; |
||
| 3184 | $departure_airport_city = $departure_airport_array[0]['city']; |
||
| 3185 | $departure_airport_country = $departure_airport_array[0]['country']; |
||
| 3186 | $arrival_airport_icao = $arrival_airport_icao; |
||
| 3187 | $arrival_airport_name = $arrival_airport_array[0]['name']; |
||
| 3188 | $arrival_airport_city = $arrival_airport_array[0]['city']; |
||
| 3189 | $arrival_airport_country = $arrival_airport_array[0]['country']; |
||
| 3190 | $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); |
||
| 3191 | |||
| 3192 | try { |
||
| 3193 | |||
| 3194 | $sth = $this->db->prepare($query); |
||
| 3195 | $sth->execute($query_values); |
||
| 3196 | $this->db = null; |
||
| 3197 | } catch (PDOException $e) { |
||
| 3198 | return "error : ".$e->getMessage(); |
||
| 3199 | } |
||
| 3200 | |||
| 3201 | return "success"; |
||
| 3202 | |||
| 3203 | } |
||
| 3204 | |||
| 3205 | |||
| 3206 | /** |
||
| 3207 | * Gets the aircraft ident within the last hour |
||
| 3208 | * |
||
| 3209 | * @return String the ident |
||
| 3210 | * |
||
| 3211 | */ |
||
| 3212 | View Code Duplication | public function getIdentFromLastHour($ident) |
|
| 3213 | { |
||
| 3214 | global $globalDBdriver, $globalTimezone; |
||
| 3215 | if ($globalDBdriver == 'mysql') { |
||
| 3216 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
| 3217 | WHERE spotter_output.ident = :ident |
||
| 3218 | AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
||
| 3219 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
| 3220 | $query_data = array(':ident' => $ident); |
||
| 3221 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 3222 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
| 3223 | WHERE spotter_output.ident = :ident |
||
| 3224 | AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
||
| 3225 | AND spotter_output.date < now() AT TIME ZONE 'UTC'"; |
||
| 3226 | $query_data = array(':ident' => $ident); |
||
| 3227 | } |
||
| 3228 | |||
| 3229 | $sth = $this->db->prepare($query); |
||
| 3230 | $sth->execute($query_data); |
||
| 3231 | $ident_result=''; |
||
| 3232 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3233 | { |
||
| 3234 | $ident_result = $row['ident']; |
||
| 3235 | } |
||
| 3236 | |||
| 3237 | return $ident_result; |
||
| 3238 | } |
||
| 3239 | |||
| 3240 | |||
| 3241 | /** |
||
| 3242 | * Gets the aircraft data from the last 20 seconds |
||
| 3243 | * |
||
| 3244 | * @return Array the spotter data |
||
| 3245 | * |
||
| 3246 | */ |
||
| 3247 | public function getRealTimeData($q = '') |
||
| 3248 | { |
||
| 3249 | global $globalDBdriver; |
||
| 3250 | $additional_query = ''; |
||
| 3251 | if ($q != "") |
||
| 3252 | { |
||
| 3253 | if (!is_string($q)) |
||
| 3254 | { |
||
| 3255 | return false; |
||
| 3256 | } else { |
||
| 3257 | $q_array = explode(" ", $q); |
||
| 3258 | foreach ($q_array as $q_item){ |
||
| 3259 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
| 3260 | $additional_query .= " AND ("; |
||
| 3261 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
| 3262 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
| 3263 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
| 3264 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
| 3265 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
| 3266 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
| 3267 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
| 3268 | $additional_query .= "(spotter_output.ident like '%".$q_item."%')"; |
||
| 3269 | $additional_query .= ")"; |
||
| 3270 | } |
||
| 3271 | } |
||
| 3272 | } |
||
| 3273 | if ($globalDBdriver == 'mysql') { |
||
| 3274 | $query = "SELECT spotter_output.* FROM spotter_output |
||
| 3275 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." |
||
| 3276 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
| 3277 | } else { |
||
| 3278 | $query = "SELECT spotter_output.* FROM spotter_output |
||
| 3279 | WHERE spotter_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." |
||
| 3280 | AND spotter_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
||
| 3281 | } |
||
| 3282 | $spotter_array = $this->getDataFromDB($query, array()); |
||
| 3283 | |||
| 3284 | return $spotter_array; |
||
| 3285 | } |
||
| 3286 | |||
| 3287 | |||
| 3288 | |||
| 3289 | /** |
||
| 3290 | * Gets all airlines that have flown over |
||
| 3291 | * |
||
| 3292 | * @return Array the airline list |
||
| 3293 | * |
||
| 3294 | */ |
||
| 3295 | View Code Duplication | public function countAllAirlines($limit = true, $olderthanmonths = 0, $sincedate = '') |
|
| 3296 | { |
||
| 3297 | global $globalDBdriver; |
||
| 3298 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3299 | FROM spotter_output |
||
| 3300 | WHERE spotter_output.airline_name <> '' AND spotter_output.airline_icao <> 'NA' "; |
||
| 3301 | if ($olderthanmonths > 0) { |
||
| 3302 | if ($globalDBdriver == 'mysql') { |
||
| 3303 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 3304 | } else { |
||
| 3305 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 3306 | } |
||
| 3307 | } |
||
| 3308 | if ($sincedate != '') { |
||
| 3309 | if ($globalDBdriver == 'mysql') { |
||
| 3310 | $query .= "AND date > '".$sincedate."' "; |
||
| 3311 | } else { |
||
| 3312 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 3313 | } |
||
| 3314 | } |
||
| 3315 | $query .= "GROUP BY spotter_output.airline_name,spotter_output.airline_icao, spotter_output.airline_country ORDER BY airline_count DESC"; |
||
| 3316 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 3317 | |||
| 3318 | |||
| 3319 | $sth = $this->db->prepare($query); |
||
| 3320 | $sth->execute(); |
||
| 3321 | |||
| 3322 | $airline_array = array(); |
||
| 3323 | $temp_array = array(); |
||
| 3324 | |||
| 3325 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3326 | { |
||
| 3327 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3328 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3329 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3330 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3331 | |||
| 3332 | $airline_array[] = $temp_array; |
||
| 3333 | } |
||
| 3334 | |||
| 3335 | return $airline_array; |
||
| 3336 | } |
||
| 3337 | |||
| 3338 | /** |
||
| 3339 | * Gets all pilots that have flown over |
||
| 3340 | * |
||
| 3341 | * @return Array the pilots list |
||
| 3342 | * |
||
| 3343 | */ |
||
| 3344 | View Code Duplication | public function countAllPilots($limit = true, $olderthanmonths = 0, $sincedate = '') |
|
| 3345 | { |
||
| 3346 | global $globalDBdriver; |
||
| 3347 | $query = "SELECT DISTINCT spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count |
||
| 3348 | FROM spotter_output |
||
| 3349 | WHERE spotter_output.pilot_id <> '' "; |
||
| 3350 | if ($olderthanmonths > 0) { |
||
| 3351 | if ($globalDBdriver == 'mysql') { |
||
| 3352 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 3353 | } else { |
||
| 3354 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 3355 | } |
||
| 3356 | } |
||
| 3357 | if ($sincedate != '') { |
||
| 3358 | if ($globalDBdriver == 'mysql') { |
||
| 3359 | $query .= "AND date > '".$sincedate."' "; |
||
| 3360 | } else { |
||
| 3361 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 3362 | } |
||
| 3363 | } |
||
| 3364 | $query .= "GROUP BY spotter_output.pilot_id,spotter_output.pilot_name ORDER BY pilot_count DESC"; |
||
| 3365 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 3366 | |||
| 3367 | |||
| 3368 | $sth = $this->db->prepare($query); |
||
| 3369 | $sth->execute(); |
||
| 3370 | |||
| 3371 | $airline_array = array(); |
||
| 3372 | $temp_array = array(); |
||
| 3373 | |||
| 3374 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3375 | { |
||
| 3376 | $temp_array['pilot_name'] = $row['pilot_name']; |
||
| 3377 | $temp_array['pilot_id'] = $row['pilot_id']; |
||
| 3378 | $temp_array['pilot_count'] = $row['pilot_count']; |
||
| 3379 | $airline_array[] = $temp_array; |
||
| 3380 | } |
||
| 3381 | return $airline_array; |
||
| 3382 | } |
||
| 3383 | |||
| 3384 | /** |
||
| 3385 | * Gets all owner that have flown over |
||
| 3386 | * |
||
| 3387 | * @return Array the pilots list |
||
| 3388 | * |
||
| 3389 | */ |
||
| 3390 | public function countAllOwners($limit = true, $olderthanmonths = 0, $sincedate = '') |
||
| 3391 | { |
||
| 3392 | global $globalDBdriver; |
||
| 3393 | $query = "SELECT DISTINCT spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count |
||
| 3394 | FROM spotter_output |
||
| 3395 | WHERE spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL "; |
||
| 3396 | $query .= "GROUP BY spotter_output.owner_name ORDER BY owner_count DESC"; |
||
| 3397 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 3398 | |||
| 3399 | |||
| 3400 | $sth = $this->db->prepare($query); |
||
| 3401 | $sth->execute(); |
||
| 3402 | |||
| 3403 | $airline_array = array(); |
||
| 3404 | $temp_array = array(); |
||
| 3405 | |||
| 3406 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3407 | { |
||
| 3408 | $temp_array['owner_name'] = $row['owner_name']; |
||
| 3409 | $temp_array['owner_count'] = $row['owner_count']; |
||
| 3410 | $airline_array[] = $temp_array; |
||
| 3411 | } |
||
| 3412 | return $airline_array; |
||
| 3413 | } |
||
| 3414 | |||
| 3415 | |||
| 3416 | /** |
||
| 3417 | * Gets all airlines that have flown over by aircraft |
||
| 3418 | * |
||
| 3419 | * @return Array the airline list |
||
| 3420 | * |
||
| 3421 | */ |
||
| 3422 | View Code Duplication | public function countAllAirlinesByAircraft($aircraft_icao) |
|
| 3423 | { |
||
| 3424 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 3425 | |||
| 3426 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3427 | FROM spotter_output |
||
| 3428 | WHERE spotter_output.airline_name <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 3429 | GROUP BY spotter_output.airline_name |
||
| 3430 | ORDER BY airline_count DESC"; |
||
| 3431 | |||
| 3432 | |||
| 3433 | $sth = $this->db->prepare($query); |
||
| 3434 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 3435 | |||
| 3436 | $airline_array = array(); |
||
| 3437 | $temp_array = array(); |
||
| 3438 | |||
| 3439 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3440 | { |
||
| 3441 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3442 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3443 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3444 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3445 | |||
| 3446 | $airline_array[] = $temp_array; |
||
| 3447 | } |
||
| 3448 | |||
| 3449 | return $airline_array; |
||
| 3450 | } |
||
| 3451 | |||
| 3452 | |||
| 3453 | /** |
||
| 3454 | * Gets all airline countries that have flown over by aircraft |
||
| 3455 | * |
||
| 3456 | * @return Array the airline country list |
||
| 3457 | * |
||
| 3458 | */ |
||
| 3459 | public function countAllAirlineCountriesByAircraft($aircraft_icao) |
||
| 3460 | { |
||
| 3461 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 3462 | |||
| 3463 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3464 | FROM spotter_output |
||
| 3465 | WHERE spotter_output.airline_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 3466 | GROUP BY spotter_output.airline_country |
||
| 3467 | ORDER BY airline_country_count DESC |
||
| 3468 | LIMIT 10 OFFSET 0"; |
||
| 3469 | |||
| 3470 | |||
| 3471 | $sth = $this->db->prepare($query); |
||
| 3472 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 3473 | |||
| 3474 | $airline_country_array = array(); |
||
| 3475 | $temp_array = array(); |
||
| 3476 | |||
| 3477 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3478 | { |
||
| 3479 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3480 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3481 | |||
| 3482 | $airline_country_array[] = $temp_array; |
||
| 3483 | } |
||
| 3484 | return $airline_country_array; |
||
| 3485 | } |
||
| 3486 | |||
| 3487 | |||
| 3488 | |||
| 3489 | |||
| 3490 | /** |
||
| 3491 | * Gets all airlines that have flown over by airport |
||
| 3492 | * |
||
| 3493 | * @return Array the airline list |
||
| 3494 | * |
||
| 3495 | */ |
||
| 3496 | View Code Duplication | public function countAllAirlinesByAirport($airport_icao) |
|
| 3497 | { |
||
| 3498 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 3499 | |||
| 3500 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3501 | FROM spotter_output |
||
| 3502 | WHERE spotter_output.airline_name <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
| 3503 | GROUP BY spotter_output.airline_name |
||
| 3504 | ORDER BY airline_count DESC"; |
||
| 3505 | |||
| 3506 | |||
| 3507 | $sth = $this->db->prepare($query); |
||
| 3508 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 3509 | |||
| 3510 | $airline_array = array(); |
||
| 3511 | $temp_array = array(); |
||
| 3512 | |||
| 3513 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3514 | { |
||
| 3515 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3516 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3517 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3518 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3519 | |||
| 3520 | $airline_array[] = $temp_array; |
||
| 3521 | } |
||
| 3522 | return $airline_array; |
||
| 3523 | } |
||
| 3524 | |||
| 3525 | |||
| 3526 | /** |
||
| 3527 | * Gets all airline countries that have flown over by airport icao |
||
| 3528 | * |
||
| 3529 | * @return Array the airline country list |
||
| 3530 | * |
||
| 3531 | */ |
||
| 3532 | public function countAllAirlineCountriesByAirport($airport_icao) |
||
| 3533 | { |
||
| 3534 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 3535 | |||
| 3536 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3537 | FROM spotter_output |
||
| 3538 | WHERE spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
| 3539 | GROUP BY spotter_output.airline_country |
||
| 3540 | ORDER BY airline_country_count DESC |
||
| 3541 | LIMIT 10 OFFSET 0"; |
||
| 3542 | |||
| 3543 | |||
| 3544 | $sth = $this->db->prepare($query); |
||
| 3545 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 3546 | |||
| 3547 | $airline_country_array = array(); |
||
| 3548 | $temp_array = array(); |
||
| 3549 | |||
| 3550 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3551 | { |
||
| 3552 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3553 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3554 | |||
| 3555 | $airline_country_array[] = $temp_array; |
||
| 3556 | } |
||
| 3557 | return $airline_country_array; |
||
| 3558 | } |
||
| 3559 | |||
| 3560 | |||
| 3561 | /** |
||
| 3562 | * Gets all airlines that have flown over by aircraft manufacturer |
||
| 3563 | * |
||
| 3564 | * @return Array the airline list |
||
| 3565 | * |
||
| 3566 | */ |
||
| 3567 | View Code Duplication | public function countAllAirlinesByManufacturer($aircraft_manufacturer) |
|
| 3568 | { |
||
| 3569 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 3570 | |||
| 3571 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3572 | FROM spotter_output |
||
| 3573 | WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 3574 | GROUP BY spotter_output.airline_name |
||
| 3575 | ORDER BY airline_count DESC"; |
||
| 3576 | |||
| 3577 | $sth = $this->db->prepare($query); |
||
| 3578 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 3579 | |||
| 3580 | $airline_array = array(); |
||
| 3581 | $temp_array = array(); |
||
| 3582 | |||
| 3583 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3584 | { |
||
| 3585 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3586 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3587 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3588 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3589 | |||
| 3590 | $airline_array[] = $temp_array; |
||
| 3591 | } |
||
| 3592 | return $airline_array; |
||
| 3593 | } |
||
| 3594 | |||
| 3595 | |||
| 3596 | |||
| 3597 | /** |
||
| 3598 | * Gets all airline countries that have flown over by aircraft manufacturer |
||
| 3599 | * |
||
| 3600 | * @return Array the airline country list |
||
| 3601 | * |
||
| 3602 | */ |
||
| 3603 | public function countAllAirlineCountriesByManufacturer($aircraft_manufacturer) |
||
| 3604 | { |
||
| 3605 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 3606 | |||
| 3607 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3608 | FROM spotter_output |
||
| 3609 | WHERE spotter_output.airline_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 3610 | GROUP BY spotter_output.airline_country |
||
| 3611 | ORDER BY airline_country_count DESC |
||
| 3612 | LIMIT 10 OFFSET 0"; |
||
| 3613 | |||
| 3614 | |||
| 3615 | $sth = $this->db->prepare($query); |
||
| 3616 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 3617 | |||
| 3618 | $airline_country_array = array(); |
||
| 3619 | $temp_array = array(); |
||
| 3620 | |||
| 3621 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3622 | { |
||
| 3623 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3624 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3625 | $airline_country_array[] = $temp_array; |
||
| 3626 | } |
||
| 3627 | return $airline_country_array; |
||
| 3628 | } |
||
| 3629 | |||
| 3630 | |||
| 3631 | /** |
||
| 3632 | * Gets all airlines that have flown over by date |
||
| 3633 | * |
||
| 3634 | * @return Array the airline list |
||
| 3635 | * |
||
| 3636 | */ |
||
| 3637 | public function countAllAirlinesByDate($date) |
||
| 3638 | { |
||
| 3639 | global $globalTimezone, $globalDBdriver; |
||
| 3640 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 3641 | |||
| 3642 | if ($globalTimezone != '') { |
||
| 3643 | date_default_timezone_set($globalTimezone); |
||
| 3644 | $datetime = new DateTime($date); |
||
| 3645 | $offset = $datetime->format('P'); |
||
| 3646 | } else $offset = '+00:00'; |
||
| 3647 | |||
| 3648 | if ($globalDBdriver == 'mysql') { |
||
| 3649 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3650 | FROM spotter_output |
||
| 3651 | WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 3652 | GROUP BY spotter_output.airline_name |
||
| 3653 | ORDER BY airline_count DESC"; |
||
| 3654 | } else { |
||
| 3655 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3656 | FROM spotter_output |
||
| 3657 | WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 3658 | GROUP BY spotter_output.airline_name |
||
| 3659 | ORDER BY airline_count DESC"; |
||
| 3660 | } |
||
| 3661 | |||
| 3662 | $sth = $this->db->prepare($query); |
||
| 3663 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 3664 | |||
| 3665 | $airline_array = array(); |
||
| 3666 | $temp_array = array(); |
||
| 3667 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3668 | { |
||
| 3669 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3670 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3671 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3672 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3673 | |||
| 3674 | $airline_array[] = $temp_array; |
||
| 3675 | } |
||
| 3676 | |||
| 3677 | return $airline_array; |
||
| 3678 | } |
||
| 3679 | |||
| 3680 | |||
| 3681 | /** |
||
| 3682 | * Gets all airline countries that have flown over by date |
||
| 3683 | * |
||
| 3684 | * @return Array the airline country list |
||
| 3685 | * |
||
| 3686 | */ |
||
| 3687 | View Code Duplication | public function countAllAirlineCountriesByDate($date) |
|
| 3688 | { |
||
| 3689 | global $globalTimezone, $globalDBdriver; |
||
| 3690 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 3691 | if ($globalTimezone != '') { |
||
| 3692 | date_default_timezone_set($globalTimezone); |
||
| 3693 | $datetime = new DateTime($date); |
||
| 3694 | $offset = $datetime->format('P'); |
||
| 3695 | } else $offset = '+00:00'; |
||
| 3696 | |||
| 3697 | if ($globalDBdriver == 'mysql') { |
||
| 3698 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3699 | FROM spotter_output |
||
| 3700 | WHERE spotter_output.airline_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 3701 | GROUP BY spotter_output.airline_country |
||
| 3702 | ORDER BY airline_country_count DESC |
||
| 3703 | LIMIT 10 OFFSET 0"; |
||
| 3704 | } else { |
||
| 3705 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3706 | FROM spotter_output |
||
| 3707 | WHERE spotter_output.airline_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 3708 | GROUP BY spotter_output.airline_country |
||
| 3709 | ORDER BY airline_country_count DESC |
||
| 3710 | LIMIT 10 OFFSET 0"; |
||
| 3711 | } |
||
| 3712 | |||
| 3713 | $sth = $this->db->prepare($query); |
||
| 3714 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 3715 | |||
| 3716 | $airline_country_array = array(); |
||
| 3717 | $temp_array = array(); |
||
| 3718 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3719 | { |
||
| 3720 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3721 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3722 | |||
| 3723 | $airline_country_array[] = $temp_array; |
||
| 3724 | } |
||
| 3725 | return $airline_country_array; |
||
| 3726 | } |
||
| 3727 | |||
| 3728 | |||
| 3729 | /** |
||
| 3730 | * Gets all airlines that have flown over by ident/callsign |
||
| 3731 | * |
||
| 3732 | * @return Array the airline list |
||
| 3733 | * |
||
| 3734 | */ |
||
| 3735 | View Code Duplication | public function countAllAirlinesByIdent($ident) |
|
| 3736 | { |
||
| 3737 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 3738 | |||
| 3739 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3740 | FROM spotter_output |
||
| 3741 | WHERE spotter_output.ident = :ident |
||
| 3742 | GROUP BY spotter_output.airline_name |
||
| 3743 | ORDER BY airline_count DESC"; |
||
| 3744 | |||
| 3745 | |||
| 3746 | $sth = $this->db->prepare($query); |
||
| 3747 | $sth->execute(array(':ident' => $ident)); |
||
| 3748 | |||
| 3749 | $airline_array = array(); |
||
| 3750 | $temp_array = array(); |
||
| 3751 | |||
| 3752 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3753 | { |
||
| 3754 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3755 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3756 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3757 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3758 | |||
| 3759 | $airline_array[] = $temp_array; |
||
| 3760 | } |
||
| 3761 | return $airline_array; |
||
| 3762 | } |
||
| 3763 | |||
| 3764 | /** |
||
| 3765 | * Gets all airlines that have flown over by route |
||
| 3766 | * |
||
| 3767 | * @return Array the airline list |
||
| 3768 | * |
||
| 3769 | */ |
||
| 3770 | public function countAllAirlinesByRoute($departure_airport_icao, $arrival_airport_icao) |
||
| 3771 | { |
||
| 3772 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3773 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3774 | |||
| 3775 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3776 | FROM spotter_output |
||
| 3777 | WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 3778 | GROUP BY spotter_output.airline_name |
||
| 3779 | ORDER BY airline_count DESC"; |
||
| 3780 | |||
| 3781 | |||
| 3782 | $sth = $this->db->prepare($query); |
||
| 3783 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 3784 | |||
| 3785 | $airline_array = array(); |
||
| 3786 | $temp_array = array(); |
||
| 3787 | |||
| 3788 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3789 | { |
||
| 3790 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3791 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3792 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3793 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3794 | |||
| 3795 | $airline_array[] = $temp_array; |
||
| 3796 | } |
||
| 3797 | return $airline_array; |
||
| 3798 | } |
||
| 3799 | |||
| 3800 | /** |
||
| 3801 | * Gets all airline countries that have flown over by route |
||
| 3802 | * |
||
| 3803 | * @return Array the airline country list |
||
| 3804 | * |
||
| 3805 | */ |
||
| 3806 | View Code Duplication | public function countAllAirlineCountriesByRoute($departure_airport_icao, $arrival_airport_icao) |
|
| 3807 | { |
||
| 3808 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3809 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 3810 | |||
| 3811 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3812 | FROM spotter_output |
||
| 3813 | WHERE spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 3814 | GROUP BY spotter_output.airline_country |
||
| 3815 | ORDER BY airline_country_count DESC |
||
| 3816 | LIMIT 10 OFFSET 0"; |
||
| 3817 | |||
| 3818 | |||
| 3819 | $sth = $this->db->prepare($query); |
||
| 3820 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 3821 | |||
| 3822 | $airline_country_array = array(); |
||
| 3823 | $temp_array = array(); |
||
| 3824 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3825 | { |
||
| 3826 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3827 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3828 | |||
| 3829 | $airline_country_array[] = $temp_array; |
||
| 3830 | } |
||
| 3831 | |||
| 3832 | return $airline_country_array; |
||
| 3833 | } |
||
| 3834 | |||
| 3835 | |||
| 3836 | /** |
||
| 3837 | * Gets all airlines that have flown over by country |
||
| 3838 | * |
||
| 3839 | * @return Array the airline list |
||
| 3840 | * |
||
| 3841 | */ |
||
| 3842 | View Code Duplication | public function countAllAirlinesByCountry($country) |
|
| 3843 | { |
||
| 3844 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 3845 | |||
| 3846 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
| 3847 | FROM spotter_output |
||
| 3848 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 3849 | GROUP BY spotter_output.airline_name |
||
| 3850 | ORDER BY airline_count DESC"; |
||
| 3851 | |||
| 3852 | |||
| 3853 | $sth = $this->db->prepare($query); |
||
| 3854 | $sth->execute(array(':country' => $country)); |
||
| 3855 | |||
| 3856 | $airline_array = array(); |
||
| 3857 | $temp_array = array(); |
||
| 3858 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3859 | { |
||
| 3860 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 3861 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 3862 | $temp_array['airline_count'] = $row['airline_count']; |
||
| 3863 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3864 | |||
| 3865 | $airline_array[] = $temp_array; |
||
| 3866 | } |
||
| 3867 | return $airline_array; |
||
| 3868 | } |
||
| 3869 | |||
| 3870 | |||
| 3871 | /** |
||
| 3872 | * Gets all airline countries that have flown over by country |
||
| 3873 | * |
||
| 3874 | * @return Array the airline country list |
||
| 3875 | * |
||
| 3876 | */ |
||
| 3877 | public function countAllAirlineCountriesByCountry($country) |
||
| 3878 | { |
||
| 3879 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 3880 | |||
| 3881 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3882 | FROM spotter_output |
||
| 3883 | WHERE spotter_output.airline_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 3884 | GROUP BY spotter_output.airline_country |
||
| 3885 | ORDER BY airline_country_count DESC |
||
| 3886 | LIMIT 10 OFFSET 0"; |
||
| 3887 | |||
| 3888 | |||
| 3889 | $sth = $this->db->prepare($query); |
||
| 3890 | $sth->execute(array(':country' => $country)); |
||
| 3891 | |||
| 3892 | $airline_country_array = array(); |
||
| 3893 | $temp_array = array(); |
||
| 3894 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3895 | { |
||
| 3896 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3897 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3898 | |||
| 3899 | $airline_country_array[] = $temp_array; |
||
| 3900 | } |
||
| 3901 | return $airline_country_array; |
||
| 3902 | } |
||
| 3903 | |||
| 3904 | |||
| 3905 | /** |
||
| 3906 | * Gets all airlines countries |
||
| 3907 | * |
||
| 3908 | * @return Array the airline country list |
||
| 3909 | * |
||
| 3910 | */ |
||
| 3911 | View Code Duplication | public function countAllAirlineCountries($limit = true) |
|
| 3912 | { |
||
| 3913 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
| 3914 | FROM spotter_output |
||
| 3915 | WHERE spotter_output.airline_country <> '' AND spotter_output.airline_country <> 'NA' |
||
| 3916 | GROUP BY spotter_output.airline_country |
||
| 3917 | ORDER BY airline_country_count DESC"; |
||
| 3918 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 3919 | |||
| 3920 | $sth = $this->db->prepare($query); |
||
| 3921 | $sth->execute(); |
||
| 3922 | |||
| 3923 | $airline_array = array(); |
||
| 3924 | $temp_array = array(); |
||
| 3925 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3926 | { |
||
| 3927 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
| 3928 | $temp_array['airline_country'] = $row['airline_country']; |
||
| 3929 | |||
| 3930 | $airline_array[] = $temp_array; |
||
| 3931 | } |
||
| 3932 | return $airline_array; |
||
| 3933 | } |
||
| 3934 | |||
| 3935 | /** |
||
| 3936 | * Gets all number of flight over countries |
||
| 3937 | * |
||
| 3938 | * @return Array the airline country list |
||
| 3939 | * |
||
| 3940 | */ |
||
| 3941 | View Code Duplication | public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') |
|
| 3942 | { |
||
| 3943 | global $globalDBdriver; |
||
| 3944 | /* |
||
| 3945 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
| 3946 | FROM countries c, spotter_output s |
||
| 3947 | WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
||
| 3948 | */ |
||
| 3949 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
| 3950 | FROM countries c, spotter_live s |
||
| 3951 | WHERE c.iso2 = s.over_country "; |
||
| 3952 | if ($olderthanmonths > 0) { |
||
| 3953 | if ($globalDBdriver == 'mysql') { |
||
| 3954 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 3955 | } else { |
||
| 3956 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
| 3957 | } |
||
| 3958 | } |
||
| 3959 | if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 3960 | $query .= "GROUP BY c.name ORDER BY nb DESC"; |
||
| 3961 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 3962 | |||
| 3963 | |||
| 3964 | $sth = $this->db->prepare($query); |
||
| 3965 | $sth->execute(); |
||
| 3966 | |||
| 3967 | $flight_array = array(); |
||
| 3968 | $temp_array = array(); |
||
| 3969 | |||
| 3970 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 3971 | { |
||
| 3972 | $temp_array['flight_count'] = $row['nb']; |
||
| 3973 | $temp_array['flight_country'] = $row['name']; |
||
| 3974 | $temp_array['flight_country_iso3'] = $row['iso3']; |
||
| 3975 | $temp_array['flight_country_iso2'] = $row['iso2']; |
||
| 3976 | $flight_array[] = $temp_array; |
||
| 3977 | } |
||
| 3978 | return $flight_array; |
||
| 3979 | } |
||
| 3980 | |||
| 3981 | |||
| 3982 | /** |
||
| 3983 | * Gets all aircraft types that have flown over |
||
| 3984 | * |
||
| 3985 | * @return Array the aircraft list |
||
| 3986 | * |
||
| 3987 | */ |
||
| 3988 | View Code Duplication | public function countAllAircraftTypes($limit = true,$olderthanmonths = 0,$sincedate = '') |
|
| 3989 | { |
||
| 3990 | global $globalDBdriver; |
||
| 3991 | $query = "SELECT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 3992 | FROM spotter_output |
||
| 3993 | WHERE spotter_output.aircraft_name <> '' AND spotter_output.aircraft_icao <> '' "; |
||
| 3994 | if ($olderthanmonths > 0) { |
||
| 3995 | if ($globalDBdriver == 'mysql') { |
||
| 3996 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 3997 | } else { |
||
| 3998 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 3999 | } |
||
| 4000 | } |
||
| 4001 | if ($sincedate != '') { |
||
| 4002 | if ($globalDBdriver == 'mysql') { |
||
| 4003 | $query .= "AND date > '".$sincedate."' "; |
||
| 4004 | } else { |
||
| 4005 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4006 | } |
||
| 4007 | } |
||
| 4008 | |||
| 4009 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4010 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 4011 | $query .= "GROUP BY spotter_output.aircraft_icao, spotter_output.aircraft_name ORDER BY aircraft_icao_count DESC"; |
||
| 4012 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4013 | |||
| 4014 | |||
| 4015 | $sth = $this->db->prepare($query); |
||
| 4016 | $sth->execute(); |
||
| 4017 | |||
| 4018 | $aircraft_array = array(); |
||
| 4019 | $temp_array = array(); |
||
| 4020 | |||
| 4021 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4022 | { |
||
| 4023 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4024 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4025 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4026 | |||
| 4027 | $aircraft_array[] = $temp_array; |
||
| 4028 | } |
||
| 4029 | return $aircraft_array; |
||
| 4030 | } |
||
| 4031 | |||
| 4032 | |||
| 4033 | /** |
||
| 4034 | * Gets all aircraft registration that have flown over by aircaft icao |
||
| 4035 | * |
||
| 4036 | * @return Array the aircraft list |
||
| 4037 | * |
||
| 4038 | */ |
||
| 4039 | View Code Duplication | public function countAllAircraftRegistrationByAircraft($aircraft_icao) |
|
| 4040 | { |
||
| 4041 | $Image = new Image($this->db); |
||
| 4042 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 4043 | |||
| 4044 | $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 |
||
| 4045 | FROM spotter_output |
||
| 4046 | WHERE spotter_output.registration <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 4047 | GROUP BY spotter_output.registration |
||
| 4048 | ORDER BY registration_count DESC"; |
||
| 4049 | |||
| 4050 | $sth = $this->db->prepare($query); |
||
| 4051 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 4052 | |||
| 4053 | $aircraft_array = array(); |
||
| 4054 | $temp_array = array(); |
||
| 4055 | |||
| 4056 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4057 | { |
||
| 4058 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4059 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4060 | $temp_array['registration'] = $row['registration']; |
||
| 4061 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4062 | $temp_array['image_thumbnail'] = ""; |
||
| 4063 | if($row['registration'] != "") |
||
| 4064 | { |
||
| 4065 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4066 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4067 | } |
||
| 4068 | $emp_array['registration_count'] = $row['registration_count']; |
||
| 4069 | |||
| 4070 | $aircraft_array[] = $temp_array; |
||
| 4071 | } |
||
| 4072 | return $aircraft_array; |
||
| 4073 | } |
||
| 4074 | |||
| 4075 | |||
| 4076 | /** |
||
| 4077 | * Gets all aircraft types that have flown over by airline icao |
||
| 4078 | * |
||
| 4079 | * @return Array the aircraft list |
||
| 4080 | * |
||
| 4081 | */ |
||
| 4082 | View Code Duplication | public function countAllAircraftTypesByAirline($airline_icao) |
|
| 4083 | { |
||
| 4084 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 4085 | |||
| 4086 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4087 | FROM spotter_output |
||
| 4088 | WHERE spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 4089 | GROUP BY spotter_output.aircraft_name |
||
| 4090 | ORDER BY aircraft_icao_count DESC"; |
||
| 4091 | |||
| 4092 | $sth = $this->db->prepare($query); |
||
| 4093 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 4094 | |||
| 4095 | $ircraft_array = array(); |
||
| 4096 | $temp_array = array(); |
||
| 4097 | |||
| 4098 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4099 | { |
||
| 4100 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4101 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4102 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4103 | |||
| 4104 | $aircraft_array[] = $temp_array; |
||
| 4105 | } |
||
| 4106 | return $aircraft_array; |
||
| 4107 | } |
||
| 4108 | |||
| 4109 | |||
| 4110 | /** |
||
| 4111 | * Gets all aircraft registration that have flown over by airline icao |
||
| 4112 | * |
||
| 4113 | * @return Array the aircraft list |
||
| 4114 | * |
||
| 4115 | */ |
||
| 4116 | View Code Duplication | public function countAllAircraftRegistrationByAirline($airline_icao) |
|
| 4117 | { |
||
| 4118 | $Image = new Image($this->db); |
||
| 4119 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 4120 | |||
| 4121 | $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 |
||
| 4122 | FROM spotter_output |
||
| 4123 | WHERE spotter_output.registration <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 4124 | GROUP BY spotter_output.registration |
||
| 4125 | ORDER BY registration_count DESC"; |
||
| 4126 | |||
| 4127 | $sth = $this->db->prepare($query); |
||
| 4128 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 4129 | |||
| 4130 | $aircraft_array = array(); |
||
| 4131 | $temp_array = array(); |
||
| 4132 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4133 | { |
||
| 4134 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4135 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4136 | $temp_array['registration'] = $row['registration']; |
||
| 4137 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4138 | $temp_array['image_thumbnail'] = ""; |
||
| 4139 | if($row['registration'] != "") |
||
| 4140 | { |
||
| 4141 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4142 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4143 | } |
||
| 4144 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4145 | |||
| 4146 | $aircraft_array[] = $temp_array; |
||
| 4147 | } |
||
| 4148 | return $aircraft_array; |
||
| 4149 | } |
||
| 4150 | |||
| 4151 | |||
| 4152 | /** |
||
| 4153 | * Gets all aircraft manufacturer that have flown over by airline icao |
||
| 4154 | * |
||
| 4155 | * @return Array the aircraft list |
||
| 4156 | * |
||
| 4157 | */ |
||
| 4158 | public function countAllAircraftManufacturerByAirline($airline_icao) |
||
| 4159 | { |
||
| 4160 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 4161 | |||
| 4162 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4163 | FROM spotter_output |
||
| 4164 | WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 4165 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4166 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4167 | |||
| 4168 | $sth = $this->db->prepare($query); |
||
| 4169 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 4170 | |||
| 4171 | $aircraft_array = array(); |
||
| 4172 | $temp_array = array(); |
||
| 4173 | |||
| 4174 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4175 | { |
||
| 4176 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4177 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4178 | |||
| 4179 | $aircraft_array[] = $temp_array; |
||
| 4180 | } |
||
| 4181 | return $aircraft_array; |
||
| 4182 | } |
||
| 4183 | |||
| 4184 | |||
| 4185 | /** |
||
| 4186 | * Gets all aircraft types that have flown over by airline icao |
||
| 4187 | * |
||
| 4188 | * @return Array the aircraft list |
||
| 4189 | * |
||
| 4190 | */ |
||
| 4191 | View Code Duplication | public function countAllAircraftTypesByAirport($airport_icao) |
|
| 4192 | { |
||
| 4193 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 4194 | |||
| 4195 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4196 | FROM spotter_output |
||
| 4197 | WHERE spotter_output.aircraft_icao <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 4198 | GROUP BY spotter_output.aircraft_name |
||
| 4199 | ORDER BY aircraft_icao_count DESC"; |
||
| 4200 | |||
| 4201 | $sth = $this->db->prepare($query); |
||
| 4202 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 4203 | |||
| 4204 | $aircraft_array = array(); |
||
| 4205 | $temp_array = array(); |
||
| 4206 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4207 | { |
||
| 4208 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4209 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4210 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4211 | |||
| 4212 | $aircraft_array[] = $temp_array; |
||
| 4213 | } |
||
| 4214 | return $aircraft_array; |
||
| 4215 | } |
||
| 4216 | |||
| 4217 | |||
| 4218 | /** |
||
| 4219 | * Gets all aircraft registration that have flown over by airport icao |
||
| 4220 | * |
||
| 4221 | * @return Array the aircraft list |
||
| 4222 | * |
||
| 4223 | */ |
||
| 4224 | View Code Duplication | public function countAllAircraftRegistrationByAirport($airport_icao) |
|
| 4225 | { |
||
| 4226 | $Image = new Image($this->db); |
||
| 4227 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 4228 | |||
| 4229 | $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 |
||
| 4230 | FROM spotter_output |
||
| 4231 | WHERE spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 4232 | GROUP BY spotter_output.registration |
||
| 4233 | ORDER BY registration_count DESC"; |
||
| 4234 | |||
| 4235 | |||
| 4236 | $sth = $this->db->prepare($query); |
||
| 4237 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 4238 | |||
| 4239 | $aircraft_array = array(); |
||
| 4240 | $temp_array = array(); |
||
| 4241 | |||
| 4242 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4243 | { |
||
| 4244 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4245 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4246 | $temp_array['registration'] = $row['registration']; |
||
| 4247 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4248 | $temp_array['image_thumbnail'] = ""; |
||
| 4249 | if($row['registration'] != "") |
||
| 4250 | { |
||
| 4251 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4252 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4253 | } |
||
| 4254 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4255 | |||
| 4256 | $aircraft_array[] = $temp_array; |
||
| 4257 | } |
||
| 4258 | |||
| 4259 | return $aircraft_array; |
||
| 4260 | } |
||
| 4261 | |||
| 4262 | |||
| 4263 | /** |
||
| 4264 | * Gets all aircraft manufacturer that have flown over by airport icao |
||
| 4265 | * |
||
| 4266 | * @return Array the aircraft list |
||
| 4267 | * |
||
| 4268 | */ |
||
| 4269 | public function countAllAircraftManufacturerByAirport($airport_icao) |
||
| 4270 | { |
||
| 4271 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 4272 | |||
| 4273 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4274 | FROM spotter_output |
||
| 4275 | WHERE spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 4276 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4277 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4278 | |||
| 4279 | |||
| 4280 | $sth = $this->db->prepare($query); |
||
| 4281 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 4282 | |||
| 4283 | $aircraft_array = array(); |
||
| 4284 | $temp_array = array(); |
||
| 4285 | |||
| 4286 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4287 | { |
||
| 4288 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4289 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4290 | |||
| 4291 | $aircraft_array[] = $temp_array; |
||
| 4292 | } |
||
| 4293 | |||
| 4294 | return $aircraft_array; |
||
| 4295 | } |
||
| 4296 | |||
| 4297 | |||
| 4298 | |||
| 4299 | /** |
||
| 4300 | * Gets all aircraft types that have flown over by aircraft manufacturer |
||
| 4301 | * |
||
| 4302 | * @return Array the aircraft list |
||
| 4303 | * |
||
| 4304 | */ |
||
| 4305 | View Code Duplication | public function countAllAircraftTypesByManufacturer($aircraft_manufacturer) |
|
| 4306 | { |
||
| 4307 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 4308 | |||
| 4309 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4310 | FROM spotter_output |
||
| 4311 | WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 4312 | GROUP BY spotter_output.aircraft_name |
||
| 4313 | ORDER BY aircraft_icao_count DESC"; |
||
| 4314 | |||
| 4315 | |||
| 4316 | $sth = $this->db->prepare($query); |
||
| 4317 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 4318 | |||
| 4319 | $aircraft_array = array(); |
||
| 4320 | $temp_array = array(); |
||
| 4321 | |||
| 4322 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4323 | { |
||
| 4324 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4325 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4326 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4327 | |||
| 4328 | $aircraft_array[] = $temp_array; |
||
| 4329 | } |
||
| 4330 | |||
| 4331 | return $aircraft_array; |
||
| 4332 | } |
||
| 4333 | |||
| 4334 | |||
| 4335 | /** |
||
| 4336 | * Gets all aircraft registration that have flown over by aircaft manufacturer |
||
| 4337 | * |
||
| 4338 | * @return Array the aircraft list |
||
| 4339 | * |
||
| 4340 | */ |
||
| 4341 | View Code Duplication | public function countAllAircraftRegistrationByManufacturer($aircraft_manufacturer) |
|
| 4342 | { |
||
| 4343 | $Image = new Image($this->db); |
||
| 4344 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 4345 | |||
| 4346 | $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 |
||
| 4347 | FROM spotter_output |
||
| 4348 | WHERE spotter_output.registration <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 4349 | GROUP BY spotter_output.registration |
||
| 4350 | ORDER BY registration_count DESC"; |
||
| 4351 | |||
| 4352 | |||
| 4353 | $sth = $this->db->prepare($query); |
||
| 4354 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 4355 | |||
| 4356 | $aircraft_array = array(); |
||
| 4357 | $temp_array = array(); |
||
| 4358 | |||
| 4359 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4360 | { |
||
| 4361 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4362 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4363 | $temp_array['registration'] = $row['registration']; |
||
| 4364 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4365 | $temp_array['image_thumbnail'] = ""; |
||
| 4366 | if($row['registration'] != "") |
||
| 4367 | { |
||
| 4368 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4369 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4370 | } |
||
| 4371 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4372 | |||
| 4373 | $aircraft_array[] = $temp_array; |
||
| 4374 | } |
||
| 4375 | |||
| 4376 | return $aircraft_array; |
||
| 4377 | } |
||
| 4378 | |||
| 4379 | |||
| 4380 | |||
| 4381 | /** |
||
| 4382 | * Gets all aircraft types that have flown over by date |
||
| 4383 | * |
||
| 4384 | * @return Array the aircraft list |
||
| 4385 | * |
||
| 4386 | */ |
||
| 4387 | public function countAllAircraftTypesByDate($date) |
||
| 4388 | { |
||
| 4389 | global $globalTimezone, $globalDBdriver; |
||
| 4390 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 4391 | if ($globalTimezone != '') { |
||
| 4392 | date_default_timezone_set($globalTimezone); |
||
| 4393 | $datetime = new DateTime($date); |
||
| 4394 | $offset = $datetime->format('P'); |
||
| 4395 | } else $offset = '+00:00'; |
||
| 4396 | |||
| 4397 | if ($globalDBdriver == 'mysql') { |
||
| 4398 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4399 | FROM spotter_output |
||
| 4400 | WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 4401 | GROUP BY spotter_output.aircraft_name |
||
| 4402 | ORDER BY aircraft_icao_count DESC"; |
||
| 4403 | } else { |
||
| 4404 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4405 | FROM spotter_output |
||
| 4406 | WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 4407 | GROUP BY spotter_output.aircraft_name |
||
| 4408 | ORDER BY aircraft_icao_count DESC"; |
||
| 4409 | } |
||
| 4410 | |||
| 4411 | $sth = $this->db->prepare($query); |
||
| 4412 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 4413 | |||
| 4414 | $aircraft_array = array(); |
||
| 4415 | $temp_array = array(); |
||
| 4416 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4417 | { |
||
| 4418 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4419 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4420 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4421 | |||
| 4422 | $aircraft_array[] = $temp_array; |
||
| 4423 | } |
||
| 4424 | return $aircraft_array; |
||
| 4425 | } |
||
| 4426 | |||
| 4427 | |||
| 4428 | /** |
||
| 4429 | * Gets all aircraft registration that have flown over by date |
||
| 4430 | * |
||
| 4431 | * @return Array the aircraft list |
||
| 4432 | * |
||
| 4433 | */ |
||
| 4434 | public function countAllAircraftRegistrationByDate($date) |
||
| 4435 | { |
||
| 4436 | global $globalTimezone, $globalDBdriver; |
||
| 4437 | $Image = new Image($this->db); |
||
| 4438 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 4439 | if ($globalTimezone != '') { |
||
| 4440 | date_default_timezone_set($globalTimezone); |
||
| 4441 | $datetime = new DateTime($date); |
||
| 4442 | $offset = $datetime->format('P'); |
||
| 4443 | } else $offset = '+00:00'; |
||
| 4444 | |||
| 4445 | if ($globalDBdriver == 'mysql') { |
||
| 4446 | $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 |
||
| 4447 | FROM spotter_output |
||
| 4448 | WHERE spotter_output.registration <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 4449 | GROUP BY spotter_output.registration |
||
| 4450 | ORDER BY registration_count DESC"; |
||
| 4451 | } else { |
||
| 4452 | $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 |
||
| 4453 | FROM spotter_output |
||
| 4454 | WHERE spotter_output.registration <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 4455 | GROUP BY spotter_output.registration |
||
| 4456 | ORDER BY registration_count DESC"; |
||
| 4457 | } |
||
| 4458 | |||
| 4459 | $sth = $this->db->prepare($query); |
||
| 4460 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 4461 | |||
| 4462 | $aircraft_array = array(); |
||
| 4463 | $temp_array = array(); |
||
| 4464 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4465 | { |
||
| 4466 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4467 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4468 | $temp_array['registration'] = $row['registration']; |
||
| 4469 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4470 | $temp_array['image_thumbnail'] = ""; |
||
| 4471 | if($row['registration'] != "") |
||
| 4472 | { |
||
| 4473 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4474 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4475 | } |
||
| 4476 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4477 | |||
| 4478 | $aircraft_array[] = $temp_array; |
||
| 4479 | } |
||
| 4480 | return $aircraft_array; |
||
| 4481 | } |
||
| 4482 | |||
| 4483 | |||
| 4484 | /** |
||
| 4485 | * Gets all aircraft manufacturer that have flown over by date |
||
| 4486 | * |
||
| 4487 | * @return Array the aircraft manufacturer list |
||
| 4488 | * |
||
| 4489 | */ |
||
| 4490 | View Code Duplication | public function countAllAircraftManufacturerByDate($date) |
|
| 4491 | { |
||
| 4492 | global $globalTimezone, $globalDBdriver; |
||
| 4493 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 4494 | if ($globalTimezone != '') { |
||
| 4495 | date_default_timezone_set($globalTimezone); |
||
| 4496 | $datetime = new DateTime($date); |
||
| 4497 | $offset = $datetime->format('P'); |
||
| 4498 | } else $offset = '+00:00'; |
||
| 4499 | |||
| 4500 | if ($globalDBdriver == 'mysql') { |
||
| 4501 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4502 | FROM spotter_output |
||
| 4503 | WHERE spotter_output.aircraft_manufacturer <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 4504 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4505 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4506 | } else { |
||
| 4507 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4508 | FROM spotter_output |
||
| 4509 | WHERE spotter_output.aircraft_manufacturer <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 4510 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4511 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4512 | } |
||
| 4513 | |||
| 4514 | $sth = $this->db->prepare($query); |
||
| 4515 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 4516 | |||
| 4517 | $aircraft_array = array(); |
||
| 4518 | $temp_array = array(); |
||
| 4519 | |||
| 4520 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4521 | { |
||
| 4522 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4523 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4524 | |||
| 4525 | $aircraft_array[] = $temp_array; |
||
| 4526 | } |
||
| 4527 | return $aircraft_array; |
||
| 4528 | } |
||
| 4529 | |||
| 4530 | |||
| 4531 | /** |
||
| 4532 | * Gets all aircraft types that have flown over by ident/callsign |
||
| 4533 | * |
||
| 4534 | * @return Array the aircraft list |
||
| 4535 | * |
||
| 4536 | */ |
||
| 4537 | View Code Duplication | public function countAllAircraftTypesByIdent($ident) |
|
| 4538 | { |
||
| 4539 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 4540 | |||
| 4541 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4542 | FROM spotter_output |
||
| 4543 | WHERE spotter_output.ident = :ident |
||
| 4544 | GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao |
||
| 4545 | ORDER BY aircraft_icao_count DESC"; |
||
| 4546 | |||
| 4547 | $sth = $this->db->prepare($query); |
||
| 4548 | $sth->execute(array(':ident' => $ident)); |
||
| 4549 | |||
| 4550 | $aircraft_array = array(); |
||
| 4551 | $temp_array = array(); |
||
| 4552 | |||
| 4553 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4554 | { |
||
| 4555 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4556 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4557 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4558 | |||
| 4559 | $aircraft_array[] = $temp_array; |
||
| 4560 | } |
||
| 4561 | return $aircraft_array; |
||
| 4562 | } |
||
| 4563 | |||
| 4564 | |||
| 4565 | /** |
||
| 4566 | * Gets all aircraft registration that have flown over by ident/callsign |
||
| 4567 | * |
||
| 4568 | * @return Array the aircraft list |
||
| 4569 | * |
||
| 4570 | */ |
||
| 4571 | View Code Duplication | public function countAllAircraftRegistrationByIdent($ident) |
|
| 4572 | { |
||
| 4573 | $Image = new Image($this->db); |
||
| 4574 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 4575 | |||
| 4576 | $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 |
||
| 4577 | FROM spotter_output |
||
| 4578 | WHERE spotter_output.registration <> '' AND spotter_output.ident = :ident |
||
| 4579 | GROUP BY spotter_output.registration,spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name |
||
| 4580 | ORDER BY registration_count DESC"; |
||
| 4581 | |||
| 4582 | |||
| 4583 | $sth = $this->db->prepare($query); |
||
| 4584 | $sth->execute(array(':ident' => $ident)); |
||
| 4585 | |||
| 4586 | $aircraft_array = array(); |
||
| 4587 | $temp_array = array(); |
||
| 4588 | |||
| 4589 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4590 | { |
||
| 4591 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4592 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4593 | $temp_array['registration'] = $row['registration']; |
||
| 4594 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4595 | $temp_array['image_thumbnail'] = ""; |
||
| 4596 | if($row['registration'] != "") |
||
| 4597 | { |
||
| 4598 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4599 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4600 | else $temp_array['image_thumbnail'] = ''; |
||
| 4601 | } |
||
| 4602 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4603 | $aircraft_array[] = $temp_array; |
||
| 4604 | } |
||
| 4605 | return $aircraft_array; |
||
| 4606 | } |
||
| 4607 | |||
| 4608 | |||
| 4609 | /** |
||
| 4610 | * Gets all aircraft manufacturer that have flown over by ident/callsign |
||
| 4611 | * |
||
| 4612 | * @return Array the aircraft manufacturer list |
||
| 4613 | * |
||
| 4614 | */ |
||
| 4615 | public function countAllAircraftManufacturerByIdent($ident) |
||
| 4616 | { |
||
| 4617 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 4618 | |||
| 4619 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4620 | FROM spotter_output |
||
| 4621 | WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.ident = :ident |
||
| 4622 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4623 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4624 | |||
| 4625 | |||
| 4626 | $sth = $this->db->prepare($query); |
||
| 4627 | $sth->execute(array(':ident' => $ident)); |
||
| 4628 | |||
| 4629 | $aircraft_array = array(); |
||
| 4630 | $temp_array = array(); |
||
| 4631 | |||
| 4632 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4633 | { |
||
| 4634 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4635 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4636 | |||
| 4637 | $aircraft_array[] = $temp_array; |
||
| 4638 | } |
||
| 4639 | |||
| 4640 | return $aircraft_array; |
||
| 4641 | } |
||
| 4642 | |||
| 4643 | |||
| 4644 | /** |
||
| 4645 | * Gets all aircraft types that have flown over by route |
||
| 4646 | * |
||
| 4647 | * @return Array the aircraft list |
||
| 4648 | * |
||
| 4649 | */ |
||
| 4650 | public function countAllAircraftTypesByRoute($departure_airport_icao, $arrival_airport_icao) |
||
| 4651 | { |
||
| 4652 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4653 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4654 | |||
| 4655 | |||
| 4656 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4657 | FROM spotter_output |
||
| 4658 | WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 4659 | GROUP BY spotter_output.aircraft_name |
||
| 4660 | ORDER BY aircraft_icao_count DESC"; |
||
| 4661 | |||
| 4662 | |||
| 4663 | $sth = $this->db->prepare($query); |
||
| 4664 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 4665 | |||
| 4666 | $aircraft_array = array(); |
||
| 4667 | $temp_array = array(); |
||
| 4668 | |||
| 4669 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4670 | { |
||
| 4671 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4672 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4673 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4674 | |||
| 4675 | $aircraft_array[] = $temp_array; |
||
| 4676 | } |
||
| 4677 | |||
| 4678 | return $aircraft_array; |
||
| 4679 | } |
||
| 4680 | |||
| 4681 | |||
| 4682 | /** |
||
| 4683 | * Gets all aircraft registration that have flown over by route |
||
| 4684 | * |
||
| 4685 | * @return Array the aircraft list |
||
| 4686 | * |
||
| 4687 | */ |
||
| 4688 | public function countAllAircraftRegistrationByRoute($departure_airport_icao, $arrival_airport_icao) |
||
| 4689 | { |
||
| 4690 | $Image = new Image($this->db); |
||
| 4691 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4692 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4693 | |||
| 4694 | $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 |
||
| 4695 | FROM spotter_output |
||
| 4696 | WHERE spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 4697 | GROUP BY spotter_output.registration |
||
| 4698 | ORDER BY registration_count DESC"; |
||
| 4699 | |||
| 4700 | |||
| 4701 | $sth = $this->db->prepare($query); |
||
| 4702 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 4703 | |||
| 4704 | $aircraft_array = array(); |
||
| 4705 | $temp_array = array(); |
||
| 4706 | |||
| 4707 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4708 | { |
||
| 4709 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4710 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4711 | $temp_array['registration'] = $row['registration']; |
||
| 4712 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4713 | $temp_array['image_thumbnail'] = ""; |
||
| 4714 | if($row['registration'] != "") |
||
| 4715 | { |
||
| 4716 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4717 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4718 | } |
||
| 4719 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4720 | |||
| 4721 | $aircraft_array[] = $temp_array; |
||
| 4722 | } |
||
| 4723 | |||
| 4724 | return $aircraft_array; |
||
| 4725 | } |
||
| 4726 | |||
| 4727 | |||
| 4728 | /** |
||
| 4729 | * Gets all aircraft manufacturer that have flown over by route |
||
| 4730 | * |
||
| 4731 | * @return Array the aircraft manufacturer list |
||
| 4732 | * |
||
| 4733 | */ |
||
| 4734 | View Code Duplication | public function countAllAircraftManufacturerByRoute($departure_airport_icao, $arrival_airport_icao) |
|
| 4735 | { |
||
| 4736 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4737 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 4738 | |||
| 4739 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4740 | FROM spotter_output |
||
| 4741 | WHERE spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 4742 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4743 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4744 | |||
| 4745 | |||
| 4746 | $sth = $this->db->prepare($query); |
||
| 4747 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
| 4748 | |||
| 4749 | $aircraft_array = array(); |
||
| 4750 | $temp_array = array(); |
||
| 4751 | |||
| 4752 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4753 | { |
||
| 4754 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4755 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4756 | |||
| 4757 | $aircraft_array[] = $temp_array; |
||
| 4758 | } |
||
| 4759 | |||
| 4760 | return $aircraft_array; |
||
| 4761 | } |
||
| 4762 | |||
| 4763 | |||
| 4764 | |||
| 4765 | |||
| 4766 | /** |
||
| 4767 | * Gets all aircraft types that have flown over by country |
||
| 4768 | * |
||
| 4769 | * @return Array the aircraft list |
||
| 4770 | * |
||
| 4771 | */ |
||
| 4772 | View Code Duplication | public function countAllAircraftTypesByCountry($country) |
|
| 4773 | { |
||
| 4774 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 4775 | |||
| 4776 | $query = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name |
||
| 4777 | FROM spotter_output |
||
| 4778 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 4779 | GROUP BY spotter_output.aircraft_name |
||
| 4780 | ORDER BY aircraft_icao_count DESC"; |
||
| 4781 | |||
| 4782 | |||
| 4783 | $sth = $this->db->prepare($query); |
||
| 4784 | $sth->execute(array(':country' => $country)); |
||
| 4785 | |||
| 4786 | $aircraft_array = array(); |
||
| 4787 | $temp_array = array(); |
||
| 4788 | |||
| 4789 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4790 | { |
||
| 4791 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4792 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4793 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
| 4794 | |||
| 4795 | $aircraft_array[] = $temp_array; |
||
| 4796 | } |
||
| 4797 | |||
| 4798 | return $aircraft_array; |
||
| 4799 | } |
||
| 4800 | |||
| 4801 | |||
| 4802 | /** |
||
| 4803 | * Gets all aircraft registration that have flown over by country |
||
| 4804 | * |
||
| 4805 | * @return Array the aircraft list |
||
| 4806 | * |
||
| 4807 | */ |
||
| 4808 | View Code Duplication | public function countAllAircraftRegistrationByCountry($country) |
|
| 4809 | { |
||
| 4810 | $Image = new Image($this->db); |
||
| 4811 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 4812 | |||
| 4813 | $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 |
||
| 4814 | FROM spotter_output |
||
| 4815 | WHERE spotter_output.registration <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country) |
||
| 4816 | GROUP BY spotter_output.registration |
||
| 4817 | ORDER BY registration_count DESC"; |
||
| 4818 | |||
| 4819 | |||
| 4820 | $sth = $this->db->prepare($query); |
||
| 4821 | $sth->execute(array(':country' => $country)); |
||
| 4822 | |||
| 4823 | $aircraft_array = array(); |
||
| 4824 | $temp_array = array(); |
||
| 4825 | |||
| 4826 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4827 | { |
||
| 4828 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4829 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4830 | $temp_array['registration'] = $row['registration']; |
||
| 4831 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4832 | $temp_array['image_thumbnail'] = ""; |
||
| 4833 | if($row['registration'] != "") |
||
| 4834 | { |
||
| 4835 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4836 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4837 | } |
||
| 4838 | $temp_array['registration_count'] = $row['registration_count']; |
||
| 4839 | |||
| 4840 | $aircraft_array[] = $temp_array; |
||
| 4841 | } |
||
| 4842 | |||
| 4843 | return $aircraft_array; |
||
| 4844 | } |
||
| 4845 | |||
| 4846 | |||
| 4847 | /** |
||
| 4848 | * Gets all aircraft manufacturer that have flown over by country |
||
| 4849 | * |
||
| 4850 | * @return Array the aircraft manufacturer list |
||
| 4851 | * |
||
| 4852 | */ |
||
| 4853 | public function countAllAircraftManufacturerByCountry($country) |
||
| 4854 | { |
||
| 4855 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 4856 | |||
| 4857 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4858 | FROM spotter_output |
||
| 4859 | WHERE spotter_output.aircraft_manufacturer <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country) |
||
| 4860 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4861 | ORDER BY aircraft_manufacturer_count DESC"; |
||
| 4862 | |||
| 4863 | |||
| 4864 | $sth = $this->db->prepare($query); |
||
| 4865 | $sth->execute(array(':country' => $country)); |
||
| 4866 | |||
| 4867 | $aircraft_array = array(); |
||
| 4868 | $temp_array = array(); |
||
| 4869 | |||
| 4870 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4871 | { |
||
| 4872 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4873 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4874 | |||
| 4875 | $aircraft_array[] = $temp_array; |
||
| 4876 | } |
||
| 4877 | |||
| 4878 | return $aircraft_array; |
||
| 4879 | } |
||
| 4880 | |||
| 4881 | |||
| 4882 | |||
| 4883 | /** |
||
| 4884 | * Gets all aircraft manufacturers that have flown over |
||
| 4885 | * |
||
| 4886 | * @return Array the aircraft list |
||
| 4887 | * |
||
| 4888 | */ |
||
| 4889 | View Code Duplication | public function countAllAircraftManufacturers() |
|
| 4890 | { |
||
| 4891 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
||
| 4892 | FROM spotter_output |
||
| 4893 | WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.aircraft_manufacturer <> 'Not Available' |
||
| 4894 | GROUP BY spotter_output.aircraft_manufacturer |
||
| 4895 | ORDER BY aircraft_manufacturer_count DESC |
||
| 4896 | LIMIT 10"; |
||
| 4897 | |||
| 4898 | |||
| 4899 | $sth = $this->db->prepare($query); |
||
| 4900 | $sth->execute(); |
||
| 4901 | |||
| 4902 | $manufacturer_array = array(); |
||
| 4903 | $temp_array = array(); |
||
| 4904 | |||
| 4905 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4906 | { |
||
| 4907 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
| 4908 | $temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count']; |
||
| 4909 | |||
| 4910 | $manufacturer_array[] = $temp_array; |
||
| 4911 | } |
||
| 4912 | |||
| 4913 | return $manufacturer_array; |
||
| 4914 | } |
||
| 4915 | |||
| 4916 | |||
| 4917 | |||
| 4918 | /** |
||
| 4919 | * Gets all aircraft registrations that have flown over |
||
| 4920 | * |
||
| 4921 | * @return Array the aircraft list |
||
| 4922 | * |
||
| 4923 | */ |
||
| 4924 | public function countAllAircraftRegistrations($limit = true,$olderthanmonths = 0,$sincedate = '') |
||
| 4925 | { |
||
| 4926 | global $globalDBdriver; |
||
| 4927 | $Image = new Image($this->db); |
||
| 4928 | $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 |
||
| 4929 | FROM spotter_output |
||
| 4930 | WHERE spotter_output.registration <> '' AND spotter_output.registration <> 'NA' "; |
||
| 4931 | if ($olderthanmonths > 0) { |
||
| 4932 | if ($globalDBdriver == 'mysql') { |
||
| 4933 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4934 | } else { |
||
| 4935 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 4936 | } |
||
| 4937 | } |
||
| 4938 | if ($sincedate != '') { |
||
| 4939 | if ($globalDBdriver == 'mysql') { |
||
| 4940 | $query .= "AND date > '".$sincedate."' "; |
||
| 4941 | } else { |
||
| 4942 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 4943 | } |
||
| 4944 | } |
||
| 4945 | |||
| 4946 | // if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4947 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 4948 | $query .= "GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name ORDER BY aircraft_registration_count DESC"; |
||
| 4949 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 4950 | |||
| 4951 | $sth = $this->db->prepare($query); |
||
| 4952 | $sth->execute(); |
||
| 4953 | |||
| 4954 | $aircraft_array = array(); |
||
| 4955 | $temp_array = array(); |
||
| 4956 | |||
| 4957 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 4958 | { |
||
| 4959 | $temp_array['registration'] = $row['registration']; |
||
| 4960 | $temp_array['aircraft_registration_count'] = $row['aircraft_registration_count']; |
||
| 4961 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
| 4962 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
| 4963 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 4964 | $temp_array['image_thumbnail'] = ""; |
||
| 4965 | if($row['registration'] != "") |
||
| 4966 | { |
||
| 4967 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 4968 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
| 4969 | } |
||
| 4970 | |||
| 4971 | $aircraft_array[] = $temp_array; |
||
| 4972 | } |
||
| 4973 | |||
| 4974 | return $aircraft_array; |
||
| 4975 | } |
||
| 4976 | |||
| 4977 | |||
| 4978 | |||
| 4979 | |||
| 4980 | /** |
||
| 4981 | * Gets all departure airports of the airplanes that have flown over |
||
| 4982 | * |
||
| 4983 | * @return Array the airport list |
||
| 4984 | * |
||
| 4985 | */ |
||
| 4986 | View Code Duplication | public function countAllDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '') |
|
| 4987 | { |
||
| 4988 | global $globalDBdriver; |
||
| 4989 | $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 |
||
| 4990 | FROM spotter_output |
||
| 4991 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' "; |
||
| 4992 | if ($olderthanmonths > 0) { |
||
| 4993 | if ($globalDBdriver == 'mysql') { |
||
| 4994 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 4995 | } else { |
||
| 4996 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 4997 | } |
||
| 4998 | } |
||
| 4999 | if ($sincedate != '') { |
||
| 5000 | if ($globalDBdriver == 'mysql') { |
||
| 5001 | $query .= "AND date > '".$sincedate."' "; |
||
| 5002 | } else { |
||
| 5003 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5004 | } |
||
| 5005 | } |
||
| 5006 | |||
| 5007 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5008 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 5009 | $query .= "GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 5010 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5011 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 5012 | |||
| 5013 | $sth = $this->db->prepare($query); |
||
| 5014 | $sth->execute(); |
||
| 5015 | |||
| 5016 | $airport_array = array(); |
||
| 5017 | $temp_array = array(); |
||
| 5018 | |||
| 5019 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5020 | { |
||
| 5021 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5022 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5023 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5024 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5025 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5026 | |||
| 5027 | $airport_array[] = $temp_array; |
||
| 5028 | } |
||
| 5029 | return $airport_array; |
||
| 5030 | } |
||
| 5031 | |||
| 5032 | /** |
||
| 5033 | * Gets all detected departure airports of the airplanes that have flown over |
||
| 5034 | * |
||
| 5035 | * @return Array the airport list |
||
| 5036 | * |
||
| 5037 | */ |
||
| 5038 | View Code Duplication | public function countAllDetectedDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '') |
|
| 5039 | { |
||
| 5040 | global $globalDBdriver; |
||
| 5041 | $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 |
||
| 5042 | FROM spotter_output, airport |
||
| 5043 | WHERE spotter_output.real_departure_airport_icao <> '' AND spotter_output.real_departure_airport_icao <> 'NA' AND airport.icao = spotter_output.real_departure_airport_icao "; |
||
| 5044 | if ($olderthanmonths > 0) { |
||
| 5045 | if ($globalDBdriver == 'mysql') { |
||
| 5046 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5047 | } else { |
||
| 5048 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 5049 | } |
||
| 5050 | } |
||
| 5051 | if ($sincedate != '') { |
||
| 5052 | if ($globalDBdriver == 'mysql') { |
||
| 5053 | $query .= "AND date > '".$sincedate."' "; |
||
| 5054 | } else { |
||
| 5055 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5056 | } |
||
| 5057 | } |
||
| 5058 | |||
| 5059 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5060 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 5061 | $query .= "GROUP BY spotter_output.real_departure_airport_icao, airport.name, airport.city, airport.country |
||
| 5062 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5063 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 5064 | |||
| 5065 | $sth = $this->db->prepare($query); |
||
| 5066 | $sth->execute(); |
||
| 5067 | |||
| 5068 | $airport_array = array(); |
||
| 5069 | $temp_array = array(); |
||
| 5070 | |||
| 5071 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5072 | { |
||
| 5073 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5074 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5075 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5076 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5077 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5078 | |||
| 5079 | $airport_array[] = $temp_array; |
||
| 5080 | } |
||
| 5081 | return $airport_array; |
||
| 5082 | } |
||
| 5083 | |||
| 5084 | |||
| 5085 | |||
| 5086 | /** |
||
| 5087 | * Gets all departure airports of the airplanes that have flown over based on an airline icao |
||
| 5088 | * |
||
| 5089 | * @return Array the airport list |
||
| 5090 | * |
||
| 5091 | */ |
||
| 5092 | View Code Duplication | public function countAllDepartureAirportsByAirline($airline_icao) |
|
| 5093 | { |
||
| 5094 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5095 | |||
| 5096 | $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 |
||
| 5097 | FROM spotter_output |
||
| 5098 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.airline_icao = :airline_icao |
||
| 5099 | GROUP BY spotter_output.departure_airport_icao |
||
| 5100 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5101 | |||
| 5102 | |||
| 5103 | $sth = $this->db->prepare($query); |
||
| 5104 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5105 | |||
| 5106 | $airport_array = array(); |
||
| 5107 | $temp_array = array(); |
||
| 5108 | |||
| 5109 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5110 | { |
||
| 5111 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5112 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5113 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5114 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5115 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5116 | |||
| 5117 | $airport_array[] = $temp_array; |
||
| 5118 | } |
||
| 5119 | |||
| 5120 | return $airport_array; |
||
| 5121 | } |
||
| 5122 | |||
| 5123 | |||
| 5124 | |||
| 5125 | /** |
||
| 5126 | * Gets all departure airports by country of the airplanes that have flown over based on an airline icao |
||
| 5127 | * |
||
| 5128 | * @return Array the airport list |
||
| 5129 | * |
||
| 5130 | */ |
||
| 5131 | public function countAllDepartureAirportCountriesByAirline($airline_icao) |
||
| 5132 | { |
||
| 5133 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5134 | |||
| 5135 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5136 | FROM spotter_output |
||
| 5137 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 5138 | GROUP BY spotter_output.departure_airport_country |
||
| 5139 | ORDER BY airport_departure_country_count DESC"; |
||
| 5140 | |||
| 5141 | |||
| 5142 | $sth = $this->db->prepare($query); |
||
| 5143 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5144 | |||
| 5145 | $airport_array = array(); |
||
| 5146 | $temp_array = array(); |
||
| 5147 | |||
| 5148 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5149 | { |
||
| 5150 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5151 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5152 | |||
| 5153 | $airport_array[] = $temp_array; |
||
| 5154 | } |
||
| 5155 | |||
| 5156 | return $airport_array; |
||
| 5157 | } |
||
| 5158 | |||
| 5159 | |||
| 5160 | |||
| 5161 | /** |
||
| 5162 | * Gets all departure airports of the airplanes that have flown over based on an aircraft icao |
||
| 5163 | * |
||
| 5164 | * @return Array the airport list |
||
| 5165 | * |
||
| 5166 | */ |
||
| 5167 | View Code Duplication | public function countAllDepartureAirportsByAircraft($aircraft_icao) |
|
| 5168 | { |
||
| 5169 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 5170 | |||
| 5171 | $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 |
||
| 5172 | FROM spotter_output |
||
| 5173 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 5174 | GROUP BY spotter_output.departure_airport_icao |
||
| 5175 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5176 | |||
| 5177 | |||
| 5178 | $sth = $this->db->prepare($query); |
||
| 5179 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 5180 | |||
| 5181 | $airport_array = array(); |
||
| 5182 | $temp_array = array(); |
||
| 5183 | |||
| 5184 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5185 | { |
||
| 5186 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5187 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5188 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5189 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5190 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5191 | |||
| 5192 | $airport_array[] = $temp_array; |
||
| 5193 | } |
||
| 5194 | |||
| 5195 | return $airport_array; |
||
| 5196 | } |
||
| 5197 | |||
| 5198 | |||
| 5199 | /** |
||
| 5200 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 5201 | * |
||
| 5202 | * @return Array the airport list |
||
| 5203 | * |
||
| 5204 | */ |
||
| 5205 | public function countAllDepartureAirportCountriesByAircraft($aircraft_icao) |
||
| 5206 | { |
||
| 5207 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 5208 | |||
| 5209 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5210 | FROM spotter_output |
||
| 5211 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 5212 | GROUP BY spotter_output.departure_airport_country |
||
| 5213 | ORDER BY airport_departure_country_count DESC"; |
||
| 5214 | |||
| 5215 | |||
| 5216 | $sth = $this->db->prepare($query); |
||
| 5217 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 5218 | |||
| 5219 | $airport_array = array(); |
||
| 5220 | $temp_array = array(); |
||
| 5221 | |||
| 5222 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5223 | { |
||
| 5224 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5225 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5226 | |||
| 5227 | $airport_array[] = $temp_array; |
||
| 5228 | } |
||
| 5229 | |||
| 5230 | return $airport_array; |
||
| 5231 | } |
||
| 5232 | |||
| 5233 | |||
| 5234 | /** |
||
| 5235 | * Gets all departure airports of the airplanes that have flown over based on an aircraft registration |
||
| 5236 | * |
||
| 5237 | * @return Array the airport list |
||
| 5238 | * |
||
| 5239 | */ |
||
| 5240 | View Code Duplication | public function countAllDepartureAirportsByRegistration($registration) |
|
| 5241 | { |
||
| 5242 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 5243 | |||
| 5244 | $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 |
||
| 5245 | FROM spotter_output |
||
| 5246 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.registration = :registration |
||
| 5247 | GROUP BY spotter_output.departure_airport_icao |
||
| 5248 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5249 | |||
| 5250 | |||
| 5251 | $sth = $this->db->prepare($query); |
||
| 5252 | $sth->execute(array(':registration' => $registration)); |
||
| 5253 | |||
| 5254 | $airport_array = array(); |
||
| 5255 | $temp_array = array(); |
||
| 5256 | |||
| 5257 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5258 | { |
||
| 5259 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5260 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5261 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5262 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5263 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5264 | |||
| 5265 | $airport_array[] = $temp_array; |
||
| 5266 | } |
||
| 5267 | |||
| 5268 | return $airport_array; |
||
| 5269 | } |
||
| 5270 | |||
| 5271 | |||
| 5272 | /** |
||
| 5273 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft registration |
||
| 5274 | * |
||
| 5275 | * @return Array the airport list |
||
| 5276 | * |
||
| 5277 | */ |
||
| 5278 | public function countAllDepartureAirportCountriesByRegistration($registration) |
||
| 5279 | { |
||
| 5280 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 5281 | |||
| 5282 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5283 | FROM spotter_output |
||
| 5284 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.registration = :registration |
||
| 5285 | GROUP BY spotter_output.departure_airport_country |
||
| 5286 | ORDER BY airport_departure_country_count DESC"; |
||
| 5287 | |||
| 5288 | |||
| 5289 | $sth = $this->db->prepare($query); |
||
| 5290 | $sth->execute(array(':registration' => $registration)); |
||
| 5291 | |||
| 5292 | $airport_array = array(); |
||
| 5293 | $temp_array = array(); |
||
| 5294 | |||
| 5295 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5296 | { |
||
| 5297 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5298 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5299 | |||
| 5300 | $airport_array[] = $temp_array; |
||
| 5301 | } |
||
| 5302 | |||
| 5303 | return $airport_array; |
||
| 5304 | } |
||
| 5305 | |||
| 5306 | |||
| 5307 | /** |
||
| 5308 | * Gets all departure airports of the airplanes that have flown over based on an arrivl airport icao |
||
| 5309 | * |
||
| 5310 | * @return Array the airport list |
||
| 5311 | * |
||
| 5312 | */ |
||
| 5313 | View Code Duplication | public function countAllDepartureAirportsByAirport($airport_icao) |
|
| 5314 | { |
||
| 5315 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 5316 | |||
| 5317 | $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 |
||
| 5318 | FROM spotter_output |
||
| 5319 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao = :airport_icao |
||
| 5320 | GROUP BY spotter_output.departure_airport_icao |
||
| 5321 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5322 | |||
| 5323 | |||
| 5324 | $sth = $this->db->prepare($query); |
||
| 5325 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 5326 | |||
| 5327 | $airport_array = array(); |
||
| 5328 | $temp_array = array(); |
||
| 5329 | |||
| 5330 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5331 | { |
||
| 5332 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5333 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5334 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5335 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5336 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5337 | |||
| 5338 | $airport_array[] = $temp_array; |
||
| 5339 | } |
||
| 5340 | |||
| 5341 | return $airport_array; |
||
| 5342 | } |
||
| 5343 | |||
| 5344 | |||
| 5345 | /** |
||
| 5346 | * Gets all departure airports by country of the airplanes that have flown over based on an airport icao |
||
| 5347 | * |
||
| 5348 | * @return Array the airport list |
||
| 5349 | * |
||
| 5350 | */ |
||
| 5351 | public function countAllDepartureAirportCountriesByAirport($airport_icao) |
||
| 5352 | { |
||
| 5353 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 5354 | |||
| 5355 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5356 | FROM spotter_output |
||
| 5357 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.arrival_airport_icao = :airport_icao |
||
| 5358 | GROUP BY spotter_output.departure_airport_country |
||
| 5359 | ORDER BY airport_departure_country_count DESC"; |
||
| 5360 | |||
| 5361 | |||
| 5362 | $sth = $this->db->prepare($query); |
||
| 5363 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 5364 | |||
| 5365 | $airport_array = array(); |
||
| 5366 | $temp_array = array(); |
||
| 5367 | |||
| 5368 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5369 | { |
||
| 5370 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5371 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5372 | |||
| 5373 | $airport_array[] = $temp_array; |
||
| 5374 | } |
||
| 5375 | |||
| 5376 | return $airport_array; |
||
| 5377 | } |
||
| 5378 | |||
| 5379 | |||
| 5380 | |||
| 5381 | /** |
||
| 5382 | * Gets all departure airports of the airplanes that have flown over based on an aircraft manufacturer |
||
| 5383 | * |
||
| 5384 | * @return Array the airport list |
||
| 5385 | * |
||
| 5386 | */ |
||
| 5387 | View Code Duplication | public function countAllDepartureAirportsByManufacturer($aircraft_manufacturer) |
|
| 5388 | { |
||
| 5389 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 5390 | |||
| 5391 | $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 |
||
| 5392 | FROM spotter_output |
||
| 5393 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 5394 | GROUP BY spotter_output.departure_airport_icao |
||
| 5395 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5396 | |||
| 5397 | |||
| 5398 | $sth = $this->db->prepare($query); |
||
| 5399 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 5400 | |||
| 5401 | $airport_array = array(); |
||
| 5402 | $temp_array = array(); |
||
| 5403 | |||
| 5404 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5405 | { |
||
| 5406 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5407 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5408 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5409 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5410 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5411 | |||
| 5412 | $airport_array[] = $temp_array; |
||
| 5413 | } |
||
| 5414 | |||
| 5415 | return $airport_array; |
||
| 5416 | } |
||
| 5417 | |||
| 5418 | |||
| 5419 | /** |
||
| 5420 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft manufacturer |
||
| 5421 | * |
||
| 5422 | * @return Array the airport list |
||
| 5423 | * |
||
| 5424 | */ |
||
| 5425 | public function countAllDepartureAirportCountriesByManufacturer($aircraft_manufacturer) |
||
| 5426 | { |
||
| 5427 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 5428 | |||
| 5429 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5430 | FROM spotter_output |
||
| 5431 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 5432 | GROUP BY spotter_output.departure_airport_country |
||
| 5433 | ORDER BY airport_departure_country_count DESC"; |
||
| 5434 | |||
| 5435 | |||
| 5436 | $sth = $this->db->prepare($query); |
||
| 5437 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 5438 | |||
| 5439 | $airport_array = array(); |
||
| 5440 | $temp_array = array(); |
||
| 5441 | |||
| 5442 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5443 | { |
||
| 5444 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5445 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5446 | |||
| 5447 | $airport_array[] = $temp_array; |
||
| 5448 | } |
||
| 5449 | |||
| 5450 | return $airport_array; |
||
| 5451 | } |
||
| 5452 | |||
| 5453 | |||
| 5454 | /** |
||
| 5455 | * Gets all departure airports of the airplanes that have flown over based on a date |
||
| 5456 | * |
||
| 5457 | * @return Array the airport list |
||
| 5458 | * |
||
| 5459 | */ |
||
| 5460 | View Code Duplication | public function countAllDepartureAirportsByDate($date) |
|
| 5461 | { |
||
| 5462 | global $globalTimezone, $globalDBdriver; |
||
| 5463 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5464 | |||
| 5465 | if ($globalTimezone != '') { |
||
| 5466 | date_default_timezone_set($globalTimezone); |
||
| 5467 | $datetime = new DateTime($date); |
||
| 5468 | $offset = $datetime->format('P'); |
||
| 5469 | } else $offset = '+00:00'; |
||
| 5470 | |||
| 5471 | if ($globalDBdriver == 'mysql') { |
||
| 5472 | $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 |
||
| 5473 | FROM spotter_output |
||
| 5474 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 5475 | GROUP BY spotter_output.departure_airport_icao |
||
| 5476 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5477 | } else { |
||
| 5478 | $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 |
||
| 5479 | FROM spotter_output |
||
| 5480 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 5481 | GROUP BY spotter_output.departure_airport_icao |
||
| 5482 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5483 | } |
||
| 5484 | |||
| 5485 | $sth = $this->db->prepare($query); |
||
| 5486 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 5487 | |||
| 5488 | $airport_array = array(); |
||
| 5489 | $temp_array = array(); |
||
| 5490 | |||
| 5491 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5492 | { |
||
| 5493 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5494 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5495 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5496 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5497 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5498 | |||
| 5499 | $airport_array[] = $temp_array; |
||
| 5500 | } |
||
| 5501 | return $airport_array; |
||
| 5502 | } |
||
| 5503 | |||
| 5504 | |||
| 5505 | |||
| 5506 | /** |
||
| 5507 | * Gets all departure airports by country of the airplanes that have flown over based on a date |
||
| 5508 | * |
||
| 5509 | * @return Array the airport list |
||
| 5510 | * |
||
| 5511 | */ |
||
| 5512 | View Code Duplication | public function countAllDepartureAirportCountriesByDate($date) |
|
| 5513 | { |
||
| 5514 | global $globalTimezone, $globalDBdriver; |
||
| 5515 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5516 | if ($globalTimezone != '') { |
||
| 5517 | date_default_timezone_set($globalTimezone); |
||
| 5518 | $datetime = new DateTime($date); |
||
| 5519 | $offset = $datetime->format('P'); |
||
| 5520 | } else $offset = '+00:00'; |
||
| 5521 | |||
| 5522 | if ($globalDBdriver == 'mysql') { |
||
| 5523 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5524 | FROM spotter_output |
||
| 5525 | WHERE spotter_output.departure_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 5526 | GROUP BY spotter_output.departure_airport_country |
||
| 5527 | ORDER BY airport_departure_country_count DESC"; |
||
| 5528 | } else { |
||
| 5529 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5530 | FROM spotter_output |
||
| 5531 | WHERE spotter_output.departure_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 5532 | GROUP BY spotter_output.departure_airport_country |
||
| 5533 | ORDER BY airport_departure_country_count DESC"; |
||
| 5534 | } |
||
| 5535 | |||
| 5536 | $sth = $this->db->prepare($query); |
||
| 5537 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 5538 | |||
| 5539 | $airport_array = array(); |
||
| 5540 | $temp_array = array(); |
||
| 5541 | |||
| 5542 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5543 | { |
||
| 5544 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5545 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5546 | |||
| 5547 | $airport_array[] = $temp_array; |
||
| 5548 | } |
||
| 5549 | return $airport_array; |
||
| 5550 | } |
||
| 5551 | |||
| 5552 | |||
| 5553 | |||
| 5554 | /** |
||
| 5555 | * Gets all departure airports of the airplanes that have flown over based on a ident/callsign |
||
| 5556 | * |
||
| 5557 | * @return Array the airport list |
||
| 5558 | * |
||
| 5559 | */ |
||
| 5560 | View Code Duplication | public function countAllDepartureAirportsByIdent($ident) |
|
| 5561 | { |
||
| 5562 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 5563 | |||
| 5564 | $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 |
||
| 5565 | FROM spotter_output |
||
| 5566 | WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.ident = :ident |
||
| 5567 | GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country |
||
| 5568 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5569 | |||
| 5570 | |||
| 5571 | $sth = $this->db->prepare($query); |
||
| 5572 | $sth->execute(array(':ident' => $ident)); |
||
| 5573 | |||
| 5574 | $airport_array = array(); |
||
| 5575 | $temp_array = array(); |
||
| 5576 | |||
| 5577 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5578 | { |
||
| 5579 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5580 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5581 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5582 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5583 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5584 | |||
| 5585 | $airport_array[] = $temp_array; |
||
| 5586 | } |
||
| 5587 | |||
| 5588 | return $airport_array; |
||
| 5589 | } |
||
| 5590 | |||
| 5591 | |||
| 5592 | |||
| 5593 | /** |
||
| 5594 | * Gets all departure airports by country of the airplanes that have flown over based on a callsign/ident |
||
| 5595 | * |
||
| 5596 | * @return Array the airport list |
||
| 5597 | * |
||
| 5598 | */ |
||
| 5599 | public function countAllDepartureAirportCountriesByIdent($ident) |
||
| 5600 | { |
||
| 5601 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 5602 | |||
| 5603 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5604 | FROM spotter_output |
||
| 5605 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.ident = :ident |
||
| 5606 | GROUP BY spotter_output.departure_airport_country |
||
| 5607 | ORDER BY airport_departure_country_count DESC"; |
||
| 5608 | |||
| 5609 | |||
| 5610 | $sth = $this->db->prepare($query); |
||
| 5611 | $sth->execute(array(':ident' => $ident)); |
||
| 5612 | |||
| 5613 | $airport_array = array(); |
||
| 5614 | $temp_array = array(); |
||
| 5615 | |||
| 5616 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5617 | { |
||
| 5618 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5619 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5620 | |||
| 5621 | $airport_array[] = $temp_array; |
||
| 5622 | } |
||
| 5623 | |||
| 5624 | return $airport_array; |
||
| 5625 | } |
||
| 5626 | |||
| 5627 | |||
| 5628 | |||
| 5629 | /** |
||
| 5630 | * Gets all departure airports of the airplanes that have flown over based on a country |
||
| 5631 | * |
||
| 5632 | * @return Array the airport list |
||
| 5633 | * |
||
| 5634 | */ |
||
| 5635 | View Code Duplication | public function countAllDepartureAirportsByCountry($country) |
|
| 5636 | { |
||
| 5637 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 5638 | |||
| 5639 | $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 |
||
| 5640 | FROM spotter_output |
||
| 5641 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 5642 | GROUP BY spotter_output.departure_airport_icao |
||
| 5643 | ORDER BY airport_departure_icao_count DESC"; |
||
| 5644 | |||
| 5645 | |||
| 5646 | $sth = $this->db->prepare($query); |
||
| 5647 | $sth->execute(array(':country' => $country)); |
||
| 5648 | |||
| 5649 | $airport_array = array(); |
||
| 5650 | $temp_array = array(); |
||
| 5651 | |||
| 5652 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5653 | { |
||
| 5654 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 5655 | $temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
||
| 5656 | $temp_array['airport_departure_name'] = $row['departure_airport_name']; |
||
| 5657 | $temp_array['airport_departure_city'] = $row['departure_airport_city']; |
||
| 5658 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 5659 | |||
| 5660 | $airport_array[] = $temp_array; |
||
| 5661 | } |
||
| 5662 | |||
| 5663 | return $airport_array; |
||
| 5664 | } |
||
| 5665 | |||
| 5666 | |||
| 5667 | /** |
||
| 5668 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 5669 | * |
||
| 5670 | * @return Array the airport list |
||
| 5671 | * |
||
| 5672 | */ |
||
| 5673 | public function countAllDepartureAirportCountriesByCountry($country) |
||
| 5674 | { |
||
| 5675 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 5676 | |||
| 5677 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 5678 | FROM spotter_output |
||
| 5679 | WHERE 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 |
||
| 5680 | GROUP BY spotter_output.departure_airport_country |
||
| 5681 | ORDER BY airport_departure_country_count DESC"; |
||
| 5682 | |||
| 5683 | |||
| 5684 | $sth = $this->db->prepare($query); |
||
| 5685 | $sth->execute(array(':country' => $country)); |
||
| 5686 | |||
| 5687 | $airport_array = array(); |
||
| 5688 | $temp_array = array(); |
||
| 5689 | |||
| 5690 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5691 | { |
||
| 5692 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
| 5693 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 5694 | |||
| 5695 | $airport_array[] = $temp_array; |
||
| 5696 | } |
||
| 5697 | |||
| 5698 | return $airport_array; |
||
| 5699 | } |
||
| 5700 | |||
| 5701 | |||
| 5702 | /** |
||
| 5703 | * Gets all arrival airports of the airplanes that have flown over |
||
| 5704 | * |
||
| 5705 | * @return Array the airport list |
||
| 5706 | * |
||
| 5707 | */ |
||
| 5708 | View Code Duplication | public function countAllArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false) |
|
| 5709 | { |
||
| 5710 | global $globalDBdriver; |
||
| 5711 | $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 |
||
| 5712 | FROM spotter_output |
||
| 5713 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' "; |
||
| 5714 | if ($olderthanmonths > 0) { |
||
| 5715 | if ($globalDBdriver == 'mysql') { |
||
| 5716 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5717 | } else { |
||
| 5718 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 5719 | } |
||
| 5720 | if ($sincedate != '') { |
||
| 5721 | if ($globalDBdriver == 'mysql') { |
||
| 5722 | $query .= "AND date > '".$sincedate."' "; |
||
| 5723 | } else { |
||
| 5724 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5725 | } |
||
| 5726 | } |
||
| 5727 | if ($globalDBdriver == 'mysql') { |
||
| 5728 | $query .= "AND date > '".$sincedate."' "; |
||
| 5729 | } else { |
||
| 5730 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5731 | } |
||
| 5732 | } |
||
| 5733 | |||
| 5734 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5735 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 5736 | $query .= "GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 5737 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 5738 | if ($limit) $query .= " LIMIT 10"; |
||
| 5739 | |||
| 5740 | |||
| 5741 | $sth = $this->db->prepare($query); |
||
| 5742 | $sth->execute(); |
||
| 5743 | |||
| 5744 | $airport_array = array(); |
||
| 5745 | $temp_array = array(); |
||
| 5746 | |||
| 5747 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5748 | { |
||
| 5749 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 5750 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 5751 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 5752 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 5753 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 5754 | |||
| 5755 | if ($icaoaskey) { |
||
| 5756 | $icao = $row['arrival_airport_icao']; |
||
| 5757 | $airport_array[$icao] = $temp_array; |
||
| 5758 | } else $airport_array[] = $temp_array; |
||
| 5759 | } |
||
| 5760 | |||
| 5761 | return $airport_array; |
||
| 5762 | } |
||
| 5763 | |||
| 5764 | /** |
||
| 5765 | * Gets all detected arrival airports of the airplanes that have flown over |
||
| 5766 | * |
||
| 5767 | * @return Array the airport list |
||
| 5768 | * |
||
| 5769 | */ |
||
| 5770 | View Code Duplication | public function countAllDetectedArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false) |
|
| 5771 | { |
||
| 5772 | global $globalDBdriver; |
||
| 5773 | $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 |
||
| 5774 | FROM spotter_output, airport |
||
| 5775 | WHERE spotter_output.real_arrival_airport_icao <> '' AND spotter_output.real_arrival_airport_icao <> 'NA' AND airport.icao = spotter_output.real_arrival_airport_icao "; |
||
| 5776 | if ($olderthanmonths > 0) { |
||
| 5777 | if ($globalDBdriver == 'mysql') { |
||
| 5778 | $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5779 | } else { |
||
| 5780 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 5781 | } |
||
| 5782 | if ($sincedate != '') { |
||
| 5783 | if ($globalDBdriver == 'mysql') { |
||
| 5784 | $query .= "AND date > '".$sincedate."' "; |
||
| 5785 | } else { |
||
| 5786 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5787 | } |
||
| 5788 | } |
||
| 5789 | if ($globalDBdriver == 'mysql') { |
||
| 5790 | $query .= "AND date > '".$sincedate."' "; |
||
| 5791 | } else { |
||
| 5792 | $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
| 5793 | } |
||
| 5794 | } |
||
| 5795 | |||
| 5796 | //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 5797 | //if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
||
| 5798 | $query .= "GROUP BY spotter_output.real_arrival_airport_icao, airport.name, airport.city, airport.country |
||
| 5799 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 5800 | if ($limit) $query .= " LIMIT 10"; |
||
| 5801 | |||
| 5802 | |||
| 5803 | $sth = $this->db->prepare($query); |
||
| 5804 | $sth->execute(); |
||
| 5805 | |||
| 5806 | $airport_array = array(); |
||
| 5807 | $temp_array = array(); |
||
| 5808 | |||
| 5809 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5810 | { |
||
| 5811 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 5812 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 5813 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 5814 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 5815 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 5816 | |||
| 5817 | if ($icaoaskey) { |
||
| 5818 | $icao = $row['arrival_airport_icao']; |
||
| 5819 | $airport_array[$icao] = $temp_array; |
||
| 5820 | } else $airport_array[] = $temp_array; |
||
| 5821 | } |
||
| 5822 | |||
| 5823 | return $airport_array; |
||
| 5824 | } |
||
| 5825 | |||
| 5826 | |||
| 5827 | |||
| 5828 | /** |
||
| 5829 | * Gets all arrival airports of the airplanes that have flown over based on an airline icao |
||
| 5830 | * |
||
| 5831 | * @return Array the airport list |
||
| 5832 | * |
||
| 5833 | */ |
||
| 5834 | View Code Duplication | public function countAllArrivalAirportsByAirline($airline_icao) |
|
| 5835 | { |
||
| 5836 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5837 | |||
| 5838 | $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 |
||
| 5839 | FROM spotter_output |
||
| 5840 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.airline_icao = :airline_icao |
||
| 5841 | GROUP BY spotter_output.arrival_airport_icao |
||
| 5842 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 5843 | |||
| 5844 | |||
| 5845 | $sth = $this->db->prepare($query); |
||
| 5846 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5847 | |||
| 5848 | $airport_array = array(); |
||
| 5849 | $temp_array = array(); |
||
| 5850 | |||
| 5851 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5852 | { |
||
| 5853 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 5854 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 5855 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 5856 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 5857 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 5858 | |||
| 5859 | $airport_array[] = $temp_array; |
||
| 5860 | } |
||
| 5861 | |||
| 5862 | return $airport_array; |
||
| 5863 | } |
||
| 5864 | |||
| 5865 | |||
| 5866 | /** |
||
| 5867 | * Gets all arrival airports by country of the airplanes that have flown over based on an airline icao |
||
| 5868 | * |
||
| 5869 | * @return Array the airport list |
||
| 5870 | * |
||
| 5871 | */ |
||
| 5872 | public function countAllArrivalAirportCountriesByAirline($airline_icao) |
||
| 5873 | { |
||
| 5874 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 5875 | |||
| 5876 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 5877 | FROM spotter_output |
||
| 5878 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 5879 | GROUP BY spotter_output.arrival_airport_country |
||
| 5880 | ORDER BY airport_arrival_country_count DESC"; |
||
| 5881 | |||
| 5882 | |||
| 5883 | $sth = $this->db->prepare($query); |
||
| 5884 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 5885 | |||
| 5886 | $airport_array = array(); |
||
| 5887 | $temp_array = array(); |
||
| 5888 | |||
| 5889 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5890 | { |
||
| 5891 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 5892 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 5893 | |||
| 5894 | $airport_array[] = $temp_array; |
||
| 5895 | } |
||
| 5896 | |||
| 5897 | return $airport_array; |
||
| 5898 | } |
||
| 5899 | |||
| 5900 | |||
| 5901 | /** |
||
| 5902 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft icao |
||
| 5903 | * |
||
| 5904 | * @return Array the airport list |
||
| 5905 | * |
||
| 5906 | */ |
||
| 5907 | View Code Duplication | public function countAllArrivalAirportsByAircraft($aircraft_icao) |
|
| 5908 | { |
||
| 5909 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 5910 | |||
| 5911 | $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 |
||
| 5912 | FROM spotter_output |
||
| 5913 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 5914 | GROUP BY spotter_output.arrival_airport_icao |
||
| 5915 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 5916 | |||
| 5917 | |||
| 5918 | $sth = $this->db->prepare($query); |
||
| 5919 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 5920 | |||
| 5921 | $airport_array = array(); |
||
| 5922 | $temp_array = array(); |
||
| 5923 | |||
| 5924 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5925 | { |
||
| 5926 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 5927 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 5928 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 5929 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 5930 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 5931 | |||
| 5932 | $airport_array[] = $temp_array; |
||
| 5933 | } |
||
| 5934 | |||
| 5935 | return $airport_array; |
||
| 5936 | } |
||
| 5937 | |||
| 5938 | |||
| 5939 | |||
| 5940 | /** |
||
| 5941 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft icao |
||
| 5942 | * |
||
| 5943 | * @return Array the airport list |
||
| 5944 | * |
||
| 5945 | */ |
||
| 5946 | public function countAllArrivalAirportCountriesByAircraft($aircraft_icao) |
||
| 5947 | { |
||
| 5948 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 5949 | |||
| 5950 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 5951 | FROM spotter_output |
||
| 5952 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 5953 | GROUP BY spotter_output.arrival_airport_country |
||
| 5954 | ORDER BY airport_arrival_country_count DESC"; |
||
| 5955 | |||
| 5956 | |||
| 5957 | $sth = $this->db->prepare($query); |
||
| 5958 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 5959 | |||
| 5960 | $airport_array = array(); |
||
| 5961 | $temp_array = array(); |
||
| 5962 | |||
| 5963 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5964 | { |
||
| 5965 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 5966 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 5967 | |||
| 5968 | $airport_array[] = $temp_array; |
||
| 5969 | } |
||
| 5970 | |||
| 5971 | return $airport_array; |
||
| 5972 | } |
||
| 5973 | |||
| 5974 | |||
| 5975 | /** |
||
| 5976 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft registration |
||
| 5977 | * |
||
| 5978 | * @return Array the airport list |
||
| 5979 | * |
||
| 5980 | */ |
||
| 5981 | View Code Duplication | public function countAllArrivalAirportsByRegistration($registration) |
|
| 5982 | { |
||
| 5983 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 5984 | |||
| 5985 | $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 |
||
| 5986 | FROM spotter_output |
||
| 5987 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.registration = :registration |
||
| 5988 | GROUP BY spotter_output.arrival_airport_icao |
||
| 5989 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 5990 | |||
| 5991 | |||
| 5992 | $sth = $this->db->prepare($query); |
||
| 5993 | $sth->execute(array(':registration' => $registration)); |
||
| 5994 | |||
| 5995 | $airport_array = array(); |
||
| 5996 | $temp_array = array(); |
||
| 5997 | |||
| 5998 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 5999 | { |
||
| 6000 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6001 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6002 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6003 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6004 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6005 | |||
| 6006 | $airport_array[] = $temp_array; |
||
| 6007 | } |
||
| 6008 | |||
| 6009 | return $airport_array; |
||
| 6010 | } |
||
| 6011 | |||
| 6012 | |||
| 6013 | /** |
||
| 6014 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft registration |
||
| 6015 | * |
||
| 6016 | * @return Array the airport list |
||
| 6017 | * |
||
| 6018 | */ |
||
| 6019 | public function countAllArrivalAirportCountriesByRegistration($registration) |
||
| 6020 | { |
||
| 6021 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 6022 | |||
| 6023 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6024 | FROM spotter_output |
||
| 6025 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.registration = :registration |
||
| 6026 | GROUP BY spotter_output.arrival_airport_country |
||
| 6027 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6028 | |||
| 6029 | |||
| 6030 | $sth = $this->db->prepare($query); |
||
| 6031 | $sth->execute(array(':registration' => $registration)); |
||
| 6032 | |||
| 6033 | $airport_array = array(); |
||
| 6034 | $temp_array = array(); |
||
| 6035 | |||
| 6036 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6037 | { |
||
| 6038 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6039 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6040 | |||
| 6041 | $airport_array[] = $temp_array; |
||
| 6042 | } |
||
| 6043 | |||
| 6044 | return $airport_array; |
||
| 6045 | } |
||
| 6046 | |||
| 6047 | |||
| 6048 | |||
| 6049 | /** |
||
| 6050 | * Gets all arrival airports of the airplanes that have flown over based on an departure airport |
||
| 6051 | * |
||
| 6052 | * @return Array the airport list |
||
| 6053 | * |
||
| 6054 | */ |
||
| 6055 | View Code Duplication | public function countAllArrivalAirportsByAirport($airport_icao) |
|
| 6056 | { |
||
| 6057 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 6058 | |||
| 6059 | $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 |
||
| 6060 | FROM spotter_output |
||
| 6061 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.departure_airport_icao = :airport_icao |
||
| 6062 | GROUP BY spotter_output.arrival_airport_icao |
||
| 6063 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6064 | |||
| 6065 | |||
| 6066 | $sth = $this->db->prepare($query); |
||
| 6067 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 6068 | |||
| 6069 | $airport_array = array(); |
||
| 6070 | $temp_array = array(); |
||
| 6071 | |||
| 6072 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6073 | { |
||
| 6074 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6075 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6076 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6077 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6078 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6079 | |||
| 6080 | $airport_array[] = $temp_array; |
||
| 6081 | } |
||
| 6082 | |||
| 6083 | return $airport_array; |
||
| 6084 | } |
||
| 6085 | |||
| 6086 | |||
| 6087 | /** |
||
| 6088 | * Gets all arrival airports by country of the airplanes that have flown over based on an airport icao |
||
| 6089 | * |
||
| 6090 | * @return Array the airport list |
||
| 6091 | * |
||
| 6092 | */ |
||
| 6093 | public function countAllArrivalAirportCountriesByAirport($airport_icao) |
||
| 6094 | { |
||
| 6095 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 6096 | |||
| 6097 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6098 | FROM spotter_output |
||
| 6099 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.departure_airport_icao = :airport_icao |
||
| 6100 | GROUP BY spotter_output.arrival_airport_country |
||
| 6101 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6102 | |||
| 6103 | |||
| 6104 | $sth = $this->db->prepare($query); |
||
| 6105 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 6106 | |||
| 6107 | $airport_array = array(); |
||
| 6108 | $temp_array = array(); |
||
| 6109 | |||
| 6110 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6111 | { |
||
| 6112 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6113 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6114 | |||
| 6115 | $airport_array[] = $temp_array; |
||
| 6116 | } |
||
| 6117 | |||
| 6118 | return $airport_array; |
||
| 6119 | } |
||
| 6120 | |||
| 6121 | |||
| 6122 | /** |
||
| 6123 | * Gets all arrival airports of the airplanes that have flown over based on a aircraft manufacturer |
||
| 6124 | * |
||
| 6125 | * @return Array the airport list |
||
| 6126 | * |
||
| 6127 | */ |
||
| 6128 | View Code Duplication | public function countAllArrivalAirportsByManufacturer($aircraft_manufacturer) |
|
| 6129 | { |
||
| 6130 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 6131 | |||
| 6132 | $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 |
||
| 6133 | FROM spotter_output |
||
| 6134 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 6135 | GROUP BY spotter_output.arrival_airport_icao |
||
| 6136 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6137 | |||
| 6138 | |||
| 6139 | $sth = $this->db->prepare($query); |
||
| 6140 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 6141 | |||
| 6142 | $airport_array = array(); |
||
| 6143 | $temp_array = array(); |
||
| 6144 | |||
| 6145 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6146 | { |
||
| 6147 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6148 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6149 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6150 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6151 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6152 | |||
| 6153 | $airport_array[] = $temp_array; |
||
| 6154 | } |
||
| 6155 | |||
| 6156 | return $airport_array; |
||
| 6157 | } |
||
| 6158 | |||
| 6159 | |||
| 6160 | |||
| 6161 | /** |
||
| 6162 | * Gets all arrival airports by country of the airplanes that have flown over based on a aircraft manufacturer |
||
| 6163 | * |
||
| 6164 | * @return Array the airport list |
||
| 6165 | * |
||
| 6166 | */ |
||
| 6167 | public function countAllArrivalAirportCountriesByManufacturer($aircraft_manufacturer) |
||
| 6168 | { |
||
| 6169 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 6170 | |||
| 6171 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6172 | FROM spotter_output |
||
| 6173 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 6174 | GROUP BY spotter_output.arrival_airport_country |
||
| 6175 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6176 | |||
| 6177 | |||
| 6178 | $sth = $this->db->prepare($query); |
||
| 6179 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 6180 | |||
| 6181 | $airport_array = array(); |
||
| 6182 | $temp_array = array(); |
||
| 6183 | |||
| 6184 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6185 | { |
||
| 6186 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6187 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6188 | |||
| 6189 | $airport_array[] = $temp_array; |
||
| 6190 | } |
||
| 6191 | |||
| 6192 | return $airport_array; |
||
| 6193 | } |
||
| 6194 | |||
| 6195 | |||
| 6196 | |||
| 6197 | /** |
||
| 6198 | * Gets all arrival airports of the airplanes that have flown over based on a date |
||
| 6199 | * |
||
| 6200 | * @return Array the airport list |
||
| 6201 | * |
||
| 6202 | */ |
||
| 6203 | View Code Duplication | public function countAllArrivalAirportsByDate($date) |
|
| 6204 | { |
||
| 6205 | global $globalTimezone, $globalDBdriver; |
||
| 6206 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 6207 | if ($globalTimezone != '') { |
||
| 6208 | date_default_timezone_set($globalTimezone); |
||
| 6209 | $datetime = new DateTime($date); |
||
| 6210 | $offset = $datetime->format('P'); |
||
| 6211 | } else $offset = '+00:00'; |
||
| 6212 | |||
| 6213 | if ($globalDBdriver == 'mysql') { |
||
| 6214 | $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 |
||
| 6215 | FROM spotter_output |
||
| 6216 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 6217 | GROUP BY spotter_output.arrival_airport_icao |
||
| 6218 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6219 | } else { |
||
| 6220 | $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 |
||
| 6221 | FROM spotter_output |
||
| 6222 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 6223 | GROUP BY spotter_output.arrival_airport_icao |
||
| 6224 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6225 | } |
||
| 6226 | |||
| 6227 | $sth = $this->db->prepare($query); |
||
| 6228 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 6229 | |||
| 6230 | $airport_array = array(); |
||
| 6231 | $temp_array = array(); |
||
| 6232 | |||
| 6233 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6234 | { |
||
| 6235 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6236 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6237 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6238 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6239 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6240 | |||
| 6241 | $airport_array[] = $temp_array; |
||
| 6242 | } |
||
| 6243 | return $airport_array; |
||
| 6244 | } |
||
| 6245 | |||
| 6246 | |||
| 6247 | |||
| 6248 | /** |
||
| 6249 | * Gets all arrival airports by country of the airplanes that have flown over based on a date |
||
| 6250 | * |
||
| 6251 | * @return Array the airport list |
||
| 6252 | * |
||
| 6253 | */ |
||
| 6254 | View Code Duplication | public function countAllArrivalAirportCountriesByDate($date) |
|
| 6255 | { |
||
| 6256 | global $globalTimezone, $globalDBdriver; |
||
| 6257 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 6258 | if ($globalTimezone != '') { |
||
| 6259 | date_default_timezone_set($globalTimezone); |
||
| 6260 | $datetime = new DateTime($date); |
||
| 6261 | $offset = $datetime->format('P'); |
||
| 6262 | } else $offset = '+00:00'; |
||
| 6263 | |||
| 6264 | if ($globalDBdriver == 'mysql') { |
||
| 6265 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6266 | FROM spotter_output |
||
| 6267 | WHERE spotter_output.arrival_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 6268 | GROUP BY spotter_output.arrival_airport_country |
||
| 6269 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6270 | } else { |
||
| 6271 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6272 | FROM spotter_output |
||
| 6273 | WHERE spotter_output.arrival_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 6274 | GROUP BY spotter_output.arrival_airport_country |
||
| 6275 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6276 | } |
||
| 6277 | |||
| 6278 | $sth = $this->db->prepare($query); |
||
| 6279 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 6280 | |||
| 6281 | $airport_array = array(); |
||
| 6282 | $temp_array = array(); |
||
| 6283 | |||
| 6284 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6285 | { |
||
| 6286 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6287 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6288 | |||
| 6289 | $airport_array[] = $temp_array; |
||
| 6290 | } |
||
| 6291 | return $airport_array; |
||
| 6292 | } |
||
| 6293 | |||
| 6294 | |||
| 6295 | |||
| 6296 | /** |
||
| 6297 | * Gets all arrival airports of the airplanes that have flown over based on a ident/callsign |
||
| 6298 | * |
||
| 6299 | * @return Array the airport list |
||
| 6300 | * |
||
| 6301 | */ |
||
| 6302 | View Code Duplication | public function countAllArrivalAirportsByIdent($ident) |
|
| 6303 | { |
||
| 6304 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 6305 | |||
| 6306 | $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 |
||
| 6307 | FROM spotter_output |
||
| 6308 | WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.ident = :ident |
||
| 6309 | GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country |
||
| 6310 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6311 | |||
| 6312 | |||
| 6313 | $sth = $this->db->prepare($query); |
||
| 6314 | $sth->execute(array(':ident' => $ident)); |
||
| 6315 | |||
| 6316 | $airport_array = array(); |
||
| 6317 | $temp_array = array(); |
||
| 6318 | |||
| 6319 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6320 | { |
||
| 6321 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6322 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6323 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6324 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6325 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6326 | |||
| 6327 | $airport_array[] = $temp_array; |
||
| 6328 | } |
||
| 6329 | |||
| 6330 | return $airport_array; |
||
| 6331 | } |
||
| 6332 | |||
| 6333 | |||
| 6334 | /** |
||
| 6335 | * Gets all arrival airports by country of the airplanes that have flown over based on a callsign/ident |
||
| 6336 | * |
||
| 6337 | * @return Array the airport list |
||
| 6338 | * |
||
| 6339 | */ |
||
| 6340 | public function countAllArrivalAirportCountriesByIdent($ident) |
||
| 6341 | { |
||
| 6342 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 6343 | |||
| 6344 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6345 | FROM spotter_output |
||
| 6346 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.ident = :ident |
||
| 6347 | GROUP BY spotter_output.arrival_airport_country |
||
| 6348 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6349 | |||
| 6350 | |||
| 6351 | $sth = $this->db->prepare($query); |
||
| 6352 | $sth->execute(array(':ident' => $ident)); |
||
| 6353 | |||
| 6354 | $airport_array = array(); |
||
| 6355 | $temp_array = array(); |
||
| 6356 | |||
| 6357 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6358 | { |
||
| 6359 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6360 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6361 | |||
| 6362 | $airport_array[] = $temp_array; |
||
| 6363 | } |
||
| 6364 | |||
| 6365 | return $airport_array; |
||
| 6366 | } |
||
| 6367 | |||
| 6368 | |||
| 6369 | |||
| 6370 | /** |
||
| 6371 | * Gets all arrival airports of the airplanes that have flown over based on a country |
||
| 6372 | * |
||
| 6373 | * @return Array the airport list |
||
| 6374 | * |
||
| 6375 | */ |
||
| 6376 | View Code Duplication | public function countAllArrivalAirportsByCountry($country) |
|
| 6377 | { |
||
| 6378 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 6379 | |||
| 6380 | $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 |
||
| 6381 | FROM spotter_output |
||
| 6382 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 6383 | GROUP BY spotter_output.arrival_airport_icao |
||
| 6384 | ORDER BY airport_arrival_icao_count DESC"; |
||
| 6385 | |||
| 6386 | |||
| 6387 | $sth = $this->db->prepare($query); |
||
| 6388 | $sth->execute(array(':country' => $country)); |
||
| 6389 | |||
| 6390 | $airport_array = array(); |
||
| 6391 | $temp_array = array(); |
||
| 6392 | |||
| 6393 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6394 | { |
||
| 6395 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6396 | $temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
||
| 6397 | $temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
||
| 6398 | $temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
||
| 6399 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6400 | |||
| 6401 | $airport_array[] = $temp_array; |
||
| 6402 | } |
||
| 6403 | |||
| 6404 | return $airport_array; |
||
| 6405 | } |
||
| 6406 | |||
| 6407 | |||
| 6408 | /** |
||
| 6409 | * Gets all arrival airports by country of the airplanes that have flown over based on a country |
||
| 6410 | * |
||
| 6411 | * @return Array the airport list |
||
| 6412 | * |
||
| 6413 | */ |
||
| 6414 | public function countAllArrivalAirportCountriesByCountry($country) |
||
| 6415 | { |
||
| 6416 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 6417 | |||
| 6418 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6419 | FROM spotter_output |
||
| 6420 | WHERE 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 |
||
| 6421 | GROUP BY spotter_output.arrival_airport_country |
||
| 6422 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6423 | |||
| 6424 | |||
| 6425 | $sth = $this->db->prepare($query); |
||
| 6426 | $sth->execute(array(':country' => $country)); |
||
| 6427 | |||
| 6428 | $airport_array = array(); |
||
| 6429 | $temp_array = array(); |
||
| 6430 | |||
| 6431 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6432 | { |
||
| 6433 | $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; |
||
| 6434 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6435 | |||
| 6436 | $airport_array[] = $temp_array; |
||
| 6437 | } |
||
| 6438 | |||
| 6439 | return $airport_array; |
||
| 6440 | } |
||
| 6441 | |||
| 6442 | |||
| 6443 | |||
| 6444 | /** |
||
| 6445 | * Counts all airport departure countries |
||
| 6446 | * |
||
| 6447 | * @return Array the airport departure list |
||
| 6448 | * |
||
| 6449 | */ |
||
| 6450 | View Code Duplication | public function countAllDepartureCountries() |
|
| 6451 | { |
||
| 6452 | $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count |
||
| 6453 | FROM spotter_output |
||
| 6454 | WHERE spotter_output.departure_airport_country <> '' AND spotter_output.departure_airport_icao <> 'NA' |
||
| 6455 | GROUP BY spotter_output.departure_airport_country |
||
| 6456 | ORDER BY airport_departure_country_count DESC |
||
| 6457 | LIMIT 10 OFFSET 0"; |
||
| 6458 | |||
| 6459 | |||
| 6460 | $sth = $this->db->prepare($query); |
||
| 6461 | $sth->execute(); |
||
| 6462 | |||
| 6463 | $airport_array = array(); |
||
| 6464 | $temp_array = array(); |
||
| 6465 | |||
| 6466 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6467 | { |
||
| 6468 | $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; |
||
| 6469 | $temp_array['airport_departure_country'] = $row['departure_airport_country']; |
||
| 6470 | |||
| 6471 | $airport_array[] = $temp_array; |
||
| 6472 | } |
||
| 6473 | |||
| 6474 | return $airport_array; |
||
| 6475 | } |
||
| 6476 | |||
| 6477 | |||
| 6478 | /** |
||
| 6479 | * Counts all airport arrival countries |
||
| 6480 | * |
||
| 6481 | * @return Array the airport arrival list |
||
| 6482 | * |
||
| 6483 | */ |
||
| 6484 | View Code Duplication | public function countAllArrivalCountries($limit = true) |
|
| 6485 | { |
||
| 6486 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count |
||
| 6487 | FROM spotter_output |
||
| 6488 | WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.arrival_airport_icao <> 'NA' |
||
| 6489 | GROUP BY spotter_output.arrival_airport_country |
||
| 6490 | ORDER BY airport_arrival_country_count DESC"; |
||
| 6491 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6492 | |||
| 6493 | |||
| 6494 | $sth = $this->db->prepare($query); |
||
| 6495 | $sth->execute(); |
||
| 6496 | |||
| 6497 | $airport_array = array(); |
||
| 6498 | $temp_array = array(); |
||
| 6499 | |||
| 6500 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6501 | { |
||
| 6502 | $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; |
||
| 6503 | $temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
||
| 6504 | |||
| 6505 | $airport_array[] = $temp_array; |
||
| 6506 | } |
||
| 6507 | |||
| 6508 | return $airport_array; |
||
| 6509 | } |
||
| 6510 | |||
| 6511 | |||
| 6512 | |||
| 6513 | |||
| 6514 | |||
| 6515 | /** |
||
| 6516 | * Gets all route combinations |
||
| 6517 | * |
||
| 6518 | * @return Array the route list |
||
| 6519 | * |
||
| 6520 | */ |
||
| 6521 | public function countAllRoutes() |
||
| 6522 | { |
||
| 6523 | |||
| 6524 | $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 |
||
| 6525 | FROM spotter_output |
||
| 6526 | WHERE spotter_output.ident <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> 'NA' |
||
| 6527 | 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 |
||
| 6528 | ORDER BY route_count DESC |
||
| 6529 | LIMIT 10 OFFSET 0"; |
||
| 6530 | |||
| 6531 | |||
| 6532 | $sth = $this->db->prepare($query); |
||
| 6533 | $sth->execute(); |
||
| 6534 | |||
| 6535 | $routes_array = array(); |
||
| 6536 | $temp_array = array(); |
||
| 6537 | |||
| 6538 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6539 | { |
||
| 6540 | $temp_array['route_count'] = $row['route_count']; |
||
| 6541 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6542 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6543 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6544 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6545 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6546 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6547 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6548 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6549 | |||
| 6550 | $routes_array[] = $temp_array; |
||
| 6551 | } |
||
| 6552 | |||
| 6553 | return $routes_array; |
||
| 6554 | } |
||
| 6555 | |||
| 6556 | |||
| 6557 | |||
| 6558 | |||
| 6559 | /** |
||
| 6560 | * Gets all route combinations based on an aircraft |
||
| 6561 | * |
||
| 6562 | * @return Array the route list |
||
| 6563 | * |
||
| 6564 | */ |
||
| 6565 | View Code Duplication | public function countAllRoutesByAircraft($aircraft_icao) |
|
| 6566 | { |
||
| 6567 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 6568 | |||
| 6569 | $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 |
||
| 6570 | FROM spotter_output |
||
| 6571 | WHERE spotter_output.ident <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
| 6572 | GROUP BY route |
||
| 6573 | ORDER BY route_count DESC"; |
||
| 6574 | |||
| 6575 | |||
| 6576 | $sth = $this->db->prepare($query); |
||
| 6577 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
| 6578 | |||
| 6579 | $routes_array = array(); |
||
| 6580 | $temp_array = array(); |
||
| 6581 | |||
| 6582 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6583 | { |
||
| 6584 | $temp_array['route_count'] = $row['route_count']; |
||
| 6585 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6586 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6587 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6588 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6589 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6590 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6591 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6592 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6593 | |||
| 6594 | $routes_array[] = $temp_array; |
||
| 6595 | } |
||
| 6596 | |||
| 6597 | return $routes_array; |
||
| 6598 | } |
||
| 6599 | |||
| 6600 | |||
| 6601 | /** |
||
| 6602 | * Gets all route combinations based on an aircraft registration |
||
| 6603 | * |
||
| 6604 | * @return Array the route list |
||
| 6605 | * |
||
| 6606 | */ |
||
| 6607 | View Code Duplication | public function countAllRoutesByRegistration($registration) |
|
| 6608 | { |
||
| 6609 | $registration = filter_var($registration, FILTER_SANITIZE_STRING); |
||
| 6610 | |||
| 6611 | $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 |
||
| 6612 | FROM spotter_output |
||
| 6613 | WHERE spotter_output.ident <> '' AND spotter_output.registration = :registration |
||
| 6614 | GROUP BY route |
||
| 6615 | ORDER BY route_count DESC"; |
||
| 6616 | |||
| 6617 | |||
| 6618 | $sth = $this->db->prepare($query); |
||
| 6619 | $sth->execute(array(':registration' => $registration)); |
||
| 6620 | |||
| 6621 | $routes_array = array(); |
||
| 6622 | $temp_array = array(); |
||
| 6623 | |||
| 6624 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6625 | { |
||
| 6626 | $temp_array['route_count'] = $row['route_count']; |
||
| 6627 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6628 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6629 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6630 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6631 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6632 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6633 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6634 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6635 | |||
| 6636 | $routes_array[] = $temp_array; |
||
| 6637 | } |
||
| 6638 | |||
| 6639 | return $routes_array; |
||
| 6640 | } |
||
| 6641 | |||
| 6642 | |||
| 6643 | |||
| 6644 | /** |
||
| 6645 | * Gets all route combinations based on an airline |
||
| 6646 | * |
||
| 6647 | * @return Array the route list |
||
| 6648 | * |
||
| 6649 | */ |
||
| 6650 | View Code Duplication | public function countAllRoutesByAirline($airline_icao) |
|
| 6651 | { |
||
| 6652 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 6653 | |||
| 6654 | $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 |
||
| 6655 | FROM spotter_output |
||
| 6656 | WHERE spotter_output.ident <> '' AND spotter_output.airline_icao = :airline_icao |
||
| 6657 | GROUP BY route |
||
| 6658 | ORDER BY route_count DESC"; |
||
| 6659 | |||
| 6660 | |||
| 6661 | $sth = $this->db->prepare($query); |
||
| 6662 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
| 6663 | |||
| 6664 | $routes_array = array(); |
||
| 6665 | $temp_array = array(); |
||
| 6666 | |||
| 6667 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6668 | { |
||
| 6669 | $temp_array['route_count'] = $row['route_count']; |
||
| 6670 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6671 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6672 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6673 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6674 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6675 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6676 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6677 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6678 | |||
| 6679 | $routes_array[] = $temp_array; |
||
| 6680 | } |
||
| 6681 | |||
| 6682 | return $routes_array; |
||
| 6683 | } |
||
| 6684 | |||
| 6685 | |||
| 6686 | |||
| 6687 | /** |
||
| 6688 | * Gets all route combinations based on an airport |
||
| 6689 | * |
||
| 6690 | * @return Array the route list |
||
| 6691 | * |
||
| 6692 | */ |
||
| 6693 | View Code Duplication | public function countAllRoutesByAirport($airport_icao) |
|
| 6694 | { |
||
| 6695 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 6696 | |||
| 6697 | $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 |
||
| 6698 | FROM spotter_output |
||
| 6699 | WHERE spotter_output.ident <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 6700 | GROUP BY route |
||
| 6701 | ORDER BY route_count DESC"; |
||
| 6702 | |||
| 6703 | |||
| 6704 | $sth = $this->db->prepare($query); |
||
| 6705 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
| 6706 | |||
| 6707 | $routes_array = array(); |
||
| 6708 | $temp_array = array(); |
||
| 6709 | |||
| 6710 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6711 | { |
||
| 6712 | $temp_array['route_count'] = $row['route_count']; |
||
| 6713 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6714 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6715 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6716 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6717 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6718 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6719 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6720 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6721 | |||
| 6722 | $routes_array[] = $temp_array; |
||
| 6723 | } |
||
| 6724 | |||
| 6725 | return $routes_array; |
||
| 6726 | } |
||
| 6727 | |||
| 6728 | |||
| 6729 | |||
| 6730 | /** |
||
| 6731 | * Gets all route combinations based on an country |
||
| 6732 | * |
||
| 6733 | * @return Array the route list |
||
| 6734 | * |
||
| 6735 | */ |
||
| 6736 | View Code Duplication | public function countAllRoutesByCountry($country) |
|
| 6737 | { |
||
| 6738 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 6739 | |||
| 6740 | $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 |
||
| 6741 | FROM spotter_output |
||
| 6742 | WHERE spotter_output.ident <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 6743 | GROUP BY route |
||
| 6744 | ORDER BY route_count DESC"; |
||
| 6745 | |||
| 6746 | |||
| 6747 | $sth = $this->db->prepare($query); |
||
| 6748 | $sth->execute(array(':country' => $country)); |
||
| 6749 | |||
| 6750 | $routes_array = array(); |
||
| 6751 | $temp_array = array(); |
||
| 6752 | |||
| 6753 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6754 | { |
||
| 6755 | $temp_array['route_count'] = $row['route_count']; |
||
| 6756 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6757 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6758 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6759 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6760 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6761 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6762 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6763 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6764 | |||
| 6765 | $routes_array[] = $temp_array; |
||
| 6766 | } |
||
| 6767 | |||
| 6768 | return $routes_array; |
||
| 6769 | } |
||
| 6770 | |||
| 6771 | |||
| 6772 | /** |
||
| 6773 | * Gets all route combinations based on an date |
||
| 6774 | * |
||
| 6775 | * @return Array the route list |
||
| 6776 | * |
||
| 6777 | */ |
||
| 6778 | public function countAllRoutesByDate($date) |
||
| 6779 | { |
||
| 6780 | global $globalTimezone, $globalDBdriver; |
||
| 6781 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 6782 | if ($globalTimezone != '') { |
||
| 6783 | date_default_timezone_set($globalTimezone); |
||
| 6784 | $datetime = new DateTime($date); |
||
| 6785 | $offset = $datetime->format('P'); |
||
| 6786 | } else $offset = '+00:00'; |
||
| 6787 | |||
| 6788 | if ($globalDBdriver == 'mysql') { |
||
| 6789 | $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 |
||
| 6790 | FROM spotter_output |
||
| 6791 | WHERE spotter_output.ident <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 6792 | GROUP BY route |
||
| 6793 | ORDER BY route_count DESC"; |
||
| 6794 | } else { |
||
| 6795 | $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 |
||
| 6796 | FROM spotter_output |
||
| 6797 | WHERE spotter_output.ident <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
| 6798 | GROUP BY route |
||
| 6799 | ORDER BY route_count DESC"; |
||
| 6800 | } |
||
| 6801 | |||
| 6802 | $sth = $this->db->prepare($query); |
||
| 6803 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 6804 | |||
| 6805 | $routes_array = array(); |
||
| 6806 | $temp_array = array(); |
||
| 6807 | |||
| 6808 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6809 | { |
||
| 6810 | $temp_array['route_count'] = $row['route_count']; |
||
| 6811 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6812 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6813 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6814 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6815 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6816 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6817 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6818 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6819 | |||
| 6820 | $routes_array[] = $temp_array; |
||
| 6821 | } |
||
| 6822 | |||
| 6823 | return $routes_array; |
||
| 6824 | } |
||
| 6825 | |||
| 6826 | |||
| 6827 | /** |
||
| 6828 | * Gets all route combinations based on an ident/callsign |
||
| 6829 | * |
||
| 6830 | * @return Array the route list |
||
| 6831 | * |
||
| 6832 | */ |
||
| 6833 | View Code Duplication | public function countAllRoutesByIdent($ident) |
|
| 6834 | { |
||
| 6835 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 6836 | |||
| 6837 | $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 |
||
| 6838 | FROM spotter_output |
||
| 6839 | WHERE spotter_output.ident <> '' AND spotter_output.ident = :ident |
||
| 6840 | 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 |
||
| 6841 | ORDER BY route_count DESC"; |
||
| 6842 | |||
| 6843 | |||
| 6844 | $sth = $this->db->prepare($query); |
||
| 6845 | $sth->execute(array(':ident' => $ident)); |
||
| 6846 | |||
| 6847 | $routes_array = array(); |
||
| 6848 | $temp_array = array(); |
||
| 6849 | |||
| 6850 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6851 | { |
||
| 6852 | $temp_array['route_count'] = $row['route_count']; |
||
| 6853 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6854 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6855 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6856 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6857 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6858 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6859 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6860 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6861 | |||
| 6862 | $routes_array[] = $temp_array; |
||
| 6863 | } |
||
| 6864 | |||
| 6865 | return $routes_array; |
||
| 6866 | } |
||
| 6867 | |||
| 6868 | |||
| 6869 | /** |
||
| 6870 | * Gets all route combinations based on an manufacturer |
||
| 6871 | * |
||
| 6872 | * @return Array the route list |
||
| 6873 | * |
||
| 6874 | */ |
||
| 6875 | View Code Duplication | public function countAllRoutesByManufacturer($aircraft_manufacturer) |
|
| 6876 | { |
||
| 6877 | $aircraft_manufacturer = filter_var($aircraft_manufactuer,FILTER_SANITIZE_STRING); |
||
| 6878 | |||
| 6879 | $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 |
||
| 6880 | FROM spotter_output |
||
| 6881 | WHERE spotter_output.ident <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 6882 | GROUP BY route |
||
| 6883 | ORDER BY route_count DESC"; |
||
| 6884 | |||
| 6885 | |||
| 6886 | $sth = $this->db->prepare($query); |
||
| 6887 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
| 6888 | |||
| 6889 | $routes_array = array(); |
||
| 6890 | $temp_array = array(); |
||
| 6891 | |||
| 6892 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6893 | { |
||
| 6894 | $temp_array['route_count'] = $row['route_count']; |
||
| 6895 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6896 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6897 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6898 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6899 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6900 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6901 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6902 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6903 | |||
| 6904 | $routes_array[] = $temp_array; |
||
| 6905 | } |
||
| 6906 | |||
| 6907 | return $routes_array; |
||
| 6908 | } |
||
| 6909 | |||
| 6910 | |||
| 6911 | |||
| 6912 | /** |
||
| 6913 | * Gets all route combinations with waypoints |
||
| 6914 | * |
||
| 6915 | * @return Array the route list |
||
| 6916 | * |
||
| 6917 | */ |
||
| 6918 | public function countAllRoutesWithWaypoints() |
||
| 6919 | { |
||
| 6920 | $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 |
||
| 6921 | FROM spotter_output |
||
| 6922 | WHERE spotter_output.ident <> '' AND spotter_output.waypoints <> '' |
||
| 6923 | 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 |
||
| 6924 | ORDER BY route_count DESC |
||
| 6925 | LIMIT 10 OFFSET 0"; |
||
| 6926 | |||
| 6927 | |||
| 6928 | $sth = $this->db->prepare($query); |
||
| 6929 | $sth->execute(); |
||
| 6930 | |||
| 6931 | $routes_array = array(); |
||
| 6932 | $temp_array = array(); |
||
| 6933 | |||
| 6934 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6935 | { |
||
| 6936 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
| 6937 | $temp_array['route_count'] = $row['route_count']; |
||
| 6938 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
| 6939 | $temp_array['airport_departure_name'] = $row['airport_departure_name']; |
||
| 6940 | $temp_array['airport_departure_city'] = $row['airport_departure_city']; |
||
| 6941 | $temp_array['airport_departure_country'] = $row['airport_departure_country']; |
||
| 6942 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
| 6943 | $temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
||
| 6944 | $temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
||
| 6945 | $temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
||
| 6946 | |||
| 6947 | $routes_array[] = $temp_array; |
||
| 6948 | } |
||
| 6949 | |||
| 6950 | return $routes_array; |
||
| 6951 | } |
||
| 6952 | |||
| 6953 | |||
| 6954 | |||
| 6955 | |||
| 6956 | /** |
||
| 6957 | * Gets all callsigns that have flown over |
||
| 6958 | * |
||
| 6959 | * @return Array the callsign list |
||
| 6960 | * |
||
| 6961 | */ |
||
| 6962 | View Code Duplication | public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '') |
|
| 6963 | { |
||
| 6964 | global $globalDBdriver; |
||
| 6965 | $query = "SELECT DISTINCT spotter_output.ident, COUNT(spotter_output.ident) AS callsign_icao_count, spotter_output.airline_name, spotter_output.airline_icao |
||
| 6966 | FROM spotter_output |
||
| 6967 | WHERE spotter_output.ident <> '' "; |
||
| 6968 | if ($olderthanmonths > 0) { |
||
| 6969 | if ($globalDBdriver == 'mysql') $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
| 6970 | else $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
| 6971 | } |
||
| 6972 | if ($sincedate != '') { |
||
| 6973 | if ($globalDBdriver == 'mysql') $query .= "AND date > '".$sincedate."' "; |
||
| 6974 | else $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP) "; |
||
| 6975 | } |
||
| 6976 | $query .= "GROUP BY spotter_output.ident, spotter_output.airline_name, spotter_output.airline_icao ORDER BY callsign_icao_count DESC"; |
||
| 6977 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
| 6978 | |||
| 6979 | $sth = $this->db->prepare($query); |
||
| 6980 | $sth->execute(); |
||
| 6981 | |||
| 6982 | $callsign_array = array(); |
||
| 6983 | $temp_array = array(); |
||
| 6984 | |||
| 6985 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 6986 | { |
||
| 6987 | $temp_array['callsign_icao'] = $row['ident']; |
||
| 6988 | $temp_array['airline_name'] = $row['airline_name']; |
||
| 6989 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
| 6990 | $temp_array['callsign_icao_count'] = $row['callsign_icao_count']; |
||
| 6991 | |||
| 6992 | $callsign_array[] = $temp_array; |
||
| 6993 | } |
||
| 6994 | |||
| 6995 | return $callsign_array; |
||
| 6996 | } |
||
| 6997 | |||
| 6998 | |||
| 6999 | |||
| 7000 | |||
| 7001 | /** |
||
| 7002 | * Counts all dates |
||
| 7003 | * |
||
| 7004 | * @return Array the date list |
||
| 7005 | * |
||
| 7006 | */ |
||
| 7007 | View Code Duplication | public function countAllDates() |
|
| 7008 | { |
||
| 7009 | global $globalTimezone, $globalDBdriver; |
||
| 7010 | if ($globalTimezone != '') { |
||
| 7011 | date_default_timezone_set($globalTimezone); |
||
| 7012 | $datetime = new DateTime(); |
||
| 7013 | $offset = $datetime->format('P'); |
||
| 7014 | } else $offset = '+00:00'; |
||
| 7015 | |||
| 7016 | if ($globalDBdriver == 'mysql') { |
||
| 7017 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 7018 | FROM spotter_output |
||
| 7019 | GROUP BY date_name |
||
| 7020 | ORDER BY date_count DESC |
||
| 7021 | LIMIT 10 OFFSET 0"; |
||
| 7022 | } else { |
||
| 7023 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 7024 | FROM spotter_output |
||
| 7025 | GROUP BY date_name |
||
| 7026 | ORDER BY date_count DESC |
||
| 7027 | LIMIT 10 OFFSET 0"; |
||
| 7028 | } |
||
| 7029 | |||
| 7030 | |||
| 7031 | $sth = $this->db->prepare($query); |
||
| 7032 | $sth->execute(array(':offset' => $offset)); |
||
| 7033 | |||
| 7034 | $date_array = array(); |
||
| 7035 | $temp_array = array(); |
||
| 7036 | |||
| 7037 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7038 | { |
||
| 7039 | $temp_array['date_name'] = $row['date_name']; |
||
| 7040 | $temp_array['date_count'] = $row['date_count']; |
||
| 7041 | |||
| 7042 | $date_array[] = $temp_array; |
||
| 7043 | } |
||
| 7044 | |||
| 7045 | return $date_array; |
||
| 7046 | } |
||
| 7047 | |||
| 7048 | |||
| 7049 | |||
| 7050 | /** |
||
| 7051 | * Counts all dates during the last 7 days |
||
| 7052 | * |
||
| 7053 | * @return Array the date list |
||
| 7054 | * |
||
| 7055 | */ |
||
| 7056 | View Code Duplication | public function countAllDatesLast7Days() |
|
| 7057 | { |
||
| 7058 | global $globalTimezone, $globalDBdriver; |
||
| 7059 | if ($globalTimezone != '') { |
||
| 7060 | date_default_timezone_set($globalTimezone); |
||
| 7061 | $datetime = new DateTime(); |
||
| 7062 | $offset = $datetime->format('P'); |
||
| 7063 | } else $offset = '+00:00'; |
||
| 7064 | |||
| 7065 | if ($globalDBdriver == 'mysql') { |
||
| 7066 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 7067 | FROM spotter_output |
||
| 7068 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) |
||
| 7069 | GROUP BY date_name |
||
| 7070 | ORDER BY spotter_output.date ASC"; |
||
| 7071 | $query_data = array(':offset' => $offset); |
||
| 7072 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 7073 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 7074 | FROM spotter_output |
||
| 7075 | WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '7 DAYS' |
||
| 7076 | GROUP BY date_name |
||
| 7077 | ORDER BY date_name ASC"; |
||
| 7078 | $query_data = array(':offset' => $offset); |
||
| 7079 | } |
||
| 7080 | |||
| 7081 | $sth = $this->db->prepare($query); |
||
| 7082 | $sth->execute($query_data); |
||
| 7083 | |||
| 7084 | $date_array = array(); |
||
| 7085 | $temp_array = array(); |
||
| 7086 | |||
| 7087 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7088 | { |
||
| 7089 | $temp_array['date_name'] = $row['date_name']; |
||
| 7090 | $temp_array['date_count'] = $row['date_count']; |
||
| 7091 | |||
| 7092 | $date_array[] = $temp_array; |
||
| 7093 | } |
||
| 7094 | |||
| 7095 | return $date_array; |
||
| 7096 | } |
||
| 7097 | |||
| 7098 | /** |
||
| 7099 | * Counts all dates during the last month |
||
| 7100 | * |
||
| 7101 | * @return Array the date list |
||
| 7102 | * |
||
| 7103 | */ |
||
| 7104 | View Code Duplication | public function countAllDatesLastMonth() |
|
| 7105 | { |
||
| 7106 | global $globalTimezone, $globalDBdriver; |
||
| 7107 | if ($globalTimezone != '') { |
||
| 7108 | date_default_timezone_set($globalTimezone); |
||
| 7109 | $datetime = new DateTime(); |
||
| 7110 | $offset = $datetime->format('P'); |
||
| 7111 | } else $offset = '+00:00'; |
||
| 7112 | |||
| 7113 | if ($globalDBdriver == 'mysql') { |
||
| 7114 | $query = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
||
| 7115 | FROM spotter_output |
||
| 7116 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH) |
||
| 7117 | GROUP BY date_name |
||
| 7118 | ORDER BY spotter_output.date ASC"; |
||
| 7119 | $query_data = array(':offset' => $offset); |
||
| 7120 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 7121 | $query = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count |
||
| 7122 | FROM spotter_output |
||
| 7123 | WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS' |
||
| 7124 | GROUP BY date_name |
||
| 7125 | ORDER BY date_name ASC"; |
||
| 7126 | $query_data = array(':offset' => $offset); |
||
| 7127 | } |
||
| 7128 | |||
| 7129 | $sth = $this->db->prepare($query); |
||
| 7130 | $sth->execute($query_data); |
||
| 7131 | |||
| 7132 | $date_array = array(); |
||
| 7133 | $temp_array = array(); |
||
| 7134 | |||
| 7135 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7136 | { |
||
| 7137 | $temp_array['date_name'] = $row['date_name']; |
||
| 7138 | $temp_array['date_count'] = $row['date_count']; |
||
| 7139 | |||
| 7140 | $date_array[] = $temp_array; |
||
| 7141 | } |
||
| 7142 | |||
| 7143 | return $date_array; |
||
| 7144 | } |
||
| 7145 | |||
| 7146 | /** |
||
| 7147 | * Counts all month |
||
| 7148 | * |
||
| 7149 | * @return Array the month list |
||
| 7150 | * |
||
| 7151 | */ |
||
| 7152 | View Code Duplication | public function countAllMonths() |
|
| 7153 | { |
||
| 7154 | global $globalTimezone, $globalDBdriver; |
||
| 7155 | if ($globalTimezone != '') { |
||
| 7156 | date_default_timezone_set($globalTimezone); |
||
| 7157 | $datetime = new DateTime(); |
||
| 7158 | $offset = $datetime->format('P'); |
||
| 7159 | } else $offset = '+00:00'; |
||
| 7160 | |||
| 7161 | if ($globalDBdriver == 'mysql') { |
||
| 7162 | $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 |
||
| 7163 | FROM spotter_output |
||
| 7164 | GROUP BY year_name, month_name |
||
| 7165 | ORDER BY date_count DESC"; |
||
| 7166 | } else { |
||
| 7167 | $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 |
||
| 7168 | FROM spotter_output |
||
| 7169 | GROUP BY year_name, month_name |
||
| 7170 | ORDER BY date_count DESC"; |
||
| 7171 | } |
||
| 7172 | |||
| 7173 | |||
| 7174 | $sth = $this->db->prepare($query); |
||
| 7175 | $sth->execute(array(':offset' => $offset)); |
||
| 7176 | |||
| 7177 | $date_array = array(); |
||
| 7178 | $temp_array = array(); |
||
| 7179 | |||
| 7180 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7181 | { |
||
| 7182 | $temp_array['month_name'] = $row['month_name']; |
||
| 7183 | $temp_array['year_name'] = $row['year_name']; |
||
| 7184 | $temp_array['date_count'] = $row['date_count']; |
||
| 7185 | |||
| 7186 | $date_array[] = $temp_array; |
||
| 7187 | } |
||
| 7188 | |||
| 7189 | return $date_array; |
||
| 7190 | } |
||
| 7191 | |||
| 7192 | /** |
||
| 7193 | * Counts all military month |
||
| 7194 | * |
||
| 7195 | * @return Array the month list |
||
| 7196 | * |
||
| 7197 | */ |
||
| 7198 | View Code Duplication | public function countAllMilitaryMonths() |
|
| 7199 | { |
||
| 7200 | global $globalTimezone, $globalDBdriver; |
||
| 7201 | if ($globalTimezone != '') { |
||
| 7202 | date_default_timezone_set($globalTimezone); |
||
| 7203 | $datetime = new DateTime(); |
||
| 7204 | $offset = $datetime->format('P'); |
||
| 7205 | } else $offset = '+00:00'; |
||
| 7206 | |||
| 7207 | if ($globalDBdriver == 'mysql') { |
||
| 7208 | $query = "SELECT YEAR(CONVERT_TZ(s.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(s.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
||
| 7209 | FROM spotter_output s |
||
| 7210 | WHERE s.airline_type = 'military' |
||
| 7211 | GROUP BY year_name, month_name |
||
| 7212 | ORDER BY date_count DESC"; |
||
| 7213 | } else { |
||
| 7214 | $query = "SELECT EXTRACT(YEAR FROM s.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM s.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count |
||
| 7215 | FROM spotter_output s |
||
| 7216 | WHERE s.airline_type = 'military' |
||
| 7217 | GROUP BY year_name, month_name |
||
| 7218 | ORDER BY date_count DESC"; |
||
| 7219 | } |
||
| 7220 | |||
| 7221 | $sth = $this->db->prepare($query); |
||
| 7222 | $sth->execute(array(':offset' => $offset)); |
||
| 7223 | |||
| 7224 | $date_array = array(); |
||
| 7225 | $temp_array = array(); |
||
| 7226 | |||
| 7227 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7228 | { |
||
| 7229 | $temp_array['month_name'] = $row['month_name']; |
||
| 7230 | $temp_array['year_name'] = $row['year_name']; |
||
| 7231 | $temp_array['date_count'] = $row['date_count']; |
||
| 7232 | |||
| 7233 | $date_array[] = $temp_array; |
||
| 7234 | } |
||
| 7235 | |||
| 7236 | return $date_array; |
||
| 7237 | } |
||
| 7238 | |||
| 7239 | /** |
||
| 7240 | * Counts all month owners |
||
| 7241 | * |
||
| 7242 | * @return Array the month list |
||
| 7243 | * |
||
| 7244 | */ |
||
| 7245 | View Code Duplication | public function countAllMonthsOwners() |
|
| 7246 | { |
||
| 7247 | global $globalTimezone, $globalDBdriver; |
||
| 7248 | if ($globalTimezone != '') { |
||
| 7249 | date_default_timezone_set($globalTimezone); |
||
| 7250 | $datetime = new DateTime(); |
||
| 7251 | $offset = $datetime->format('P'); |
||
| 7252 | } else $offset = '+00:00'; |
||
| 7253 | |||
| 7254 | if ($globalDBdriver == 'mysql') { |
||
| 7255 | $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 |
||
| 7256 | FROM spotter_output |
||
| 7257 | WHERE owner_name <> '' |
||
| 7258 | GROUP BY year_name, month_name |
||
| 7259 | ORDER BY date_count DESC"; |
||
| 7260 | } else { |
||
| 7261 | $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 |
||
| 7262 | FROM spotter_output |
||
| 7263 | WHERE owner_name <> '' |
||
| 7264 | GROUP BY year_name, month_name |
||
| 7265 | ORDER BY date_count DESC"; |
||
| 7266 | } |
||
| 7267 | |||
| 7268 | $sth = $this->db->prepare($query); |
||
| 7269 | $sth->execute(array(':offset' => $offset)); |
||
| 7270 | |||
| 7271 | $date_array = array(); |
||
| 7272 | $temp_array = array(); |
||
| 7273 | |||
| 7274 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7275 | { |
||
| 7276 | $temp_array['month_name'] = $row['month_name']; |
||
| 7277 | $temp_array['year_name'] = $row['year_name']; |
||
| 7278 | $temp_array['date_count'] = $row['date_count']; |
||
| 7279 | |||
| 7280 | $date_array[] = $temp_array; |
||
| 7281 | } |
||
| 7282 | |||
| 7283 | return $date_array; |
||
| 7284 | } |
||
| 7285 | |||
| 7286 | /** |
||
| 7287 | * Counts all month pilot |
||
| 7288 | * |
||
| 7289 | * @return Array the month list |
||
| 7290 | * |
||
| 7291 | */ |
||
| 7292 | View Code Duplication | public function countAllMonthsPilots() |
|
| 7293 | { |
||
| 7294 | global $globalTimezone, $globalDBdriver; |
||
| 7295 | if ($globalTimezone != '') { |
||
| 7296 | date_default_timezone_set($globalTimezone); |
||
| 7297 | $datetime = new DateTime(); |
||
| 7298 | $offset = $datetime->format('P'); |
||
| 7299 | } else $offset = '+00:00'; |
||
| 7300 | |||
| 7301 | if ($globalDBdriver == 'mysql') { |
||
| 7302 | $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 |
||
| 7303 | FROM spotter_output |
||
| 7304 | WHERE pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 7305 | GROUP BY year_name, month_name |
||
| 7306 | ORDER BY date_count DESC"; |
||
| 7307 | } else { |
||
| 7308 | $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 |
||
| 7309 | FROM spotter_output |
||
| 7310 | WHERE pilot_id <> '' AND pilot_id IS NOT NULL |
||
| 7311 | GROUP BY year_name, month_name |
||
| 7312 | ORDER BY date_count DESC"; |
||
| 7313 | } |
||
| 7314 | |||
| 7315 | $sth = $this->db->prepare($query); |
||
| 7316 | $sth->execute(array(':offset' => $offset)); |
||
| 7317 | |||
| 7318 | $date_array = array(); |
||
| 7319 | $temp_array = array(); |
||
| 7320 | |||
| 7321 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7322 | { |
||
| 7323 | $temp_array['month_name'] = $row['month_name']; |
||
| 7324 | $temp_array['year_name'] = $row['year_name']; |
||
| 7325 | $temp_array['date_count'] = $row['date_count']; |
||
| 7326 | |||
| 7327 | $date_array[] = $temp_array; |
||
| 7328 | } |
||
| 7329 | |||
| 7330 | return $date_array; |
||
| 7331 | } |
||
| 7332 | |||
| 7333 | |||
| 7334 | /** |
||
| 7335 | * Counts all month airline |
||
| 7336 | * |
||
| 7337 | * @return Array the month list |
||
| 7338 | * |
||
| 7339 | */ |
||
| 7340 | View Code Duplication | public function countAllMonthsAirlines() |
|
| 7341 | { |
||
| 7342 | global $globalTimezone, $globalDBdriver; |
||
| 7343 | if ($globalTimezone != '') { |
||
| 7344 | date_default_timezone_set($globalTimezone); |
||
| 7345 | $datetime = new DateTime(); |
||
| 7346 | $offset = $datetime->format('P'); |
||
| 7347 | } else $offset = '+00:00'; |
||
| 7348 | |||
| 7349 | if ($globalDBdriver == 'mysql') { |
||
| 7350 | $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 |
||
| 7351 | FROM spotter_output |
||
| 7352 | WHERE airline_icao <> '' |
||
| 7353 | GROUP BY year_name, month_name |
||
| 7354 | ORDER BY date_count DESC"; |
||
| 7355 | } else { |
||
| 7356 | $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 |
||
| 7357 | FROM spotter_output |
||
| 7358 | WHERE airline_icao <> '' |
||
| 7359 | GROUP BY year_name, month_name |
||
| 7360 | ORDER BY date_count DESC"; |
||
| 7361 | } |
||
| 7362 | |||
| 7363 | $sth = $this->db->prepare($query); |
||
| 7364 | $sth->execute(array(':offset' => $offset)); |
||
| 7365 | |||
| 7366 | $date_array = array(); |
||
| 7367 | $temp_array = array(); |
||
| 7368 | |||
| 7369 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7370 | { |
||
| 7371 | $temp_array['month_name'] = $row['month_name']; |
||
| 7372 | $temp_array['year_name'] = $row['year_name']; |
||
| 7373 | $temp_array['date_count'] = $row['date_count']; |
||
| 7374 | |||
| 7375 | $date_array[] = $temp_array; |
||
| 7376 | } |
||
| 7377 | |||
| 7378 | return $date_array; |
||
| 7379 | } |
||
| 7380 | |||
| 7381 | /** |
||
| 7382 | * Counts all month aircraft |
||
| 7383 | * |
||
| 7384 | * @return Array the month list |
||
| 7385 | * |
||
| 7386 | */ |
||
| 7387 | View Code Duplication | public function countAllMonthsAircrafts() |
|
| 7388 | { |
||
| 7389 | global $globalTimezone, $globalDBdriver; |
||
| 7390 | if ($globalTimezone != '') { |
||
| 7391 | date_default_timezone_set($globalTimezone); |
||
| 7392 | $datetime = new DateTime(); |
||
| 7393 | $offset = $datetime->format('P'); |
||
| 7394 | } else $offset = '+00:00'; |
||
| 7395 | |||
| 7396 | if ($globalDBdriver == 'mysql') { |
||
| 7397 | $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 |
||
| 7398 | FROM spotter_output |
||
| 7399 | WHERE aircraft_icao <> '' |
||
| 7400 | GROUP BY year_name, month_name |
||
| 7401 | ORDER BY date_count DESC"; |
||
| 7402 | } else { |
||
| 7403 | $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 |
||
| 7404 | FROM spotter_output |
||
| 7405 | WHERE aircraft_icao <> '' |
||
| 7406 | GROUP BY year_name, month_name |
||
| 7407 | ORDER BY date_count DESC"; |
||
| 7408 | } |
||
| 7409 | |||
| 7410 | $sth = $this->db->prepare($query); |
||
| 7411 | $sth->execute(array(':offset' => $offset)); |
||
| 7412 | |||
| 7413 | $date_array = array(); |
||
| 7414 | $temp_array = array(); |
||
| 7415 | |||
| 7416 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7417 | { |
||
| 7418 | $temp_array['month_name'] = $row['month_name']; |
||
| 7419 | $temp_array['year_name'] = $row['year_name']; |
||
| 7420 | $temp_array['date_count'] = $row['date_count']; |
||
| 7421 | |||
| 7422 | $date_array[] = $temp_array; |
||
| 7423 | } |
||
| 7424 | |||
| 7425 | return $date_array; |
||
| 7426 | } |
||
| 7427 | |||
| 7428 | |||
| 7429 | /** |
||
| 7430 | * Counts all month real arrival |
||
| 7431 | * |
||
| 7432 | * @return Array the month list |
||
| 7433 | * |
||
| 7434 | */ |
||
| 7435 | View Code Duplication | public function countAllMonthsRealArrivals() |
|
| 7436 | { |
||
| 7437 | global $globalTimezone, $globalDBdriver; |
||
| 7438 | if ($globalTimezone != '') { |
||
| 7439 | date_default_timezone_set($globalTimezone); |
||
| 7440 | $datetime = new DateTime(); |
||
| 7441 | $offset = $datetime->format('P'); |
||
| 7442 | } else $offset = '+00:00'; |
||
| 7443 | |||
| 7444 | if ($globalDBdriver == 'mysql') { |
||
| 7445 | $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 |
||
| 7446 | FROM spotter_output |
||
| 7447 | WHERE real_arrival_airport_icao <> '' |
||
| 7448 | GROUP BY year_name, month_name |
||
| 7449 | ORDER BY date_count DESC"; |
||
| 7450 | } else { |
||
| 7451 | $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 |
||
| 7452 | FROM spotter_output |
||
| 7453 | WHERE real_arrival_airport_icao <> '' |
||
| 7454 | GROUP BY year_name, month_name |
||
| 7455 | ORDER BY date_count DESC"; |
||
| 7456 | } |
||
| 7457 | |||
| 7458 | $sth = $this->db->prepare($query); |
||
| 7459 | $sth->execute(array(':offset' => $offset)); |
||
| 7460 | |||
| 7461 | $date_array = array(); |
||
| 7462 | $temp_array = array(); |
||
| 7463 | |||
| 7464 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7465 | { |
||
| 7466 | $temp_array['month_name'] = $row['month_name']; |
||
| 7467 | $temp_array['year_name'] = $row['year_name']; |
||
| 7468 | $temp_array['date_count'] = $row['date_count']; |
||
| 7469 | |||
| 7470 | $date_array[] = $temp_array; |
||
| 7471 | } |
||
| 7472 | |||
| 7473 | return $date_array; |
||
| 7474 | } |
||
| 7475 | |||
| 7476 | |||
| 7477 | |||
| 7478 | /** |
||
| 7479 | * Counts all dates during the last year |
||
| 7480 | * |
||
| 7481 | * @return Array the date list |
||
| 7482 | * |
||
| 7483 | */ |
||
| 7484 | public function countAllMonthsLastYear() |
||
| 7485 | { |
||
| 7486 | global $globalTimezone, $globalDBdriver; |
||
| 7487 | if ($globalTimezone != '') { |
||
| 7488 | date_default_timezone_set($globalTimezone); |
||
| 7489 | $datetime = new DateTime(); |
||
| 7490 | $offset = $datetime->format('P'); |
||
| 7491 | } else $offset = '+00:00'; |
||
| 7492 | |||
| 7493 | if ($globalDBdriver == 'mysql') { |
||
| 7494 | $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 |
||
| 7495 | FROM spotter_output |
||
| 7496 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR) |
||
| 7497 | GROUP BY year_name, month_name |
||
| 7498 | ORDER BY year_name, month_name ASC"; |
||
| 7499 | $query_data = array(':offset' => $offset); |
||
| 7500 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 7501 | $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 |
||
| 7502 | FROM spotter_output |
||
| 7503 | WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 YEARS' |
||
| 7504 | GROUP BY year_name, month_name |
||
| 7505 | ORDER BY year_name, month_name ASC"; |
||
| 7506 | $query_data = array(':offset' => $offset); |
||
| 7507 | } |
||
| 7508 | |||
| 7509 | $sth = $this->db->prepare($query); |
||
| 7510 | $sth->execute($query_data); |
||
| 7511 | |||
| 7512 | $date_array = array(); |
||
| 7513 | $temp_array = array(); |
||
| 7514 | |||
| 7515 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7516 | { |
||
| 7517 | $temp_array['year_name'] = $row['year_name']; |
||
| 7518 | $temp_array['month_name'] = $row['month_name']; |
||
| 7519 | $temp_array['date_count'] = $row['date_count']; |
||
| 7520 | |||
| 7521 | $date_array[] = $temp_array; |
||
| 7522 | } |
||
| 7523 | |||
| 7524 | return $date_array; |
||
| 7525 | } |
||
| 7526 | |||
| 7527 | |||
| 7528 | |||
| 7529 | /** |
||
| 7530 | * Counts all hours |
||
| 7531 | * |
||
| 7532 | * @return Array the hour list |
||
| 7533 | * |
||
| 7534 | */ |
||
| 7535 | public function countAllHours($orderby) |
||
| 7536 | { |
||
| 7537 | global $globalTimezone, $globalDBdriver; |
||
| 7538 | if ($globalTimezone != '') { |
||
| 7539 | date_default_timezone_set($globalTimezone); |
||
| 7540 | $datetime = new DateTime(); |
||
| 7541 | $offset = $datetime->format('P'); |
||
| 7542 | } else $offset = '+00:00'; |
||
| 7543 | |||
| 7544 | if ($orderby == "hour") |
||
| 7545 | { |
||
| 7546 | $orderby_sql = "ORDER BY hour_name ASC"; |
||
| 7547 | } |
||
| 7548 | if ($orderby == "count") |
||
| 7549 | { |
||
| 7550 | $orderby_sql = "ORDER BY hour_count DESC"; |
||
| 7551 | } |
||
| 7552 | |||
| 7553 | if ($globalDBdriver == 'mysql') { |
||
| 7554 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7555 | FROM spotter_output |
||
| 7556 | GROUP BY hour_name |
||
| 7557 | ".$orderby_sql; |
||
| 7558 | |||
| 7559 | /* $query = "SELECT HOUR(spotter_output.date) AS hour_name, count(*) as hour_count |
||
| 7560 | FROM spotter_output |
||
| 7561 | GROUP BY hour_name |
||
| 7562 | ".$orderby_sql." |
||
| 7563 | LIMIT 10 OFFSET 00"; |
||
| 7564 | */ |
||
| 7565 | $query_data = array(':offset' => $offset); |
||
| 7566 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 7567 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7568 | FROM spotter_output |
||
| 7569 | GROUP BY hour_name |
||
| 7570 | ".$orderby_sql; |
||
| 7571 | $query_data = array(':offset' => $offset); |
||
| 7572 | } |
||
| 7573 | |||
| 7574 | $sth = $this->db->prepare($query); |
||
| 7575 | $sth->execute($query_data); |
||
| 7576 | |||
| 7577 | $hour_array = array(); |
||
| 7578 | $temp_array = array(); |
||
| 7579 | |||
| 7580 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7581 | { |
||
| 7582 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7583 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7584 | |||
| 7585 | $hour_array[] = $temp_array; |
||
| 7586 | } |
||
| 7587 | |||
| 7588 | return $hour_array; |
||
| 7589 | } |
||
| 7590 | |||
| 7591 | |||
| 7592 | /** |
||
| 7593 | * Counts all hours by airline |
||
| 7594 | * |
||
| 7595 | * @return Array the hour list |
||
| 7596 | * |
||
| 7597 | */ |
||
| 7598 | View Code Duplication | public function countAllHoursByAirline($airline_icao) |
|
| 7599 | { |
||
| 7600 | global $globalTimezone, $globalDBdriver; |
||
| 7601 | if ($globalTimezone != '') { |
||
| 7602 | date_default_timezone_set($globalTimezone); |
||
| 7603 | $datetime = new DateTime(); |
||
| 7604 | $offset = $datetime->format('P'); |
||
| 7605 | } else $offset = '+00:00'; |
||
| 7606 | |||
| 7607 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
| 7608 | |||
| 7609 | if ($globalDBdriver == 'mysql') { |
||
| 7610 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7611 | FROM spotter_output |
||
| 7612 | WHERE spotter_output.airline_icao = :airline_icao |
||
| 7613 | GROUP BY hour_name |
||
| 7614 | ORDER BY hour_name ASC"; |
||
| 7615 | } else { |
||
| 7616 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7617 | FROM spotter_output |
||
| 7618 | WHERE spotter_output.airline_icao = :airline_icao |
||
| 7619 | GROUP BY hour_name |
||
| 7620 | ORDER BY hour_name ASC"; |
||
| 7621 | } |
||
| 7622 | |||
| 7623 | $sth = $this->db->prepare($query); |
||
| 7624 | $sth->execute(array(':airline_icao' => $airline_icao,':offset' => $offset)); |
||
| 7625 | |||
| 7626 | $hour_array = array(); |
||
| 7627 | $temp_array = array(); |
||
| 7628 | |||
| 7629 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7630 | { |
||
| 7631 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7632 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7633 | |||
| 7634 | $hour_array[] = $temp_array; |
||
| 7635 | } |
||
| 7636 | |||
| 7637 | return $hour_array; |
||
| 7638 | } |
||
| 7639 | |||
| 7640 | |||
| 7641 | |||
| 7642 | |||
| 7643 | /** |
||
| 7644 | * Counts all hours by aircraft |
||
| 7645 | * |
||
| 7646 | * @return Array the hour list |
||
| 7647 | * |
||
| 7648 | */ |
||
| 7649 | View Code Duplication | public function countAllHoursByAircraft($aircraft_icao) |
|
| 7650 | { |
||
| 7651 | global $globalTimezone, $globalDBdriver; |
||
| 7652 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 7653 | if ($globalTimezone != '') { |
||
| 7654 | date_default_timezone_set($globalTimezone); |
||
| 7655 | $datetime = new DateTime(); |
||
| 7656 | $offset = $datetime->format('P'); |
||
| 7657 | } else $offset = '+00:00'; |
||
| 7658 | |||
| 7659 | if ($globalDBdriver == 'mysql') { |
||
| 7660 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7661 | FROM spotter_output |
||
| 7662 | WHERE spotter_output.aircraft_icao = :aircraft_icao |
||
| 7663 | GROUP BY hour_name |
||
| 7664 | ORDER BY hour_name ASC"; |
||
| 7665 | } else { |
||
| 7666 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7667 | FROM spotter_output |
||
| 7668 | WHERE spotter_output.aircraft_icao = :aircraft_icao |
||
| 7669 | GROUP BY hour_name |
||
| 7670 | ORDER BY hour_name ASC"; |
||
| 7671 | } |
||
| 7672 | |||
| 7673 | $sth = $this->db->prepare($query); |
||
| 7674 | $sth->execute(array(':aircraft_icao' => $aircraft_icao,':offset' => $offset)); |
||
| 7675 | |||
| 7676 | $hour_array = array(); |
||
| 7677 | $temp_array = array(); |
||
| 7678 | |||
| 7679 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7680 | { |
||
| 7681 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7682 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7683 | |||
| 7684 | $hour_array[] = $temp_array; |
||
| 7685 | } |
||
| 7686 | |||
| 7687 | return $hour_array; |
||
| 7688 | } |
||
| 7689 | |||
| 7690 | |||
| 7691 | /** |
||
| 7692 | * Counts all hours by aircraft registration |
||
| 7693 | * |
||
| 7694 | * @return Array the hour list |
||
| 7695 | * |
||
| 7696 | */ |
||
| 7697 | View Code Duplication | public function countAllHoursByRegistration($registration) |
|
| 7698 | { |
||
| 7699 | global $globalTimezone, $globalDBdriver; |
||
| 7700 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 7701 | if ($globalTimezone != '') { |
||
| 7702 | date_default_timezone_set($globalTimezone); |
||
| 7703 | $datetime = new DateTime(); |
||
| 7704 | $offset = $datetime->format('P'); |
||
| 7705 | } else $offset = '+00:00'; |
||
| 7706 | |||
| 7707 | if ($globalDBdriver == 'mysql') { |
||
| 7708 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7709 | FROM spotter_output |
||
| 7710 | WHERE spotter_output.registration = :registration |
||
| 7711 | GROUP BY hour_name |
||
| 7712 | ORDER BY hour_name ASC"; |
||
| 7713 | } else { |
||
| 7714 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7715 | FROM spotter_output |
||
| 7716 | WHERE spotter_output.registration = :registration |
||
| 7717 | GROUP BY hour_name |
||
| 7718 | ORDER BY hour_name ASC"; |
||
| 7719 | } |
||
| 7720 | |||
| 7721 | $sth = $this->db->prepare($query); |
||
| 7722 | $sth->execute(array(':registration' => $registration,':offset' => $offset)); |
||
| 7723 | |||
| 7724 | $hour_array = array(); |
||
| 7725 | $temp_array = array(); |
||
| 7726 | |||
| 7727 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7728 | { |
||
| 7729 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7730 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7731 | |||
| 7732 | $hour_array[] = $temp_array; |
||
| 7733 | } |
||
| 7734 | |||
| 7735 | return $hour_array; |
||
| 7736 | } |
||
| 7737 | |||
| 7738 | |||
| 7739 | /** |
||
| 7740 | * Counts all hours by airport |
||
| 7741 | * |
||
| 7742 | * @return Array the hour list |
||
| 7743 | * |
||
| 7744 | */ |
||
| 7745 | View Code Duplication | public function countAllHoursByAirport($airport_icao) |
|
| 7746 | { |
||
| 7747 | global $globalTimezone, $globalDBdriver; |
||
| 7748 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
| 7749 | if ($globalTimezone != '') { |
||
| 7750 | date_default_timezone_set($globalTimezone); |
||
| 7751 | $datetime = new DateTime(); |
||
| 7752 | $offset = $datetime->format('P'); |
||
| 7753 | } else $offset = '+00:00'; |
||
| 7754 | |||
| 7755 | if ($globalDBdriver == 'mysql') { |
||
| 7756 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7757 | FROM spotter_output |
||
| 7758 | WHERE (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 7759 | GROUP BY hour_name |
||
| 7760 | ORDER BY hour_name ASC"; |
||
| 7761 | } else { |
||
| 7762 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7763 | FROM spotter_output |
||
| 7764 | WHERE (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) |
||
| 7765 | GROUP BY hour_name |
||
| 7766 | ORDER BY hour_name ASC"; |
||
| 7767 | } |
||
| 7768 | |||
| 7769 | $sth = $this->db->prepare($query); |
||
| 7770 | $sth->execute(array(':airport_icao' => $airport_icao,':offset' => $offset)); |
||
| 7771 | |||
| 7772 | $hour_array = array(); |
||
| 7773 | $temp_array = array(); |
||
| 7774 | |||
| 7775 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7776 | { |
||
| 7777 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7778 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7779 | |||
| 7780 | $hour_array[] = $temp_array; |
||
| 7781 | } |
||
| 7782 | |||
| 7783 | return $hour_array; |
||
| 7784 | } |
||
| 7785 | |||
| 7786 | |||
| 7787 | |||
| 7788 | /** |
||
| 7789 | * Counts all hours by manufacturer |
||
| 7790 | * |
||
| 7791 | * @return Array the hour list |
||
| 7792 | * |
||
| 7793 | */ |
||
| 7794 | View Code Duplication | public function countAllHoursByManufacturer($aircraft_manufacturer) |
|
| 7795 | { |
||
| 7796 | global $globalTimezone, $globalDBdriver; |
||
| 7797 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
| 7798 | if ($globalTimezone != '') { |
||
| 7799 | date_default_timezone_set($globalTimezone); |
||
| 7800 | $datetime = new DateTime(); |
||
| 7801 | $offset = $datetime->format('P'); |
||
| 7802 | } else $offset = '+00:00'; |
||
| 7803 | |||
| 7804 | if ($globalDBdriver == 'mysql') { |
||
| 7805 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7806 | FROM spotter_output |
||
| 7807 | WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 7808 | GROUP BY hour_name |
||
| 7809 | ORDER BY hour_name ASC"; |
||
| 7810 | } else { |
||
| 7811 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7812 | FROM spotter_output |
||
| 7813 | WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
| 7814 | GROUP BY hour_name |
||
| 7815 | ORDER BY hour_name ASC"; |
||
| 7816 | } |
||
| 7817 | |||
| 7818 | $sth = $this->db->prepare($query); |
||
| 7819 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer,':offset' => $offset)); |
||
| 7820 | |||
| 7821 | $hour_array = array(); |
||
| 7822 | $temp_array = array(); |
||
| 7823 | |||
| 7824 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7825 | { |
||
| 7826 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7827 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7828 | |||
| 7829 | $hour_array[] = $temp_array; |
||
| 7830 | } |
||
| 7831 | |||
| 7832 | return $hour_array; |
||
| 7833 | } |
||
| 7834 | |||
| 7835 | |||
| 7836 | |||
| 7837 | /** |
||
| 7838 | * Counts all hours by date |
||
| 7839 | * |
||
| 7840 | * @return Array the hour list |
||
| 7841 | * |
||
| 7842 | */ |
||
| 7843 | View Code Duplication | public function countAllHoursByDate($date) |
|
| 7844 | { |
||
| 7845 | global $globalTimezone, $globalDBdriver; |
||
| 7846 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
| 7847 | if ($globalTimezone != '') { |
||
| 7848 | date_default_timezone_set($globalTimezone); |
||
| 7849 | $datetime = new DateTime($date); |
||
| 7850 | $offset = $datetime->format('P'); |
||
| 7851 | } else $offset = '+00:00'; |
||
| 7852 | |||
| 7853 | if ($globalDBdriver == 'mysql') { |
||
| 7854 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7855 | FROM spotter_output |
||
| 7856 | WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
| 7857 | GROUP BY hour_name |
||
| 7858 | ORDER BY hour_name ASC"; |
||
| 7859 | } else { |
||
| 7860 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7861 | FROM spotter_output |
||
| 7862 | WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date |
||
| 7863 | GROUP BY hour_name |
||
| 7864 | ORDER BY hour_name ASC"; |
||
| 7865 | } |
||
| 7866 | |||
| 7867 | $sth = $this->db->prepare($query); |
||
| 7868 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
| 7869 | |||
| 7870 | $hour_array = array(); |
||
| 7871 | $temp_array = array(); |
||
| 7872 | |||
| 7873 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7874 | { |
||
| 7875 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7876 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7877 | |||
| 7878 | $hour_array[] = $temp_array; |
||
| 7879 | } |
||
| 7880 | |||
| 7881 | return $hour_array; |
||
| 7882 | } |
||
| 7883 | |||
| 7884 | |||
| 7885 | |||
| 7886 | /** |
||
| 7887 | * Counts all hours by a ident/callsign |
||
| 7888 | * |
||
| 7889 | * @return Array the hour list |
||
| 7890 | * |
||
| 7891 | */ |
||
| 7892 | View Code Duplication | public function countAllHoursByIdent($ident) |
|
| 7893 | { |
||
| 7894 | global $globalTimezone, $globalDBdriver; |
||
| 7895 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 7896 | if ($globalTimezone != '') { |
||
| 7897 | date_default_timezone_set($globalTimezone); |
||
| 7898 | $datetime = new DateTime(); |
||
| 7899 | $offset = $datetime->format('P'); |
||
| 7900 | } else $offset = '+00:00'; |
||
| 7901 | |||
| 7902 | if ($globalDBdriver == 'mysql') { |
||
| 7903 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7904 | FROM spotter_output |
||
| 7905 | WHERE spotter_output.ident = :ident |
||
| 7906 | GROUP BY hour_name |
||
| 7907 | ORDER BY hour_name ASC"; |
||
| 7908 | } else { |
||
| 7909 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7910 | FROM spotter_output |
||
| 7911 | WHERE spotter_output.ident = :ident |
||
| 7912 | GROUP BY hour_name |
||
| 7913 | ORDER BY hour_name ASC"; |
||
| 7914 | } |
||
| 7915 | |||
| 7916 | |||
| 7917 | $sth = $this->db->prepare($query); |
||
| 7918 | $sth->execute(array(':ident' => $ident,':offset' => $offset)); |
||
| 7919 | |||
| 7920 | $hour_array = array(); |
||
| 7921 | $temp_array = array(); |
||
| 7922 | |||
| 7923 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7924 | { |
||
| 7925 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7926 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7927 | |||
| 7928 | $hour_array[] = $temp_array; |
||
| 7929 | } |
||
| 7930 | |||
| 7931 | return $hour_array; |
||
| 7932 | } |
||
| 7933 | |||
| 7934 | |||
| 7935 | |||
| 7936 | /** |
||
| 7937 | * Counts all hours by route |
||
| 7938 | * |
||
| 7939 | * @return Array the hour list |
||
| 7940 | * |
||
| 7941 | */ |
||
| 7942 | public function countAllHoursByRoute($departure_airport_icao, $arrival_airport_icao) |
||
| 7943 | { |
||
| 7944 | global $globalTimezone, $globalDBdriver; |
||
| 7945 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 7946 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 7947 | if ($globalTimezone != '') { |
||
| 7948 | date_default_timezone_set($globalTimezone); |
||
| 7949 | $datetime = new DateTime(); |
||
| 7950 | $offset = $datetime->format('P'); |
||
| 7951 | } else $offset = '+00:00'; |
||
| 7952 | |||
| 7953 | if ($globalDBdriver == 'mysql') { |
||
| 7954 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 7955 | FROM spotter_output |
||
| 7956 | WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 7957 | GROUP BY hour_name |
||
| 7958 | ORDER BY hour_name ASC"; |
||
| 7959 | } else { |
||
| 7960 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 7961 | FROM spotter_output |
||
| 7962 | WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
| 7963 | GROUP BY hour_name |
||
| 7964 | ORDER BY hour_name ASC"; |
||
| 7965 | } |
||
| 7966 | |||
| 7967 | $sth = $this->db->prepare($query); |
||
| 7968 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':offset' => $offset)); |
||
| 7969 | |||
| 7970 | $hour_array = array(); |
||
| 7971 | $temp_array = array(); |
||
| 7972 | |||
| 7973 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 7974 | { |
||
| 7975 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 7976 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 7977 | |||
| 7978 | $hour_array[] = $temp_array; |
||
| 7979 | } |
||
| 7980 | |||
| 7981 | return $hour_array; |
||
| 7982 | } |
||
| 7983 | |||
| 7984 | |||
| 7985 | /** |
||
| 7986 | * Counts all hours by country |
||
| 7987 | * |
||
| 7988 | * @return Array the hour list |
||
| 7989 | * |
||
| 7990 | */ |
||
| 7991 | View Code Duplication | public function countAllHoursByCountry($country) |
|
| 7992 | { |
||
| 7993 | global $globalTimezone, $globalDBdriver; |
||
| 7994 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
| 7995 | if ($globalTimezone != '') { |
||
| 7996 | date_default_timezone_set($globalTimezone); |
||
| 7997 | $datetime = new DateTime(); |
||
| 7998 | $offset = $datetime->format('P'); |
||
| 7999 | } else $offset = '+00:00'; |
||
| 8000 | |||
| 8001 | if ($globalDBdriver == 'mysql') { |
||
| 8002 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 8003 | FROM spotter_output |
||
| 8004 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 8005 | GROUP BY hour_name |
||
| 8006 | ORDER BY hour_name ASC"; |
||
| 8007 | } else { |
||
| 8008 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 8009 | FROM spotter_output |
||
| 8010 | WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
| 8011 | GROUP BY hour_name |
||
| 8012 | ORDER BY hour_name ASC"; |
||
| 8013 | } |
||
| 8014 | |||
| 8015 | $sth = $this->db->prepare($query); |
||
| 8016 | $sth->execute(array(':country' => $country,':offset' => $offset)); |
||
| 8017 | |||
| 8018 | $hour_array = array(); |
||
| 8019 | $temp_array = array(); |
||
| 8020 | |||
| 8021 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8022 | { |
||
| 8023 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 8024 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 8025 | |||
| 8026 | $hour_array[] = $temp_array; |
||
| 8027 | } |
||
| 8028 | |||
| 8029 | return $hour_array; |
||
| 8030 | } |
||
| 8031 | |||
| 8032 | |||
| 8033 | |||
| 8034 | |||
| 8035 | /** |
||
| 8036 | * Counts all aircraft that have flown over |
||
| 8037 | * |
||
| 8038 | * @return Integer the number of aircrafts |
||
| 8039 | * |
||
| 8040 | */ |
||
| 8041 | public function countOverallAircrafts() |
||
| 8042 | { |
||
| 8043 | $query = "SELECT COUNT(DISTINCT spotter_output.aircraft_icao) AS aircraft_count |
||
| 8044 | FROM spotter_output |
||
| 8045 | WHERE spotter_output.ident <> ''"; |
||
| 8046 | |||
| 8047 | |||
| 8048 | $sth = $this->db->prepare($query); |
||
| 8049 | $sth->execute(); |
||
| 8050 | return $sth->fetchColumn(); |
||
| 8051 | } |
||
| 8052 | |||
| 8053 | /** |
||
| 8054 | * Counts all flight that really arrival |
||
| 8055 | * |
||
| 8056 | * @return Integer the number of aircrafts |
||
| 8057 | * |
||
| 8058 | */ |
||
| 8059 | public function countOverallArrival() |
||
| 8060 | { |
||
| 8061 | $query = "SELECT COUNT(spotter_output.real_arrival_airport_icao) AS arrival_count |
||
| 8062 | FROM spotter_output |
||
| 8063 | WHERE spotter_output.arrival_airport_icao <> ''"; |
||
| 8064 | |||
| 8065 | |||
| 8066 | $sth = $this->db->prepare($query); |
||
| 8067 | $sth->execute(); |
||
| 8068 | return $sth->fetchColumn(); |
||
| 8069 | } |
||
| 8070 | |||
| 8071 | /** |
||
| 8072 | * Counts all pilots that have flown over |
||
| 8073 | * |
||
| 8074 | * @return Integer the number of pilots |
||
| 8075 | * |
||
| 8076 | */ |
||
| 8077 | public function countOverallPilots() |
||
| 8078 | { |
||
| 8079 | $query = "SELECT COUNT(DISTINCT spotter_output.pilot_id) AS pilot_count |
||
| 8080 | FROM spotter_output |
||
| 8081 | WHERE spotter_output.pilot_id <> ''"; |
||
| 8082 | |||
| 8083 | |||
| 8084 | $sth = $this->db->prepare($query); |
||
| 8085 | $sth->execute(); |
||
| 8086 | return $sth->fetchColumn(); |
||
| 8087 | } |
||
| 8088 | |||
| 8089 | /** |
||
| 8090 | * Counts all owners that have flown over |
||
| 8091 | * |
||
| 8092 | * @return Integer the number of owners |
||
| 8093 | * |
||
| 8094 | */ |
||
| 8095 | public function countOverallOwners() |
||
| 8096 | { |
||
| 8097 | $query = "SELECT COUNT(DISTINCT spotter_output.owner_name) AS owner_count |
||
| 8098 | FROM spotter_output |
||
| 8099 | WHERE spotter_output.owner_name <> ''"; |
||
| 8100 | |||
| 8101 | |||
| 8102 | $sth = $this->db->prepare($query); |
||
| 8103 | $sth->execute(); |
||
| 8104 | return $sth->fetchColumn(); |
||
| 8105 | } |
||
| 8106 | |||
| 8107 | |||
| 8108 | /** |
||
| 8109 | * Counts all flights that have flown over |
||
| 8110 | * |
||
| 8111 | * @return Integer the number of flights |
||
| 8112 | * |
||
| 8113 | */ |
||
| 8114 | public function countOverallFlights() |
||
| 8115 | { |
||
| 8116 | $query = "SELECT COUNT(spotter_output.spotter_id) AS flight_count |
||
| 8117 | FROM spotter_output"; |
||
| 8118 | |||
| 8119 | |||
| 8120 | $sth = $this->db->prepare($query); |
||
| 8121 | $sth->execute(); |
||
| 8122 | return $sth->fetchColumn(); |
||
| 8123 | } |
||
| 8124 | |||
| 8125 | /** |
||
| 8126 | * Counts all military flights that have flown over |
||
| 8127 | * |
||
| 8128 | * @return Integer the number of flights |
||
| 8129 | * |
||
| 8130 | */ |
||
| 8131 | public function countOverallMilitaryFlights() |
||
| 8132 | { |
||
| 8133 | $query = "SELECT COUNT(s.spotter_id) AS flight_count |
||
| 8134 | FROM spotter_output s, airlines a WHERE s.airline_icao = a.icao AND a.type = 'military'"; |
||
| 8135 | |||
| 8136 | |||
| 8137 | $sth = $this->db->prepare($query); |
||
| 8138 | $sth->execute(); |
||
| 8139 | return $sth->fetchColumn(); |
||
| 8140 | } |
||
| 8141 | |||
| 8142 | |||
| 8143 | |||
| 8144 | /** |
||
| 8145 | * Counts all airlines that have flown over |
||
| 8146 | * |
||
| 8147 | * @return Integer the number of airlines |
||
| 8148 | * |
||
| 8149 | */ |
||
| 8150 | public function countOverallAirlines() |
||
| 8151 | { |
||
| 8152 | $query = "SELECT COUNT(DISTINCT spotter_output.airline_name) AS airline_count |
||
| 8153 | FROM spotter_output"; |
||
| 8154 | |||
| 8155 | |||
| 8156 | $sth = $this->db->prepare($query); |
||
| 8157 | $sth->execute(); |
||
| 8158 | return $sth->fetchColumn(); |
||
| 8159 | } |
||
| 8160 | |||
| 8161 | |||
| 8162 | /** |
||
| 8163 | * Counts all hours of today |
||
| 8164 | * |
||
| 8165 | * @return Array the hour list |
||
| 8166 | * |
||
| 8167 | */ |
||
| 8168 | View Code Duplication | public function countAllHoursFromToday() |
|
| 8169 | { |
||
| 8170 | global $globalTimezone, $globalDBdriver; |
||
| 8171 | if ($globalTimezone != '') { |
||
| 8172 | date_default_timezone_set($globalTimezone); |
||
| 8173 | $datetime = new DateTime(); |
||
| 8174 | $offset = $datetime->format('P'); |
||
| 8175 | } else $offset = '+00:00'; |
||
| 8176 | |||
| 8177 | if ($globalDBdriver == 'mysql') { |
||
| 8178 | $query = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
||
| 8179 | FROM spotter_output |
||
| 8180 | WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = CURDATE() |
||
| 8181 | GROUP BY hour_name |
||
| 8182 | ORDER BY hour_name ASC"; |
||
| 8183 | } else { |
||
| 8184 | $query = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
||
| 8185 | FROM spotter_output |
||
| 8186 | WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date) |
||
| 8187 | GROUP BY hour_name |
||
| 8188 | ORDER BY hour_name ASC"; |
||
| 8189 | } |
||
| 8190 | |||
| 8191 | $sth = $this->db->prepare($query); |
||
| 8192 | $sth->execute(array(':offset' => $offset)); |
||
| 8193 | |||
| 8194 | $hour_array = array(); |
||
| 8195 | $temp_array = array(); |
||
| 8196 | |||
| 8197 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8198 | { |
||
| 8199 | $temp_array['hour_name'] = $row['hour_name']; |
||
| 8200 | $temp_array['hour_count'] = $row['hour_count']; |
||
| 8201 | $hour_array[] = $temp_array; |
||
| 8202 | } |
||
| 8203 | |||
| 8204 | return $hour_array; |
||
| 8205 | } |
||
| 8206 | |||
| 8207 | /** |
||
| 8208 | * Gets all the spotter information based on calculated upcoming flights |
||
| 8209 | * |
||
| 8210 | * @return Array the spotter information |
||
| 8211 | * |
||
| 8212 | */ |
||
| 8213 | public function getUpcomingFlights($limit = '', $sort = '') |
||
| 8214 | { |
||
| 8215 | global $global_query, $globalDBdriver, $globalTimezone; |
||
| 8216 | date_default_timezone_set('UTC'); |
||
| 8217 | if ($limit != "") |
||
| 8218 | { |
||
| 8219 | $limit_array = explode(",", $limit); |
||
| 8220 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 8221 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 8222 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 8223 | { |
||
| 8224 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
| 8225 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 8226 | } |
||
| 8227 | } |
||
| 8228 | $currentHour = date("G"); |
||
| 8229 | $next3Hours = date("G", strtotime("+3 hour")); |
||
| 8230 | //if the next 3 hours is already equal to/past midnight, we limit it to stay there, otherwise the query will fail |
||
| 8231 | if ($currentHour >= 21 && $next3Hours >= 00) |
||
| 8232 | { |
||
| 8233 | $next3Hours = 24; |
||
| 8234 | } |
||
| 8235 | $currentDayofWeek = date("l"); |
||
| 8236 | if ($globalDBdriver == 'mysql') { |
||
| 8237 | if ($sort != "") |
||
| 8238 | { |
||
| 8239 | $search_orderby_array = $this->getOrderBy(); |
||
| 8240 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 8241 | } else { |
||
| 8242 | $orderby_query = " ORDER BY HOUR(spotter_output.date) ASC"; |
||
| 8243 | } |
||
| 8244 | |||
| 8245 | $query = "SELECT spotter_output.*, count(spotter_output.ident) as ident_count |
||
| 8246 | FROM spotter_output |
||
| 8247 | 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' |
||
| 8248 | 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"; |
||
| 8249 | |||
| 8250 | /* $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 |
||
| 8251 | FROM spotter_output |
||
| 8252 | 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' |
||
| 8253 | 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"; |
||
| 8254 | */ |
||
| 8255 | $spotter_array = $this->getDataFromDB($query.$limit_query); |
||
| 8256 | } else if ($globalDBdriver == 'pgsql') { |
||
| 8257 | if ($sort != "") |
||
| 8258 | { |
||
| 8259 | $search_orderby_array = $this->getOrderBy(); |
||
| 8260 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
| 8261 | } else { |
||
| 8262 | $orderby_query = " ORDER BY EXTRACT (HOUR FROM spotter_output.date) ASC"; |
||
| 8263 | } |
||
| 8264 | $query = "SELECT spotter_output.*, count(spotter_output.ident) as ident_count |
||
| 8265 | FROM spotter_output |
||
| 8266 | WHERE 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 <> '' |
||
| 8267 | GROUP BY spotter_output.ident, spotter_output.spotter_id HAVING count(spotter_output.ident) > 10 $orderby_query"; |
||
| 8268 | $spotter_array = $this->getDataFromDB($query.$limit_query,array(':timezone' => $globalTimezone)); |
||
| 8269 | } |
||
| 8270 | return $spotter_array; |
||
| 8271 | } |
||
| 8272 | |||
| 8273 | |||
| 8274 | /** |
||
| 8275 | * Gets the Barrie Spotter ID based on the FlightAware ID |
||
| 8276 | * |
||
| 8277 | * @return Integer the Barrie Spotter ID |
||
| 8278 | * |
||
| 8279 | */ |
||
| 8280 | public function getSpotterIDBasedOnFlightAwareID($flightaware_id) |
||
| 8281 | { |
||
| 8282 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
| 8283 | |||
| 8284 | $query = "SELECT spotter_output.spotter_id |
||
| 8285 | FROM spotter_output |
||
| 8286 | WHERE spotter_output.flightaware_id = '".$flightaware_id."'"; |
||
| 8287 | |||
| 8288 | |||
| 8289 | $sth = $this->db->prepare($query); |
||
| 8290 | $sth->execute(); |
||
| 8291 | |||
| 8292 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8293 | { |
||
| 8294 | return $row['spotter_id']; |
||
| 8295 | } |
||
| 8296 | } |
||
| 8297 | |||
| 8298 | |||
| 8299 | /** |
||
| 8300 | * Parses a date string |
||
| 8301 | * |
||
| 8302 | * @param String $dateString the date string |
||
| 8303 | * @param String $timezone the timezone of a user |
||
| 8304 | * @return Array the time information |
||
| 8305 | * |
||
| 8306 | */ |
||
| 8307 | public function parseDateString($dateString, $timezone = '') |
||
| 8308 | { |
||
| 8309 | $time_array = array(); |
||
| 8310 | |||
| 8311 | if ($timezone != "") |
||
| 8312 | { |
||
| 8313 | date_default_timezone_set($timezone); |
||
| 8314 | } |
||
| 8315 | |||
| 8316 | $current_date = date("Y-m-d H:i:s"); |
||
| 8317 | $date = date("Y-m-d H:i:s",strtotime($dateString." UTC")); |
||
| 8318 | |||
| 8319 | $diff = abs(strtotime($current_date) - strtotime($date)); |
||
| 8320 | |||
| 8321 | $time_array['years'] = floor($diff / (365*60*60*24)); |
||
| 8322 | $years = $time_array['years']; |
||
| 8323 | |||
| 8324 | $time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); |
||
| 8325 | $months = $time_array['months']; |
||
| 8326 | |||
| 8327 | $time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); |
||
| 8328 | $days = $time_array['days']; |
||
| 8329 | $time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); |
||
| 8330 | $hours = $time_array['hours']; |
||
| 8331 | $time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); |
||
| 8332 | $minutes = $time_array['minutes']; |
||
| 8333 | $time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60)); |
||
| 8334 | |||
| 8335 | return $time_array; |
||
| 8336 | } |
||
| 8337 | |||
| 8338 | |||
| 8339 | |||
| 8340 | |||
| 8341 | /** |
||
| 8342 | * Parses the direction degrees to working |
||
| 8343 | * |
||
| 8344 | * @param Float $direction the direction in degrees |
||
| 8345 | * @return Array the direction information |
||
| 8346 | * |
||
| 8347 | */ |
||
| 8348 | public function parseDirection($direction = 0) |
||
| 8349 | { |
||
| 8350 | if ($direction == '') $direction = 0; |
||
| 8351 | $direction_array = array(); |
||
| 8352 | $temp_array = array(); |
||
| 8353 | |||
| 8354 | if ($direction == 360 || ($direction >= 0 && $direction < 22.5)) |
||
| 8355 | { |
||
| 8356 | $temp_array['direction_degree'] = $direction; |
||
| 8357 | $temp_array['direction_shortname'] = "N"; |
||
| 8358 | $temp_array['direction_fullname'] = "North"; |
||
| 8359 | View Code Duplication | } elseif ($direction >= 22.5 && $direction < 45){ |
|
| 8360 | $temp_array['direction_degree'] = $direction; |
||
| 8361 | $temp_array['direction_shortname'] = "NNE"; |
||
| 8362 | $temp_array['direction_fullname'] = "North-Northeast"; |
||
| 8363 | } elseif ($direction >= 45 && $direction < 67.5){ |
||
| 8364 | $temp_array['direction_degree'] = $direction; |
||
| 8365 | $temp_array['direction_shortname'] = "NE"; |
||
| 8366 | $temp_array['direction_fullname'] = "Northeast"; |
||
| 8367 | View Code Duplication | } elseif ($direction >= 67.5 && $direction < 90){ |
|
| 8368 | $temp_array['direction_degree'] = $direction; |
||
| 8369 | $temp_array['direction_shortname'] = "ENE"; |
||
| 8370 | $temp_array['direction_fullname'] = "East-Northeast"; |
||
| 8371 | } elseif ($direction >= 90 && $direction < 112.5){ |
||
| 8372 | $temp_array['direction_degree'] = $direction; |
||
| 8373 | $temp_array['direction_shortname'] = "E"; |
||
| 8374 | $temp_array['direction_fullname'] = "East"; |
||
| 8375 | View Code Duplication | } elseif ($direction >= 112.5 && $direction < 135){ |
|
| 8376 | $temp_array['direction_degree'] = $direction; |
||
| 8377 | $temp_array['direction_shortname'] = "ESE"; |
||
| 8378 | $temp_array['direction_fullname'] = "East-Southeast"; |
||
| 8379 | } elseif ($direction >= 135 && $direction < 157.5){ |
||
| 8380 | $temp_array['direction_degree'] = $direction; |
||
| 8381 | $temp_array['direction_shortname'] = "SE"; |
||
| 8382 | $temp_array['direction_fullname'] = "Southeast"; |
||
| 8383 | View Code Duplication | } elseif ($direction >= 157.5 && $direction < 180){ |
|
| 8384 | $temp_array['direction_degree'] = $direction; |
||
| 8385 | $temp_array['direction_shortname'] = "SSE"; |
||
| 8386 | $temp_array['direction_fullname'] = "South-Southeast"; |
||
| 8387 | } elseif ($direction >= 180 && $direction < 202.5){ |
||
| 8388 | $temp_array['direction_degree'] = $direction; |
||
| 8389 | $temp_array['direction_shortname'] = "S"; |
||
| 8390 | $temp_array['direction_fullname'] = "South"; |
||
| 8391 | View Code Duplication | } elseif ($direction >= 202.5 && $direction < 225){ |
|
| 8392 | $temp_array['direction_degree'] = $direction; |
||
| 8393 | $temp_array['direction_shortname'] = "SSW"; |
||
| 8394 | $temp_array['direction_fullname'] = "South-Southwest"; |
||
| 8395 | } elseif ($direction >= 225 && $direction < 247.5){ |
||
| 8396 | $temp_array['direction_degree'] = $direction; |
||
| 8397 | $temp_array['direction_shortname'] = "SW"; |
||
| 8398 | $temp_array['direction_fullname'] = "Southwest"; |
||
| 8399 | View Code Duplication | } elseif ($direction >= 247.5 && $direction < 270){ |
|
| 8400 | $temp_array['direction_degree'] = $direction; |
||
| 8401 | $temp_array['direction_shortname'] = "WSW"; |
||
| 8402 | $temp_array['direction_fullname'] = "West-Southwest"; |
||
| 8403 | } elseif ($direction >= 270 && $direction < 292.5){ |
||
| 8404 | $temp_array['direction_degree'] = $direction; |
||
| 8405 | $temp_array['direction_shortname'] = "W"; |
||
| 8406 | $temp_array['direction_fullname'] = "West"; |
||
| 8407 | View Code Duplication | } elseif ($direction >= 292.5 && $direction < 315){ |
|
| 8408 | $temp_array['direction_degree'] = $direction; |
||
| 8409 | $temp_array['direction_shortname'] = "WNW"; |
||
| 8410 | $temp_array['direction_fullname'] = "West-Northwest"; |
||
| 8411 | } elseif ($direction >= 315 && $direction < 337.5){ |
||
| 8412 | $temp_array['direction_degree'] = $direction; |
||
| 8413 | $temp_array['direction_shortname'] = "NW"; |
||
| 8414 | $temp_array['direction_fullname'] = "Northwest"; |
||
| 8415 | View Code Duplication | } elseif ($direction >= 337.5 && $direction < 360){ |
|
| 8416 | $temp_array['direction_degree'] = $direction; |
||
| 8417 | $temp_array['direction_shortname'] = "NNW"; |
||
| 8418 | $temp_array['direction_fullname'] = "North-Northwest"; |
||
| 8419 | } |
||
| 8420 | $direction_array[] = $temp_array; |
||
| 8421 | return $direction_array; |
||
| 8422 | } |
||
| 8423 | |||
| 8424 | |||
| 8425 | /** |
||
| 8426 | * Gets the aircraft registration |
||
| 8427 | * |
||
| 8428 | * @param String $flightaware_id the flight aware id |
||
| 8429 | * @return String the aircraft registration |
||
| 8430 | * |
||
| 8431 | */ |
||
| 8432 | |||
| 8433 | public function getAircraftRegistration($flightaware_id) |
||
| 8434 | { |
||
| 8435 | global $globalFlightAwareUsername, $globalFlightAwarePassword; |
||
| 8436 | |||
| 8437 | $options = array( |
||
| 8438 | 'trace' => true, |
||
| 8439 | 'exceptions' => 0, |
||
| 8440 | 'login' => $globalFlightAwareUsername, |
||
| 8441 | 'password' => $globalFlightAwarePassword, |
||
| 8442 | ); |
||
| 8443 | $client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options); |
||
| 8444 | |||
| 8445 | $params = array('faFlightID' => $flightaware_id); |
||
| 8446 | $result = $client->AirlineFlightInfo($params); |
||
| 8447 | |||
| 8448 | if (isset($result->AirlineFlightInfoResult)) |
||
| 8449 | { |
||
| 8450 | $registration = $result->AirlineFlightInfoResult->tailnumber; |
||
| 8451 | } |
||
| 8452 | |||
| 8453 | $registration = $this->convertAircraftRegistration($registration); |
||
| 8454 | |||
| 8455 | return $registration; |
||
| 8456 | } |
||
| 8457 | |||
| 8458 | |||
| 8459 | /** |
||
| 8460 | * Gets the aircraft registration from ModeS |
||
| 8461 | * |
||
| 8462 | * @param String $aircraft_modes the flight ModeS in hex |
||
| 8463 | * @return String the aircraft registration |
||
| 8464 | * |
||
| 8465 | */ |
||
| 8466 | |||
| 8467 | View Code Duplication | public function getAircraftRegistrationBymodeS($aircraft_modes) |
|
| 8468 | { |
||
| 8469 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 8470 | |||
| 8471 | $query = "SELECT aircraft_modes.Registration FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1"; |
||
| 8472 | |||
| 8473 | $sth = $this->db->prepare($query); |
||
| 8474 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 8475 | |||
| 8476 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 8477 | if (count($row) > 0) { |
||
| 8478 | //return $row['Registration']; |
||
| 8479 | return $row['registration']; |
||
| 8480 | } else return ''; |
||
| 8481 | |||
| 8482 | } |
||
| 8483 | |||
| 8484 | /** |
||
| 8485 | * Gets the aircraft type from ModeS |
||
| 8486 | * |
||
| 8487 | * @param String $aircraft_modes the flight ModeS in hex |
||
| 8488 | * @return String the aircraft type |
||
| 8489 | * |
||
| 8490 | */ |
||
| 8491 | |||
| 8492 | public function getAircraftTypeBymodeS($aircraft_modes) |
||
| 8493 | { |
||
| 8494 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
| 8495 | |||
| 8496 | $query = "SELECT aircraft_modes.type_flight FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1"; |
||
| 8497 | |||
| 8498 | $sth = $this->db->prepare($query); |
||
| 8499 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
| 8500 | |||
| 8501 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 8502 | if (count($row) > 0) { |
||
| 8503 | if ($row['type_flight'] == null) return ''; |
||
| 8504 | else return $row['type_flight']; |
||
| 8505 | } else return ''; |
||
| 8506 | |||
| 8507 | } |
||
| 8508 | |||
| 8509 | /** |
||
| 8510 | * Gets Countrie from latitude/longitude |
||
| 8511 | * |
||
| 8512 | * @param String $aircraft_modes the flight ModeS in hex |
||
| 8513 | * @return String the aircraft registration |
||
| 8514 | * |
||
| 8515 | */ |
||
| 8516 | |||
| 8517 | public function getCountryFromLatitudeLongitude($latitude,$longitude) |
||
| 8518 | { |
||
| 8519 | global $globalDBdriver; |
||
| 8520 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 8521 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 8522 | |||
| 8523 | try { |
||
| 8524 | /* |
||
|
1 ignored issue
–
show
|
|||
| 8525 | if ($globalDBdriver == 'mysql') { |
||
| 8526 | //$query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(:latitude :longitude)'), ogc_geom) LIMIT 1"; |
||
| 8527 | $query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(".$longitude.' '.$latitude.")'), ogc_geom) LIMIT 1"; |
||
| 8528 | } |
||
| 8529 | */ |
||
| 8530 | // This query seems to work both for MariaDB and PostgreSQL |
||
| 8531 | $query = "SELECT name,iso2,iso3 FROM countries WHERE ST_Within(ST_GeomFromText('POINT(".$longitude." ".$latitude.")',4326), ogc_geom) LIMIT 1"; |
||
| 8532 | |||
| 8533 | $sth = $this->db->prepare($query); |
||
| 8534 | //$sth->execute(array(':latitude' => $latitude,':longitude' => $longitude)); |
||
| 8535 | $sth->execute(); |
||
| 8536 | |||
| 8537 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 8538 | if (count($row) > 0) { |
||
| 8539 | return $row; |
||
| 8540 | } else return ''; |
||
| 8541 | } catch (PDOException $e) { |
||
| 8542 | if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
||
| 8543 | return ''; |
||
| 8544 | } |
||
| 8545 | |||
| 8546 | } |
||
| 8547 | |||
| 8548 | /** |
||
| 8549 | * converts the registration code using the country prefix |
||
| 8550 | * |
||
| 8551 | * @param String $registration the aircraft registration |
||
| 8552 | * @return String the aircraft registration |
||
| 8553 | * |
||
| 8554 | */ |
||
| 8555 | public function convertAircraftRegistration($registration) |
||
| 8556 | { |
||
| 8557 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 8558 | $registration_prefix = ''; |
||
| 8559 | $registration_1 = substr($registration, 0, 1); |
||
| 8560 | $registration_2 = substr($registration, 0, 2); |
||
| 8561 | |||
| 8562 | //first get the prefix based on two characters |
||
| 8563 | $query = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_2"; |
||
| 8564 | |||
| 8565 | |||
| 8566 | $sth = $this->db->prepare($query); |
||
| 8567 | $sth->execute(array(':registration_2' => $registration_2)); |
||
| 8568 | |||
| 8569 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8570 | { |
||
| 8571 | $registration_prefix = $row['registration_prefix']; |
||
| 8572 | } |
||
| 8573 | |||
| 8574 | //if we didn't find a two chracter prefix lets just search the one with one character |
||
| 8575 | View Code Duplication | if ($registration_prefix == "") |
|
| 8576 | { |
||
| 8577 | $query = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_1"; |
||
| 8578 | |||
| 8579 | $sth = $this->db->prepare($query); |
||
| 8580 | $sth->execute(array(':registration_1' => $registration_1)); |
||
| 8581 | |||
| 8582 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8583 | { |
||
| 8584 | $registration_prefix = $row['registration_prefix']; |
||
| 8585 | } |
||
| 8586 | } |
||
| 8587 | |||
| 8588 | //determine which characters are being used and convert the registration code appropiately |
||
| 8589 | if (strlen($registration_prefix) == 1) |
||
| 8590 | { |
||
| 8591 | View Code Duplication | if (0 === strpos($registration, 'N')) { |
|
| 8592 | $registration = preg_replace("/^(.{1})/", "$1", $registration); |
||
| 8593 | } else { |
||
| 8594 | $registration = preg_replace("/^(.{1})/", "$1-", $registration); |
||
| 8595 | } |
||
| 8596 | View Code Duplication | } else if(strlen($registration_prefix) == 2){ |
|
| 8597 | if (0 === strpos($registration, 'N')) { |
||
| 8598 | $registration = preg_replace("/^(.{2})/", "$1", $registration); |
||
| 8599 | } else { |
||
| 8600 | $registration = preg_replace("/^(.{2})/", "$1-", $registration); |
||
| 8601 | } |
||
| 8602 | } |
||
| 8603 | |||
| 8604 | return $registration; |
||
| 8605 | } |
||
| 8606 | |||
| 8607 | /** |
||
| 8608 | * Country from the registration code |
||
| 8609 | * |
||
| 8610 | * @param String $registration the aircraft registration |
||
| 8611 | * @return String the country |
||
| 8612 | * |
||
| 8613 | */ |
||
| 8614 | public function countryFromAircraftRegistration($registration) |
||
| 8615 | { |
||
| 8616 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
| 8617 | |||
| 8618 | $registration_prefix = ''; |
||
| 8619 | |||
| 8620 | $registration_test = explode('-',$registration); |
||
| 8621 | $country = ''; |
||
| 8622 | if ($registration_test[0] != $registration) { |
||
| 8623 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 8624 | |||
| 8625 | $sth = $this->db->prepare($query); |
||
| 8626 | $sth->execute(array(':registration_1' => $registration_test[0])); |
||
| 8627 | |||
| 8628 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8629 | { |
||
| 8630 | $registration_prefix = $row['registration_prefix']; |
||
| 8631 | $country = $row['country']; |
||
| 8632 | } |
||
| 8633 | } else { |
||
| 8634 | $registration_1 = substr($registration, 0, 1); |
||
| 8635 | $registration_2 = substr($registration, 0, 2); |
||
| 8636 | |||
| 8637 | $country = ''; |
||
| 8638 | //first get the prefix based on two characters |
||
| 8639 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_2 LIMIT 1"; |
||
| 8640 | |||
| 8641 | |||
| 8642 | $sth = $this->db->prepare($query); |
||
| 8643 | $sth->execute(array(':registration_2' => $registration_2)); |
||
| 8644 | |||
| 8645 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8646 | { |
||
| 8647 | $registration_prefix = $row['registration_prefix']; |
||
| 8648 | $country = $row['country']; |
||
| 8649 | } |
||
| 8650 | |||
| 8651 | //if we didn't find a two chracter prefix lets just search the one with one character |
||
| 8652 | View Code Duplication | if ($registration_prefix == "") |
|
| 8653 | { |
||
| 8654 | $query = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1"; |
||
| 8655 | |||
| 8656 | $sth = $this->db->prepare($query); |
||
| 8657 | $sth->execute(array(':registration_1' => $registration_1)); |
||
| 8658 | |||
| 8659 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8660 | { |
||
| 8661 | $registration_prefix = $row['registration_prefix']; |
||
| 8662 | $country = $row['country']; |
||
| 8663 | } |
||
| 8664 | } |
||
| 8665 | } |
||
| 8666 | |||
| 8667 | return $country; |
||
| 8668 | } |
||
| 8669 | |||
| 8670 | /** |
||
| 8671 | * Set a new highlight value for a flight |
||
| 8672 | * |
||
| 8673 | * @param String $flightaware_id flightaware_id from spotter_output table |
||
| 8674 | * @param String $highlight New highlight value |
||
| 8675 | */ |
||
| 8676 | public function setHighlightFlight($flightaware_id,$highlight) { |
||
| 8677 | |||
| 8678 | $query = "UPDATE spotter_output SET highlight = :highlight WHERE flightaware_id = :flightaware_id"; |
||
| 8679 | $sth = $this->db->prepare($query); |
||
| 8680 | $sth->execute(array(':flightaware_id' => $flightaware_id, ':highlight' => $highlight)); |
||
| 8681 | } |
||
| 8682 | |||
| 8683 | /** |
||
| 8684 | * Gets the short url from bit.ly |
||
| 8685 | * |
||
| 8686 | * @param String $url the full url |
||
| 8687 | * @return String the bit.ly url |
||
| 8688 | * |
||
| 8689 | */ |
||
| 8690 | public function getBitlyURL($url) |
||
| 8691 | { |
||
| 8692 | global $globalBitlyAccessToken; |
||
| 8693 | |||
| 8694 | if ($globalBitlyAccessToken == '') return $url; |
||
| 8695 | |||
| 8696 | $google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; |
||
| 8697 | |||
| 8698 | $ch = curl_init(); |
||
| 8699 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
| 8700 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 8701 | curl_setopt($ch, CURLOPT_URL, $google_url); |
||
| 8702 | $bitly_data = curl_exec($ch); |
||
| 8703 | curl_close($ch); |
||
| 8704 | |||
| 8705 | $bitly_data = json_decode($bitly_data); |
||
| 8706 | |||
| 8707 | if ($bitly_data->status_txt = "OK"){ |
||
| 8708 | $bitly_url = $bitly_data->data->url; |
||
| 8709 | } |
||
| 8710 | |||
| 8711 | return $bitly_url; |
||
| 8712 | } |
||
| 8713 | |||
| 8714 | |||
| 8715 | public function getOrderBy() |
||
| 8716 | { |
||
| 8717 | $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")); |
||
| 8718 | |||
| 8719 | return $orderby; |
||
| 8720 | |||
| 8721 | } |
||
| 8722 | |||
| 8723 | |||
| 8724 | public function importFromFlightAware() |
||
| 8725 | { |
||
| 8726 | global $globalFlightAwareUsername, $globalFlightAwarePassword, $globalLatitudeMax, $globalLatitudeMin, $globalLongitudeMax, $globalLongitudeMin, $globalAirportIgnore; |
||
| 8727 | $Spotter = new Spotter($this->db); |
||
| 8728 | $SPotterLive = new SpotterLive($this->db); |
||
| 8729 | $options = array( |
||
| 8730 | 'trace' => true, |
||
| 8731 | 'exceptions' => 0, |
||
| 8732 | 'login' => $globalFlightAwareUsername, |
||
| 8733 | 'password' => $globalFlightAwarePassword, |
||
| 8734 | ); |
||
| 8735 | $client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options); |
||
| 8736 | |||
| 8737 | $params = array('query' => '{range lat '.$globalLatitudeMin.' '.$globalLatitudeMax.'} {range lon '.$globalLongitudeMax.' '.$globalLongitudeMin.'} {true inAir}', 'howMany' => '15', 'offset' => '0'); |
||
| 8738 | |||
| 8739 | $result = $client->SearchBirdseyeInFlight($params); |
||
| 8740 | |||
| 8741 | $dataFound = false; |
||
| 8742 | $ignoreImport = false; |
||
| 8743 | |||
| 8744 | if (isset($result->SearchBirdseyeInFlightResult)) |
||
| 8745 | { |
||
| 8746 | if (is_array($result->SearchBirdseyeInFlightResult->aircraft)) |
||
| 8747 | { |
||
| 8748 | foreach($result->SearchBirdseyeInFlightResult->aircraft as $aircraft) |
||
| 8749 | { |
||
| 8750 | if (!strstr($aircraft->origin, 'L ') && !strstr($aircraft->destination, 'L ')) |
||
| 8751 | { |
||
| 8752 | View Code Duplication | foreach($globalAirportIgnore as $airportIgnore) |
|
| 8753 | { |
||
| 8754 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
| 8755 | { |
||
| 8756 | $ignoreImport = true; |
||
| 8757 | } |
||
| 8758 | } |
||
| 8759 | if ($ignoreImport == false) |
||
| 8760 | { |
||
| 8761 | $flightaware_id = $aircraft->faFlightID; |
||
| 8762 | $ident = $aircraft->ident; |
||
| 8763 | $aircraft_type = $aircraft->type; |
||
| 8764 | $departure_airport = $aircraft->origin; |
||
| 8765 | $arrival_airport = $aircraft->destination; |
||
| 8766 | $latitude = $aircraft->latitude; |
||
| 8767 | $longitude = $aircraft->longitude; |
||
| 8768 | $waypoints = $aircraft->waypoints; |
||
| 8769 | $altitude = $aircraft->altitude; |
||
| 8770 | $heading = $aircraft->heading; |
||
| 8771 | $groundspeed = $aircraft->groundspeed; |
||
| 8772 | |||
| 8773 | $dataFound = true; |
||
| 8774 | |||
| 8775 | //gets the callsign from the last hour |
||
| 8776 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
| 8777 | |||
| 8778 | //change the departure/arrival airport to NA if its not available |
||
| 8779 | View Code Duplication | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
|
| 8780 | View Code Duplication | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
|
| 8781 | |||
| 8782 | |||
| 8783 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
| 8784 | View Code Duplication | if($last_hour_ident == "") |
|
| 8785 | { |
||
| 8786 | //adds the spotter data for the archive |
||
| 8787 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 8788 | } |
||
| 8789 | |||
| 8790 | //adds the spotter LIVE data |
||
| 8791 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 8792 | } |
||
| 8793 | } |
||
| 8794 | $ignoreImport = false; |
||
| 8795 | } |
||
| 8796 | } else { |
||
| 8797 | if (!strstr($result->SearchBirdseyeInFlightResult->aircraft->origin, 'L ') && !strstr($result->SearchBirdseyeInFlightResult->aircraft->destination, 'L ')) |
||
| 8798 | { |
||
| 8799 | foreach($globalAirportIgnore as $airportIgnore) |
||
| 8800 | { |
||
| 8801 | View Code Duplication | foreach($globalAirportIgnore as $airportIgnore) |
|
| 8802 | { |
||
| 8803 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
| 8804 | { |
||
| 8805 | $ignoreImport = true; |
||
| 8806 | } |
||
| 8807 | } |
||
| 8808 | if ($ignoreImport == false) |
||
| 8809 | { |
||
| 8810 | $flightaware_id = $result->SearchBirdseyeInFlightResult->aircraft->faFlightID; |
||
| 8811 | $ident = $result->SearchBirdseyeInFlightResult->aircraft->ident; |
||
| 8812 | $aircraft_type = $result->SearchBirdseyeInFlightResult->aircraft->type; |
||
| 8813 | $departure_airport = $result->SearchBirdseyeInFlightResult->aircraft->origin; |
||
| 8814 | $arrival_airport = $result->SearchBirdseyeInFlightResult->aircraft->destination; |
||
| 8815 | $latitude = $result->SearchBirdseyeInFlightResult->aircraft->latitude; |
||
| 8816 | $longitude = $result->SearchBirdseyeInFlightResult->aircraft->longitude; |
||
| 8817 | $waypoints = $result->SearchBirdseyeInFlightResult->aircraft->waypoints; |
||
| 8818 | $altitude = $result->SearchBirdseyeInFlightResult->aircraft->altitude; |
||
| 8819 | $heading = $result->SearchBirdseyeInFlightResult->aircraft->heading; |
||
| 8820 | $groundspeed = $result->SearchBirdseyeInFlightResult->aircraft->groundspeed; |
||
| 8821 | |||
| 8822 | $dataFound = true; |
||
| 8823 | |||
| 8824 | //gets the callsign from the last hour |
||
| 8825 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
| 8826 | |||
| 8827 | //change the departure/arrival airport to NA if its not available |
||
| 8828 | View Code Duplication | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
|
| 8829 | View Code Duplication | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
|
| 8830 | |||
| 8831 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
| 8832 | View Code Duplication | if($last_hour_ident == "") |
|
| 8833 | { |
||
| 8834 | //adds the spotter data for the archive |
||
| 8835 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 8836 | } |
||
| 8837 | |||
| 8838 | //adds the spotter LIVE data |
||
| 8839 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 8840 | } |
||
| 8841 | $ignoreImport = false; |
||
| 8842 | } |
||
| 8843 | } |
||
| 8844 | |||
| 8845 | } |
||
| 8846 | } |
||
| 8847 | } |
||
| 8848 | |||
| 8849 | |||
| 8850 | // Update flights data when new data in DB |
||
| 8851 | public function updateFieldsFromOtherTables() |
||
| 8852 | { |
||
| 8853 | global $globalDebug, $globalDBdriver; |
||
| 8854 | $Image = new Image($this->db); |
||
| 8855 | |||
| 8856 | |||
| 8857 | // routes |
||
| 8858 | if ($globalDebug) print "Routes...\n"; |
||
| 8859 | if ($globalDBdriver == 'mysql') { |
||
| 8860 | $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)"; |
||
| 8861 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 8862 | $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'"; |
||
| 8863 | } |
||
| 8864 | $sth = $this->db->prepare($query); |
||
| 8865 | $sth->execute(); |
||
| 8866 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8867 | { |
||
| 8868 | $departure_airport_array = $this->getAllAirportInfo($row['fromairport_icao']); |
||
| 8869 | $arrival_airport_array = $this->getAllAirportInfo($row['toairport_icao']); |
||
| 8870 | if (count($departure_airport_array) > 0 && count($arrival_airport_array) > 0) { |
||
| 8871 | $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"; |
||
| 8872 | $sthu = $this->db->prepare($update_query); |
||
| 8873 | $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'])); |
||
| 8874 | } |
||
| 8875 | } |
||
| 8876 | |||
| 8877 | if ($globalDebug) print "Airlines...\n"; |
||
| 8878 | //airlines |
||
| 8879 | if ($globalDBdriver == 'mysql') { |
||
| 8880 | $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)"; |
||
| 8881 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 8882 | $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'"; |
||
| 8883 | } |
||
| 8884 | $sth = $this->db->prepare($query); |
||
| 8885 | $sth->execute(); |
||
| 8886 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8887 | { |
||
| 8888 | if (is_numeric(substr($row['ident'], -1, 1))) |
||
| 8889 | { |
||
| 8890 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3)); |
||
| 8891 | if (isset($airline_array[0]['name'])) { |
||
| 8892 | $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"; |
||
| 8893 | $sthu = $this->db->prepare($update_query); |
||
| 8894 | $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'])); |
||
| 8895 | } |
||
| 8896 | } |
||
| 8897 | } |
||
| 8898 | |||
| 8899 | if ($globalDebug) print "Remove Duplicate in aircraft_modes...\n"; |
||
| 8900 | //duplicate modes |
||
| 8901 | $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"; |
||
| 8902 | $sth = $this->db->prepare($query); |
||
| 8903 | $sth->execute(); |
||
| 8904 | |||
| 8905 | if ($globalDebug) print "Aircraft...\n"; |
||
| 8906 | //aircraft |
||
| 8907 | if ($globalDBdriver == 'mysql') { |
||
| 8908 | $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)"; |
||
| 8909 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 8910 | $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'"; |
||
| 8911 | } |
||
| 8912 | $sth = $this->db->prepare($query); |
||
| 8913 | $sth->execute(); |
||
| 8914 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8915 | { |
||
| 8916 | if ($row['aircraft_icao'] != '') { |
||
| 8917 | $aircraft_name = $this->getAllAircraftInfo($row['aircraft_icao']); |
||
| 8918 | if ($row['registration'] != ""){ |
||
| 8919 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 8920 | if (count($image_array) == 0) { |
||
| 8921 | $Image->addSpotterImage($row['registration']); |
||
| 8922 | } |
||
| 8923 | } |
||
| 8924 | if (count($aircraft_name) > 0) { |
||
| 8925 | $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"; |
||
| 8926 | $sthu = $this->db->prepare($update_query); |
||
| 8927 | $sthu->execute(array(':aircraft_name' => $aircraft_name[0]['type'], ':aircraft_manufacturer' => $aircraft_name[0]['manufacturer'], ':spotter_id' => $row['spotter_id'])); |
||
| 8928 | } |
||
| 8929 | } |
||
| 8930 | } |
||
| 8931 | } |
||
| 8932 | |||
| 8933 | // Update arrival airports for data already in DB |
||
| 8934 | public function updateArrivalAirports() |
||
| 8935 | { |
||
| 8936 | global $globalDebug, $globalDBdriver, $globalClosestMinDist; |
||
| 8937 | $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"; |
||
| 8938 | $sth = $this->db->prepare($query); |
||
| 8939 | $sth->execute(); |
||
| 8940 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 8941 | { |
||
| 8942 | if ($row['last_latitude'] != '' && $row['last_longitude'] != '') { |
||
| 8943 | $closestAirports = $this->closestAirports($row['last_latitude'],$row['last_longitude'],$globalClosestMinDist); |
||
| 8944 | $airport_icao = ''; |
||
| 8945 | if (isset($closestAirports[0])) { |
||
| 8946 | if ($row['arrival_airport_icao'] == $closestAirports[0]['icao']) { |
||
| 8947 | $airport_icao = $closestAirports[0]['icao']; |
||
| 8948 | if ($globalDebug) echo "\o/ 1st ---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
||
| 8949 | } elseif (count($closestAirports > 1) && $row['arrival_airport_icao'] != '' && $row['arrival_airport_icao'] != 'NA') { |
||
| 8950 | foreach ($closestAirports as $airport) { |
||
| 8951 | if ($row['arrival_airport_icao'] == $airport['icao']) { |
||
| 8952 | $airport_icao = $airport['icao']; |
||
| 8953 | if ($globalDebug) echo "\o/ try --++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
||
| 8954 | break; |
||
| 8955 | } |
||
| 8956 | } |
||
| 8957 | } elseif ($row['last_altitude'] == 0 || ($row['last_altitude'] != '' && ($closestAirports[0]['altitude'] <= $row['last_altitude']*100+1000 && $row['last_altitude']*100 < $closestAirports[0]['altitude']+5000))) { |
||
| 8958 | $airport_icao = $closestAirports[0]['icao']; |
||
| 8959 | View Code Duplication | 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"; |
|
| 8960 | View Code Duplication | } else { |
|
| 8961 | 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"; |
||
| 8962 | } |
||
| 8963 | } else { |
||
| 8964 | if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
||
| 8965 | } |
||
| 8966 | if ($row['real_arrival_airport_icao'] != $airport_icao) { |
||
| 8967 | if ($globalDebug) echo "Updating airport to ".$airport_icao."...\n"; |
||
| 8968 | $update_query="UPDATE spotter_output SET real_arrival_airport_icao = :airport_icao WHERE spotter_id = :spotter_id"; |
||
| 8969 | $sthu = $this->db->prepare($update_query); |
||
| 8970 | $sthu->execute(array(':airport_icao' => $airport_icao,':spotter_id' => $row['spotter_id'])); |
||
| 8971 | } |
||
| 8972 | } |
||
| 8973 | } |
||
| 8974 | } |
||
| 8975 | |||
| 8976 | public function closestAirports($origLat,$origLon,$dist = 10) { |
||
| 8977 | global $globalDBdriver; |
||
| 8978 | $dist = number_format($dist*0.621371,2,'.',''); // convert km to mile |
||
| 8979 | /* |
||
| 8980 | $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 |
||
| 8981 | 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)) |
||
| 8982 | having distance < $dist ORDER BY distance limit 100;"; |
||
| 8983 | */ |
||
| 8984 | if ($globalDBdriver == 'mysql') { |
||
| 8985 | $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 |
||
| 8986 | 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)) |
||
| 8987 | 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;"; |
||
| 8988 | } else { |
||
| 8989 | $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 |
||
| 8990 | 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)) |
||
| 8991 | 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;"; |
||
| 8992 | } |
||
| 8993 | $sth = $this->db->prepare($query); |
||
| 8994 | $sth->execute(); |
||
| 8995 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 8996 | } |
||
| 8997 | } |
||
| 8998 | /* |
||
|
1 ignored issue
–
show
Unused Code
Comprehensibility
introduced
by
66% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 8999 | $Spotter = new Spotter(); |
||
| 9000 | print_r($Spotter->closestAirports('-19.9813','-47.8286',10)); |
||
| 9001 | */ |
||
| 9002 | /* |
||
|
1 ignored issue
–
show
Unused Code
Comprehensibility
introduced
by
68% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 9003 | $Spotter = new Spotter(); |
||
| 9004 | $da = $Spotter->countAllDetectedArrivalAirports(true,0,'',true); |
||
| 9005 | $aa = $Spotter->countAllArrivalAirports(true,0,'',true); |
||
| 9006 | print_r($da); |
||
| 9007 | print_r($aa); |
||
| 9008 | print_r(array_merge($da,$aa)); |
||
| 9009 | */ |
||
| 9010 | ?> |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.