Complex classes like Spotter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Spotter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class Spotter{ |
||
8 | public $db; |
||
9 | |||
10 | public function __construct($dbc = null) { |
||
14 | |||
15 | /** |
||
16 | * Get SQL query part for filter used |
||
17 | * @param Array $filter the filter |
||
18 | * @return Array the SQL part |
||
19 | */ |
||
20 | public function getFilter($filter = array(),$where = false,$and = false) { |
||
21 | global $globalFilter, $globalStatsFilters, $globalFilterName; |
||
22 | if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) $filter = array_merge($globalStatsFilters[$globalFilterName],$filter); |
||
23 | if (is_array($globalFilter)) $filter = array_merge($globalFilter,$filter); |
||
24 | $filter_query_join = ''; |
||
25 | $filter_query_where = ''; |
||
26 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
||
27 | if ($filter['airlines'][0] != '') { |
||
28 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
||
33 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_output.flightaware_id "; |
||
34 | } |
||
35 | if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
||
36 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) so ON so.flightaware_id = spotter_output.flightaware_id"; |
||
37 | } |
||
38 | if (isset($filter['source']) && !empty($filter['source'])) { |
||
39 | $filter_query_where = " WHERE format_source IN ('".implode("','",$filter['source'])."')"; |
||
40 | } |
||
41 | if (isset($filter['ident']) && !empty($filter['ident'])) { |
||
42 | $filter_query_where = " WHERE ident = '".$filter['ident']."'"; |
||
43 | } |
||
44 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
||
45 | if ($filter_query_where == '') { |
||
46 | $filter_query_where = " WHERE format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
47 | } else { |
||
48 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
49 | } |
||
50 | } |
||
51 | if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
||
52 | elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
||
53 | $filter_query = $filter_query_join.$filter_query_where; |
||
54 | return $filter_query; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Executes the SQL statements to get the spotter information |
||
59 | * |
||
60 | * @param String $query the SQL query |
||
61 | * @param Array $params parameter of the query |
||
62 | * @param String $limitQuery the limit query |
||
63 | * @return Array the spotter information |
||
64 | * |
||
65 | */ |
||
66 | public function getDataFromDB($query, $params = array(), $limitQuery = '') |
||
67 | { |
||
68 | global $globalSquawkCountry, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalAirlinesSource, $globalVAM; |
||
69 | $Image = new Image($this->db); |
||
70 | $Schedule = new Schedule($this->db); |
||
71 | $ACARS = new ACARS($this->db); |
||
72 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
73 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
74 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
75 | if (!isset($globalVAM)) $globalVAM = FALSE; |
||
76 | date_default_timezone_set('UTC'); |
||
77 | |||
78 | if (!is_string($query)) |
||
79 | { |
||
80 | return false; |
||
81 | } |
||
82 | |||
83 | if ($limitQuery != "") |
||
84 | { |
||
85 | if (!is_string($limitQuery)) |
||
86 | { |
||
87 | return false; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | |||
92 | try { |
||
93 | $sth = $this->db->prepare($query.$limitQuery); |
||
94 | $sth->execute($params); |
||
95 | } catch (PDOException $e) { |
||
96 | printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery); |
||
97 | exit(); |
||
98 | } |
||
99 | |||
100 | // $num_rows = count($sth->fetchAll()); |
||
101 | $num_rows = 0; |
||
102 | |||
103 | $spotter_array = array(); |
||
104 | |||
105 | |||
106 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
107 | { |
||
108 | $num_rows++; |
||
109 | $temp_array = array(); |
||
110 | if (isset($row['spotter_live_id'])) { |
||
111 | //$temp_array['spotter_id'] = $row['spotter_live_id']; |
||
112 | $temp_array['spotter_id'] = $this->getSpotterIDBasedOnFlightAwareID($row['flightaware_id']); |
||
113 | } elseif (isset($row['spotter_archive_id'])) { |
||
114 | $temp_array['spotter_id'] = $row['spotter_archive_id']; |
||
115 | } elseif (isset($row['spotter_archive_output_id'])) { |
||
116 | $temp_array['spotter_id'] = $row['spotter_archive_output_id']; |
||
117 | } elseif (isset($row['spotter_id'])) { |
||
118 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
119 | } else { |
||
120 | $temp_array['spotter_id'] = ''; |
||
121 | } |
||
122 | if (isset($row['flightaware_id'])) $temp_array['flightaware_id'] = $row['flightaware_id']; |
||
123 | if (isset($row['modes'])) $temp_array['modes'] = $row['modes']; |
||
124 | $temp_array['ident'] = $row['ident']; |
||
125 | if (isset($row['registration']) && $row['registration'] != '') { |
||
126 | $temp_array['registration'] = $row['registration']; |
||
127 | } elseif (isset($temp_array['modes'])) { |
||
128 | $temp_array['registration'] = $this->getAircraftRegistrationBymodeS($temp_array['modes']); |
||
129 | } else $temp_array['registration'] = ''; |
||
130 | if (isset($row['aircraft_icao'])) $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
131 | |||
132 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
133 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
134 | if (isset($row['real_arrival_airport_icao']) && $row['real_arrival_airport_icao'] != NULL) $temp_array['real_arrival_airport'] = $row['real_arrival_airport_icao']; |
||
135 | if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude']; |
||
136 | if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude']; |
||
137 | /* |
||
138 | if (Connection->tableExists('countries')) { |
||
139 | $country_info = $this->getCountryFromLatitudeLongitude($temp_array['latitude'],$temp_array['longitude']); |
||
140 | if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) { |
||
141 | $temp_array['country'] = $country_info['name']; |
||
142 | $temp_array['country_iso2'] = $country_info['iso2']; |
||
143 | } |
||
144 | } |
||
145 | */ |
||
146 | if (isset($row['waypoints'])) $temp_array['waypoints'] = $row['waypoints']; |
||
147 | if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source']; |
||
148 | if (isset($row['route_stop'])) { |
||
149 | $temp_array['route_stop'] = $row['route_stop']; |
||
150 | if ($row['route_stop'] != '') { |
||
151 | $allroute = explode(' ',$row['route_stop']); |
||
152 | |||
153 | foreach ($allroute as $route) { |
||
154 | $route_airport_array = $this->getAllAirportInfo($route); |
||
155 | if (isset($route_airport_array[0]['name'])) { |
||
156 | $route_stop_details = array(); |
||
157 | $route_stop_details['airport_name'] = $route_airport_array[0]['name']; |
||
158 | $route_stop_details['airport_city'] = $route_airport_array[0]['city']; |
||
159 | $route_stop_details['airport_country'] = $route_airport_array[0]['country']; |
||
160 | $route_stop_details['airport_icao'] = $route_airport_array[0]['icao']; |
||
161 | $temp_array['route_stop_details'][] = $route_stop_details; |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | if (isset($row['altitude'])) $temp_array['altitude'] = $row['altitude']; |
||
167 | if (isset($row['heading'])) { |
||
168 | $temp_array['heading'] = $row['heading']; |
||
169 | $heading_direction = $this->parseDirection($row['heading']); |
||
170 | if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
||
171 | } |
||
172 | if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed']; |
||
173 | $temp_array['image'] = ""; |
||
174 | $temp_array['image_thumbnail'] = ""; |
||
175 | $temp_array['image_source'] = ""; |
||
176 | $temp_array['image_copyright'] = ""; |
||
177 | |||
178 | if (isset($row['highlight'])) { |
||
179 | $temp_array['highlight'] = $row['highlight']; |
||
180 | } else $temp_array['highlight'] = ''; |
||
181 | |||
182 | if (isset($row['date'])) { |
||
183 | $dateArray = $this->parseDateString($row['date']); |
||
184 | if ($dateArray['seconds'] < 10) |
||
185 | { |
||
186 | $temp_array['date'] = "a few seconds ago"; |
||
187 | } elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) |
||
188 | { |
||
189 | $temp_array['date'] = "half a minute ago"; |
||
190 | } elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) |
||
191 | { |
||
192 | $temp_array['date'] = "about a minute ago"; |
||
193 | } elseif ($dateArray['minutes'] < 5) |
||
194 | { |
||
195 | $temp_array['date'] = "a few minutes ago"; |
||
196 | } elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) |
||
197 | { |
||
198 | $temp_array['date'] = "about ".$dateArray['minutes']." minutes ago"; |
||
199 | } elseif ($dateArray['hours'] < 2) |
||
200 | { |
||
201 | $temp_array['date'] = "about an hour ago"; |
||
202 | } elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) |
||
203 | { |
||
204 | $temp_array['date'] = "about ".$dateArray['hours']." hours ago"; |
||
205 | } else { |
||
206 | $temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC")); |
||
207 | } |
||
208 | $temp_array['date_minutes_past'] = $dateArray['minutes']; |
||
209 | $temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC")); |
||
210 | $temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC")); |
||
211 | $temp_array['date_unix'] = strtotime($row['date']." UTC"); |
||
212 | } |
||
213 | |||
214 | if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') { |
||
215 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
216 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
217 | if (isset($row['aircraft_shadow'])) { |
||
218 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
219 | } |
||
220 | } elseif (isset($row['aircraft_icao'])) { |
||
221 | $aircraft_array = $this->getAllAircraftInfo($row['aircraft_icao']); |
||
222 | if (count($aircraft_array) > 0) { |
||
223 | $temp_array['aircraft_name'] = $aircraft_array[0]['type']; |
||
224 | $temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer']; |
||
225 | |||
226 | if ($aircraft_array[0]['aircraft_shadow'] != NULL) { |
||
227 | $temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow']; |
||
228 | } else $temp_array['aircraft_shadow'] = 'default.png'; |
||
229 | } else { |
||
230 | $temp_array['aircraft_shadow'] = 'default.png'; |
||
231 | $temp_array['aircraft_name'] = 'N/A'; |
||
232 | $temp_array['aircraft_manufacturer'] = 'N/A'; |
||
233 | } |
||
234 | } |
||
235 | $fromsource = NULL; |
||
236 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
||
237 | elseif (isset($row['format_source']) && $row['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
||
238 | elseif (isset($row['format_source']) && $row['format_source'] == 'whazzup') $fromsource = 'ivao'; |
||
239 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
||
240 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
||
241 | if (!isset($row['airline_name']) || $row['airline_name'] == '') { |
||
242 | if (!is_numeric(substr($row['ident'], 0, 3))) { |
||
243 | if (is_numeric(substr($row['ident'], 2, 1))) { |
||
244 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 2),$fromsource); |
||
245 | } elseif (is_numeric(substr($row['ident'], 3, 1))) { |
||
246 | $airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3),$fromsource); |
||
247 | } else { |
||
248 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
249 | } |
||
250 | } else { |
||
251 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
252 | } |
||
253 | if (count($airline_array) > 0) { |
||
254 | $temp_array['airline_icao'] = $airline_array[0]['icao']; |
||
255 | $temp_array['airline_iata'] = $airline_array[0]['iata']; |
||
256 | $temp_array['airline_name'] = $airline_array[0]['name']; |
||
257 | $temp_array['airline_country'] = $airline_array[0]['country']; |
||
258 | $temp_array['airline_callsign'] = $airline_array[0]['callsign']; |
||
259 | $temp_array['airline_type'] = $airline_array[0]['type']; |
||
260 | } |
||
261 | } else { |
||
262 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
263 | if (isset($row['airline_iata'])) $temp_array['airline_iata'] = $row['airline_iata']; |
||
264 | else $temp_array['airline_iata'] = ''; |
||
265 | $temp_array['airline_name'] = $row['airline_name']; |
||
266 | $temp_array['airline_country'] = $row['airline_country']; |
||
267 | if (isset($row['airline_callsign'])) $temp_array['airline_callsign'] = $row['airline_callsign']; |
||
268 | else $temp_array['airline_callsign'] = 'N/A'; |
||
269 | $temp_array['airline_type'] = $row['airline_type']; |
||
270 | } |
||
271 | if (isset($temp_array['airline_iata']) && $temp_array['airline_iata'] != '') { |
||
272 | $acars_array = $ACARS->getLiveAcarsData($temp_array['airline_iata'].substr($temp_array['ident'],3)); |
||
273 | //$acars_array = ACARS->getLiveAcarsData('BA40YL'); |
||
274 | if (count($acars_array) > 0) { |
||
275 | $temp_array['acars'] = $acars_array; |
||
276 | //print_r($acars_array); |
||
277 | } |
||
278 | } |
||
279 | if (isset($row['owner_name']) && $row['owner_name'] != '' && $row['owner_name'] != NULL) { |
||
280 | $temp_array['aircraft_owner'] = $row['owner_name']; |
||
281 | } |
||
282 | if ($temp_array['registration'] != "" && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && !isset($temp_array['aircraft_owner'])) { |
||
283 | $owner_info = $this->getAircraftOwnerByRegistration($temp_array['registration']); |
||
284 | if ($owner_info['owner'] != '') $temp_array['aircraft_owner'] = ucwords(strtolower($owner_info['owner'])); |
||
285 | $temp_array['aircraft_base'] = $owner_info['base']; |
||
286 | $temp_array['aircraft_date_first_reg'] = $owner_info['date_first_reg']; |
||
287 | } |
||
288 | |||
289 | if($temp_array['registration'] != "" || ($globalIVAO && isset($temp_array['aircraft_type']) && $temp_array['aircraft_type'] != '')) |
||
290 | { |
||
291 | if ($globalIVAO) { |
||
292 | if (isset($temp_array['airline_icao'])) $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type'],$temp_array['airline_icao']); |
||
293 | else $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type']); |
||
294 | } else $image_array = $Image->getSpotterImage($temp_array['registration']); |
||
295 | if (count($image_array) > 0) { |
||
296 | $temp_array['image'] = $image_array[0]['image']; |
||
297 | $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
298 | $temp_array['image_source'] = $image_array[0]['image_source']; |
||
299 | $temp_array['image_source_website'] = $image_array[0]['image_source_website']; |
||
300 | if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') { |
||
301 | $planespotter_url_array = explode("_", $temp_array['image']); |
||
302 | $planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]); |
||
303 | $temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id; |
||
304 | } |
||
305 | $temp_array['image_copyright'] = $image_array[0]['image_copyright']; |
||
306 | } |
||
307 | } |
||
308 | |||
309 | |||
310 | if (isset($row['departure_airport_time']) && $row['departure_airport_time'] != '') { |
||
311 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
312 | } |
||
313 | if (isset($row['arrival_airport_time']) && $row['arrival_airport_time'] != '') { |
||
314 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
315 | } |
||
316 | if ((!isset($globalIVAO) || ! $globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalVAM) || !$globalVAM)) { |
||
317 | $schedule_array = $Schedule->getSchedule($temp_array['ident']); |
||
318 | //print_r($schedule_array); |
||
319 | if (count($schedule_array) > 0) { |
||
320 | if ($schedule_array['departure_airport_icao'] != '') { |
||
321 | $row['departure_airport_icao'] = $schedule_array['departure_airport_icao']; |
||
322 | $temp_array['departure_airport'] = $row['departure_airport_icao']; |
||
323 | } |
||
324 | if ($schedule_array['arrival_airport_icao'] != '') { |
||
325 | $row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao']; |
||
326 | $temp_array['arrival_airport'] = $row['arrival_airport_icao']; |
||
327 | } |
||
328 | |||
329 | $temp_array['departure_airport_time'] = $schedule_array['departure_airport_time']; |
||
330 | $temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time']; |
||
331 | } |
||
332 | } else { |
||
333 | if (isset($row['real_departure_airport_time']) && $row['real_departure_airport_time'] != '') { |
||
334 | $temp_array['departure_airport_time'] = $row['real_departure_airport_time']; |
||
335 | } |
||
336 | if (isset($row['real_arrival_airport_time']) && $row['real_arrival_airport_time'] != '') { |
||
337 | $temp_array['real_arrival_airport_time'] = $row['real_arrival_airport_time']; |
||
338 | } |
||
339 | } |
||
340 | |||
341 | //if ($row['departure_airport_icao'] != '' && $row['departure_airport_name'] == '') { |
||
342 | if ($row['departure_airport_icao'] != '') { |
||
343 | $departure_airport_array = $this->getAllAirportInfo($row['departure_airport_icao']); |
||
344 | if (!isset($departure_airport_array[0]['name'])) $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
345 | /* |
||
346 | } elseif ($row['departure_airport_name'] != '') { |
||
347 | $temp_array['departure_airport_name'] = $row['departure_airport_name']; |
||
348 | $temp_array['departure_airport_city'] = $row['departure_airport_city']; |
||
349 | $temp_array['departure_airport_country'] = $row['departure_airport_country']; |
||
350 | $temp_array['departure_airport_icao'] = $row['departure_airport_icao']; |
||
351 | */ |
||
352 | } else $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
353 | if (isset($departure_airport_array[0]['name'])) { |
||
354 | $temp_array['departure_airport_name'] = $departure_airport_array[0]['name']; |
||
355 | $temp_array['departure_airport_city'] = $departure_airport_array[0]['city']; |
||
356 | $temp_array['departure_airport_country'] = $departure_airport_array[0]['country']; |
||
357 | $temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata']; |
||
358 | $temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao']; |
||
359 | $temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude']; |
||
360 | $temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude']; |
||
361 | $temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude']; |
||
362 | } |
||
363 | |||
364 | /* |
||
365 | if (isset($row['departure_airport_time'])) { |
||
366 | $temp_array['departure_airport_time'] = $row['departure_airport_time']; |
||
367 | } |
||
368 | */ |
||
369 | |||
370 | if ($row['arrival_airport_icao'] != '') { |
||
371 | $arrival_airport_array = $this->getAllAirportInfo($row['arrival_airport_icao']); |
||
372 | if (count($arrival_airport_array) == 0) $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
373 | } else $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
374 | if (isset($arrival_airport_array[0]['name'])) { |
||
375 | $temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name']; |
||
376 | $temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city']; |
||
377 | $temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country']; |
||
378 | $temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata']; |
||
379 | $temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao']; |
||
380 | $temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude']; |
||
381 | $temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude']; |
||
382 | $temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude']; |
||
383 | } |
||
384 | /* |
||
385 | if (isset($row['arrival_airport_time'])) { |
||
386 | $temp_array['arrival_airport_time'] = $row['arrival_airport_time']; |
||
387 | } |
||
388 | */ |
||
389 | if (isset($row['pilot_id']) && $row['pilot_id'] != '') $temp_array['pilot_id'] = $row['pilot_id']; |
||
390 | if (isset($row['pilot_name']) && $row['pilot_name'] != '') $temp_array['pilot_name'] = $row['pilot_name']; |
||
391 | if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; |
||
392 | if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; |
||
393 | if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
||
394 | if (isset($row['squawk'])) { |
||
395 | $temp_array['squawk'] = $row['squawk']; |
||
396 | if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) { |
||
397 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['country_iso2']); |
||
398 | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
399 | } elseif ($row['squawk'] != '' && isset($temp_array['over_country'])) { |
||
400 | $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['over_country']); |
||
401 | if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
402 | } elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry); |
||
403 | } |
||
404 | |||
405 | $temp_array['query_number_rows'] = $num_rows; |
||
406 | |||
407 | $spotter_array[] = $temp_array; |
||
408 | } |
||
409 | if ($num_rows == 0) return array(); |
||
410 | $spotter_array[0]['query_number_rows'] = $num_rows; |
||
411 | return $spotter_array; |
||
412 | } |
||
413 | |||
414 | |||
415 | /** |
||
416 | * Gets all the spotter information |
||
417 | * |
||
418 | * @return Array the spotter information |
||
419 | * |
||
420 | */ |
||
421 | 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 = '',$filter = array()) |
||
422 | { |
||
423 | global $globalTimezone, $globalDBdriver; |
||
424 | require_once(dirname(__FILE__).'/class.Translation.php'); |
||
425 | $Translation = new Translation(); |
||
426 | |||
427 | date_default_timezone_set('UTC'); |
||
428 | |||
429 | $query_values = array(); |
||
430 | $additional_query = ''; |
||
431 | $filter_query = $this->getFilter($filter,true,true); |
||
432 | if ($q != "") |
||
433 | { |
||
434 | if (!is_string($q)) |
||
435 | { |
||
436 | return false; |
||
437 | } else { |
||
438 | $q_array = explode(" ", $q); |
||
439 | foreach ($q_array as $q_item){ |
||
440 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
441 | $additional_query .= " AND ("; |
||
442 | if (is_int($q_item)) $additional_query .= "(spotter_output.spotter_id like '%".$q_item."%') OR "; |
||
443 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
444 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
445 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
446 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
447 | $additional_query .= "(spotter_output.airline_name like '%".$q_item."%') OR "; |
||
448 | $additional_query .= "(spotter_output.airline_country like '%".$q_item."%') OR "; |
||
449 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
450 | $additional_query .= "(spotter_output.departure_airport_name like '%".$q_item."%') OR "; |
||
451 | $additional_query .= "(spotter_output.departure_airport_city like '%".$q_item."%') OR "; |
||
452 | $additional_query .= "(spotter_output.departure_airport_country like '%".$q_item."%') OR "; |
||
453 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
454 | $additional_query .= "(spotter_output.arrival_airport_name like '%".$q_item."%') OR "; |
||
455 | $additional_query .= "(spotter_output.arrival_airport_city like '%".$q_item."%') OR "; |
||
456 | $additional_query .= "(spotter_output.arrival_airport_country like '%".$q_item."%') OR "; |
||
457 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
458 | $additional_query .= "(spotter_output.owner_name like '%".$q_item."%') OR "; |
||
459 | $additional_query .= "(spotter_output.pilot_id like '%".$q_item."%') OR "; |
||
460 | $additional_query .= "(spotter_output.pilot_name like '%".$q_item."%') OR "; |
||
461 | $additional_query .= "(spotter_output.ident like '%".$q_item."%') OR "; |
||
462 | $translate = $Translation->ident2icao($q_item); |
||
463 | if ($translate != $q_item) $additional_query .= "(spotter_output.ident like '%".$translate."%') OR "; |
||
464 | $additional_query .= "(spotter_output.highlight like '%".$q_item."%')"; |
||
465 | $additional_query .= ")"; |
||
466 | } |
||
467 | } |
||
468 | } |
||
469 | |||
470 | if ($registration != "") |
||
471 | { |
||
472 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
473 | if (!is_string($registration)) |
||
474 | { |
||
475 | return false; |
||
476 | } else { |
||
477 | $additional_query .= " AND spotter_output.registration = :registration"; |
||
478 | $query_values = array_merge($query_values,array(':registration' => $registration)); |
||
479 | } |
||
480 | } |
||
481 | |||
482 | if ($aircraft_icao != "") |
||
483 | { |
||
484 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
485 | if (!is_string($aircraft_icao)) |
||
486 | { |
||
487 | return false; |
||
488 | } else { |
||
489 | $additional_query .= " AND spotter_output.aircraft_icao = :aircraft_icao"; |
||
490 | $query_values = array_merge($query_values,array(':aircraft_icao' => $aircraft_icao)); |
||
491 | } |
||
492 | } |
||
493 | |||
494 | if ($aircraft_manufacturer != "") |
||
495 | { |
||
496 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
497 | if (!is_string($aircraft_manufacturer)) |
||
498 | { |
||
499 | return false; |
||
500 | } else { |
||
501 | $additional_query .= " AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer"; |
||
502 | $query_values = array_merge($query_values,array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
503 | } |
||
504 | } |
||
505 | |||
506 | if ($highlights == "true") |
||
507 | { |
||
508 | if (!is_string($highlights)) |
||
509 | { |
||
510 | return false; |
||
511 | } else { |
||
512 | $additional_query .= " AND (spotter_output.highlight <> '')"; |
||
513 | } |
||
514 | } |
||
515 | |||
516 | if ($airline_icao != "") |
||
517 | { |
||
518 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
||
519 | if (!is_string($airline_icao)) |
||
520 | { |
||
521 | return false; |
||
522 | } else { |
||
523 | $additional_query .= " AND spotter_output.airline_icao = :airline_icao"; |
||
524 | $query_values = array_merge($query_values,array(':airline_icao' => $airline_icao)); |
||
525 | } |
||
526 | } |
||
527 | |||
528 | if ($airline_country != "") |
||
529 | { |
||
530 | $airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING); |
||
531 | if (!is_string($airline_country)) |
||
532 | { |
||
533 | return false; |
||
534 | } else { |
||
535 | $additional_query .= " AND spotter_output.airline_country = :airline_country"; |
||
536 | $query_values = array_merge($query_values,array(':airline_country' => $airline_country)); |
||
537 | } |
||
538 | } |
||
539 | |||
540 | if ($airline_type != "") |
||
541 | { |
||
542 | if (!is_string($airline_type)) |
||
543 | { |
||
544 | return false; |
||
545 | } else { |
||
546 | if ($airline_type == "passenger") |
||
547 | { |
||
548 | $additional_query .= " AND (spotter_output.airline_type = 'passenger')"; |
||
549 | } |
||
550 | if ($airline_type == "cargo") |
||
551 | { |
||
552 | $additional_query .= " AND (spotter_output.airline_type = 'cargo')"; |
||
553 | } |
||
554 | if ($airline_type == "military") |
||
555 | { |
||
556 | $additional_query .= " AND (spotter_output.airline_type = 'military')"; |
||
557 | } |
||
558 | } |
||
559 | } |
||
560 | |||
561 | if ($airport != "") |
||
562 | { |
||
563 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
564 | if (!is_string($airport)) |
||
565 | { |
||
566 | return false; |
||
567 | } else { |
||
568 | $additional_query .= " AND (spotter_output.departure_airport_icao = :airport OR spotter_output.arrival_airport_icao = :airport)"; |
||
569 | $query_values = array_merge($query_values,array(':airport' => $airport)); |
||
570 | } |
||
571 | } |
||
572 | |||
573 | if ($airport_country != "") |
||
574 | { |
||
575 | $airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING); |
||
576 | if (!is_string($airport_country)) |
||
577 | { |
||
578 | return false; |
||
579 | } else { |
||
580 | $additional_query .= " AND (spotter_output.departure_airport_country = :airport_country OR spotter_output.arrival_airport_country = :airport_country)"; |
||
581 | $query_values = array_merge($query_values,array(':airport_country' => $airport_country)); |
||
582 | } |
||
583 | } |
||
584 | |||
585 | if ($callsign != "") |
||
586 | { |
||
587 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
588 | if (!is_string($callsign)) |
||
589 | { |
||
590 | return false; |
||
591 | } else { |
||
592 | $translate = $Translation->ident2icao($callsign); |
||
593 | if ($translate != $callsign) { |
||
594 | $additional_query .= " AND (spotter_output.ident = :callsign OR spotter_output.ident = :translate)"; |
||
595 | $query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate)); |
||
596 | } else { |
||
597 | $additional_query .= " AND spotter_output.ident = :callsign"; |
||
598 | $query_values = array_merge($query_values,array(':callsign' => $callsign)); |
||
599 | } |
||
600 | } |
||
601 | } |
||
602 | |||
603 | if ($owner != "") |
||
604 | { |
||
605 | $owner = filter_var($owner,FILTER_SANITIZE_STRING); |
||
606 | if (!is_string($owner)) |
||
607 | { |
||
608 | return false; |
||
609 | } else { |
||
610 | $additional_query .= " AND spotter_output.owner_name = :owner"; |
||
611 | $query_values = array_merge($query_values,array(':owner' => $owner)); |
||
612 | } |
||
613 | } |
||
614 | |||
615 | if ($pilot_name != "") |
||
616 | { |
||
617 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
618 | if (!is_string($pilot_name)) |
||
619 | { |
||
620 | return false; |
||
621 | } else { |
||
622 | $additional_query .= " AND spotter_output.pilot_name = :pilot_name"; |
||
623 | $query_values = array_merge($query_values,array(':pilot_name' => $pilot_name)); |
||
624 | } |
||
625 | } |
||
626 | |||
627 | if ($pilot_id != "") |
||
628 | { |
||
629 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT); |
||
630 | if (!is_string($pilot_id)) |
||
631 | { |
||
632 | return false; |
||
633 | } else { |
||
634 | $additional_query .= " AND spotter_output.pilot_id = :pilot_id"; |
||
635 | $query_values = array_merge($query_values,array(':pilot_id' => $pilot_id)); |
||
636 | } |
||
637 | } |
||
638 | |||
639 | if ($departure_airport_route != "") |
||
640 | { |
||
641 | $departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING); |
||
642 | if (!is_string($departure_airport_route)) |
||
643 | { |
||
644 | return false; |
||
645 | } else { |
||
646 | $additional_query .= " AND spotter_output.departure_airport_icao = :departure_airport_route"; |
||
647 | $query_values = array_merge($query_values,array(':departure_airport_route' => $departure_airport_route)); |
||
648 | } |
||
649 | } |
||
650 | |||
651 | if ($arrival_airport_route != "") |
||
652 | { |
||
653 | $arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING); |
||
654 | if (!is_string($arrival_airport_route)) |
||
655 | { |
||
656 | return false; |
||
657 | } else { |
||
658 | $additional_query .= " AND spotter_output.arrival_airport_icao = :arrival_airport_route"; |
||
659 | $query_values = array_merge($query_values,array(':arrival_airport_route' => $arrival_airport_route)); |
||
660 | } |
||
661 | } |
||
662 | |||
663 | if ($altitude != "") |
||
664 | { |
||
665 | $altitude_array = explode(",", $altitude); |
||
666 | $altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
667 | $altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
668 | |||
669 | if ($altitude_array[1] != "") |
||
670 | { |
||
671 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
672 | $altitude_array[1] = substr($altitude_array[1], 0, -2); |
||
673 | $additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' "; |
||
674 | } else { |
||
675 | $altitude_array[0] = substr($altitude_array[0], 0, -2); |
||
676 | $additional_query .= " AND altitude <= '".$altitude_array[0]."' "; |
||
677 | } |
||
678 | } |
||
679 | |||
680 | if ($date_posted != "") |
||
681 | { |
||
682 | $date_array = explode(",", $date_posted); |
||
683 | $date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); |
||
684 | $date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); |
||
685 | |||
686 | if ($globalTimezone != '') { |
||
687 | date_default_timezone_set($globalTimezone); |
||
688 | $datetime = new DateTime(); |
||
689 | $offset = $datetime->format('P'); |
||
690 | } else $offset = '+00:00'; |
||
691 | |||
692 | if ($date_array[1] != "") |
||
693 | { |
||
694 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
695 | $date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
||
696 | if ($globalDBdriver == 'mysql') { |
||
697 | $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]."' "; |
||
698 | } else { |
||
699 | $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]."' "; |
||
700 | } |
||
701 | } else { |
||
702 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
||
703 | if ($globalDBdriver == 'mysql') { |
||
704 | $additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; |
||
705 | } else { |
||
706 | $additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' "; |
||
707 | } |
||
708 | } |
||
709 | } |
||
710 | |||
711 | if ($limit != "") |
||
712 | { |
||
713 | $limit_array = explode(",", $limit); |
||
714 | |||
715 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
716 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
717 | |||
718 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
719 | { |
||
720 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
721 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
722 | } else $limit_query = ""; |
||
723 | } else $limit_query = ""; |
||
724 | |||
725 | |||
726 | if ($sort != "") |
||
727 | { |
||
728 | $search_orderby_array = $this->getOrderBy(); |
||
729 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
730 | } else { |
||
731 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
732 | $orderby_query = " ORDER BY distance ASC"; |
||
733 | } else { |
||
734 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
735 | } |
||
736 | } |
||
737 | |||
738 | if ($includegeodata == "true") |
||
739 | { |
||
740 | $additional_query .= " AND spotter_output.waypoints <> ''"; |
||
741 | } |
||
742 | |||
743 | |||
744 | if ($origLat != "" && $origLon != "" && $dist != "") { |
||
745 | $dist = number_format($dist*0.621371,2,'.',''); // convert km to mile |
||
746 | |||
747 | if ($globalDBdriver == 'mysql') { |
||
748 | $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 |
||
749 | FROM spotter_output, spotter_archive".$filter_query." spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND spotter_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and spotter_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
750 | 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; |
||
751 | } else { |
||
752 | $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 |
||
753 | FROM spotter_output, spotter_archive".$filter_query." spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
||
754 | AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(spotter_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(spotter_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query.$orderby_query; |
||
755 | } |
||
756 | } else { |
||
757 | $query = "SELECT spotter_output.* FROM spotter_output ".$filter_query." spotter_output.ident <> '' |
||
758 | ".$additional_query." |
||
759 | ".$orderby_query; |
||
760 | } |
||
761 | $spotter_array = $this->getDataFromDB($query, $query_values,$limit_query); |
||
762 | return $spotter_array; |
||
763 | } |
||
764 | |||
765 | |||
766 | /** |
||
767 | * Gets all the spotter information based on the latest data entry |
||
768 | * |
||
769 | * @return Array the spotter information |
||
770 | * |
||
771 | */ |
||
772 | public function getLatestSpotterData($limit = '', $sort = '', $filter = array()) |
||
773 | { |
||
774 | global $global_query; |
||
775 | |||
776 | date_default_timezone_set('UTC'); |
||
777 | |||
778 | $filter_query = $this->getFilter($filter); |
||
779 | |||
780 | if ($limit != "") |
||
781 | { |
||
782 | $limit_array = explode(",", $limit); |
||
783 | |||
784 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
785 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
786 | |||
787 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
788 | { |
||
789 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
790 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
791 | } else $limit_query = ""; |
||
792 | } else $limit_query = ""; |
||
793 | |||
794 | if ($sort != "") |
||
795 | { |
||
796 | $search_orderby_array = $this->getOrderBy(); |
||
797 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
798 | } else { |
||
799 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
800 | } |
||
801 | |||
802 | $query = $global_query.$filter_query." ".$orderby_query; |
||
803 | |||
804 | $spotter_array = $this->getDataFromDB($query, array(),$limit_query); |
||
805 | |||
806 | return $spotter_array; |
||
807 | } |
||
808 | |||
809 | |||
810 | /** |
||
811 | * Gets all the spotter information based on a user's latitude and longitude |
||
812 | * |
||
813 | * @return Array the spotter information |
||
814 | * |
||
815 | */ |
||
816 | public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
||
817 | { |
||
818 | date_default_timezone_set('UTC'); |
||
819 | $limit_query = ''; |
||
820 | if ($lat != "") |
||
821 | { |
||
822 | if (!is_numeric($lat)) |
||
823 | { |
||
824 | return false; |
||
825 | } |
||
826 | } |
||
827 | |||
828 | if ($lng != "") |
||
829 | { |
||
830 | if (!is_numeric($lng)) |
||
831 | { |
||
832 | return false; |
||
833 | } |
||
834 | } |
||
835 | |||
836 | if ($radius != "") |
||
837 | { |
||
838 | if (!is_numeric($radius)) |
||
839 | { |
||
840 | return false; |
||
841 | } |
||
842 | } |
||
843 | $additional_query = ''; |
||
844 | if ($interval != "") |
||
845 | { |
||
846 | if (!is_string($interval)) |
||
847 | { |
||
848 | return false; |
||
849 | } else { |
||
850 | if ($interval == "30m"){ |
||
851 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) <= $this_output.date '; |
||
852 | } else if ($interval == "1h"){ |
||
853 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) <= $this_output.date '; |
||
854 | } else if ($interval == "3h"){ |
||
855 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 3 HOUR) <= $this_output.date '; |
||
856 | } else if ($interval == "6h"){ |
||
857 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 6 HOUR) <= $this_output.date '; |
||
858 | } else if ($interval == "12h"){ |
||
859 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 HOUR) <= $this_output.date '; |
||
860 | } else if ($interval == "24h"){ |
||
861 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) <= $this_output.date '; |
||
862 | } else if ($interval == "7d"){ |
||
863 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) <= $this_output.date '; |
||
864 | } else if ($interval == "30d"){ |
||
865 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 DAY) <= $this_output.date '; |
||
866 | } |
||
867 | } |
||
868 | } |
||
869 | |||
870 | $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 |
||
871 | WHERE spotter_output.latitude <> '' |
||
872 | AND spotter_output.longitude <> '' |
||
873 | ".$additional_query." |
||
874 | HAVING distance < :radius |
||
875 | ORDER BY distance"; |
||
876 | |||
877 | $spotter_array = $this->getDataFromDB($query, array(':radius' => $radius),$limit_query); |
||
878 | |||
879 | return $spotter_array; |
||
880 | } |
||
881 | |||
882 | |||
883 | /** |
||
884 | * Gets all the spotter information sorted by the newest aircraft type |
||
885 | * |
||
886 | * @return Array the spotter information |
||
887 | * |
||
888 | */ |
||
889 | public function getNewestSpotterDataSortedByAircraftType($limit = '', $sort = '',$filter = array()) |
||
890 | { |
||
891 | global $global_query; |
||
892 | |||
893 | date_default_timezone_set('UTC'); |
||
894 | |||
895 | $filter_query = $this->getFilter($filter,true,true); |
||
896 | |||
897 | $limit_query = ''; |
||
898 | if ($limit != "") |
||
899 | { |
||
900 | $limit_array = explode(",", $limit); |
||
901 | |||
902 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
903 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
904 | |||
905 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
906 | { |
||
907 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
908 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
909 | } |
||
910 | } |
||
911 | |||
912 | if ($sort != "") |
||
913 | { |
||
914 | $search_orderby_array = $this->getOrderBy(); |
||
915 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
916 | } else { |
||
917 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
918 | } |
||
919 | |||
920 | $query = $global_query." ".$filter_query." spotter_output.aircraft_name <> '' GROUP BY spotter_output.aircraft_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
921 | |||
922 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
923 | |||
924 | return $spotter_array; |
||
925 | } |
||
926 | |||
927 | |||
928 | /** |
||
929 | * Gets all the spotter information sorted by the newest aircraft registration |
||
930 | * |
||
931 | * @return Array the spotter information |
||
932 | * |
||
933 | */ |
||
934 | public function getNewestSpotterDataSortedByAircraftRegistration($limit = '', $sort = '', $filter = array()) |
||
935 | { |
||
936 | global $global_query; |
||
937 | |||
938 | date_default_timezone_set('UTC'); |
||
939 | $filter_query = $this->getFilter($filter,true,true); |
||
940 | |||
941 | $limit_query = ''; |
||
942 | if ($limit != "") |
||
943 | { |
||
944 | $limit_array = explode(",", $limit); |
||
945 | |||
946 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
947 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
948 | |||
949 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
950 | { |
||
951 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
952 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
953 | } |
||
954 | } |
||
955 | |||
956 | if ($sort != "") |
||
957 | { |
||
958 | $search_orderby_array = $this->getOrderBy(); |
||
959 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
960 | } else { |
||
961 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
962 | } |
||
963 | |||
964 | $query = $global_query." ".$filter_query." spotter_output.registration <> '' GROUP BY spotter_output.registration,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
965 | |||
966 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
967 | |||
968 | return $spotter_array; |
||
969 | } |
||
970 | |||
971 | |||
972 | /** |
||
973 | * Gets all the spotter information sorted by the newest airline |
||
974 | * |
||
975 | * @return Array the spotter information |
||
976 | * |
||
977 | */ |
||
978 | public function getNewestSpotterDataSortedByAirline($limit = '', $sort = '',$filter = array()) |
||
979 | { |
||
980 | global $global_query; |
||
981 | |||
982 | date_default_timezone_set('UTC'); |
||
983 | $filter_query = $this->getFilter($filter,true,true); |
||
984 | |||
985 | $limit_query = ''; |
||
986 | if ($limit != "") |
||
987 | { |
||
988 | $limit_array = explode(",", $limit); |
||
989 | |||
990 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
991 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
992 | |||
993 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
994 | { |
||
995 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
996 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
997 | } |
||
998 | } |
||
999 | |||
1000 | if ($sort != "") |
||
1001 | { |
||
1002 | $search_orderby_array = $this->getOrderBy(); |
||
1003 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1004 | } else { |
||
1005 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
1006 | } |
||
1007 | |||
1008 | $query = $global_query." ".$filter_query." spotter_output.airline_name <> '' GROUP BY spotter_output.airline_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query; |
||
1009 | |||
1010 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
1011 | |||
1012 | return $spotter_array; |
||
1013 | } |
||
1014 | |||
1015 | |||
1016 | /** |
||
1017 | * Gets all the spotter information sorted by the newest departure airport |
||
1018 | * |
||
1019 | * @return Array the spotter information |
||
1020 | * |
||
1021 | */ |
||
1022 | public function getNewestSpotterDataSortedByDepartureAirport($limit = '', $sort = '', $filter = array()) |
||
1023 | { |
||
1024 | global $global_query; |
||
1025 | |||
1026 | date_default_timezone_set('UTC'); |
||
1027 | |||
1028 | $filter_query = $this->getFilter($filter,true,true); |
||
1029 | |||
1030 | $limit_query = ''; |
||
1031 | |||
1032 | if ($limit != "") |
||
1033 | { |
||
1034 | $limit_array = explode(",", $limit); |
||
1035 | |||
1036 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1037 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1038 | |||
1039 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1040 | { |
||
1041 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1042 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1043 | } |
||
1044 | } |
||
1045 | |||
1046 | if ($sort != "") |
||
1047 | { |
||
1048 | $search_orderby_array = $this->getOrderBy(); |
||
1049 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1050 | } else { |
||
1051 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
1052 | } |
||
1053 | |||
1054 | $query = $global_query." ".$filter_query." spotter_output.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; |
||
1055 | |||
1056 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
1057 | |||
1058 | return $spotter_array; |
||
1059 | } |
||
1060 | |||
1061 | |||
1062 | /** |
||
1063 | * Gets all the spotter information sorted by the newest arrival airport |
||
1064 | * |
||
1065 | * @return Array the spotter information |
||
1066 | * |
||
1067 | */ |
||
1068 | public function getNewestSpotterDataSortedByArrivalAirport($limit = '', $sort = '', $filter = array()) |
||
1069 | { |
||
1070 | global $global_query; |
||
1071 | |||
1072 | date_default_timezone_set('UTC'); |
||
1073 | $filter_query = $this->getFilter($filter,true,true); |
||
1074 | $limit_query = ''; |
||
1075 | if ($limit != "") |
||
1076 | { |
||
1077 | $limit_array = explode(",", $limit); |
||
1078 | |||
1079 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1080 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1081 | |||
1082 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1083 | { |
||
1084 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1085 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1086 | } |
||
1087 | } |
||
1088 | |||
1089 | if ($sort != "") |
||
1090 | { |
||
1091 | $search_orderby_array = $this->getOrderBy(); |
||
1092 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1093 | } else { |
||
1094 | $orderby_query = " ORDER BY spotter_output.date DESC "; |
||
1095 | } |
||
1096 | |||
1097 | $query = $global_query.$filter_query." 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; |
||
1098 | |||
1099 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
1100 | |||
1101 | return $spotter_array; |
||
1102 | } |
||
1103 | |||
1104 | |||
1105 | /** |
||
1106 | * Gets all the spotter information based on the spotter id |
||
1107 | * |
||
1108 | * @return Array the spotter information |
||
1109 | * |
||
1110 | */ |
||
1111 | public function getSpotterDataByID($id = '') |
||
1112 | { |
||
1113 | global $global_query; |
||
1114 | |||
1115 | date_default_timezone_set('UTC'); |
||
1116 | if ($id == '') return array(); |
||
1117 | $additional_query = "spotter_output.spotter_id = :id"; |
||
1118 | $query_values = array(':id' => $id); |
||
1119 | |||
1120 | //$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." "; |
||
1121 | $query = $global_query." WHERE ".$additional_query." "; |
||
1122 | |||
1123 | $spotter_array = $this->getDataFromDB($query,$query_values); |
||
1124 | |||
1125 | return $spotter_array; |
||
1126 | } |
||
1127 | |||
1128 | |||
1129 | |||
1130 | |||
1131 | /** |
||
1132 | * Gets all the spotter information based on the callsign |
||
1133 | * |
||
1134 | * @return Array the spotter information |
||
1135 | * |
||
1136 | */ |
||
1137 | public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') |
||
1138 | { |
||
1139 | global $global_query; |
||
1140 | |||
1141 | date_default_timezone_set('UTC'); |
||
1142 | |||
1143 | $query_values = array(); |
||
1144 | $limit_query = ''; |
||
1145 | $additional_query = ''; |
||
1146 | if ($ident != "") |
||
1147 | { |
||
1148 | if (!is_string($ident)) |
||
1149 | { |
||
1150 | return false; |
||
1151 | } else { |
||
1152 | $additional_query = " AND (spotter_output.ident = :ident)"; |
||
1153 | $query_values = array(':ident' => $ident); |
||
1154 | } |
||
1155 | } |
||
1156 | |||
1157 | if ($limit != "") |
||
1158 | { |
||
1159 | $limit_array = explode(",", $limit); |
||
1160 | |||
1161 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1162 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1163 | |||
1164 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1165 | { |
||
1166 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1167 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1168 | } |
||
1169 | } |
||
1170 | |||
1171 | if ($sort != "") |
||
1172 | { |
||
1173 | $search_orderby_array = $this->getOrderBy(); |
||
1174 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1175 | } else { |
||
1176 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1177 | } |
||
1178 | |||
1179 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1180 | |||
1181 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1182 | |||
1183 | return $spotter_array; |
||
1184 | } |
||
1185 | |||
1186 | |||
1187 | |||
1188 | /** |
||
1189 | * Gets all the spotter information based on the aircraft type |
||
1190 | * |
||
1191 | * @return Array the spotter information |
||
1192 | * |
||
1193 | */ |
||
1194 | public function getSpotterDataByAircraft($aircraft_type = '', $limit = '', $sort = '', $filter = array()) |
||
1195 | { |
||
1196 | global $global_query; |
||
1197 | |||
1198 | date_default_timezone_set('UTC'); |
||
1199 | |||
1200 | $query_values = array(); |
||
1201 | $limit_query = ''; |
||
1202 | $additional_query = ''; |
||
1203 | $filter_query = $this->getFilter($filter,true,true); |
||
1204 | |||
1205 | if ($aircraft_type != "") |
||
1206 | { |
||
1207 | if (!is_string($aircraft_type)) |
||
1208 | { |
||
1209 | return false; |
||
1210 | } else { |
||
1211 | $additional_query = " AND (spotter_output.aircraft_icao = :aircraft_type)"; |
||
1212 | $query_values = array(':aircraft_type' => $aircraft_type); |
||
1213 | } |
||
1214 | } |
||
1215 | |||
1216 | if ($limit != "") |
||
1217 | { |
||
1218 | $limit_array = explode(",", $limit); |
||
1219 | |||
1220 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1221 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1222 | |||
1223 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1224 | { |
||
1225 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1226 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1227 | } |
||
1228 | } |
||
1229 | |||
1230 | if ($sort != "") |
||
1231 | { |
||
1232 | $search_orderby_array = $this->getOrderBy(); |
||
1233 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1234 | } else { |
||
1235 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1236 | } |
||
1237 | |||
1238 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1239 | |||
1240 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1241 | |||
1242 | return $spotter_array; |
||
1243 | } |
||
1244 | |||
1245 | |||
1246 | /** |
||
1247 | * Gets all the spotter information based on the aircraft registration |
||
1248 | * |
||
1249 | * @return Array the spotter information |
||
1250 | * |
||
1251 | */ |
||
1252 | public function getSpotterDataByRegistration($registration = '', $limit = '', $sort = '', $filter = array()) |
||
1253 | { |
||
1254 | global $global_query; |
||
1255 | |||
1256 | date_default_timezone_set('UTC'); |
||
1257 | |||
1258 | $query_values = array(); |
||
1259 | $limit_query = ''; |
||
1260 | $additional_query = ''; |
||
1261 | $filter_query = $this->getFilter($filter,true,true); |
||
1262 | |||
1263 | if ($registration != "") |
||
1264 | { |
||
1265 | if (!is_string($registration)) |
||
1266 | { |
||
1267 | return false; |
||
1268 | } else { |
||
1269 | $additional_query = " AND (spotter_output.registration = :registration)"; |
||
1270 | $query_values = array(':registration' => $registration); |
||
1271 | } |
||
1272 | } |
||
1273 | |||
1274 | if ($limit != "") |
||
1275 | { |
||
1276 | $limit_array = explode(",", $limit); |
||
1277 | |||
1278 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1279 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1280 | |||
1281 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1282 | { |
||
1283 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1284 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1285 | } |
||
1286 | } |
||
1287 | |||
1288 | if ($sort != "") |
||
1289 | { |
||
1290 | $search_orderby_array = $this->getOrderBy(); |
||
1291 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1292 | } else { |
||
1293 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1294 | } |
||
1295 | |||
1296 | $query = $global_query.$filter_query." spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1297 | |||
1298 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1299 | |||
1300 | return $spotter_array; |
||
1301 | } |
||
1302 | |||
1303 | |||
1304 | |||
1305 | |||
1306 | /** |
||
1307 | * Gets all the spotter information based on the airline |
||
1308 | * |
||
1309 | * @return Array the spotter information |
||
1310 | * |
||
1311 | */ |
||
1312 | public function getSpotterDataByAirline($airline = '', $limit = '', $sort = '') |
||
1313 | { |
||
1314 | global $global_query; |
||
1315 | |||
1316 | date_default_timezone_set('UTC'); |
||
1317 | |||
1318 | $query_values = array(); |
||
1319 | $limit_query = ''; |
||
1320 | $additional_query = ''; |
||
1321 | |||
1322 | if ($airline != "") |
||
1323 | { |
||
1324 | if (!is_string($airline)) |
||
1325 | { |
||
1326 | return false; |
||
1327 | } else { |
||
1328 | $additional_query = " AND (spotter_output.airline_icao = :airline)"; |
||
1329 | $query_values = array(':airline' => $airline); |
||
1330 | } |
||
1331 | } |
||
1332 | |||
1333 | if ($limit != "") |
||
1334 | { |
||
1335 | $limit_array = explode(",", $limit); |
||
1336 | |||
1337 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1338 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1339 | |||
1340 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1341 | { |
||
1342 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1343 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1344 | } |
||
1345 | } |
||
1346 | |||
1347 | if ($sort != "") |
||
1348 | { |
||
1349 | $search_orderby_array = $this->getOrderBy(); |
||
1350 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1351 | } else { |
||
1352 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1353 | } |
||
1354 | |||
1355 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1356 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1357 | |||
1358 | return $spotter_array; |
||
1359 | } |
||
1360 | |||
1361 | |||
1362 | /** |
||
1363 | * Gets all the spotter information based on the airport |
||
1364 | * |
||
1365 | * @return Array the spotter information |
||
1366 | * |
||
1367 | */ |
||
1368 | public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '') |
||
1369 | { |
||
1370 | global $global_query; |
||
1371 | |||
1372 | date_default_timezone_set('UTC'); |
||
1373 | $query_values = array(); |
||
1374 | $limit_query = ''; |
||
1375 | $additional_query = ''; |
||
1376 | |||
1377 | if ($airport != "") |
||
1378 | { |
||
1379 | if (!is_string($airport)) |
||
1380 | { |
||
1381 | return false; |
||
1382 | } else { |
||
1383 | $additional_query .= " AND ((spotter_output.departure_airport_icao = :airport) OR (spotter_output.arrival_airport_icao = :airport))"; |
||
1384 | $query_values = array(':airport' => $airport); |
||
1385 | } |
||
1386 | } |
||
1387 | |||
1388 | if ($limit != "") |
||
1389 | { |
||
1390 | $limit_array = explode(",", $limit); |
||
1391 | |||
1392 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1393 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1394 | |||
1395 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1396 | { |
||
1397 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1398 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1399 | } |
||
1400 | } |
||
1401 | |||
1402 | if ($sort != "") |
||
1403 | { |
||
1404 | $search_orderby_array = $this->getOrderBy(); |
||
1405 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1406 | } else { |
||
1407 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1408 | } |
||
1409 | |||
1410 | $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; |
||
1411 | |||
1412 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1413 | |||
1414 | return $spotter_array; |
||
1415 | } |
||
1416 | |||
1417 | |||
1418 | |||
1419 | /** |
||
1420 | * Gets all the spotter information based on the date |
||
1421 | * |
||
1422 | * @return Array the spotter information |
||
1423 | * |
||
1424 | */ |
||
1425 | public function getSpotterDataByDate($date = '', $limit = '', $sort = '',$filter = array()) |
||
1426 | { |
||
1427 | global $global_query, $globalTimezone, $globalDBdriver; |
||
1428 | |||
1429 | $query_values = array(); |
||
1430 | $limit_query = ''; |
||
1431 | $additional_query = ''; |
||
1432 | |||
1433 | $filter_query = ''; |
||
1434 | if (isset($filter['source']) && !empty($filter['source'])) { |
||
1435 | $filter_query = " AND format_source IN ('".implode("','",$filter['source'])."')"; |
||
1436 | } |
||
1437 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
||
1438 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
||
1439 | } |
||
1440 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
||
1441 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
||
1442 | } |
||
1443 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
||
1444 | $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
1445 | } |
||
1446 | if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
||
1447 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
||
1448 | } |
||
1449 | |||
1450 | |||
1451 | if ($date != "") |
||
1452 | { |
||
1453 | if ($globalTimezone != '') { |
||
1454 | date_default_timezone_set($globalTimezone); |
||
1455 | $datetime = new DateTime($date); |
||
1456 | $offset = $datetime->format('P'); |
||
1457 | } else { |
||
1458 | date_default_timezone_set('UTC'); |
||
1459 | $datetime = new DateTime($date); |
||
1460 | $offset = '+00:00'; |
||
1461 | } |
||
1462 | if ($globalDBdriver == 'mysql') { |
||
1463 | $additional_query = " AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date "; |
||
1464 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset); |
||
1465 | } elseif ($globalDBdriver == 'pgsql') { |
||
1466 | $additional_query = " AND to_char(spotter_output.date AT TIME ZONE :timezone,'YYYY-mm-dd') = :date "; |
||
1467 | $query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone); |
||
1468 | } |
||
1469 | } |
||
1470 | |||
1471 | if ($limit != "") |
||
1472 | { |
||
1473 | $limit_array = explode(",", $limit); |
||
1474 | |||
1475 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1476 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1477 | |||
1478 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1479 | { |
||
1480 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1481 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1482 | } |
||
1483 | } |
||
1484 | |||
1485 | if ($sort != "") |
||
1486 | { |
||
1487 | $search_orderby_array = $this->getOrderBy(); |
||
1488 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1489 | } else { |
||
1490 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1491 | } |
||
1492 | |||
1493 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query.$filter_query." ".$orderby_query; |
||
1494 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1495 | return $spotter_array; |
||
1496 | } |
||
1497 | |||
1498 | |||
1499 | |||
1500 | /** |
||
1501 | * Gets all the spotter information based on the country name |
||
1502 | * |
||
1503 | * @return Array the spotter information |
||
1504 | * |
||
1505 | */ |
||
1506 | public function getSpotterDataByCountry($country = '', $limit = '', $sort = '') |
||
1507 | { |
||
1508 | global $global_query; |
||
1509 | |||
1510 | date_default_timezone_set('UTC'); |
||
1511 | |||
1512 | $query_values = array(); |
||
1513 | $limit_query = ''; |
||
1514 | $additional_query = ''; |
||
1515 | if ($country != "") |
||
1516 | { |
||
1517 | if (!is_string($country)) |
||
1518 | { |
||
1519 | return false; |
||
1520 | } else { |
||
1521 | $additional_query .= " AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country))"; |
||
1522 | $additional_query .= " OR spotter_output.airline_country = :country"; |
||
1523 | $query_values = array(':country' => $country); |
||
1524 | } |
||
1525 | } |
||
1526 | |||
1527 | if ($limit != "") |
||
1528 | { |
||
1529 | $limit_array = explode(",", $limit); |
||
1530 | |||
1531 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1532 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1533 | |||
1534 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1535 | { |
||
1536 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1537 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1538 | } |
||
1539 | } |
||
1540 | |||
1541 | if ($sort != "") |
||
1542 | { |
||
1543 | $search_orderby_array = $this->getOrderBy(); |
||
1544 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1545 | } else { |
||
1546 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1547 | } |
||
1548 | |||
1549 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1550 | |||
1551 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1552 | |||
1553 | return $spotter_array; |
||
1554 | } |
||
1555 | |||
1556 | |||
1557 | /** |
||
1558 | * Gets all the spotter information based on the manufacturer name |
||
1559 | * |
||
1560 | * @return Array the spotter information |
||
1561 | * |
||
1562 | */ |
||
1563 | public function getSpotterDataByManufacturer($aircraft_manufacturer = '', $limit = '', $sort = '') |
||
1564 | { |
||
1565 | global $global_query; |
||
1566 | |||
1567 | date_default_timezone_set('UTC'); |
||
1568 | |||
1569 | $query_values = array(); |
||
1570 | $additional_query = ''; |
||
1571 | $limit_query = ''; |
||
1572 | |||
1573 | if ($aircraft_manufacturer != "") |
||
1574 | { |
||
1575 | if (!is_string($aircraft_manufacturer)) |
||
1576 | { |
||
1577 | return false; |
||
1578 | } else { |
||
1579 | $additional_query .= " AND (spotter_output.aircraft_manufacturer = :aircraft_manufacturer)"; |
||
1580 | $query_values = array(':aircraft_manufacturer' => $aircraft_manufacturer); |
||
1581 | } |
||
1582 | } |
||
1583 | |||
1584 | if ($limit != "") |
||
1585 | { |
||
1586 | $limit_array = explode(",", $limit); |
||
1587 | |||
1588 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1589 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1590 | |||
1591 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1592 | { |
||
1593 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1594 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1595 | } |
||
1596 | } |
||
1597 | |||
1598 | if ($sort != "") |
||
1599 | { |
||
1600 | $search_orderby_array = $this->getOrderBy(); |
||
1601 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1602 | } else { |
||
1603 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1604 | } |
||
1605 | |||
1606 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1607 | |||
1608 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1609 | |||
1610 | return $spotter_array; |
||
1611 | } |
||
1612 | |||
1613 | |||
1614 | |||
1615 | |||
1616 | /** |
||
1617 | * Gets a list of all aircraft that take a route |
||
1618 | * |
||
1619 | * @param String $departure_airport_icao ICAO code of departure airport |
||
1620 | * @param String $arrival_airport_icao ICAO code of arrival airport |
||
1621 | * @return Array the spotter information |
||
1622 | * |
||
1623 | */ |
||
1624 | public function getSpotterDataByRoute($departure_airport_icao = '', $arrival_airport_icao = '', $limit = '', $sort = '') |
||
1625 | { |
||
1626 | global $global_query; |
||
1627 | |||
1628 | $query_values = array(); |
||
1629 | $additional_query = ''; |
||
1630 | $limit_query = ''; |
||
1631 | if ($departure_airport_icao != "") |
||
1632 | { |
||
1633 | if (!is_string($departure_airport_icao)) |
||
1634 | { |
||
1635 | return false; |
||
1636 | } else { |
||
1637 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
1638 | $additional_query .= " AND (spotter_output.departure_airport_icao = :departure_airport_icao)"; |
||
1639 | $query_values = array(':departure_airport_icao' => $departure_airport_icao); |
||
1640 | } |
||
1641 | } |
||
1642 | |||
1643 | if ($arrival_airport_icao != "") |
||
1644 | { |
||
1645 | if (!is_string($arrival_airport_icao)) |
||
1646 | { |
||
1647 | return false; |
||
1648 | } else { |
||
1649 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
1650 | $additional_query .= " AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)"; |
||
1651 | $query_values = array_merge($query_values,array(':arrival_airport_icao' => $arrival_airport_icao)); |
||
1652 | } |
||
1653 | } |
||
1654 | |||
1655 | if ($limit != "") |
||
1656 | { |
||
1657 | $limit_array = explode(",", $limit); |
||
1658 | |||
1659 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1660 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1661 | |||
1662 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1663 | { |
||
1664 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1665 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1666 | } |
||
1667 | } |
||
1668 | |||
1669 | if ($sort != "") |
||
1670 | { |
||
1671 | $search_orderby_array = $this->getOrderBy(); |
||
1672 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1673 | } else { |
||
1674 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1675 | } |
||
1676 | |||
1677 | $query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query; |
||
1678 | |||
1679 | //$result = mysqli_query($GLOBALS["___mysqli_ston"], $query); |
||
1680 | |||
1681 | $spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); |
||
1682 | |||
1683 | return $spotter_array; |
||
1684 | } |
||
1685 | |||
1686 | |||
1687 | |||
1688 | /** |
||
1689 | * Gets all the spotter information based on the special column in the table |
||
1690 | * |
||
1691 | * @return Array the spotter information |
||
1692 | * |
||
1693 | */ |
||
1694 | public function getSpotterDataByHighlight($limit = '', $sort = '', $filter = array()) |
||
1695 | { |
||
1696 | global $global_query; |
||
1697 | |||
1698 | date_default_timezone_set('UTC'); |
||
1699 | $filter_query = $this->getFilter($filter,true,true); |
||
1700 | $limit_query = ''; |
||
1701 | |||
1702 | if ($limit != "") |
||
1703 | { |
||
1704 | $limit_array = explode(",", $limit); |
||
1705 | |||
1706 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
1707 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
1708 | |||
1709 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
1710 | { |
||
1711 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
||
1712 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
1713 | } |
||
1714 | } |
||
1715 | |||
1716 | if ($sort != "") |
||
1717 | { |
||
1718 | $search_orderby_array = $this->getOrderBy(); |
||
1719 | $orderby_query = $search_orderby_array[$sort]['sql']; |
||
1720 | } else { |
||
1721 | $orderby_query = " ORDER BY spotter_output.date DESC"; |
||
1722 | } |
||
1723 | |||
1724 | $query = $global_query.$filter_query." spotter_output.highlight <> '' ".$orderby_query; |
||
1725 | |||
1726 | $spotter_array = $this->getDataFromDB($query, array(), $limit_query); |
||
1727 | |||
1728 | return $spotter_array; |
||
1729 | } |
||
1730 | |||
1731 | /** |
||
1732 | * Gets all the highlight based on a aircraft registration |
||
1733 | * |
||
1734 | * @return String the highlight text |
||
1735 | * |
||
1736 | */ |
||
1737 | public function getHighlightByRegistration($registration,$filter = array()) |
||
1738 | { |
||
1739 | global $global_query; |
||
1740 | |||
1741 | date_default_timezone_set('UTC'); |
||
1742 | $filter_query = $this->getFilter($filter,true,true); |
||
1743 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
1744 | |||
1745 | $query = $global_query.$filter_query." spotter_output.highlight <> '' AND spotter_output.registration = :registration"; |
||
1746 | $sth = $this->db->prepare($query); |
||
1747 | $sth->execute(array(':registration' => $registration)); |
||
1748 | |||
1749 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
1750 | { |
||
1751 | $highlight = $row['highlight']; |
||
1752 | } |
||
1753 | if (isset($highlight)) return $highlight; |
||
1754 | } |
||
1755 | |||
1756 | |||
1757 | /** |
||
1758 | * Gets the squawk usage from squawk code |
||
1759 | * |
||
1760 | * @param String $squawk squawk code |
||
1761 | * @param String $country country |
||
1762 | * @return String usage |
||
1763 | * |
||
1764 | */ |
||
1765 | public function getSquawkUsage($squawk = '',$country = 'FR') |
||
1766 | { |
||
1767 | |||
1768 | $squawk = filter_var($squawk,FILTER_SANITIZE_STRING); |
||
1769 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
1770 | |||
1771 | $query = "SELECT squawk.* FROM squawk WHERE squawk.code = :squawk AND squawk.country = :country LIMIT 1"; |
||
1772 | $query_values = array(':squawk' => ltrim($squawk,'0'), ':country' => $country); |
||
1773 | |||
1774 | $sth = $this->db->prepare($query); |
||
1775 | $sth->execute($query_values); |
||
1776 | |||
1777 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
1778 | $sth->closeCursor(); |
||
1779 | if (count($row) > 0) { |
||
1780 | return $row['usage']; |
||
1781 | } else return ''; |
||
1782 | } |
||
1783 | |||
1784 | /** |
||
1785 | * Gets the airport icao from the iata |
||
1786 | * |
||
1787 | * @param String $airport_iata the iata code of the airport |
||
1788 | * @return String airport iata |
||
1789 | * |
||
1790 | */ |
||
1791 | public function getAirportIcao($airport_iata = '') |
||
1792 | { |
||
1793 | |||
1794 | $airport_iata = filter_var($airport_iata,FILTER_SANITIZE_STRING); |
||
1795 | |||
1796 | $query = "SELECT airport.* FROM airport WHERE airport.iata = :airport LIMIT 1"; |
||
1797 | $query_values = array(':airport' => $airport_iata); |
||
1798 | |||
1799 | $sth = $this->db->prepare($query); |
||
1800 | $sth->execute($query_values); |
||
1801 | |||
1802 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
1803 | $sth->closeCursor(); |
||
1804 | if (count($row) > 0) { |
||
1805 | return $row['icao']; |
||
1806 | } else return ''; |
||
1807 | } |
||
1808 | |||
1809 | /** |
||
1810 | * Gets the airport distance |
||
1811 | * |
||
1812 | * @param String $airport_icao the icao code of the airport |
||
1813 | * @param Float $latitude the latitude |
||
1814 | * @param Float $longitude the longitude |
||
1815 | * @return Float distance to the airport |
||
1816 | * |
||
1817 | */ |
||
1818 | public function getAirportDistance($airport_icao,$latitude,$longitude) |
||
1819 | { |
||
1820 | |||
1821 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
1822 | |||
1823 | $query = "SELECT airport.latitude, airport.longitude FROM airport WHERE airport.icao = :airport LIMIT 1"; |
||
1824 | $query_values = array(':airport' => $airport_icao); |
||
1825 | $sth = $this->db->prepare($query); |
||
1826 | $sth->execute($query_values); |
||
1827 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
1828 | $sth->closeCursor(); |
||
1829 | if (count($row) > 0) { |
||
1830 | $airport_latitude = $row['latitude']; |
||
1831 | $airport_longitude = $row['longitude']; |
||
1832 | $Common = new Common(); |
||
1833 | return $Common->distance($latitude,$longitude,$airport_latitude,$airport_longitude); |
||
1834 | } else return ''; |
||
1835 | } |
||
1836 | |||
1837 | /** |
||
1838 | * Gets the airport info based on the icao |
||
1839 | * |
||
1840 | * @param String $airport the icao code of the airport |
||
1841 | * @return Array airport information |
||
1842 | * |
||
1843 | */ |
||
1844 | public function getAllAirportInfo($airport = '') |
||
1845 | { |
||
1846 | |||
1847 | $airport = filter_var($airport,FILTER_SANITIZE_STRING); |
||
1848 | |||
1849 | $query_values = array(); |
||
1850 | if ($airport == 'NA') { |
||
1851 | 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' => '')); |
||
1852 | } elseif ($airport == '') { |
||
1853 | $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"; |
||
1854 | } else { |
||
1855 | $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"; |
||
1856 | $query_values = array(':airport' => $airport); |
||
1857 | } |
||
1858 | |||
1859 | $sth = $this->db->prepare($query); |
||
1860 | $sth->execute($query_values); |
||
1861 | /* |
||
1862 | $airport_array = array(); |
||
1863 | $temp_array = array(); |
||
1864 | |||
1865 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
1866 | { |
||
1867 | $temp_array['name'] = $row['name']; |
||
1868 | $temp_array['city'] = $row['city']; |
||
1869 | $temp_array['country'] = $row['country']; |
||
1870 | $temp_array['iata'] = $row['iata']; |
||
1871 | $temp_array['icao'] = $row['icao']; |
||
1872 | $temp_array['latitude'] = $row['latitude']; |
||
1873 | $temp_array['longitude'] = $row['longitude']; |
||
1874 | $temp_array['altitude'] = $row['altitude']; |
||
1875 | $temp_array['home_link'] = $row['home_link']; |
||
1876 | $temp_array['wikipedia_link'] = $row['wikipedia_link']; |
||
1877 | $temp_array['image'] = $row['image']; |
||
1878 | $temp_array['image_thumb'] = $row['image_thumb']; |
||
1879 | |||
1880 | $airport_array[] = $temp_array; |
||
1881 | } |
||
1882 | |||
1883 | return $airport_array; |
||
1884 | */ |
||
1885 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1886 | } |
||
1887 | |||
1888 | /** |
||
1889 | * Gets the airport info based on the country |
||
1890 | * |
||
1891 | * @param Array $countries Airports countries |
||
1892 | * @return Array airport information |
||
1893 | * |
||
1894 | */ |
||
1895 | public function getAllAirportInfobyCountry($countries) |
||
1896 | { |
||
1897 | $lst_countries = ''; |
||
1898 | foreach ($countries as $country) { |
||
1899 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
1900 | if ($lst_countries == '') { |
||
1901 | $lst_countries = "'".$country."'"; |
||
1902 | } else { |
||
1903 | $lst_countries .= ",'".$country."'"; |
||
1904 | } |
||
1905 | } |
||
1906 | $query = "SELECT airport.* FROM airport WHERE airport.country IN (".$lst_countries.")"; |
||
1907 | |||
1908 | $sth = $this->db->prepare($query); |
||
1909 | $sth->execute(); |
||
1910 | |||
1911 | $airport_array = array(); |
||
1912 | $temp_array = array(); |
||
1913 | |||
1914 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
1915 | { |
||
1916 | $temp_array['name'] = $row['name']; |
||
1917 | $temp_array['city'] = $row['city']; |
||
1918 | $temp_array['country'] = $row['country']; |
||
1919 | $temp_array['iata'] = $row['iata']; |
||
1920 | $temp_array['icao'] = $row['icao']; |
||
1921 | $temp_array['latitude'] = $row['latitude']; |
||
1922 | $temp_array['longitude'] = $row['longitude']; |
||
1923 | $temp_array['altitude'] = $row['altitude']; |
||
1924 | |||
1925 | $airport_array[] = $temp_array; |
||
1926 | } |
||
1927 | |||
1928 | return $airport_array; |
||
1929 | } |
||
1930 | |||
1931 | /** |
||
1932 | * Gets airports info based on the coord |
||
1933 | * |
||
1934 | * @param Array $coord Airports longitude min,latitude min, longitude max, latitude max |
||
1935 | * @return Array airport information |
||
1936 | * |
||
1937 | */ |
||
1938 | public function getAllAirportInfobyCoord($coord) |
||
1939 | { |
||
1940 | global $globalDBdriver; |
||
1941 | if (is_array($coord)) { |
||
1942 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1943 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1944 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1945 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1946 | } else return array(); |
||
1947 | if ($globalDBdriver == 'mysql') { |
||
1948 | $query = "SELECT airport.* FROM airport WHERE airport.latitude BETWEEN ".$minlat." AND ".$maxlat." AND airport.longitude BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'"; |
||
1949 | } else { |
||
1950 | $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'"; |
||
1951 | } |
||
1952 | $sth = $this->db->prepare($query); |
||
1953 | $sth->execute(); |
||
1954 | |||
1955 | $airport_array = array(); |
||
1956 | |||
1957 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
1958 | { |
||
1959 | $temp_array = $row; |
||
1960 | |||
1961 | $airport_array[] = $temp_array; |
||
1962 | } |
||
1963 | |||
1964 | return $airport_array; |
||
1965 | } |
||
1966 | |||
1967 | /** |
||
1968 | * Gets waypoints info based on the coord |
||
1969 | * |
||
1970 | * @param Array $coord waypoints coord |
||
1971 | * @return Array airport information |
||
1972 | * |
||
1973 | */ |
||
1974 | public function getAllWaypointsInfobyCoord($coord) |
||
1975 | { |
||
1976 | if (is_array($coord)) { |
||
1977 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1978 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1979 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1980 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
1981 | } else return array(); |
||
1982 | //$query = "SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong; |
||
1983 | $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.")"; |
||
1984 | //$query = "SELECT waypoints.* FROM waypoints"; |
||
1985 | //$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"; |
||
1986 | //$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; |
||
1987 | //$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; |
||
1988 | //echo $query; |
||
1989 | |||
1990 | $sth = $this->db->prepare($query); |
||
1991 | $sth->execute(); |
||
1992 | |||
1993 | $waypoints_array = array(); |
||
1994 | |||
1995 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
1996 | { |
||
1997 | $temp_array = $row; |
||
1998 | |||
1999 | $waypoints_array[] = $temp_array; |
||
2000 | } |
||
2001 | |||
2002 | return $waypoints_array; |
||
2003 | } |
||
2004 | |||
2005 | |||
2006 | /** |
||
2007 | * Gets the airline info based on the icao code or iata code |
||
2008 | * |
||
2009 | * @param String $airline_icao the iata code of the airport |
||
2010 | * @return Array airport information |
||
2011 | * |
||
2012 | */ |
||
2013 | public function getAllAirlineInfo($airline_icao, $fromsource = NULL) |
||
2014 | { |
||
2015 | global $globalUseRealAirlines; |
||
2016 | if (isset($globalUseRealAirlines) && $globalUseRealAirlines) $fromsource = NULL; |
||
2017 | $airline_icao = strtoupper(filter_var($airline_icao,FILTER_SANITIZE_STRING)); |
||
2018 | if ($airline_icao == 'NA') { |
||
2019 | $airline_array = array(); |
||
2020 | $airline_array[] = array('name' => 'Not Available','iata' => 'NA', 'icao' => 'NA', 'callsign' => '', 'country' => 'NA', 'type' =>''); |
||
2021 | return $airline_array; |
||
2022 | } else { |
||
2023 | if (strlen($airline_icao) == 2) { |
||
2024 | if ($fromsource === NULL) { |
||
2025 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.iata = :airline_icao AND airlines.active = 'Y' AND airlines.forsource IS NULL LIMIT 1"; |
||
2026 | } else { |
||
2027 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.iata = :airline_icao AND airlines.active = 'Y' AND airlines.forsource = :fromsource LIMIT 1"; |
||
2028 | } |
||
2029 | } else { |
||
2030 | if ($fromsource === NULL) { |
||
2031 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.icao = :airline_icao AND airlines.active = 'Y' AND airlines.forsource IS NULL LIMIT 1"; |
||
2032 | } else { |
||
2033 | $query = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.icao = :airline_icao AND airlines.active = 'Y' AND airlines.forsource = :fromsource LIMIT 1"; |
||
2034 | } |
||
2035 | } |
||
2036 | |||
2037 | $sth = $this->db->prepare($query); |
||
2038 | if ($fromsource === NULL) { |
||
2039 | $sth->execute(array(':airline_icao' => $airline_icao)); |
||
2040 | } else { |
||
2041 | $sth->execute(array(':airline_icao' => $airline_icao,':fromsource' => $fromsource)); |
||
2042 | } |
||
2043 | /* |
||
2044 | $airline_array = array(); |
||
2045 | $temp_array = array(); |
||
2046 | |||
2047 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2048 | { |
||
2049 | $temp_array['name'] = $row['name']; |
||
2050 | $temp_array['iata'] = $row['iata']; |
||
2051 | $temp_array['icao'] = $row['icao']; |
||
2052 | $temp_array['callsign'] = $row['callsign']; |
||
2053 | $temp_array['country'] = $row['country']; |
||
2054 | $temp_array['type'] = $row['type']; |
||
2055 | $airline_array[] = $temp_array; |
||
2056 | } |
||
2057 | return $airline_array; |
||
2058 | */ |
||
2059 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2060 | if (empty($result) && $fromsource !== NULL) { |
||
2061 | $query = 'SELECT COUNT(*) AS nb FROM airlines WHERE forsource = :fromsource'; |
||
2062 | $sth = $this->db->prepare($query); |
||
2063 | $sth->execute(array(':fromsource' => $fromsource)); |
||
2064 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
2065 | $sth->closeCursor(); |
||
2066 | if ($row['nb'] == 0) $result = $this->getAllAirlineInfo($airline_icao); |
||
2067 | } |
||
2068 | return $result; |
||
2069 | } |
||
2070 | } |
||
2071 | |||
2072 | |||
2073 | |||
2074 | /** |
||
2075 | * Gets the aircraft info based on the aircraft type |
||
2076 | * |
||
2077 | * @param String $aircraft_type the aircraft type |
||
2078 | * @return Array aircraft information |
||
2079 | * |
||
2080 | */ |
||
2081 | public function getAllAircraftInfo($aircraft_type) |
||
2082 | { |
||
2083 | $aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING); |
||
2084 | |||
2085 | if ($aircraft_type == 'NA') { |
||
2086 | return array(array('icao' => 'NA','type' => 'Not Available', 'manufacturer' => 'Not Available', 'aircraft_shadow' => NULL)); |
||
2087 | } |
||
2088 | $query = "SELECT aircraft.icao, aircraft.type,aircraft.manufacturer,aircraft.aircraft_shadow FROM aircraft WHERE aircraft.icao = :aircraft_type"; |
||
2089 | |||
2090 | $sth = $this->db->prepare($query); |
||
2091 | $sth->execute(array(':aircraft_type' => $aircraft_type)); |
||
2092 | /* |
||
2093 | $aircraft_array = array(); |
||
2094 | $temp_array = array(); |
||
2095 | |||
2096 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2097 | { |
||
2098 | $temp_array = array(); |
||
2099 | $temp_array['icao'] = $row['icao']; |
||
2100 | $temp_array['type'] = $row['type']; |
||
2101 | $temp_array['manufacturer'] = $row['manufacturer']; |
||
2102 | $temp_array['aircraft_shadow'] = $row['aircraft_shadow']; |
||
2103 | |||
2104 | $aircraft_array[] = $temp_array; |
||
2105 | } |
||
2106 | return $aircraft_array; |
||
2107 | */ |
||
2108 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2109 | } |
||
2110 | |||
2111 | /** |
||
2112 | * Gets the aircraft icao based on the aircraft name/type |
||
2113 | * |
||
2114 | * @param String $aircraft_type the aircraft type |
||
2115 | * @return String aircraft information |
||
2116 | * |
||
2117 | */ |
||
2118 | public function getAircraftIcao($aircraft_type) |
||
2119 | { |
||
2120 | $aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING); |
||
2121 | $all_aircraft = array('737-300' => 'B733', |
||
2122 | '777-200' => 'B772', |
||
2123 | '777-200ER' => 'B772', |
||
2124 | '777-300ER' => 'B77W', |
||
2125 | 'c172p' => 'C172', |
||
2126 | 'aerostar' => 'AEST', |
||
2127 | 'A320-211' => 'A320', |
||
2128 | '747-8i' => 'B748', |
||
2129 | 'A380' => 'A388'); |
||
2130 | if (isset($all_aircraft[$aircraft_type])) return $all_aircraft[$aircraft_type]; |
||
2131 | |||
2132 | $query = "SELECT aircraft.icao FROM aircraft WHERE aircraft.type LIKE :saircraft_type OR aircraft.type = :aircraft_type OR aircraft.icao = :aircraft_type LIMIT 1"; |
||
2133 | $aircraft_type = strtoupper($aircraft_type); |
||
2134 | $sth = $this->db->prepare($query); |
||
2135 | $sth->execute(array(':saircraft_type' => '%'.$aircraft_type.'%',':aircraft_type' => $aircraft_type,)); |
||
2136 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2137 | if (isset($result[0]['icao'])) return $result[0]['icao']; |
||
2138 | else return ''; |
||
2139 | } |
||
2140 | |||
2141 | /** |
||
2142 | * Gets the aircraft info based on the aircraft ident |
||
2143 | * |
||
2144 | * @param String $aircraft_modes the aircraft ident (hex) |
||
2145 | * @return String aircraft type |
||
2146 | * |
||
2147 | */ |
||
2148 | public function getAllAircraftType($aircraft_modes) |
||
2149 | { |
||
2150 | $aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING); |
||
2151 | |||
2152 | $query = "SELECT aircraft_modes.ICAOTypeCode FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1"; |
||
2153 | |||
2154 | $sth = $this->db->prepare($query); |
||
2155 | $sth->execute(array(':aircraft_modes' => $aircraft_modes)); |
||
2156 | |||
2157 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
2158 | $sth->closeCursor(); |
||
2159 | if (isset($row['icaotypecode'])) { |
||
2160 | return $row['icaotypecode']; |
||
2161 | } else return ''; |
||
2162 | } |
||
2163 | |||
2164 | /** |
||
2165 | * Gets correct aircraft operator corde |
||
2166 | * |
||
2167 | * @param String $operator the aircraft operator code (callsign) |
||
2168 | * @return String aircraft operator code |
||
2169 | * |
||
2170 | */ |
||
2171 | public function getOperator($operator) |
||
2172 | { |
||
2173 | $operator = filter_var($operator,FILTER_SANITIZE_STRING); |
||
2174 | $query = "SELECT translation.operator_correct FROM translation WHERE translation.operator = :operator LIMIT 1"; |
||
2175 | |||
2176 | $sth = $this->db->prepare($query); |
||
2177 | $sth->execute(array(':operator' => $operator)); |
||
2178 | |||
2179 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
2180 | $sth->closeCursor(); |
||
2181 | if (isset($row['operator_correct'])) { |
||
2182 | return $row['operator_correct']; |
||
2183 | } else return $operator; |
||
2184 | } |
||
2185 | |||
2186 | /** |
||
2187 | * Gets the aircraft route based on the aircraft callsign |
||
2188 | * |
||
2189 | * @param String $callsign the aircraft callsign |
||
2190 | * @return Array aircraft type |
||
2191 | * |
||
2192 | */ |
||
2193 | public function getRouteInfo($callsign) |
||
2194 | { |
||
2195 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
||
2196 | if ($callsign == '') return array(); |
||
2197 | $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"; |
||
2198 | |||
2199 | $sth = $this->db->prepare($query); |
||
2200 | $sth->execute(array(':callsign' => $callsign)); |
||
2201 | |||
2202 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
2203 | $sth->closeCursor(); |
||
2204 | if (count($row) > 0) { |
||
2205 | return $row; |
||
2206 | } else return array(); |
||
2207 | } |
||
2208 | |||
2209 | /** |
||
2210 | * Gets the aircraft info based on the aircraft registration |
||
2211 | * |
||
2212 | * @param String $registration the aircraft registration |
||
2213 | * @return Array aircraft information |
||
2214 | * |
||
2215 | */ |
||
2216 | public function getAircraftInfoByRegistration($registration) |
||
2217 | { |
||
2218 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
2219 | |||
2220 | $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"; |
||
2221 | |||
2222 | $sth = $this->db->prepare($query); |
||
2223 | $sth->execute(array(':registration' => $registration)); |
||
2224 | |||
2225 | $aircraft_array = array(); |
||
2226 | $temp_array = array(); |
||
2227 | |||
2228 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2229 | { |
||
2230 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
2231 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
2232 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
2233 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
2234 | |||
2235 | $aircraft_array[] = $temp_array; |
||
2236 | } |
||
2237 | |||
2238 | return $aircraft_array; |
||
2239 | } |
||
2240 | |||
2241 | /** |
||
2242 | * Gets the aircraft owner & base based on the aircraft registration |
||
2243 | * |
||
2244 | * @param String $registration the aircraft registration |
||
2245 | * @return Array aircraft information |
||
2246 | * |
||
2247 | */ |
||
2248 | public function getAircraftOwnerByRegistration($registration) |
||
2249 | { |
||
2250 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
2251 | $Connection = new Connection($this->db); |
||
2252 | if ($Connection->tableExists('aircraft_owner')) { |
||
2253 | $query = "SELECT aircraft_owner.base, aircraft_owner.owner, aircraft_owner.date_first_reg FROM aircraft_owner WHERE registration = :registration LIMIT 1"; |
||
2254 | $sth = $this->db->prepare($query); |
||
2255 | $sth->execute(array(':registration' => $registration)); |
||
2256 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
||
2257 | $sth->closeCursor(); |
||
2258 | return $result; |
||
2259 | } else return array(); |
||
2260 | } |
||
2261 | |||
2262 | |||
2263 | /** |
||
2264 | * Gets all flights (but with only little info) |
||
2265 | * |
||
2266 | * @return Array basic flight information |
||
2267 | * |
||
2268 | */ |
||
2269 | public function getAllFlightsforSitemap() |
||
2270 | { |
||
2271 | //$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 "; |
||
2272 | $query = "SELECT spotter_output.spotter_id FROM spotter_output ORDER BY spotter_id DESC LIMIT 200 OFFSET 0"; |
||
2273 | |||
2274 | $sth = $this->db->prepare($query); |
||
2275 | $sth->execute(); |
||
2276 | /* |
||
2277 | $flight_array = array(); |
||
2278 | $temp_array = array(); |
||
2279 | |||
2280 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2281 | { |
||
2282 | $temp_array['spotter_id'] = $row['spotter_id']; |
||
2283 | // $temp_array['ident'] = $row['ident']; |
||
2284 | // $temp_array['airline_name'] = $row['airline_name']; |
||
2285 | // $temp_array['aircraft_type'] = $row['aircraft_icao']; |
||
2286 | // $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
2287 | //$temp_array['image'] = $row['image']; |
||
2288 | |||
2289 | $flight_array[] = $temp_array; |
||
2290 | } |
||
2291 | |||
2292 | return $flight_array; |
||
2293 | */ |
||
2294 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2295 | } |
||
2296 | |||
2297 | /** |
||
2298 | * Gets a list of all aircraft manufacturers |
||
2299 | * |
||
2300 | * @return Array list of aircraft types |
||
2301 | * |
||
2302 | */ |
||
2303 | public function getAllManufacturers() |
||
2304 | { |
||
2305 | /* |
||
2306 | $query = "SELECT DISTINCT spotter_output.aircraft_manufacturer AS aircraft_manufacturer |
||
2307 | FROM spotter_output |
||
2308 | WHERE spotter_output.aircraft_manufacturer <> '' |
||
2309 | ORDER BY spotter_output.aircraft_manufacturer ASC"; |
||
2310 | */ |
||
2311 | |||
2312 | $query = "SELECT DISTINCT manufacturer AS aircraft_manufacturer FROM aircraft WHERE manufacturer <> '' ORDER BY manufacturer ASC"; |
||
2313 | $sth = $this->db->prepare($query); |
||
2314 | $sth->execute(); |
||
2315 | |||
2316 | $manufacturer_array = array(); |
||
2317 | $temp_array = array(); |
||
2318 | |||
2319 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2320 | { |
||
2321 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
2322 | |||
2323 | $manufacturer_array[] = $temp_array; |
||
2324 | } |
||
2325 | |||
2326 | return $manufacturer_array; |
||
2327 | } |
||
2328 | |||
2329 | |||
2330 | /** |
||
2331 | * Gets a list of all aircraft types |
||
2332 | * |
||
2333 | * @return Array list of aircraft types |
||
2334 | * |
||
2335 | */ |
||
2336 | public function getAllAircraftTypes($filters = array()) |
||
2337 | { |
||
2338 | /* |
||
2339 | $query = "SELECT DISTINCT spotter_output.aircraft_icao AS aircraft_icao, spotter_output.aircraft_name AS aircraft_name |
||
2340 | FROM spotter_output |
||
2341 | WHERE spotter_output.aircraft_icao <> '' |
||
2342 | ORDER BY spotter_output.aircraft_name ASC"; |
||
2343 | |||
2344 | */ |
||
2345 | $filter_query = $this->getFilter($filters,true,true); |
||
2346 | $query = "SELECT DISTINCT icao AS aircraft_icao, type AS aircraft_name, manufacturer AS aircraft_manufacturer FROM aircraft".$filter_query." icao <> '' ORDER BY aircraft_manufacturer ASC"; |
||
2347 | |||
2348 | $sth = $this->db->prepare($query); |
||
2349 | $sth->execute(); |
||
2350 | |||
2351 | $aircraft_array = array(); |
||
2352 | $temp_array = array(); |
||
2353 | |||
2354 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2355 | { |
||
2356 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
2357 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
2358 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
2359 | |||
2360 | $aircraft_array[] = $temp_array; |
||
2361 | } |
||
2362 | |||
2363 | return $aircraft_array; |
||
2364 | } |
||
2365 | |||
2366 | |||
2367 | /** |
||
2368 | * Gets a list of all aircraft registrations |
||
2369 | * |
||
2370 | * @return Array list of aircraft registrations |
||
2371 | * |
||
2372 | */ |
||
2373 | public function getAllAircraftRegistrations($filters = array()) |
||
2374 | { |
||
2375 | $filter_query = $this->getFilter($filters,true,true); |
||
2376 | $query = "SELECT DISTINCT spotter_output.registration |
||
2377 | FROM spotter_output".$filter_query." spotter_output.registration <> '' |
||
2378 | ORDER BY spotter_output.registration ASC"; |
||
2379 | |||
2380 | $sth = $this->db->prepare($query); |
||
2381 | $sth->execute(); |
||
2382 | |||
2383 | $aircraft_array = array(); |
||
2384 | $temp_array = array(); |
||
2385 | |||
2386 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2387 | { |
||
2388 | $temp_array['registration'] = $row['registration']; |
||
2389 | |||
2390 | $aircraft_array[] = $temp_array; |
||
2391 | } |
||
2392 | |||
2393 | return $aircraft_array; |
||
2394 | } |
||
2395 | |||
2396 | /** |
||
2397 | * Gets all source name |
||
2398 | * |
||
2399 | * @param String type format of source |
||
2400 | * @return Array list of source name |
||
2401 | * |
||
2402 | */ |
||
2403 | public function getAllSourceName($type = '',$filters = array()) |
||
2404 | { |
||
2405 | $filter_query = $this->getFilter($filters,true,true); |
||
2406 | $query_values = array(); |
||
2407 | $query = "SELECT DISTINCT spotter_output.source_name |
||
2408 | FROM spotter_output".$filter_query." spotter_output.source_name <> ''"; |
||
2409 | if ($type != '') { |
||
2410 | $query_values = array(':type' => $type); |
||
2411 | $query .= " AND format_source = :type"; |
||
2412 | } |
||
2413 | $query .= " ORDER BY spotter_output.source_name ASC"; |
||
2414 | |||
2415 | $sth = $this->db->prepare($query); |
||
2416 | if (!empty($query_values)) $sth->execute($query_values); |
||
2417 | else $sth->execute(); |
||
2418 | |||
2419 | $source_array = array(); |
||
2420 | $temp_array = array(); |
||
2421 | |||
2422 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2423 | { |
||
2424 | $temp_array['source_name'] = $row['source_name']; |
||
2425 | $source_array[] = $temp_array; |
||
2426 | } |
||
2427 | return $source_array; |
||
2428 | } |
||
2429 | |||
2430 | |||
2431 | |||
2432 | /** |
||
2433 | * Gets a list of all airline names |
||
2434 | * |
||
2435 | * @return Array list of airline names |
||
2436 | * |
||
2437 | */ |
||
2438 | public function getAllAirlineNames($airline_type = '',$forsource = NULL,$filters = array()) |
||
2439 | { |
||
2440 | global $globalAirlinesSource,$globalVATSIM, $globalIVAO; |
||
2441 | $filter_query = $this->getFilter($filters,true,true); |
||
2442 | $airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING); |
||
2443 | if ($airline_type == '' || $airline_type == 'all') { |
||
2444 | /* |
||
2445 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
2446 | FROM spotter_output |
||
2447 | WHERE spotter_output.airline_icao <> '' |
||
2448 | ORDER BY spotter_output.airline_name ASC"; |
||
2449 | */ |
||
2450 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $forsource = $globalAirlinesSource; |
||
2451 | elseif (isset($globalVATSIM) && $globalVATSIM) $forsource = 'vatsim'; |
||
2452 | elseif (isset($globalIVAO) && $globalIVAO) $forsource = 'ivao'; |
||
2453 | if ($forsource === NULL) { |
||
2454 | $query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines WHERE forsource IS NULL ORDER BY name ASC"; |
||
2455 | $query_data = array(); |
||
2456 | } else { |
||
2457 | $query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines WHERE forsource = :forsource ORDER BY name ASC"; |
||
2458 | $query_data = array(':forsource' => $forsource); |
||
2459 | } |
||
2460 | } else { |
||
2461 | $query = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type |
||
2462 | FROM spotter_output".$filter_query." spotter_output.airline_icao <> '' |
||
2463 | AND spotter_output.airline_type = :airline_type |
||
2464 | ORDER BY spotter_output.airline_icao ASC"; |
||
2465 | $query_data = array(':airline_type' => $airline_type); |
||
2466 | } |
||
2467 | |||
2468 | $sth = $this->db->prepare($query); |
||
2469 | $sth->execute($query_data); |
||
2470 | |||
2471 | $airline_array = array(); |
||
2472 | $temp_array = array(); |
||
2473 | |||
2474 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2475 | { |
||
2476 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
2477 | $temp_array['airline_name'] = $row['airline_name']; |
||
2478 | $temp_array['airline_type'] = $row['airline_type']; |
||
2479 | |||
2480 | $airline_array[] = $temp_array; |
||
2481 | } |
||
2482 | return $airline_array; |
||
2483 | } |
||
2484 | |||
2485 | |||
2486 | /** |
||
2487 | * Gets a list of all airline countries |
||
2488 | * |
||
2489 | * @return Array list of airline countries |
||
2490 | * |
||
2491 | */ |
||
2492 | public function getAllAirlineCountries($filters = array()) |
||
2493 | { |
||
2494 | $filter_query = $this->getFilter($filters,true,true); |
||
2495 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
2496 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' |
||
2497 | ORDER BY spotter_output.airline_country ASC"; |
||
2498 | |||
2499 | //$query = "SELECT DISTINCT country AS airline_country FROM airlines WHERE country <> '' AND active = 'Y' ORDER BY country ASC"; |
||
2500 | $sth = $this->db->prepare($query); |
||
2501 | $sth->execute(); |
||
2502 | |||
2503 | $airline_array = array(); |
||
2504 | $temp_array = array(); |
||
2505 | |||
2506 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2507 | { |
||
2508 | $temp_array['airline_country'] = $row['airline_country']; |
||
2509 | |||
2510 | $airline_array[] = $temp_array; |
||
2511 | } |
||
2512 | |||
2513 | return $airline_array; |
||
2514 | } |
||
2515 | |||
2516 | |||
2517 | |||
2518 | /** |
||
2519 | * Gets a list of all departure & arrival names |
||
2520 | * |
||
2521 | * @return Array list of airport names |
||
2522 | * |
||
2523 | */ |
||
2524 | public function getAllAirportNames($filters = array()) |
||
2525 | { |
||
2526 | $filter_query = $this->getFilter($filters,true,true); |
||
2527 | $airport_array = array(); |
||
2528 | $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 |
||
2529 | FROM spotter_output".$filter_query." spotter_output.departure_airport_icao <> '' AND spotter_output.departure_airport_icao <> 'NA' |
||
2530 | ORDER BY spotter_output.departure_airport_city ASC"; |
||
2531 | |||
2532 | //$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"; |
||
2533 | $sth = $this->db->prepare($query); |
||
2534 | $sth->execute(); |
||
2535 | |||
2536 | $temp_array = array(); |
||
2537 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2538 | { |
||
2539 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
2540 | $temp_array['airport_name'] = $row['airport_name']; |
||
2541 | $temp_array['airport_city'] = $row['airport_city']; |
||
2542 | $temp_array['airport_country'] = $row['airport_country']; |
||
2543 | |||
2544 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
2545 | } |
||
2546 | |||
2547 | $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 |
||
2548 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_icao <> '' AND spotter_output.arrival_airport_icao <> 'NA' |
||
2549 | ORDER BY spotter_output.arrival_airport_city ASC"; |
||
2550 | |||
2551 | $sth = $this->db->prepare($query); |
||
2552 | $sth->execute(); |
||
2553 | |||
2554 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2555 | { |
||
2556 | // if ($airport_array[$row['airport_city'].",".$row['airport_name']]['airport_icao'] != $row['airport_icao']) |
||
2557 | // { |
||
2558 | $temp_array['airport_icao'] = $row['airport_icao']; |
||
2559 | $temp_array['airport_name'] = $row['airport_name']; |
||
2560 | $temp_array['airport_city'] = $row['airport_city']; |
||
2561 | $temp_array['airport_country'] = $row['airport_country']; |
||
2562 | |||
2563 | $airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array; |
||
2564 | // } |
||
2565 | } |
||
2566 | |||
2567 | return $airport_array; |
||
2568 | } |
||
2569 | |||
2570 | |||
2571 | /** |
||
2572 | * Gets a list of all departure & arrival airport countries |
||
2573 | * |
||
2574 | * @return Array list of airport countries |
||
2575 | * |
||
2576 | */ |
||
2577 | public function getAllAirportCountries($filters = array()) |
||
2578 | { |
||
2579 | $airport_array = array(); |
||
2580 | |||
2581 | /* |
||
2582 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
2583 | FROM spotter_output |
||
2584 | WHERE spotter_output.departure_airport_country <> '' |
||
2585 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
2586 | */ |
||
2587 | $query = "SELECT DISTINCT country AS airport_country FROM airport ORDER BY country ASC"; |
||
2588 | |||
2589 | $sth = $this->db->prepare($query); |
||
2590 | $sth->execute(); |
||
2591 | |||
2592 | $temp_array = array(); |
||
2593 | |||
2594 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2595 | { |
||
2596 | $temp_array['airport_country'] = $row['airport_country']; |
||
2597 | |||
2598 | $airport_array[$row['airport_country']] = $temp_array; |
||
2599 | } |
||
2600 | $filter_query = $this->getFilter($filters,true,true); |
||
2601 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
2602 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' |
||
2603 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
2604 | |||
2605 | $sth = $this->db->prepare($query); |
||
2606 | $sth->execute(); |
||
2607 | |||
2608 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2609 | { |
||
2610 | if (isset($airport_array[$row['airport_country']]['airport_country']) && $airport_array[$row['airport_country']]['airport_country'] != $row['airport_country']) |
||
2611 | { |
||
2612 | $temp_array['airport_country'] = $row['airport_country']; |
||
2613 | $airport_array[$row['airport_country']] = $temp_array; |
||
2614 | } |
||
2615 | } |
||
2616 | |||
2617 | return $airport_array; |
||
2618 | } |
||
2619 | |||
2620 | |||
2621 | |||
2622 | |||
2623 | /** |
||
2624 | * Gets a list of all countries (airline, departure airport & arrival airport) |
||
2625 | * |
||
2626 | * @return Array list of countries |
||
2627 | * |
||
2628 | */ |
||
2629 | public function getAllCountries($filters = array()) |
||
2630 | { |
||
2631 | $Connection= new Connection($this->db); |
||
2632 | if ($Connection->tableExists('countries')) { |
||
2633 | $query = "SELECT countries.name AS airport_country |
||
2634 | FROM countries |
||
2635 | ORDER BY countries.name ASC"; |
||
2636 | $sth = $this->db->prepare($query); |
||
2637 | $sth->execute(); |
||
2638 | |||
2639 | $temp_array = array(); |
||
2640 | $country_array = array(); |
||
2641 | |||
2642 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2643 | { |
||
2644 | $temp_array['country'] = $row['airport_country']; |
||
2645 | $country_array[$row['airport_country']] = $temp_array; |
||
2646 | } |
||
2647 | } else { |
||
2648 | $filter_query = $this->getFilter($filters,true,true); |
||
2649 | $query = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country |
||
2650 | FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' |
||
2651 | ORDER BY spotter_output.departure_airport_country ASC"; |
||
2652 | |||
2653 | $sth = $this->db->prepare($query); |
||
2654 | $sth->execute(); |
||
2655 | |||
2656 | $temp_array = array(); |
||
2657 | $country_array = array(); |
||
2658 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2659 | { |
||
2660 | $temp_array['country'] = $row['airport_country']; |
||
2661 | $country_array[$row['airport_country']] = $temp_array; |
||
2662 | } |
||
2663 | |||
2664 | $query = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country |
||
2665 | FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' |
||
2666 | ORDER BY spotter_output.arrival_airport_country ASC"; |
||
2667 | |||
2668 | $sth = $this->db->prepare($query); |
||
2669 | $sth->execute(); |
||
2670 | |||
2671 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2672 | { |
||
2673 | if ($country_array[$row['airport_country']]['country'] != $row['airport_country']) |
||
2674 | { |
||
2675 | $temp_array['country'] = $row['airport_country']; |
||
2676 | |||
2677 | $country_array[$row['country']] = $temp_array; |
||
2678 | } |
||
2679 | } |
||
2680 | |||
2681 | $query = "SELECT DISTINCT spotter_output.airline_country AS airline_country |
||
2682 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' |
||
2683 | ORDER BY spotter_output.airline_country ASC"; |
||
2684 | |||
2685 | $sth = $this->db->prepare($query); |
||
2686 | $sth->execute(); |
||
2687 | |||
2688 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2689 | { |
||
2690 | if (isset($country_array[$row['airline_country']]['country']) && $country_array[$row['airline_country']]['country'] != $row['airline_country']) |
||
2691 | { |
||
2692 | $temp_array['country'] = $row['airline_country']; |
||
2693 | |||
2694 | $country_array[$row['country']] = $temp_array; |
||
2695 | } |
||
2696 | } |
||
2697 | } |
||
2698 | return $country_array; |
||
2699 | } |
||
2700 | |||
2701 | |||
2702 | |||
2703 | |||
2704 | /** |
||
2705 | * Gets a list of all idents/callsigns |
||
2706 | * |
||
2707 | * @return Array list of ident/callsign names |
||
2708 | * |
||
2709 | */ |
||
2710 | public function getAllIdents($filters = array()) |
||
2711 | { |
||
2712 | $filter_query = $this->getFilter($filters,true,true); |
||
2713 | $query = "SELECT DISTINCT spotter_output.ident |
||
2714 | FROM spotter_output".$filter_query." spotter_output.ident <> '' |
||
2715 | ORDER BY spotter_output.date ASC LIMIT 700 OFFSET 0"; |
||
2716 | |||
2717 | $sth = $this->db->prepare($query); |
||
2718 | $sth->execute(); |
||
2719 | |||
2720 | $ident_array = array(); |
||
2721 | $temp_array = array(); |
||
2722 | |||
2723 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
2724 | { |
||
2725 | $temp_array['ident'] = $row['ident']; |
||
2726 | $ident_array[] = $temp_array; |
||
2727 | } |
||
2728 | |||
2729 | return $ident_array; |
||
2730 | } |
||
2731 | |||
2732 | /** |
||
2733 | * Get a list of flights from airport since 7 days |
||
2734 | * @return Array number, icao, name and city of airports |
||
2735 | */ |
||
2736 | |||
2737 | public function getLast7DaysAirportsDeparture($airport_icao = '',$filters = array()) { |
||
2738 | global $globalTimezone, $globalDBdriver; |
||
2739 | $filter_query = $this->getFilter($filters,true,true); |
||
2740 | if ($globalTimezone != '') { |
||
2741 | date_default_timezone_set($globalTimezone); |
||
2742 | $datetime = new DateTime(); |
||
2743 | $offset = $datetime->format('P'); |
||
2744 | } else $offset = '+00:00'; |
||
2745 | if ($airport_icao == '') { |
||
2746 | if ($globalDBdriver == 'mysql') { |
||
2747 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' 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"; |
||
2748 | } else { |
||
2749 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' 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"; |
||
2750 | } |
||
2751 | $sth = $this->db->prepare($query); |
||
2752 | $sth->execute(array(':offset' => $offset)); |
||
2753 | } else { |
||
2754 | if ($globalDBdriver == 'mysql') { |
||
2755 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output`".$filter_query." spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2756 | } else { |
||
2757 | $query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output".$filter_query." spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2758 | } |
||
2759 | $sth = $this->db->prepare($query); |
||
2760 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2761 | } |
||
2762 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2763 | } |
||
2764 | |||
2765 | /** |
||
2766 | * Get a list of flights from airport since 7 days |
||
2767 | * @return Array number, icao, name and city of airports |
||
2768 | */ |
||
2769 | |||
2770 | public function getLast7DaysAirportsDepartureByAirlines($airport_icao = '') { |
||
2771 | global $globalTimezone, $globalDBdriver; |
||
2772 | if ($globalTimezone != '') { |
||
2773 | date_default_timezone_set($globalTimezone); |
||
2774 | $datetime = new DateTime(); |
||
2775 | $offset = $datetime->format('P'); |
||
2776 | } else $offset = '+00:00'; |
||
2777 | if ($airport_icao == '') { |
||
2778 | if ($globalDBdriver == 'mysql') { |
||
2779 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2780 | } else { |
||
2781 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2782 | } |
||
2783 | $sth = $this->db->prepare($query); |
||
2784 | $sth->execute(array(':offset' => $offset)); |
||
2785 | } else { |
||
2786 | if ($globalDBdriver == 'mysql') { |
||
2787 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2788 | } else { |
||
2789 | $query = "SELECT spotter_output.airline_icao, COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC"; |
||
2790 | } |
||
2791 | $sth = $this->db->prepare($query); |
||
2792 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2793 | } |
||
2794 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2795 | } |
||
2796 | |||
2797 | /** |
||
2798 | * Get a list of flights from detected airport since 7 days |
||
2799 | * @return Array number, icao, name and city of airports |
||
2800 | */ |
||
2801 | |||
2802 | public function getLast7DaysDetectedAirportsDeparture($airport_icao = '') { |
||
2803 | global $globalTimezone, $globalDBdriver; |
||
2804 | if ($globalTimezone != '') { |
||
2805 | date_default_timezone_set($globalTimezone); |
||
2806 | $datetime = new DateTime(); |
||
2807 | $offset = $datetime->format('P'); |
||
2808 | } else $offset = '+00:00'; |
||
2809 | if ($airport_icao == '') { |
||
2810 | if ($globalDBdriver == 'mysql') { |
||
2811 | $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 |
||
2812 | FROM `spotter_output`, airport |
||
2813 | 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' |
||
2814 | 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"; |
||
2815 | } else { |
||
2816 | $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 |
||
2817 | FROM spotter_output, airport |
||
2818 | 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' |
||
2819 | 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"; |
||
2820 | } |
||
2821 | $sth = $this->db->prepare($query); |
||
2822 | $sth->execute(array(':offset' => $offset)); |
||
2823 | } else { |
||
2824 | if ($globalDBdriver == 'mysql') { |
||
2825 | $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 |
||
2826 | FROM `spotter_output`, airport |
||
2827 | 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 |
||
2828 | 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"; |
||
2829 | } else { |
||
2830 | $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 |
||
2831 | FROM spotter_output, airport |
||
2832 | 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"; |
||
2833 | } |
||
2834 | $sth = $this->db->prepare($query); |
||
2835 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2836 | } |
||
2837 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2838 | } |
||
2839 | |||
2840 | /** |
||
2841 | * Get a list of flights from detected airport since 7 days |
||
2842 | * @return Array number, icao, name and city of airports |
||
2843 | */ |
||
2844 | |||
2845 | public function getLast7DaysDetectedAirportsDepartureByAirlines($airport_icao = '') { |
||
2846 | global $globalTimezone, $globalDBdriver; |
||
2847 | if ($globalTimezone != '') { |
||
2848 | date_default_timezone_set($globalTimezone); |
||
2849 | $datetime = new DateTime(); |
||
2850 | $offset = $datetime->format('P'); |
||
2851 | } else $offset = '+00:00'; |
||
2852 | if ($airport_icao == '') { |
||
2853 | if ($globalDBdriver == 'mysql') { |
||
2854 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
2855 | FROM `spotter_output`, airport |
||
2856 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao <> 'NA' |
||
2857 | GROUP BY spotter_output.airline_icao, real_departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
2858 | } else { |
||
2859 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
2860 | FROM spotter_output, airport |
||
2861 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao <> 'NA' |
||
2862 | GROUP BY spotter_output.airline_icao, real_departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
2863 | } |
||
2864 | $sth = $this->db->prepare($query); |
||
2865 | $sth->execute(array(':offset' => $offset)); |
||
2866 | } else { |
||
2867 | if ($globalDBdriver == 'mysql') { |
||
2868 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
2869 | FROM `spotter_output`, airport |
||
2870 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao = :airport_icao |
||
2871 | GROUP BY spotter_output.airline_icao, departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
2872 | } else { |
||
2873 | $query = "SELECT spotter_output.airline_icao, COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
2874 | FROM spotter_output, airport |
||
2875 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao = :airport_icao GROUP BY spotter_output.airline_icao, departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC"; |
||
2876 | } |
||
2877 | $sth = $this->db->prepare($query); |
||
2878 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2879 | } |
||
2880 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2881 | } |
||
2882 | |||
2883 | |||
2884 | /** |
||
2885 | * Get a list of flights to airport since 7 days |
||
2886 | * @return Array number, icao, name and city of airports |
||
2887 | */ |
||
2888 | |||
2889 | public function getLast7DaysAirportsArrival($airport_icao = '') { |
||
2890 | global $globalTimezone, $globalDBdriver; |
||
2891 | if ($globalTimezone != '') { |
||
2892 | date_default_timezone_set($globalTimezone); |
||
2893 | $datetime = new DateTime(); |
||
2894 | $offset = $datetime->format('P'); |
||
2895 | } else $offset = '+00:00'; |
||
2896 | if ($airport_icao == '') { |
||
2897 | if ($globalDBdriver == 'mysql') { |
||
2898 | $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"; |
||
2899 | } else { |
||
2900 | $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"; |
||
2901 | } |
||
2902 | $sth = $this->db->prepare($query); |
||
2903 | $sth->execute(array(':offset' => $offset)); |
||
2904 | } else { |
||
2905 | if ($globalDBdriver == 'mysql') { |
||
2906 | $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"; |
||
2907 | } else { |
||
2908 | $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"; |
||
2909 | } |
||
2910 | $sth = $this->db->prepare($query); |
||
2911 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2912 | } |
||
2913 | |||
2914 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2915 | } |
||
2916 | |||
2917 | |||
2918 | /** |
||
2919 | * Get a list of flights detected to airport since 7 days |
||
2920 | * @return Array number, icao, name and city of airports |
||
2921 | */ |
||
2922 | |||
2923 | public function getLast7DaysDetectedAirportsArrival($airport_icao = '') { |
||
2924 | global $globalTimezone, $globalDBdriver; |
||
2925 | if ($globalTimezone != '') { |
||
2926 | date_default_timezone_set($globalTimezone); |
||
2927 | $datetime = new DateTime(); |
||
2928 | $offset = $datetime->format('P'); |
||
2929 | } else $offset = '+00:00'; |
||
2930 | if ($airport_icao == '') { |
||
2931 | if ($globalDBdriver == 'mysql') { |
||
2932 | $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 |
||
2933 | FROM `spotter_output`, airport |
||
2934 | 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' |
||
2935 | 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"; |
||
2936 | } else { |
||
2937 | $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 |
||
2938 | FROM spotter_output, airport |
||
2939 | 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' |
||
2940 | 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"; |
||
2941 | } |
||
2942 | $sth = $this->db->prepare($query); |
||
2943 | $sth->execute(array(':offset' => $offset)); |
||
2944 | } else { |
||
2945 | if ($globalDBdriver == 'mysql') { |
||
2946 | $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 |
||
2947 | FROM `spotter_output`, airport |
||
2948 | 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 |
||
2949 | 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"; |
||
2950 | } else { |
||
2951 | $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 |
||
2952 | FROM spotter_output, airport |
||
2953 | 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 |
||
2954 | 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"; |
||
2955 | } |
||
2956 | $sth = $this->db->prepare($query); |
||
2957 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2958 | } |
||
2959 | |||
2960 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2961 | } |
||
2962 | |||
2963 | |||
2964 | /** |
||
2965 | * Get a list of flights to airport since 7 days |
||
2966 | * @return Array number, icao, name and city of airports |
||
2967 | */ |
||
2968 | |||
2969 | public function getLast7DaysAirportsArrivalByAirlines($airport_icao = '') { |
||
2970 | global $globalTimezone, $globalDBdriver; |
||
2971 | if ($globalTimezone != '') { |
||
2972 | date_default_timezone_set($globalTimezone); |
||
2973 | $datetime = new DateTime(); |
||
2974 | $offset = $datetime->format('P'); |
||
2975 | } else $offset = '+00:00'; |
||
2976 | if ($airport_icao == '') { |
||
2977 | if ($globalDBdriver == 'mysql') { |
||
2978 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
2979 | } else { |
||
2980 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
2981 | } |
||
2982 | $sth = $this->db->prepare($query); |
||
2983 | $sth->execute(array(':offset' => $offset)); |
||
2984 | } else { |
||
2985 | if ($globalDBdriver == 'mysql') { |
||
2986 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
2987 | } else { |
||
2988 | $query = "SELECT spotter_output.airline_icao, COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao AND spotter_output.airline_icao <> '' GROUP BY spotter_output.airline_icao, arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC"; |
||
2989 | } |
||
2990 | $sth = $this->db->prepare($query); |
||
2991 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
2992 | } |
||
2993 | |||
2994 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2995 | } |
||
2996 | |||
2997 | |||
2998 | /** |
||
2999 | * Get a list of flights detected to airport since 7 days |
||
3000 | * @return Array number, icao, name and city of airports |
||
3001 | */ |
||
3002 | |||
3003 | public function getLast7DaysDetectedAirportsArrivalByAirlines($airport_icao = '') { |
||
3004 | global $globalTimezone, $globalDBdriver; |
||
3005 | if ($globalTimezone != '') { |
||
3006 | date_default_timezone_set($globalTimezone); |
||
3007 | $datetime = new DateTime(); |
||
3008 | $offset = $datetime->format('P'); |
||
3009 | } else $offset = '+00:00'; |
||
3010 | if ($airport_icao == '') { |
||
3011 | if ($globalDBdriver == 'mysql') { |
||
3012 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
3013 | FROM `spotter_output`, airport |
||
3014 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' |
||
3015 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
3016 | } else { |
||
3017 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
3018 | FROM spotter_output, airport |
||
3019 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' |
||
3020 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
3021 | } |
||
3022 | $sth = $this->db->prepare($query); |
||
3023 | $sth->execute(array(':offset' => $offset)); |
||
3024 | } else { |
||
3025 | if ($globalDBdriver == 'mysql') { |
||
3026 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date |
||
3027 | FROM `spotter_output`, airport |
||
3028 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao |
||
3029 | GROUP BY spotter_output.airline_icao, real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
3030 | } else { |
||
3031 | $query = "SELECT spotter_output.airline_icao, COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
3032 | FROM spotter_output, airport |
||
3033 | WHERE spotter_output.airline_icao <> '' AND airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao |
||
3034 | GROUP BY spotter_output.airline_icao,real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC"; |
||
3035 | } |
||
3036 | $sth = $this->db->prepare($query); |
||
3037 | $sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao)); |
||
3038 | } |
||
3039 | |||
3040 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
||
3041 | } |
||
3042 | |||
3043 | |||
3044 | /** |
||
3045 | * Gets a list of all dates |
||
3046 | * |
||
3047 | * @return Array list of date names |
||
3048 | * |
||
3049 | */ |
||
3050 | public function getAllDates() |
||
3051 | { |
||
3052 | global $globalTimezone, $globalDBdriver; |
||
3053 | if ($globalTimezone != '') { |
||
3054 | date_default_timezone_set($globalTimezone); |
||
3055 | $datetime = new DateTime(); |
||
3056 | $offset = $datetime->format('P'); |
||
3057 | } else $offset = '+00:00'; |
||
3058 | |||
3059 | if ($globalDBdriver == 'mysql') { |
||
3060 | $query = "SELECT DISTINCT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) as date |
||
3061 | FROM spotter_output |
||
3062 | WHERE spotter_output.date <> '' |
||
3063 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
3064 | } else { |
||
3065 | $query = "SELECT DISTINCT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date |
||
3066 | FROM spotter_output |
||
3067 | WHERE spotter_output.date <> '' |
||
3068 | ORDER BY spotter_output.date ASC LIMIT 0,200"; |
||
3069 | } |
||
3070 | |||
3071 | $sth = $this->db->prepare($query); |
||
3072 | $sth->execute(array(':offset' => $offset)); |
||
3073 | |||
3074 | $date_array = array(); |
||
3075 | $temp_array = array(); |
||
3076 | |||
3077 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3078 | { |
||
3079 | $temp_array['date'] = $row['date']; |
||
3080 | |||
3081 | $date_array[] = $temp_array; |
||
3082 | } |
||
3083 | |||
3084 | return $date_array; |
||
3085 | } |
||
3086 | |||
3087 | |||
3088 | |||
3089 | /** |
||
3090 | * Gets all route combinations |
||
3091 | * |
||
3092 | * @return Array the route list |
||
3093 | * |
||
3094 | */ |
||
3095 | public function getAllRoutes() |
||
3096 | { |
||
3097 | $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 |
||
3098 | FROM spotter_output |
||
3099 | WHERE spotter_output.ident <> '' |
||
3100 | GROUP BY route |
||
3101 | ORDER BY route ASC"; |
||
3102 | |||
3103 | $sth = $this->db->prepare($query); |
||
3104 | $sth->execute(); |
||
3105 | |||
3106 | $routes_array = array(); |
||
3107 | $temp_array = array(); |
||
3108 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3109 | { |
||
3110 | $temp_array['route'] = $row['route']; |
||
3111 | $temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
||
3112 | $temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
||
3113 | |||
3114 | $routes_array[] = $temp_array; |
||
3115 | } |
||
3116 | return $routes_array; |
||
3117 | } |
||
3118 | |||
3119 | /** |
||
3120 | * Update ident spotter data |
||
3121 | * |
||
3122 | * @param String $flightaware_id the ID from flightaware |
||
3123 | * @param String $ident the flight ident |
||
3124 | * @return String success or false |
||
3125 | * |
||
3126 | */ |
||
3127 | public function updateIdentSpotterData($flightaware_id = '', $ident = '',$fromsource = NULL) |
||
3128 | { |
||
3129 | if (!is_numeric(substr($ident, 0, 3))) |
||
3130 | { |
||
3131 | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
||
3132 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2),$fromsource); |
||
3133 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
3134 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3),$fromsource); |
||
3135 | } else { |
||
3136 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3137 | } |
||
3138 | if (count($airline_array) == 0) { |
||
3139 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3140 | } |
||
3141 | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
||
3142 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3143 | } |
||
3144 | } else { |
||
3145 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3146 | } |
||
3147 | $airline_name = $airline_array[0]['name']; |
||
3148 | $airline_icao = $airline_array[0]['icao']; |
||
3149 | $airline_country = $airline_array[0]['country']; |
||
3150 | $airline_type = $airline_array[0]['type']; |
||
3151 | |||
3152 | |||
3153 | $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'; |
||
3154 | $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); |
||
3155 | |||
3156 | try { |
||
3157 | $sth = $this->db->prepare($query); |
||
3158 | $sth->execute($query_values); |
||
3159 | } catch (PDOException $e) { |
||
3160 | return "error : ".$e->getMessage(); |
||
3161 | } |
||
3162 | |||
3163 | return "success"; |
||
3164 | |||
3165 | } |
||
3166 | /** |
||
3167 | * Update latest spotter data |
||
3168 | * |
||
3169 | * @param String $flightaware_id the ID from flightaware |
||
3170 | * @param String $ident the flight ident |
||
3171 | * @param String $arrival_airport_icao the arrival airport |
||
3172 | * @return String success or false |
||
3173 | * |
||
3174 | */ |
||
3175 | public function updateLatestSpotterData($flightaware_id = '', $ident = '', $latitude = '', $longitude = '', $altitude = '', $ground = false, $groundspeed = NULL, $date = '', $arrival_airport_icao = '',$arrival_airport_time = '') |
||
3176 | { |
||
3177 | if ($groundspeed == '') $groundspeed = NULL; |
||
3178 | $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'; |
||
3179 | $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); |
||
3180 | |||
3181 | try { |
||
3182 | $sth = $this->db->prepare($query); |
||
3183 | $sth->execute($query_values); |
||
3184 | } catch (PDOException $e) { |
||
3185 | return "error : ".$e->getMessage(); |
||
3186 | } |
||
3187 | |||
3188 | return "success"; |
||
3189 | |||
3190 | } |
||
3191 | |||
3192 | /** |
||
3193 | * Adds a new spotter data |
||
3194 | * |
||
3195 | * @param String $flightaware_id the ID from flightaware |
||
3196 | * @param String $ident the flight ident |
||
3197 | * @param String $aircraft_icao the aircraft type |
||
3198 | * @param String $departure_airport_icao the departure airport |
||
3199 | * @param String $arrival_airport_icao the arrival airport |
||
3200 | * @param String $latitude latitude of flight |
||
3201 | * @param String $longitude latitude of flight |
||
3202 | * @param String $waypoints waypoints of flight |
||
3203 | * @param String $altitude altitude of flight |
||
3204 | * @param String $heading heading of flight |
||
3205 | * @param String $groundspeed speed of flight |
||
3206 | * @param String $date date of flight |
||
3207 | * @param String $departure_airport_time departure time of flight |
||
3208 | * @param String $arrival_airport_time arrival time of flight |
||
3209 | * @param String $squawk squawk code of flight |
||
3210 | * @param String $route_stop route stop of flight |
||
3211 | * @param String $highlight highlight or not |
||
3212 | * @param String $ModeS ModesS code of flight |
||
3213 | * @param String $registration registration code of flight |
||
3214 | * @param String $pilot_id pilot id of flight (for virtual airlines) |
||
3215 | * @param String $pilot_name pilot name of flight (for virtual airlines) |
||
3216 | * @param String $verticalrate vertival rate of flight |
||
3217 | * @return String success or false |
||
3218 | */ |
||
3219 | 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 = '') |
||
3220 | { |
||
3221 | global $globalURL, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalDebugTimeElapsed, $globalAirlinesSource, $globalVAM; |
||
3222 | |||
3223 | //if (isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
||
3224 | $Image = new Image($this->db); |
||
3225 | $Common = new Common(); |
||
3226 | |||
3227 | if (!isset($globalIVAO)) $globalIVAO = FALSE; |
||
3228 | if (!isset($globalVATSIM)) $globalVATSIM = FALSE; |
||
3229 | if (!isset($globalphpVMS)) $globalphpVMS = FALSE; |
||
3230 | if (!isset($globalVAM)) $globalVAM = FALSE; |
||
3231 | date_default_timezone_set('UTC'); |
||
3232 | |||
3233 | //getting the registration |
||
3234 | if ($flightaware_id != "" && $registration == '') |
||
3235 | { |
||
3236 | if (!is_string($flightaware_id)) |
||
3237 | { |
||
3238 | return false; |
||
3239 | } else { |
||
3240 | if ($ModeS != '') { |
||
3241 | $timeelapsed = microtime(true); |
||
3242 | $registration = $this->getAircraftRegistrationBymodeS($ModeS); |
||
3243 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3244 | } else { |
||
3245 | $myhex = explode('-',$flightaware_id); |
||
3246 | if (count($myhex) > 0) { |
||
3247 | $timeelapsed = microtime(true); |
||
3248 | $registration = $this->getAircraftRegistrationBymodeS($myhex[0]); |
||
3249 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3250 | } |
||
3251 | } |
||
3252 | } |
||
3253 | } |
||
3254 | $fromsource = NULL; |
||
3255 | if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
||
3256 | elseif ($format_source == 'vatsimtxt') $fromsource = 'vatsim'; |
||
3257 | elseif ($format_source == 'whazzup') $fromsource = 'ivao'; |
||
3258 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
||
3259 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
||
3260 | //getting the airline information |
||
3261 | if ($ident != "") |
||
3262 | { |
||
3263 | if (!is_string($ident)) |
||
3264 | { |
||
3265 | return false; |
||
3266 | } else { |
||
3267 | if (!is_numeric(substr($ident, 0, 3))) |
||
3268 | { |
||
3269 | $timeelapsed = microtime(true); |
||
3270 | if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
||
3271 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2),$fromsource); |
||
3272 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
||
3273 | $airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3),$fromsource); |
||
3274 | } else { |
||
3275 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3276 | } |
||
3277 | if (count($airline_array) == 0) { |
||
3278 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3279 | } |
||
3280 | if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){ |
||
3281 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3282 | } |
||
3283 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3284 | |||
3285 | } else { |
||
3286 | $timeelapsed = microtime(true); |
||
3287 | $airline_array = $this->getAllAirlineInfo("NA"); |
||
3288 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3289 | } |
||
3290 | } |
||
3291 | } else $airline_array = array(); |
||
3292 | |||
3293 | //getting the aircraft information |
||
3294 | $aircraft_array = array(); |
||
3295 | if ($aircraft_icao != "") |
||
3296 | { |
||
3297 | if (!is_string($aircraft_icao)) |
||
3298 | { |
||
3299 | return false; |
||
3300 | } else { |
||
3301 | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
||
3302 | { |
||
3303 | $timeelapsed = microtime(true); |
||
3304 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
3305 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3306 | } else { |
||
3307 | $timeelapsed = microtime(true); |
||
3308 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
3309 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3310 | } |
||
3311 | } |
||
3312 | } else { |
||
3313 | if ($ModeS != '') { |
||
3314 | $timeelapsed = microtime(true); |
||
3315 | $aircraft_icao = $this->getAllAircraftType($ModeS); |
||
3316 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAircraftType : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3317 | if ($aircraft_icao == "" || $aircraft_icao == "XXXX") |
||
3318 | { |
||
3319 | $timeelapsed = microtime(true); |
||
3320 | $aircraft_array = $this->getAllAircraftInfo("NA"); |
||
3321 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3322 | } else { |
||
3323 | $timeelapsed = microtime(true); |
||
3324 | $aircraft_array = $this->getAllAircraftInfo($aircraft_icao); |
||
3325 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3326 | } |
||
3327 | } |
||
3328 | } |
||
3329 | |||
3330 | //getting the departure airport information |
||
3331 | $departure_airport_array = array(); |
||
3332 | if ($departure_airport_icao != "") |
||
3333 | { |
||
3334 | if (!is_string($departure_airport_icao)) |
||
3335 | { |
||
3336 | return false; |
||
3337 | } else { |
||
3338 | $timeelapsed = microtime(true); |
||
3339 | $departure_airport_array = $this->getAllAirportInfo($departure_airport_icao); |
||
3340 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3341 | } |
||
3342 | } |
||
3343 | |||
3344 | //getting the arrival airport information |
||
3345 | $arrival_airport_array = array(); |
||
3346 | if ($arrival_airport_icao != "") |
||
3347 | { |
||
3348 | if (!is_string($arrival_airport_icao)) |
||
3349 | { |
||
3350 | return false; |
||
3351 | } else { |
||
3352 | $timeelapsed = microtime(true); |
||
3353 | $arrival_airport_array = $this->getAllAirportInfo($arrival_airport_icao); |
||
3354 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3355 | } |
||
3356 | } |
||
3357 | |||
3358 | |||
3359 | if ($latitude != "") |
||
3360 | { |
||
3361 | if (!is_numeric($latitude)) |
||
3362 | { |
||
3363 | return false; |
||
3364 | } |
||
3365 | } |
||
3366 | |||
3367 | if ($longitude != "") |
||
3368 | { |
||
3369 | if (!is_numeric($longitude)) |
||
3370 | { |
||
3371 | return false; |
||
3372 | } |
||
3373 | } |
||
3374 | |||
3375 | if ($waypoints != "") |
||
3376 | { |
||
3377 | if (!is_string($waypoints)) |
||
3378 | { |
||
3379 | return false; |
||
3380 | } |
||
3381 | } |
||
3382 | |||
3383 | if ($altitude != "") |
||
3384 | { |
||
3385 | if (!is_numeric($altitude)) |
||
3386 | { |
||
3387 | return false; |
||
3388 | } |
||
3389 | } else $altitude = 0; |
||
3390 | |||
3391 | if ($heading != "") |
||
3392 | { |
||
3393 | if (!is_numeric($heading)) |
||
3394 | { |
||
3395 | return false; |
||
3396 | } |
||
3397 | } |
||
3398 | |||
3399 | if ($groundspeed != "") |
||
3400 | { |
||
3401 | if (!is_numeric($groundspeed)) |
||
3402 | { |
||
3403 | return false; |
||
3404 | } |
||
3405 | } |
||
3406 | |||
3407 | |||
3408 | if ($date == "") |
||
3409 | { |
||
3410 | $date = date("Y-m-d H:i:s", time()); |
||
3411 | } |
||
3412 | |||
3413 | //getting the aircraft image |
||
3414 | if (($registration != "" || $registration != 'NA') && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM) |
||
3415 | { |
||
3416 | $timeelapsed = microtime(true); |
||
3417 | $image_array = $Image->getSpotterImage($registration); |
||
3418 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getSpotterImage : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3419 | if (!isset($image_array[0]['registration'])) |
||
3420 | { |
||
3421 | //echo "Add image !!!! \n"; |
||
3422 | $Image->addSpotterImage($registration); |
||
3423 | } |
||
3424 | $timeelapsed = microtime(true); |
||
3425 | $owner_info = $this->getAircraftOwnerByRegistration($registration); |
||
3426 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftOwnerByRegistration : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3427 | if ($owner_info['owner'] != '') $aircraft_owner = ucwords(strtolower($owner_info['owner'])); |
||
3428 | } |
||
3429 | |||
3430 | if ($globalIVAO && $aircraft_icao != '') |
||
3431 | { |
||
3432 | if (isset($airline_array[0]['icao'])) $airline_icao = $airline_array[0]['icao']; |
||
3433 | else $airline_icao = ''; |
||
3434 | $image_array = $Image->getSpotterImage('',$aircraft_icao,$airline_icao); |
||
3435 | if (!isset($image_array[0]['registration'])) |
||
3436 | { |
||
3437 | //echo "Add image !!!! \n"; |
||
3438 | $Image->addSpotterImage('',$aircraft_icao,$airline_icao); |
||
3439 | } |
||
3440 | } |
||
3441 | |||
3442 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
3443 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
3444 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
||
3445 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
3446 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
3447 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
3448 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
3449 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
3450 | $waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
||
3451 | $altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
3452 | $heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
||
3453 | $groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
3454 | $squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
||
3455 | $route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
||
3456 | $ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
||
3457 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
||
3458 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
3459 | $format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
||
3460 | $verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
||
3461 | |||
3462 | if (count($airline_array) == 0) |
||
3463 | { |
||
3464 | $airline_array = $this->getAllAirlineInfo('NA'); |
||
3465 | } |
||
3466 | if (count($aircraft_array) == 0) |
||
3467 | { |
||
3468 | $aircraft_array = $this->getAllAircraftInfo('NA'); |
||
3469 | } |
||
3470 | if (count($departure_airport_array) == 0) |
||
3471 | { |
||
3472 | $departure_airport_array = $this->getAllAirportInfo('NA'); |
||
3473 | } |
||
3474 | if (count($arrival_airport_array) == 0) |
||
3475 | { |
||
3476 | $arrival_airport_array = $this->getAllAirportInfo('NA'); |
||
3477 | } |
||
3478 | if ($registration == '') $registration = 'NA'; |
||
3479 | if ($squawk == '' || $Common->isInteger($squawk) === false) $squawk = NULL; |
||
3480 | if ($verticalrate == '' || $Common->isInteger($verticalrate) === false) $verticalrate = NULL; |
||
3481 | if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; |
||
3482 | if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; |
||
3483 | if (!isset($aircraft_owner)) $aircraft_owner = NULL; |
||
3484 | $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) |
||
3485 | 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)"; |
||
3486 | |||
3487 | $airline_name = $airline_array[0]['name']; |
||
3488 | $airline_icao = $airline_array[0]['icao']; |
||
3489 | $airline_country = $airline_array[0]['country']; |
||
3490 | $airline_type = $airline_array[0]['type']; |
||
3491 | if ($airline_type == '') { |
||
3492 | $timeelapsed = microtime(true); |
||
3493 | $airline_type = $this->getAircraftTypeBymodeS($ModeS); |
||
3494 | if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftTypeBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
3495 | } |
||
3496 | if ($airline_type == null) $airline_type = ''; |
||
3497 | $aircraft_type = $aircraft_array[0]['type']; |
||
3498 | $aircraft_manufacturer = $aircraft_array[0]['manufacturer']; |
||
3499 | $departure_airport_name = $departure_airport_array[0]['name']; |
||
3500 | $departure_airport_city = $departure_airport_array[0]['city']; |
||
3501 | $departure_airport_country = $departure_airport_array[0]['country']; |
||
3502 | $arrival_airport_name = $arrival_airport_array[0]['name']; |
||
3503 | $arrival_airport_city = $arrival_airport_array[0]['city']; |
||
3504 | $arrival_airport_country = $arrival_airport_array[0]['country']; |
||
3505 | $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); |
||
3506 | |||
3507 | try { |
||
3508 | |||
3509 | $sth = $this->db->prepare($query); |
||
3510 | $sth->execute($query_values); |
||
3511 | $this->db = null; |
||
3512 | } catch (PDOException $e) { |
||
3513 | return "error : ".$e->getMessage(); |
||
3514 | } |
||
3515 | |||
3516 | return "success"; |
||
3517 | |||
3518 | } |
||
3519 | |||
3520 | |||
3521 | /** |
||
3522 | * Gets the aircraft ident within the last hour |
||
3523 | * |
||
3524 | * @return String the ident |
||
3525 | * |
||
3526 | */ |
||
3527 | public function getIdentFromLastHour($ident) |
||
3528 | { |
||
3529 | global $globalDBdriver, $globalTimezone; |
||
3530 | if ($globalDBdriver == 'mysql') { |
||
3531 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
3532 | WHERE spotter_output.ident = :ident |
||
3533 | AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
||
3534 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
3535 | $query_data = array(':ident' => $ident); |
||
3536 | } else { |
||
3537 | $query = "SELECT spotter_output.ident FROM spotter_output |
||
3538 | WHERE spotter_output.ident = :ident |
||
3539 | AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
||
3540 | AND spotter_output.date < now() AT TIME ZONE 'UTC'"; |
||
3541 | $query_data = array(':ident' => $ident); |
||
3542 | } |
||
3543 | |||
3544 | $sth = $this->db->prepare($query); |
||
3545 | $sth->execute($query_data); |
||
3546 | $ident_result=''; |
||
3547 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3548 | { |
||
3549 | $ident_result = $row['ident']; |
||
3550 | } |
||
3551 | |||
3552 | return $ident_result; |
||
3553 | } |
||
3554 | |||
3555 | |||
3556 | /** |
||
3557 | * Gets the aircraft data from the last 20 seconds |
||
3558 | * |
||
3559 | * @return Array the spotter data |
||
3560 | * |
||
3561 | */ |
||
3562 | public function getRealTimeData($q = '') |
||
3563 | { |
||
3564 | global $globalDBdriver; |
||
3565 | $additional_query = ''; |
||
3566 | if ($q != "") |
||
3567 | { |
||
3568 | if (!is_string($q)) |
||
3569 | { |
||
3570 | return false; |
||
3571 | } else { |
||
3572 | $q_array = explode(" ", $q); |
||
3573 | foreach ($q_array as $q_item){ |
||
3574 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
||
3575 | $additional_query .= " AND ("; |
||
3576 | $additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR "; |
||
3577 | $additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR "; |
||
3578 | $additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
||
3579 | $additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR "; |
||
3580 | $additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR "; |
||
3581 | $additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR "; |
||
3582 | $additional_query .= "(spotter_output.registration like '%".$q_item."%') OR "; |
||
3583 | $additional_query .= "(spotter_output.ident like '%".$q_item."%')"; |
||
3584 | $additional_query .= ")"; |
||
3585 | } |
||
3586 | } |
||
3587 | } |
||
3588 | if ($globalDBdriver == 'mysql') { |
||
3589 | $query = "SELECT spotter_output.* FROM spotter_output |
||
3590 | WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." |
||
3591 | AND spotter_output.date < UTC_TIMESTAMP()"; |
||
3592 | } else { |
||
3593 | $query = "SELECT spotter_output.* FROM spotter_output |
||
3594 | WHERE spotter_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." |
||
3595 | AND spotter_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
||
3596 | } |
||
3597 | $spotter_array = $this->getDataFromDB($query, array()); |
||
3598 | |||
3599 | return $spotter_array; |
||
3600 | } |
||
3601 | |||
3602 | |||
3603 | |||
3604 | /** |
||
3605 | * Gets all airlines that have flown over |
||
3606 | * |
||
3607 | * @return Array the airline list |
||
3608 | * |
||
3609 | */ |
||
3610 | public function countAllAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
3611 | { |
||
3612 | global $globalDBdriver; |
||
3613 | $filter_query = $this->getFilter($filters,true,true); |
||
3614 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
3615 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND spotter_output.airline_icao <> 'NA' "; |
||
3616 | if ($olderthanmonths > 0) { |
||
3617 | if ($globalDBdriver == 'mysql') { |
||
3618 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
3619 | } else { |
||
3620 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
3621 | } |
||
3622 | } |
||
3623 | if ($sincedate != '') { |
||
3624 | if ($globalDBdriver == 'mysql') { |
||
3625 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
3626 | } else { |
||
3627 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
3628 | } |
||
3629 | } |
||
3630 | $query .= "GROUP BY spotter_output.airline_name,spotter_output.airline_icao, spotter_output.airline_country ORDER BY airline_count DESC"; |
||
3631 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
3632 | |||
3633 | $sth = $this->db->prepare($query); |
||
3634 | $sth->execute(); |
||
3635 | |||
3636 | $airline_array = array(); |
||
3637 | $temp_array = array(); |
||
3638 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3639 | { |
||
3640 | $temp_array['airline_name'] = $row['airline_name']; |
||
3641 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3642 | $temp_array['airline_count'] = $row['airline_count']; |
||
3643 | $temp_array['airline_country'] = $row['airline_country']; |
||
3644 | $airline_array[] = $temp_array; |
||
3645 | } |
||
3646 | return $airline_array; |
||
3647 | } |
||
3648 | |||
3649 | /** |
||
3650 | * Gets all pilots that have flown over |
||
3651 | * |
||
3652 | * @return Array the pilots list |
||
3653 | * |
||
3654 | */ |
||
3655 | public function countAllPilots($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
3656 | { |
||
3657 | global $globalDBdriver; |
||
3658 | $filter_query = $this->getFilter($filters,true,true); |
||
3659 | $query = "SELECT DISTINCT spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count |
||
3660 | FROM spotter_output".$filter_query." spotter_output.pilot_id <> '' "; |
||
3661 | if ($olderthanmonths > 0) { |
||
3662 | if ($globalDBdriver == 'mysql') { |
||
3663 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
3664 | } else { |
||
3665 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
3666 | } |
||
3667 | } |
||
3668 | if ($sincedate != '') { |
||
3669 | if ($globalDBdriver == 'mysql') { |
||
3670 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
3671 | } else { |
||
3672 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
3673 | } |
||
3674 | } |
||
3675 | $query .= "GROUP BY spotter_output.pilot_id,spotter_output.pilot_name ORDER BY pilot_count DESC"; |
||
3676 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
3677 | |||
3678 | |||
3679 | $sth = $this->db->prepare($query); |
||
3680 | $sth->execute(); |
||
3681 | |||
3682 | $airline_array = array(); |
||
3683 | $temp_array = array(); |
||
3684 | |||
3685 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3686 | { |
||
3687 | $temp_array['pilot_name'] = $row['pilot_name']; |
||
3688 | $temp_array['pilot_id'] = $row['pilot_id']; |
||
3689 | $temp_array['pilot_count'] = $row['pilot_count']; |
||
3690 | $airline_array[] = $temp_array; |
||
3691 | } |
||
3692 | return $airline_array; |
||
3693 | } |
||
3694 | |||
3695 | /** |
||
3696 | * Gets all pilots that have flown over |
||
3697 | * |
||
3698 | * @return Array the pilots list |
||
3699 | * |
||
3700 | */ |
||
3701 | public function countAllPilotsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '') |
||
3702 | { |
||
3703 | global $globalDBdriver; |
||
3704 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count |
||
3705 | FROM spotter_output WHERE spotter_output.pilot_id <> '' "; |
||
3706 | if ($olderthanmonths > 0) { |
||
3707 | if ($globalDBdriver == 'mysql') { |
||
3708 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
3709 | } else { |
||
3710 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
3711 | } |
||
3712 | } |
||
3713 | if ($sincedate != '') { |
||
3714 | if ($globalDBdriver == 'mysql') { |
||
3715 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
3716 | } else { |
||
3717 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
3718 | } |
||
3719 | } |
||
3720 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.pilot_id,spotter_output.pilot_name ORDER BY pilot_count DESC"; |
||
3721 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
3722 | |||
3723 | |||
3724 | $sth = $this->db->prepare($query); |
||
3725 | $sth->execute(); |
||
3726 | |||
3727 | $airline_array = array(); |
||
3728 | $temp_array = array(); |
||
3729 | |||
3730 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3731 | { |
||
3732 | $temp_array['pilot_name'] = $row['pilot_name']; |
||
3733 | $temp_array['pilot_id'] = $row['pilot_id']; |
||
3734 | $temp_array['pilot_count'] = $row['pilot_count']; |
||
3735 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3736 | $airline_array[] = $temp_array; |
||
3737 | } |
||
3738 | return $airline_array; |
||
3739 | } |
||
3740 | |||
3741 | /** |
||
3742 | * Gets all owner that have flown over |
||
3743 | * |
||
3744 | * @return Array the pilots list |
||
3745 | * |
||
3746 | */ |
||
3747 | public function countAllOwners($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
3748 | { |
||
3749 | global $globalDBdriver; |
||
3750 | $filter_query = $this->getFilter($filters,true,true); |
||
3751 | $query = "SELECT DISTINCT spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count |
||
3752 | FROM spotter_output".$filter_query." spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL "; |
||
3753 | if ($olderthanmonths > 0) { |
||
3754 | if ($globalDBdriver == 'mysql') { |
||
3755 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
3756 | } else { |
||
3757 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
3758 | } |
||
3759 | } |
||
3760 | if ($sincedate != '') { |
||
3761 | if ($globalDBdriver == 'mysql') { |
||
3762 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
3763 | } else { |
||
3764 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
3765 | } |
||
3766 | } |
||
3767 | $query .= "GROUP BY spotter_output.owner_name ORDER BY owner_count DESC"; |
||
3768 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
3769 | |||
3770 | |||
3771 | $sth = $this->db->prepare($query); |
||
3772 | $sth->execute(); |
||
3773 | |||
3774 | $airline_array = array(); |
||
3775 | $temp_array = array(); |
||
3776 | |||
3777 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3778 | { |
||
3779 | $temp_array['owner_name'] = $row['owner_name']; |
||
3780 | $temp_array['owner_count'] = $row['owner_count']; |
||
3781 | $airline_array[] = $temp_array; |
||
3782 | } |
||
3783 | return $airline_array; |
||
3784 | } |
||
3785 | |||
3786 | /** |
||
3787 | * Gets all owner that have flown over |
||
3788 | * |
||
3789 | * @return Array the pilots list |
||
3790 | * |
||
3791 | */ |
||
3792 | public function countAllOwnersByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
3793 | { |
||
3794 | global $globalDBdriver; |
||
3795 | $filter_query = $this->getFilter($filters,true,true); |
||
3796 | $query = "SELECT DISTINCT spotter_output.airline_icao, spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count |
||
3797 | FROM spotter_output".$filter_query." spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL "; |
||
3798 | if ($olderthanmonths > 0) { |
||
3799 | if ($globalDBdriver == 'mysql') { |
||
3800 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
3801 | } else { |
||
3802 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
3803 | } |
||
3804 | } |
||
3805 | if ($sincedate != '') { |
||
3806 | if ($globalDBdriver == 'mysql') { |
||
3807 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
3808 | } else { |
||
3809 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
3810 | } |
||
3811 | } |
||
3812 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.owner_name ORDER BY owner_count DESC"; |
||
3813 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
3814 | |||
3815 | |||
3816 | $sth = $this->db->prepare($query); |
||
3817 | $sth->execute(); |
||
3818 | |||
3819 | $airline_array = array(); |
||
3820 | $temp_array = array(); |
||
3821 | |||
3822 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3823 | { |
||
3824 | $temp_array['owner_name'] = $row['owner_name']; |
||
3825 | $temp_array['owner_count'] = $row['owner_count']; |
||
3826 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3827 | $airline_array[] = $temp_array; |
||
3828 | } |
||
3829 | return $airline_array; |
||
3830 | } |
||
3831 | |||
3832 | /** |
||
3833 | * Gets all airlines that have flown over by aircraft |
||
3834 | * |
||
3835 | * @return Array the airline list |
||
3836 | * |
||
3837 | */ |
||
3838 | public function countAllAirlinesByAircraft($aircraft_icao,$filters = array()) |
||
3839 | { |
||
3840 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
3841 | $filter_query = $this->getFilter($filters,true,true); |
||
3842 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
3843 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
3844 | GROUP BY spotter_output.airline_name |
||
3845 | ORDER BY airline_count DESC"; |
||
3846 | |||
3847 | |||
3848 | $sth = $this->db->prepare($query); |
||
3849 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
3850 | |||
3851 | $airline_array = array(); |
||
3852 | $temp_array = array(); |
||
3853 | |||
3854 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3855 | { |
||
3856 | $temp_array['airline_name'] = $row['airline_name']; |
||
3857 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3858 | $temp_array['airline_count'] = $row['airline_count']; |
||
3859 | $temp_array['airline_country'] = $row['airline_country']; |
||
3860 | |||
3861 | $airline_array[] = $temp_array; |
||
3862 | } |
||
3863 | |||
3864 | return $airline_array; |
||
3865 | } |
||
3866 | |||
3867 | |||
3868 | /** |
||
3869 | * Gets all airline countries that have flown over by aircraft |
||
3870 | * |
||
3871 | * @return Array the airline country list |
||
3872 | * |
||
3873 | */ |
||
3874 | public function countAllAirlineCountriesByAircraft($aircraft_icao,$filters = array()) |
||
3875 | { |
||
3876 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
3877 | $filter_query = $this->getFilter($filters,true,true); |
||
3878 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
3879 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
3880 | GROUP BY spotter_output.airline_country |
||
3881 | ORDER BY airline_country_count DESC |
||
3882 | LIMIT 10 OFFSET 0"; |
||
3883 | |||
3884 | |||
3885 | $sth = $this->db->prepare($query); |
||
3886 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
3887 | |||
3888 | $airline_country_array = array(); |
||
3889 | $temp_array = array(); |
||
3890 | |||
3891 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3892 | { |
||
3893 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
3894 | $temp_array['airline_country'] = $row['airline_country']; |
||
3895 | |||
3896 | $airline_country_array[] = $temp_array; |
||
3897 | } |
||
3898 | return $airline_country_array; |
||
3899 | } |
||
3900 | |||
3901 | |||
3902 | |||
3903 | |||
3904 | /** |
||
3905 | * Gets all airlines that have flown over by airport |
||
3906 | * |
||
3907 | * @return Array the airline list |
||
3908 | * |
||
3909 | */ |
||
3910 | public function countAllAirlinesByAirport($airport_icao,$filters = array()) |
||
3911 | { |
||
3912 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
3913 | $filter_query = $this->getFilter($filters,true,true); |
||
3914 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
3915 | FROM spotter_output".$filter_query." spotter_output.airline_name <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
3916 | GROUP BY spotter_output.airline_name |
||
3917 | ORDER BY airline_count DESC"; |
||
3918 | |||
3919 | |||
3920 | $sth = $this->db->prepare($query); |
||
3921 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
3922 | |||
3923 | $airline_array = array(); |
||
3924 | $temp_array = array(); |
||
3925 | |||
3926 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3927 | { |
||
3928 | $temp_array['airline_name'] = $row['airline_name']; |
||
3929 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3930 | $temp_array['airline_count'] = $row['airline_count']; |
||
3931 | $temp_array['airline_country'] = $row['airline_country']; |
||
3932 | |||
3933 | $airline_array[] = $temp_array; |
||
3934 | } |
||
3935 | return $airline_array; |
||
3936 | } |
||
3937 | |||
3938 | |||
3939 | /** |
||
3940 | * Gets all airline countries that have flown over by airport icao |
||
3941 | * |
||
3942 | * @return Array the airline country list |
||
3943 | * |
||
3944 | */ |
||
3945 | public function countAllAirlineCountriesByAirport($airport_icao,$filters = array()) |
||
3946 | { |
||
3947 | $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); |
||
3948 | $filter_query = $this->getFilter($filters,true,true); |
||
3949 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
3950 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) |
||
3951 | GROUP BY spotter_output.airline_country |
||
3952 | ORDER BY airline_country_count DESC |
||
3953 | LIMIT 10 OFFSET 0"; |
||
3954 | |||
3955 | |||
3956 | $sth = $this->db->prepare($query); |
||
3957 | $sth->execute(array(':airport_icao' => $airport_icao)); |
||
3958 | |||
3959 | $airline_country_array = array(); |
||
3960 | $temp_array = array(); |
||
3961 | |||
3962 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3963 | { |
||
3964 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
3965 | $temp_array['airline_country'] = $row['airline_country']; |
||
3966 | |||
3967 | $airline_country_array[] = $temp_array; |
||
3968 | } |
||
3969 | return $airline_country_array; |
||
3970 | } |
||
3971 | |||
3972 | |||
3973 | /** |
||
3974 | * Gets all airlines that have flown over by aircraft manufacturer |
||
3975 | * |
||
3976 | * @return Array the airline list |
||
3977 | * |
||
3978 | */ |
||
3979 | public function countAllAirlinesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
3980 | { |
||
3981 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
3982 | $filter_query = $this->getFilter($filters,true,true); |
||
3983 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
3984 | FROM spotter_output".$filter_query." spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
3985 | GROUP BY spotter_output.airline_name |
||
3986 | ORDER BY airline_count DESC"; |
||
3987 | |||
3988 | $sth = $this->db->prepare($query); |
||
3989 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
3990 | |||
3991 | $airline_array = array(); |
||
3992 | $temp_array = array(); |
||
3993 | |||
3994 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
3995 | { |
||
3996 | $temp_array['airline_name'] = $row['airline_name']; |
||
3997 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
3998 | $temp_array['airline_count'] = $row['airline_count']; |
||
3999 | $temp_array['airline_country'] = $row['airline_country']; |
||
4000 | |||
4001 | $airline_array[] = $temp_array; |
||
4002 | } |
||
4003 | return $airline_array; |
||
4004 | } |
||
4005 | |||
4006 | |||
4007 | |||
4008 | /** |
||
4009 | * Gets all airline countries that have flown over by aircraft manufacturer |
||
4010 | * |
||
4011 | * @return Array the airline country list |
||
4012 | * |
||
4013 | */ |
||
4014 | public function countAllAirlineCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
4015 | { |
||
4016 | $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
||
4017 | $filter_query = $this->getFilter($filters,true,true); |
||
4018 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4019 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer |
||
4020 | GROUP BY spotter_output.airline_country |
||
4021 | ORDER BY airline_country_count DESC |
||
4022 | LIMIT 10 OFFSET 0"; |
||
4023 | |||
4024 | |||
4025 | $sth = $this->db->prepare($query); |
||
4026 | $sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer)); |
||
4027 | |||
4028 | $airline_country_array = array(); |
||
4029 | $temp_array = array(); |
||
4030 | |||
4031 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4032 | { |
||
4033 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
4034 | $temp_array['airline_country'] = $row['airline_country']; |
||
4035 | $airline_country_array[] = $temp_array; |
||
4036 | } |
||
4037 | return $airline_country_array; |
||
4038 | } |
||
4039 | |||
4040 | |||
4041 | /** |
||
4042 | * Gets all airlines that have flown over by date |
||
4043 | * |
||
4044 | * @return Array the airline list |
||
4045 | * |
||
4046 | */ |
||
4047 | public function countAllAirlinesByDate($date,$filters = array()) |
||
4048 | { |
||
4049 | global $globalTimezone, $globalDBdriver; |
||
4050 | $filter_query = $this->getFilter($filters,true,true); |
||
4051 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
4052 | if ($globalTimezone != '') { |
||
4053 | date_default_timezone_set($globalTimezone); |
||
4054 | $datetime = new DateTime($date); |
||
4055 | $offset = $datetime->format('P'); |
||
4056 | } else $offset = '+00:00'; |
||
4057 | |||
4058 | if ($globalDBdriver == 'mysql') { |
||
4059 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
4060 | FROM spotter_output".$filter_query." DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
4061 | GROUP BY spotter_output.airline_name |
||
4062 | ORDER BY airline_count DESC"; |
||
4063 | } else { |
||
4064 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
4065 | FROM spotter_output".$filter_query." to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
4066 | GROUP BY spotter_output.airline_name |
||
4067 | ORDER BY airline_count DESC"; |
||
4068 | } |
||
4069 | |||
4070 | $sth = $this->db->prepare($query); |
||
4071 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
4072 | |||
4073 | $airline_array = array(); |
||
4074 | $temp_array = array(); |
||
4075 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4076 | { |
||
4077 | $temp_array['airline_name'] = $row['airline_name']; |
||
4078 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
4079 | $temp_array['airline_count'] = $row['airline_count']; |
||
4080 | $temp_array['airline_country'] = $row['airline_country']; |
||
4081 | |||
4082 | $airline_array[] = $temp_array; |
||
4083 | } |
||
4084 | |||
4085 | return $airline_array; |
||
4086 | } |
||
4087 | |||
4088 | |||
4089 | /** |
||
4090 | * Gets all airline countries that have flown over by date |
||
4091 | * |
||
4092 | * @return Array the airline country list |
||
4093 | * |
||
4094 | */ |
||
4095 | public function countAllAirlineCountriesByDate($date,$filters = array()) |
||
4096 | { |
||
4097 | global $globalTimezone, $globalDBdriver; |
||
4098 | $filter_query = $this->getFilter($filters,true,true); |
||
4099 | $date = filter_var($date,FILTER_SANITIZE_STRING); |
||
4100 | if ($globalTimezone != '') { |
||
4101 | date_default_timezone_set($globalTimezone); |
||
4102 | $datetime = new DateTime($date); |
||
4103 | $offset = $datetime->format('P'); |
||
4104 | } else $offset = '+00:00'; |
||
4105 | |||
4106 | if ($globalDBdriver == 'mysql') { |
||
4107 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4108 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date |
||
4109 | GROUP BY spotter_output.airline_country |
||
4110 | ORDER BY airline_country_count DESC |
||
4111 | LIMIT 10 OFFSET 0"; |
||
4112 | } else { |
||
4113 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4114 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date |
||
4115 | GROUP BY spotter_output.airline_country |
||
4116 | ORDER BY airline_country_count DESC |
||
4117 | LIMIT 10 OFFSET 0"; |
||
4118 | } |
||
4119 | |||
4120 | $sth = $this->db->prepare($query); |
||
4121 | $sth->execute(array(':date' => $date, ':offset' => $offset)); |
||
4122 | |||
4123 | $airline_country_array = array(); |
||
4124 | $temp_array = array(); |
||
4125 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4126 | { |
||
4127 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
4128 | $temp_array['airline_country'] = $row['airline_country']; |
||
4129 | |||
4130 | $airline_country_array[] = $temp_array; |
||
4131 | } |
||
4132 | return $airline_country_array; |
||
4133 | } |
||
4134 | |||
4135 | |||
4136 | /** |
||
4137 | * Gets all airlines that have flown over by ident/callsign |
||
4138 | * |
||
4139 | * @return Array the airline list |
||
4140 | * |
||
4141 | */ |
||
4142 | public function countAllAirlinesByIdent($ident,$filters = array()) |
||
4143 | { |
||
4144 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
4145 | $filter_query = $this->getFilter($filters,true,true); |
||
4146 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
4147 | FROM spotter_output".$filter_query." spotter_output.ident = :ident |
||
4148 | GROUP BY spotter_output.airline_name |
||
4149 | ORDER BY airline_count DESC"; |
||
4150 | |||
4151 | |||
4152 | $sth = $this->db->prepare($query); |
||
4153 | $sth->execute(array(':ident' => $ident)); |
||
4154 | |||
4155 | $airline_array = array(); |
||
4156 | $temp_array = array(); |
||
4157 | |||
4158 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4159 | { |
||
4160 | $temp_array['airline_name'] = $row['airline_name']; |
||
4161 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
4162 | $temp_array['airline_count'] = $row['airline_count']; |
||
4163 | $temp_array['airline_country'] = $row['airline_country']; |
||
4164 | |||
4165 | $airline_array[] = $temp_array; |
||
4166 | } |
||
4167 | return $airline_array; |
||
4168 | } |
||
4169 | |||
4170 | /** |
||
4171 | * Gets all airlines that have flown over by route |
||
4172 | * |
||
4173 | * @return Array the airline list |
||
4174 | * |
||
4175 | */ |
||
4176 | public function countAllAirlinesByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
4177 | { |
||
4178 | $filter_query = $this->getFilter($filters,true,true); |
||
4179 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
4180 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
4181 | |||
4182 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
4183 | FROM spotter_output".$filter_query." (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
4184 | GROUP BY spotter_output.airline_name |
||
4185 | ORDER BY airline_count DESC"; |
||
4186 | |||
4187 | |||
4188 | $sth = $this->db->prepare($query); |
||
4189 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
4190 | |||
4191 | $airline_array = array(); |
||
4192 | $temp_array = array(); |
||
4193 | |||
4194 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4195 | { |
||
4196 | $temp_array['airline_name'] = $row['airline_name']; |
||
4197 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
4198 | $temp_array['airline_count'] = $row['airline_count']; |
||
4199 | $temp_array['airline_country'] = $row['airline_country']; |
||
4200 | |||
4201 | $airline_array[] = $temp_array; |
||
4202 | } |
||
4203 | return $airline_array; |
||
4204 | } |
||
4205 | |||
4206 | /** |
||
4207 | * Gets all airline countries that have flown over by route |
||
4208 | * |
||
4209 | * @return Array the airline country list |
||
4210 | * |
||
4211 | */ |
||
4212 | public function countAllAirlineCountriesByRoute($departure_airport_icao, $arrival_airport_icao,$filters= array()) |
||
4213 | { |
||
4214 | $filter_query = $this->getFilter($filters,true,true); |
||
4215 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
4216 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
4217 | |||
4218 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4219 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) |
||
4220 | GROUP BY spotter_output.airline_country |
||
4221 | ORDER BY airline_country_count DESC |
||
4222 | LIMIT 10 OFFSET 0"; |
||
4223 | |||
4224 | |||
4225 | $sth = $this->db->prepare($query); |
||
4226 | $sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao)); |
||
4227 | |||
4228 | $airline_country_array = array(); |
||
4229 | $temp_array = array(); |
||
4230 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4231 | { |
||
4232 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
4233 | $temp_array['airline_country'] = $row['airline_country']; |
||
4234 | |||
4235 | $airline_country_array[] = $temp_array; |
||
4236 | } |
||
4237 | |||
4238 | return $airline_country_array; |
||
4239 | } |
||
4240 | |||
4241 | |||
4242 | /** |
||
4243 | * Gets all airlines that have flown over by country |
||
4244 | * |
||
4245 | * @return Array the airline list |
||
4246 | * |
||
4247 | */ |
||
4248 | public function countAllAirlinesByCountry($country,$filters = array()) |
||
4249 | { |
||
4250 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
4251 | $filter_query = $this->getFilter($filters,true,true); |
||
4252 | $query = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count |
||
4253 | FROM spotter_output".$filter_query." ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
4254 | GROUP BY spotter_output.airline_name |
||
4255 | ORDER BY airline_count DESC"; |
||
4256 | |||
4257 | |||
4258 | $sth = $this->db->prepare($query); |
||
4259 | $sth->execute(array(':country' => $country)); |
||
4260 | |||
4261 | $airline_array = array(); |
||
4262 | $temp_array = array(); |
||
4263 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4264 | { |
||
4265 | $temp_array['airline_name'] = $row['airline_name']; |
||
4266 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
4267 | $temp_array['airline_count'] = $row['airline_count']; |
||
4268 | $temp_array['airline_country'] = $row['airline_country']; |
||
4269 | |||
4270 | $airline_array[] = $temp_array; |
||
4271 | } |
||
4272 | return $airline_array; |
||
4273 | } |
||
4274 | |||
4275 | |||
4276 | /** |
||
4277 | * Gets all airline countries that have flown over by country |
||
4278 | * |
||
4279 | * @return Array the airline country list |
||
4280 | * |
||
4281 | */ |
||
4282 | public function countAllAirlineCountriesByCountry($country,$filters = array()) |
||
4283 | { |
||
4284 | $filter_query = $this->getFilter($filters,true,true); |
||
4285 | $country = filter_var($country,FILTER_SANITIZE_STRING); |
||
4286 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4287 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country |
||
4288 | GROUP BY spotter_output.airline_country |
||
4289 | ORDER BY airline_country_count DESC |
||
4290 | LIMIT 10 OFFSET 0"; |
||
4291 | |||
4292 | |||
4293 | $sth = $this->db->prepare($query); |
||
4294 | $sth->execute(array(':country' => $country)); |
||
4295 | |||
4296 | $airline_country_array = array(); |
||
4297 | $temp_array = array(); |
||
4298 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4299 | { |
||
4300 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
4301 | $temp_array['airline_country'] = $row['airline_country']; |
||
4302 | |||
4303 | $airline_country_array[] = $temp_array; |
||
4304 | } |
||
4305 | return $airline_country_array; |
||
4306 | } |
||
4307 | |||
4308 | |||
4309 | /** |
||
4310 | * Gets all airlines countries |
||
4311 | * |
||
4312 | * @return Array the airline country list |
||
4313 | * |
||
4314 | */ |
||
4315 | public function countAllAirlineCountries($limit = true, $filters = array()) |
||
4316 | { |
||
4317 | $filter_query = $this->getFilter($filters,true,true); |
||
4318 | $query = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count |
||
4319 | FROM spotter_output".$filter_query." spotter_output.airline_country <> '' AND spotter_output.airline_country <> 'NA' |
||
4320 | GROUP BY spotter_output.airline_country |
||
4321 | ORDER BY airline_country_count DESC"; |
||
4322 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
4323 | |||
4324 | $sth = $this->db->prepare($query); |
||
4325 | $sth->execute(); |
||
4326 | |||
4327 | $airline_array = array(); |
||
4328 | $temp_array = array(); |
||
4329 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4330 | { |
||
4331 | $temp_array['airline_country_count'] = $row['airline_country_count']; |
||
4332 | $temp_array['airline_country'] = $row['airline_country']; |
||
4333 | |||
4334 | $airline_array[] = $temp_array; |
||
4335 | } |
||
4336 | return $airline_array; |
||
4337 | } |
||
4338 | |||
4339 | /** |
||
4340 | * Gets all number of flight over countries |
||
4341 | * |
||
4342 | * @return Array the airline country list |
||
4343 | * |
||
4344 | */ |
||
4345 | public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') |
||
4346 | { |
||
4347 | global $globalDBdriver; |
||
4348 | //$filter_query = $this->getFilter($filters,true,true); |
||
4349 | $Connection= new Connection($this->db); |
||
4350 | if (!$Connection->tableExists('countries')) return array(); |
||
4351 | /* |
||
4352 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
4353 | FROM countries c, spotter_output s |
||
4354 | WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
||
4355 | */ |
||
4356 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
||
4357 | FROM countries c, spotter_live s |
||
4358 | WHERE c.iso2 = s.over_country "; |
||
4359 | if ($olderthanmonths > 0) { |
||
4360 | if ($globalDBdriver == 'mysql') { |
||
4361 | $query .= 'AND spotter_live.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
||
4362 | } else { |
||
4363 | $query .= "AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
||
4364 | } |
||
4365 | } |
||
4366 | if ($sincedate != '') { |
||
4367 | if ($globalDBdriver == 'mysql') { |
||
4368 | $query .= "AND spotter_live.date > '".$sincedate."' "; |
||
4369 | } else { |
||
4370 | $query .= "AND spotter_live.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
4371 | } |
||
4372 | } |
||
4373 | |||
4374 | $query .= "GROUP BY c.name ORDER BY nb DESC"; |
||
4375 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
4376 | |||
4377 | |||
4378 | $sth = $this->db->prepare($query); |
||
4379 | $sth->execute(); |
||
4380 | |||
4381 | $flight_array = array(); |
||
4382 | $temp_array = array(); |
||
4383 | |||
4384 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4385 | { |
||
4386 | $temp_array['flight_count'] = $row['nb']; |
||
4387 | $temp_array['flight_country'] = $row['name']; |
||
4388 | $temp_array['flight_country_iso3'] = $row['iso3']; |
||
4389 | $temp_array['flight_country_iso2'] = $row['iso2']; |
||
4390 | $flight_array[] = $temp_array; |
||
4391 | } |
||
4392 | return $flight_array; |
||
4393 | } |
||
4394 | |||
4395 | |||
4396 | /** |
||
4397 | * Gets all aircraft types that have flown over |
||
4398 | * |
||
4399 | * @return Array the aircraft list |
||
4400 | * |
||
4401 | */ |
||
4402 | public function countAllAircraftTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
4442 | |||
4443 | /** |
||
4444 | * Gets all aircraft types that have flown over by airline |
||
4445 | * |
||
4446 | * @return Array the aircraft list |
||
4447 | * |
||
4448 | */ |
||
4449 | public function countAllAircraftTypesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
4450 | { |
||
4451 | global $globalDBdriver; |
||
4452 | $filter_query = $this->getFilter($filters,true,true); |
||
4453 | $query = "SELECT spotter_output.airline_icao, spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer |
||
4454 | FROM spotter_output".$filter_query." spotter_output.aircraft_name <> '' AND spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao <>'' AND spotter_output.airline_icao <> 'NA' "; |
||
4455 | if ($olderthanmonths > 0) { |
||
4456 | if ($globalDBdriver == 'mysql') { |
||
4457 | $query .= 'AND spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) '; |
||
4458 | } else { |
||
4459 | $query .= "AND spotter_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' "; |
||
4460 | } |
||
4461 | } |
||
4462 | if ($sincedate != '') { |
||
4463 | if ($globalDBdriver == 'mysql') { |
||
4464 | $query .= "AND spotter_output.date > '".$sincedate."' "; |
||
4465 | } else { |
||
4466 | $query .= "AND spotter_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
||
4467 | } |
||
4468 | } |
||
4469 | |||
4470 | $query .= "GROUP BY spotter_output.airline_icao, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer ORDER BY aircraft_icao_count DESC"; |
||
4471 | if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
||
4472 | |||
4473 | $sth = $this->db->prepare($query); |
||
4474 | $sth->execute(); |
||
4475 | |||
4476 | $aircraft_array = array(); |
||
4477 | $temp_array = array(); |
||
4478 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4479 | { |
||
4480 | $temp_array['airline_icao'] = $row['airline_icao']; |
||
4481 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
4482 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
4483 | $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
||
4484 | $temp_array['aircraft_icao_count'] = $row['aircraft_icao_count']; |
||
4485 | $aircraft_array[] = $temp_array; |
||
4486 | } |
||
4487 | return $aircraft_array; |
||
4488 | } |
||
4489 | |||
4490 | |||
4491 | /** |
||
4492 | * Gets all aircraft registration that have flown over by aircaft icao |
||
4493 | * |
||
4494 | * @return Array the aircraft list |
||
4495 | * |
||
4496 | */ |
||
4497 | public function countAllAircraftRegistrationByAircraft($aircraft_icao,$filters = array()) |
||
4498 | { |
||
4499 | $Image = new Image($this->db); |
||
4500 | $filter_query = $this->getFilter($filters,true,true); |
||
4501 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
4502 | |||
4503 | $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 |
||
4504 | FROM spotter_output".$filter_query." spotter_output.registration <> '' AND spotter_output.aircraft_icao = :aircraft_icao |
||
4505 | GROUP BY spotter_output.registration |
||
4506 | ORDER BY registration_count DESC"; |
||
4507 | |||
4508 | $sth = $this->db->prepare($query); |
||
4509 | $sth->execute(array(':aircraft_icao' => $aircraft_icao)); |
||
4510 | |||
4511 | $aircraft_array = array(); |
||
4512 | $temp_array = array(); |
||
4513 | |||
4514 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
4515 | { |
||
4516 | $temp_array['aircraft_icao'] = $row['aircraft_icao']; |
||
4517 | $temp_array['aircraft_name'] = $row['aircraft_name']; |
||
4518 | $temp_array['registration'] = $row['registration']; |
||
4519 | $temp_array['airline_name'] = $row['airline_name']; |
||
4520 | $temp_array['image_thumbnail'] = ""; |
||
4521 | if($row['registration'] != "") |
||
4522 | { |
||
4523 | $image_array = $Image->getSpotterImage($row['registration']); |
||
4524 | if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
||
4525 | } |
||
4526 | $temp_array['registration_count'] = $row['registration_count']; |
||
4532 | |||
4533 | |||
4534 | /** |
||
4535 | * Gets all aircraft types that have flown over by airline icao |
||
4536 | * |
||
4537 | * @return Array the aircraft list |
||
4538 | * |
||
4539 | */ |
||
4540 | public function countAllAircraftTypesByAirline($airline_icao,$filters = array()) |
||
4565 | |||
4566 | |||
4567 | /** |
||
4568 | * Gets all aircraft registration that have flown over by airline icao |
||
4569 | * |
||
4570 | * @return Array the aircraft list |
||
4571 | * |
||
4572 | */ |
||
4573 | public function countAllAircraftRegistrationByAirline($airline_icao,$filters = array()) |
||
4607 | |||
4608 | |||
4609 | /** |
||
4610 | * Gets all aircraft manufacturer that have flown over by airline icao |
||
4611 | * |
||
4612 | * @return Array the aircraft list |
||
4613 | * |
||
4614 | */ |
||
4615 | public function countAllAircraftManufacturerByAirline($airline_icao,$filters = array()) |
||
4639 | |||
4640 | |||
4641 | /** |
||
4642 | * Gets all aircraft types that have flown over by airline icao |
||
4643 | * |
||
4644 | * @return Array the aircraft list |
||
4645 | * |
||
4646 | */ |
||
4647 | public function countAllAircraftTypesByAirport($airport_icao,$filters = array()) |
||
4672 | |||
4673 | |||
4674 | /** |
||
4675 | * Gets all aircraft registration that have flown over by airport icao |
||
4676 | * |
||
4677 | * @return Array the aircraft list |
||
4678 | * |
||
4679 | */ |
||
4680 | public function countAllAircraftRegistrationByAirport($airport_icao,$filters = array()) |
||
4714 | |||
4715 | |||
4716 | /** |
||
4717 | * Gets all aircraft manufacturer that have flown over by airport icao |
||
4718 | * |
||
4719 | * @return Array the aircraft list |
||
4720 | * |
||
4721 | */ |
||
4722 | public function countAllAircraftManufacturerByAirport($airport_icao,$filters = array()) |
||
4745 | |||
4746 | /** |
||
4747 | * Gets all aircraft types that have flown over by aircraft manufacturer |
||
4748 | * |
||
4749 | * @return Array the aircraft list |
||
4750 | * |
||
4751 | */ |
||
4752 | public function countAllAircraftTypesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
4775 | |||
4776 | |||
4777 | /** |
||
4778 | * Gets all aircraft registration that have flown over by aircaft manufacturer |
||
4779 | * |
||
4780 | * @return Array the aircraft list |
||
4781 | * |
||
4782 | */ |
||
4783 | public function countAllAircraftRegistrationByManufacturer($aircraft_manufacturer, $filters = array()) |
||
4816 | |||
4817 | /** |
||
4818 | * Gets all aircraft types that have flown over by date |
||
4819 | * |
||
4820 | * @return Array the aircraft list |
||
4821 | * |
||
4822 | */ |
||
4823 | public function countAllAircraftTypesByDate($date,$filters = array()) |
||
4861 | |||
4862 | |||
4863 | /** |
||
4864 | * Gets all aircraft registration that have flown over by date |
||
4865 | * |
||
4866 | * @return Array the aircraft list |
||
4867 | * |
||
4868 | */ |
||
4869 | public function countAllAircraftRegistrationByDate($date,$filters = array()) |
||
4916 | |||
4917 | |||
4918 | /** |
||
4919 | * Gets all aircraft manufacturer that have flown over by date |
||
4920 | * |
||
4921 | * @return Array the aircraft manufacturer list |
||
4922 | * |
||
4923 | */ |
||
4924 | public function countAllAircraftManufacturerByDate($date,$filters = array()) |
||
4962 | |||
4963 | |||
4964 | /** |
||
4965 | * Gets all aircraft types that have flown over by ident/callsign |
||
4966 | * |
||
4967 | * @return Array the aircraft list |
||
4968 | * |
||
4969 | */ |
||
4970 | public function countAllAircraftTypesByIdent($ident,$filters = array()) |
||
4995 | |||
4996 | |||
4997 | /** |
||
4998 | * Gets all aircraft registration that have flown over by ident/callsign |
||
4999 | * |
||
5000 | * @return Array the aircraft list |
||
5001 | * |
||
5002 | */ |
||
5003 | public function countAllAircraftRegistrationByIdent($ident,$filters = array()) |
||
5039 | |||
5040 | |||
5041 | /** |
||
5042 | * Gets all aircraft manufacturer that have flown over by ident/callsign |
||
5043 | * |
||
5044 | * @return Array the aircraft manufacturer list |
||
5045 | * |
||
5046 | */ |
||
5047 | public function countAllAircraftManufacturerByIdent($ident,$filters = array()) |
||
5069 | |||
5070 | |||
5071 | /** |
||
5072 | * Gets all aircraft types that have flown over by route |
||
5073 | * |
||
5074 | * @return Array the aircraft list |
||
5075 | * |
||
5076 | */ |
||
5077 | public function countAllAircraftTypesByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
5103 | |||
5104 | /** |
||
5105 | * Gets all aircraft registration that have flown over by route |
||
5106 | * |
||
5107 | * @return Array the aircraft list |
||
5108 | * |
||
5109 | */ |
||
5110 | public function countAllAircraftRegistrationByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
5148 | |||
5149 | |||
5150 | /** |
||
5151 | * Gets all aircraft manufacturer that have flown over by route |
||
5152 | * |
||
5153 | * @return Array the aircraft manufacturer list |
||
5154 | * |
||
5155 | */ |
||
5156 | public function countAllAircraftManufacturerByRoute($departure_airport_icao, $arrival_airport_icao,$filters = array()) |
||
5184 | |||
5185 | |||
5186 | |||
5187 | |||
5188 | /** |
||
5189 | * Gets all aircraft types that have flown over by country |
||
5190 | * |
||
5191 | * @return Array the aircraft list |
||
5192 | * |
||
5193 | */ |
||
5194 | public function countAllAircraftTypesByCountry($country,$filters = array()) |
||
5221 | |||
5222 | |||
5223 | /** |
||
5224 | * Gets all aircraft registration that have flown over by country |
||
5225 | * |
||
5226 | * @return Array the aircraft list |
||
5227 | * |
||
5228 | */ |
||
5229 | public function countAllAircraftRegistrationByCountry($country,$filters = array()) |
||
5265 | |||
5266 | |||
5267 | /** |
||
5268 | * Gets all aircraft manufacturer that have flown over by country |
||
5269 | * |
||
5270 | * @return Array the aircraft manufacturer list |
||
5271 | * |
||
5272 | */ |
||
5273 | public function countAllAircraftManufacturerByCountry($country,$filters = array()) |
||
5299 | |||
5300 | |||
5301 | |||
5302 | /** |
||
5303 | * Gets all aircraft manufacturers that have flown over |
||
5304 | * |
||
5305 | * @return Array the aircraft list |
||
5306 | * |
||
5307 | */ |
||
5308 | public function countAllAircraftManufacturers($filters = array()) |
||
5334 | |||
5335 | |||
5336 | |||
5337 | /** |
||
5338 | * Gets all aircraft registrations that have flown over |
||
5339 | * |
||
5340 | * @return Array the aircraft list |
||
5341 | * |
||
5342 | */ |
||
5343 | public function countAllAircraftRegistrations($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
5395 | |||
5396 | |||
5397 | /** |
||
5398 | * Gets all aircraft registrations that have flown over |
||
5399 | * |
||
5400 | * @return Array the aircraft list |
||
5401 | * |
||
5402 | */ |
||
5403 | public function countAllAircraftRegistrationsByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) |
||
5456 | |||
5457 | |||
5458 | /** |
||
5459 | * Gets all departure airports of the airplanes that have flown over |
||
5460 | * |
||
5461 | * @return Array the airport list |
||
5462 | * |
||
5463 | */ |
||
5464 | public function countAllDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
5509 | |||
5510 | /** |
||
5511 | * Gets all departure airports of the airplanes that have flown over |
||
5512 | * |
||
5513 | * @return Array the airport list |
||
5514 | * |
||
5515 | */ |
||
5516 | public function countAllDepartureAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
5562 | |||
5563 | /** |
||
5564 | * Gets all detected departure airports of the airplanes that have flown over |
||
5565 | * |
||
5566 | * @return Array the airport list |
||
5567 | * |
||
5568 | */ |
||
5569 | public function countAllDetectedDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
5613 | |||
5614 | /** |
||
5615 | * Gets all detected departure airports of the airplanes that have flown over |
||
5616 | * |
||
5617 | * @return Array the airport list |
||
5618 | * |
||
5619 | */ |
||
5620 | public function countAllDetectedDepartureAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
5666 | |||
5667 | /** |
||
5668 | * Gets all departure airports of the airplanes that have flown over based on an airline icao |
||
5669 | * |
||
5670 | * @return Array the airport list |
||
5671 | * |
||
5672 | */ |
||
5673 | public function countAllDepartureAirportsByAirline($airline_icao,$filters = array()) |
||
5702 | |||
5703 | |||
5704 | |||
5705 | /** |
||
5706 | * Gets all departure airports by country of the airplanes that have flown over based on an airline icao |
||
5707 | * |
||
5708 | * @return Array the airport list |
||
5709 | * |
||
5710 | */ |
||
5711 | public function countAllDepartureAirportCountriesByAirline($airline_icao,$filters = array()) |
||
5737 | |||
5738 | |||
5739 | |||
5740 | /** |
||
5741 | * Gets all departure airports of the airplanes that have flown over based on an aircraft icao |
||
5742 | * |
||
5743 | * @return Array the airport list |
||
5744 | * |
||
5745 | */ |
||
5746 | public function countAllDepartureAirportsByAircraft($aircraft_icao,$filters = array()) |
||
5775 | |||
5776 | |||
5777 | /** |
||
5778 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
5779 | * |
||
5780 | * @return Array the airport list |
||
5781 | * |
||
5782 | */ |
||
5783 | public function countAllDepartureAirportCountriesByAircraft($aircraft_icao,$filters = array()) |
||
5809 | |||
5810 | |||
5811 | /** |
||
5812 | * Gets all departure airports of the airplanes that have flown over based on an aircraft registration |
||
5813 | * |
||
5814 | * @return Array the airport list |
||
5815 | * |
||
5816 | */ |
||
5817 | public function countAllDepartureAirportsByRegistration($registration,$filters = array()) |
||
5846 | |||
5847 | |||
5848 | /** |
||
5849 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft registration |
||
5850 | * |
||
5851 | * @return Array the airport list |
||
5852 | * |
||
5853 | */ |
||
5854 | public function countAllDepartureAirportCountriesByRegistration($registration,$filters = array()) |
||
5880 | |||
5881 | |||
5882 | /** |
||
5883 | * Gets all departure airports of the airplanes that have flown over based on an arrivl airport icao |
||
5884 | * |
||
5885 | * @return Array the airport list |
||
5886 | * |
||
5887 | */ |
||
5888 | public function countAllDepartureAirportsByAirport($airport_icao,$filters = array()) |
||
5917 | |||
5918 | |||
5919 | /** |
||
5920 | * Gets all departure airports by country of the airplanes that have flown over based on an airport icao |
||
5921 | * |
||
5922 | * @return Array the airport list |
||
5923 | * |
||
5924 | */ |
||
5925 | public function countAllDepartureAirportCountriesByAirport($airport_icao,$filters = array()) |
||
5951 | |||
5952 | |||
5953 | |||
5954 | /** |
||
5955 | * Gets all departure airports of the airplanes that have flown over based on an aircraft manufacturer |
||
5956 | * |
||
5957 | * @return Array the airport list |
||
5958 | * |
||
5959 | */ |
||
5960 | public function countAllDepartureAirportsByManufacturer($aircraft_manufacturer,$filters = array()) |
||
5989 | |||
5990 | |||
5991 | /** |
||
5992 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft manufacturer |
||
5993 | * |
||
5994 | * @return Array the airport list |
||
5995 | * |
||
5996 | */ |
||
5997 | public function countAllDepartureAirportCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
6023 | |||
6024 | |||
6025 | /** |
||
6026 | * Gets all departure airports of the airplanes that have flown over based on a date |
||
6027 | * |
||
6028 | * @return Array the airport list |
||
6029 | * |
||
6030 | */ |
||
6031 | public function countAllDepartureAirportsByDate($date,$filters = array()) |
||
6072 | |||
6073 | |||
6074 | |||
6075 | /** |
||
6076 | * Gets all departure airports by country of the airplanes that have flown over based on a date |
||
6077 | * |
||
6078 | * @return Array the airport list |
||
6079 | * |
||
6080 | */ |
||
6081 | public function countAllDepartureAirportCountriesByDate($date,$filters = array()) |
||
6119 | |||
6120 | |||
6121 | |||
6122 | /** |
||
6123 | * Gets all departure airports of the airplanes that have flown over based on a ident/callsign |
||
6124 | * |
||
6125 | * @return Array the airport list |
||
6126 | * |
||
6127 | */ |
||
6128 | public function countAllDepartureAirportsByIdent($ident,$filters = array()) |
||
6157 | |||
6158 | |||
6159 | |||
6160 | /** |
||
6161 | * Gets all departure airports by country of the airplanes that have flown over based on a callsign/ident |
||
6162 | * |
||
6163 | * @return Array the airport list |
||
6164 | * |
||
6165 | */ |
||
6166 | public function countAllDepartureAirportCountriesByIdent($ident,$filters = array()) |
||
6192 | |||
6193 | |||
6194 | |||
6195 | /** |
||
6196 | * Gets all departure airports of the airplanes that have flown over based on a country |
||
6197 | * |
||
6198 | * @return Array the airport list |
||
6199 | * |
||
6200 | */ |
||
6201 | public function countAllDepartureAirportsByCountry($country,$filters = array()) |
||
6231 | |||
6232 | |||
6233 | /** |
||
6234 | * Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao |
||
6235 | * |
||
6236 | * @return Array the airport list |
||
6237 | * |
||
6238 | */ |
||
6239 | public function countAllDepartureAirportCountriesByCountry($country,$filters = array()) |
||
6265 | |||
6266 | |||
6267 | /** |
||
6268 | * Gets all arrival airports of the airplanes that have flown over |
||
6269 | * |
||
6270 | * @return Array the airport list |
||
6271 | * |
||
6272 | */ |
||
6273 | public function countAllArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false,$filters = array()) |
||
6328 | |||
6329 | /** |
||
6330 | * Gets all arrival airports of the airplanes that have flown over |
||
6331 | * |
||
6332 | * @return Array the airport list |
||
6333 | * |
||
6334 | */ |
||
6335 | public function countAllArrivalAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false,$filters = array()) |
||
6391 | |||
6392 | |||
6393 | /** |
||
6394 | * Gets all detected arrival airports of the airplanes that have flown over |
||
6395 | * |
||
6396 | * @return Array the airport list |
||
6397 | * |
||
6398 | */ |
||
6399 | public function countAllDetectedArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false,$filters = array()) |
||
6453 | |||
6454 | /** |
||
6455 | * Gets all detected arrival airports of the airplanes that have flown over |
||
6456 | * |
||
6457 | * @return Array the airport list |
||
6458 | * |
||
6459 | */ |
||
6460 | public function countAllDetectedArrivalAirportsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false,$filters = array()) |
||
6516 | |||
6517 | /** |
||
6518 | * Gets all arrival airports of the airplanes that have flown over based on an airline icao |
||
6519 | * |
||
6520 | * @return Array the airport list |
||
6521 | * |
||
6522 | */ |
||
6523 | public function countAllArrivalAirportsByAirline($airline_icao, $filters = array()) |
||
6551 | |||
6552 | |||
6553 | /** |
||
6554 | * Gets all arrival airports by country of the airplanes that have flown over based on an airline icao |
||
6555 | * |
||
6556 | * @return Array the airport list |
||
6557 | * |
||
6558 | */ |
||
6559 | public function countAllArrivalAirportCountriesByAirline($airline_icao,$filters = array()) |
||
6586 | |||
6587 | |||
6588 | /** |
||
6589 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft icao |
||
6590 | * |
||
6591 | * @return Array the airport list |
||
6592 | * |
||
6593 | */ |
||
6594 | public function countAllArrivalAirportsByAircraft($aircraft_icao,$filters = array()) |
||
6623 | |||
6624 | |||
6625 | |||
6626 | /** |
||
6627 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft icao |
||
6628 | * |
||
6629 | * @return Array the airport list |
||
6630 | * |
||
6631 | */ |
||
6632 | public function countAllArrivalAirportCountriesByAircraft($aircraft_icao,$filters = array()) |
||
6658 | |||
6659 | |||
6660 | /** |
||
6661 | * Gets all arrival airports of the airplanes that have flown over based on an aircraft registration |
||
6662 | * |
||
6663 | * @return Array the airport list |
||
6664 | * |
||
6665 | */ |
||
6666 | public function countAllArrivalAirportsByRegistration($registration,$filters = array()) |
||
6696 | |||
6697 | |||
6698 | /** |
||
6699 | * Gets all arrival airports by country of the airplanes that have flown over based on an aircraft registration |
||
6700 | * |
||
6701 | * @return Array the airport list |
||
6702 | * |
||
6703 | */ |
||
6704 | public function countAllArrivalAirportCountriesByRegistration($registration,$filters = array()) |
||
6730 | |||
6731 | |||
6732 | |||
6733 | /** |
||
6734 | * Gets all arrival airports of the airplanes that have flown over based on an departure airport |
||
6735 | * |
||
6736 | * @return Array the airport list |
||
6737 | * |
||
6738 | */ |
||
6739 | public function countAllArrivalAirportsByAirport($airport_icao,$filters = array()) |
||
6768 | |||
6769 | |||
6770 | /** |
||
6771 | * Gets all arrival airports by country of the airplanes that have flown over based on an airport icao |
||
6772 | * |
||
6773 | * @return Array the airport list |
||
6774 | * |
||
6775 | */ |
||
6776 | public function countAllArrivalAirportCountriesByAirport($airport_icao,$filters = array()) |
||
6802 | |||
6803 | |||
6804 | /** |
||
6805 | * Gets all arrival airports of the airplanes that have flown over based on a aircraft manufacturer |
||
6806 | * |
||
6807 | * @return Array the airport list |
||
6808 | * |
||
6809 | */ |
||
6810 | public function countAllArrivalAirportsByManufacturer($aircraft_manufacturer,$filters = array()) |
||
6839 | |||
6840 | |||
6841 | |||
6842 | /** |
||
6843 | * Gets all arrival airports by country of the airplanes that have flown over based on a aircraft manufacturer |
||
6844 | * |
||
6845 | * @return Array the airport list |
||
6846 | * |
||
6847 | */ |
||
6848 | public function countAllArrivalAirportCountriesByManufacturer($aircraft_manufacturer,$filters = array()) |
||
6874 | |||
6875 | |||
6876 | |||
6877 | /** |
||
6878 | * Gets all arrival airports of the airplanes that have flown over based on a date |
||
6879 | * |
||
6880 | * @return Array the airport list |
||
6881 | * |
||
6882 | */ |
||
6883 | public function countAllArrivalAirportsByDate($date,$filters = array()) |
||
6924 | |||
6925 | |||
6926 | |||
6927 | /** |
||
6928 | * Gets all arrival airports by country of the airplanes that have flown over based on a date |
||
6929 | * |
||
6930 | * @return Array the airport list |
||
6931 | * |
||
6932 | */ |
||
6933 | public function countAllArrivalAirportCountriesByDate($date, $filters = array()) |
||
6971 | |||
6972 | |||
6973 | |||
6974 | /** |
||
6975 | * Gets all arrival airports of the airplanes that have flown over based on a ident/callsign |
||
6976 | * |
||
6977 | * @return Array the airport list |
||
6978 | * |
||
6979 | */ |
||
6980 | public function countAllArrivalAirportsByIdent($ident,$filters = array()) |
||
7009 | |||
7010 | |||
7011 | /** |
||
7012 | * Gets all arrival airports by country of the airplanes that have flown over based on a callsign/ident |
||
7013 | * |
||
7014 | * @return Array the airport list |
||
7015 | * |
||
7016 | */ |
||
7017 | public function countAllArrivalAirportCountriesByIdent($ident, $filters = array()) |
||
7043 | |||
7044 | |||
7045 | |||
7046 | /** |
||
7047 | * Gets all arrival airports of the airplanes that have flown over based on a country |
||
7048 | * |
||
7049 | * @return Array the airport list |
||
7050 | * |
||
7051 | */ |
||
7052 | public function countAllArrivalAirportsByCountry($country,$filters = array()) |
||
7081 | |||
7082 | |||
7083 | /** |
||
7084 | * Gets all arrival airports by country of the airplanes that have flown over based on a country |
||
7085 | * |
||
7086 | * @return Array the airport list |
||
7087 | * |
||
7088 | */ |
||
7089 | public function countAllArrivalAirportCountriesByCountry($country,$filters = array()) |
||
7115 | |||
7116 | |||
7117 | |||
7118 | /** |
||
7119 | * Counts all airport departure countries |
||
7120 | * |
||
7121 | * @return Array the airport departure list |
||
7122 | * |
||
7123 | */ |
||
7124 | public function countAllDepartureCountries($filters = array()) |
||
7150 | |||
7151 | |||
7152 | /** |
||
7153 | * Counts all airport arrival countries |
||
7154 | * |
||
7155 | * @return Array the airport arrival list |
||
7156 | * |
||
7157 | */ |
||
7158 | public function countAllArrivalCountries($limit = true,$filters = array()) |
||
7184 | |||
7185 | |||
7186 | |||
7187 | |||
7188 | |||
7189 | /** |
||
7190 | * Gets all route combinations |
||
7191 | * |
||
7192 | * @return Array the route list |
||
7193 | * |
||
7194 | */ |
||
7195 | public function countAllRoutes($filters = array()) |
||
7228 | |||
7229 | |||
7230 | |||
7231 | |||
7232 | /** |
||
7233 | * Gets all route combinations based on an aircraft |
||
7234 | * |
||
7235 | * @return Array the route list |
||
7236 | * |
||
7237 | */ |
||
7238 | public function countAllRoutesByAircraft($aircraft_icao,$filters = array()) |
||
7270 | |||
7271 | |||
7272 | /** |
||
7273 | * Gets all route combinations based on an aircraft registration |
||
7274 | * |
||
7275 | * @return Array the route list |
||
7276 | * |
||
7277 | */ |
||
7278 | public function countAllRoutesByRegistration($registration, $filters = array()) |
||
7311 | |||
7312 | |||
7313 | |||
7314 | /** |
||
7315 | * Gets all route combinations based on an airline |
||
7316 | * |
||
7317 | * @return Array the route list |
||
7318 | * |
||
7319 | */ |
||
7320 | public function countAllRoutesByAirline($airline_icao, $filters = array()) |
||
7353 | |||
7354 | |||
7355 | |||
7356 | /** |
||
7357 | * Gets all route combinations based on an airport |
||
7358 | * |
||
7359 | * @return Array the route list |
||
7360 | * |
||
7361 | */ |
||
7362 | public function countAllRoutesByAirport($airport_icao, $filters = array()) |
||
7394 | |||
7395 | |||
7396 | |||
7397 | /** |
||
7398 | * Gets all route combinations based on an country |
||
7399 | * |
||
7400 | * @return Array the route list |
||
7401 | * |
||
7402 | */ |
||
7403 | public function countAllRoutesByCountry($country, $filters = array()) |
||
7435 | |||
7436 | |||
7437 | /** |
||
7438 | * Gets all route combinations based on an date |
||
7439 | * |
||
7440 | * @return Array the route list |
||
7441 | * |
||
7442 | */ |
||
7443 | public function countAllRoutesByDate($date, $filters = array()) |
||
7489 | |||
7490 | |||
7491 | /** |
||
7492 | * Gets all route combinations based on an ident/callsign |
||
7493 | * |
||
7494 | * @return Array the route list |
||
7495 | * |
||
7496 | */ |
||
7497 | public function countAllRoutesByIdent($ident, $filters = array()) |
||
7530 | |||
7531 | |||
7532 | /** |
||
7533 | * Gets all route combinations based on an manufacturer |
||
7534 | * |
||
7535 | * @return Array the route list |
||
7536 | * |
||
7537 | */ |
||
7538 | public function countAllRoutesByManufacturer($aircraft_manufacturer, $filters = array()) |
||
7571 | |||
7572 | |||
7573 | |||
7574 | /** |
||
7575 | * Gets all route combinations with waypoints |
||
7576 | * |
||
7577 | * @return Array the route list |
||
7578 | * |
||
7579 | */ |
||
7580 | public function countAllRoutesWithWaypoints($filters = array()) |
||
7614 | |||
7615 | /** |
||
7616 | * Gets all callsigns that have flown over |
||
7617 | * |
||
7618 | * @return Array the callsign list |
||
7619 | * |
||
7620 | */ |
||
7621 | public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array()) |
||
7656 | |||
7657 | /** |
||
7658 | * Gets all callsigns that have flown over |
||
7659 | * |
||
7660 | * @return Array the callsign list |
||
7661 | * |
||
7662 | */ |
||
7663 | public function countAllCallsignsByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array()) |
||
7698 | |||
7699 | |||
7700 | |||
7701 | |||
7702 | /** |
||
7703 | * Counts all dates |
||
7704 | * |
||
7705 | * @return Array the date list |
||
7706 | * |
||
7707 | */ |
||
7708 | public function countAllDates($filters = array()) |
||
7750 | |||
7751 | /** |
||
7752 | * Counts all dates |
||
7753 | * |
||
7754 | * @return Array the date list |
||
7755 | * |
||
7756 | */ |
||
7757 | public function countAllDatesByAirlines($filters = array()) |
||
7799 | |||
7800 | /** |
||
7801 | * Counts all dates during the last 7 days |
||
7802 | * |
||
7803 | * @return Array the date list |
||
7804 | * |
||
7805 | */ |
||
7806 | public function countAllDatesLast7Days($filters = array()) |
||
7845 | |||
7846 | /** |
||
7847 | * Counts all dates during the last month |
||
7848 | * |
||
7849 | * @return Array the date list |
||
7850 | * |
||
7851 | */ |
||
7852 | public function countAllDatesLastMonth($filters = array()) |
||
7891 | |||
7892 | |||
7893 | /** |
||
7894 | * Counts all dates during the last month |
||
7895 | * |
||
7896 | * @return Array the date list |
||
7897 | * |
||
7898 | */ |
||
7899 | public function countAllDatesLastMonthByAirlines($filters = array()) |
||
7940 | |||
7941 | |||
7942 | /** |
||
7943 | * Counts all month |
||
7944 | * |
||
7945 | * @return Array the month list |
||
7946 | * |
||
7947 | */ |
||
7948 | public function countAllMonths($filters = array()) |
||
7987 | |||
7988 | /** |
||
7989 | * Counts all month |
||
7990 | * |
||
7991 | * @return Array the month list |
||
7992 | * |
||
7993 | */ |
||
7994 | public function countAllMonthsByAirlines($filters = array()) |
||
8036 | |||
8037 | /** |
||
8038 | * Counts all military month |
||
8039 | * |
||
8040 | * @return Array the month list |
||
8041 | * |
||
8042 | */ |
||
8043 | public function countAllMilitaryMonths($filters = array()) |
||
8081 | |||
8082 | /** |
||
8083 | * Counts all month owners |
||
8084 | * |
||
8085 | * @return Array the month list |
||
8086 | * |
||
8087 | */ |
||
8088 | public function countAllMonthsOwners($filters = array()) |
||
8127 | |||
8128 | /** |
||
8129 | * Counts all month owners |
||
8130 | * |
||
8131 | * @return Array the month list |
||
8132 | * |
||
8133 | */ |
||
8134 | public function countAllMonthsOwnersByAirlines($filters = array()) |
||
8174 | |||
8175 | /** |
||
8176 | * Counts all month pilot |
||
8177 | * |
||
8178 | * @return Array the month list |
||
8179 | * |
||
8180 | */ |
||
8181 | public function countAllMonthsPilots($filters = array()) |
||
8220 | |||
8221 | /** |
||
8222 | * Counts all month pilot |
||
8223 | * |
||
8224 | * @return Array the month list |
||
8225 | * |
||
8226 | */ |
||
8227 | public function countAllMonthsPilotsByAirlines($filters = array()) |
||
8267 | |||
8268 | /** |
||
8269 | * Counts all month airline |
||
8270 | * |
||
8271 | * @return Array the month list |
||
8272 | * |
||
8273 | */ |
||
8274 | public function countAllMonthsAirlines($filters = array()) |
||
8313 | |||
8314 | /** |
||
8315 | * Counts all month aircraft |
||
8316 | * |
||
8317 | * @return Array the month list |
||
8318 | * |
||
8319 | */ |
||
8320 | public function countAllMonthsAircrafts($filters = array()) |
||
8359 | |||
8360 | |||
8361 | /** |
||
8362 | * Counts all month aircraft |
||
8363 | * |
||
8364 | * @return Array the month list |
||
8365 | * |
||
8366 | */ |
||
8367 | public function countAllMonthsAircraftsByAirlines($filters = array()) |
||
8407 | |||
8408 | /** |
||
8409 | * Counts all month real arrival |
||
8410 | * |
||
8411 | * @return Array the month list |
||
8412 | * |
||
8413 | */ |
||
8414 | public function countAllMonthsRealArrivals($filters = array()) |
||
8453 | |||
8454 | |||
8455 | /** |
||
8456 | * Counts all month real arrival |
||
8457 | * |
||
8458 | * @return Array the month list |
||
8459 | * |
||
8460 | */ |
||
8461 | public function countAllMonthsRealArrivalsByAirlines($filters = array()) |
||
8501 | |||
8502 | |||
8503 | /** |
||
8504 | * Counts all dates during the last year |
||
8505 | * |
||
8506 | * @return Array the date list |
||
8507 | * |
||
8508 | */ |
||
8509 | public function countAllMonthsLastYear($filters) |
||
8549 | |||
8550 | |||
8551 | |||
8552 | /** |
||
8553 | * Counts all hours |
||
8554 | * |
||
8555 | * @return Array the hour list |
||
8556 | * |
||
8557 | */ |
||
8558 | public function countAllHours($orderby,$filters = array()) |
||
8616 | |||
8617 | /** |
||
8618 | * Counts all hours |
||
8619 | * |
||
8620 | * @return Array the hour list |
||
8621 | * |
||
8622 | */ |
||
8623 | public function countAllHoursByAirlines($orderby, $filters = array()) |
||
8681 | |||
8682 | |||
8683 | |||
8684 | /** |
||
8685 | * Counts all hours by airline |
||
8686 | * |
||
8687 | * @return Array the hour list |
||
8688 | * |
||
8689 | */ |
||
8690 | public function countAllHoursByAirline($airline_icao, $filters = array()) |
||
8730 | |||
8731 | |||
8732 | |||
8733 | |||
8734 | /** |
||
8735 | * Counts all hours by aircraft |
||
8736 | * |
||
8737 | * @return Array the hour list |
||
8738 | * |
||
8739 | */ |
||
8740 | public function countAllHoursByAircraft($aircraft_icao, $filters = array()) |
||
8779 | |||
8780 | |||
8781 | /** |
||
8782 | * Counts all hours by aircraft registration |
||
8783 | * |
||
8784 | * @return Array the hour list |
||
8785 | * |
||
8786 | */ |
||
8787 | public function countAllHoursByRegistration($registration, $filters = array()) |
||
8826 | |||
8827 | |||
8828 | /** |
||
8829 | * Counts all hours by airport |
||
8830 | * |
||
8831 | * @return Array the hour list |
||
8832 | * |
||
8833 | */ |
||
8834 | public function countAllHoursByAirport($airport_icao, $filters = array()) |
||
8873 | |||
8874 | |||
8875 | |||
8876 | /** |
||
8877 | * Counts all hours by manufacturer |
||
8878 | * |
||
8879 | * @return Array the hour list |
||
8880 | * |
||
8881 | */ |
||
8882 | public function countAllHoursByManufacturer($aircraft_manufacturer,$filters =array()) |
||
8921 | |||
8922 | |||
8923 | |||
8924 | /** |
||
8925 | * Counts all hours by date |
||
8926 | * |
||
8927 | * @return Array the hour list |
||
8928 | * |
||
8929 | */ |
||
8930 | public function countAllHoursByDate($date, $filters = array()) |
||
8969 | |||
8970 | |||
8971 | |||
8972 | /** |
||
8973 | * Counts all hours by a ident/callsign |
||
8974 | * |
||
8975 | * @return Array the hour list |
||
8976 | * |
||
8977 | */ |
||
8978 | public function countAllHoursByIdent($ident, $filters = array()) |
||
9018 | |||
9019 | |||
9020 | |||
9021 | /** |
||
9022 | * Counts all hours by route |
||
9023 | * |
||
9024 | * @return Array the hour list |
||
9025 | * |
||
9026 | */ |
||
9027 | public function countAllHoursByRoute($departure_airport_icao, $arrival_airport_icao, $filters =array()) |
||
9067 | |||
9068 | |||
9069 | /** |
||
9070 | * Counts all hours by country |
||
9071 | * |
||
9072 | * @return Array the hour list |
||
9073 | * |
||
9074 | */ |
||
9075 | public function countAllHoursByCountry($country, $filters = array()) |
||
9114 | |||
9115 | |||
9116 | |||
9117 | |||
9118 | /** |
||
9119 | * Counts all aircraft that have flown over |
||
9120 | * |
||
9121 | * @return Integer the number of aircrafts |
||
9122 | * |
||
9123 | */ |
||
9124 | public function countOverallAircrafts($filters = array()) |
||
9133 | |||
9134 | /** |
||
9135 | * Counts all flight that really arrival |
||
9136 | * |
||
9137 | * @return Integer the number of aircrafts |
||
9138 | * |
||
9139 | */ |
||
9140 | public function countOverallArrival($filters = array()) |
||
9150 | |||
9151 | /** |
||
9152 | * Counts all pilots that have flown over |
||
9153 | * |
||
9154 | * @return Integer the number of pilots |
||
9155 | * |
||
9156 | */ |
||
9157 | public function countOverallPilots($filters = array()) |
||
9166 | |||
9167 | /** |
||
9168 | * Counts all owners that have flown over |
||
9169 | * |
||
9170 | * @return Integer the number of owners |
||
9171 | * |
||
9172 | */ |
||
9173 | public function countOverallOwners($filters = array()) |
||
9182 | |||
9183 | |||
9184 | /** |
||
9185 | * Counts all flights that have flown over |
||
9186 | * |
||
9187 | * @return Integer the number of flights |
||
9188 | * |
||
9189 | */ |
||
9190 | public function countOverallFlights($filters = array()) |
||
9200 | |||
9201 | /** |
||
9202 | * Counts all military flights that have flown over |
||
9203 | * |
||
9204 | * @return Integer the number of flights |
||
9205 | * |
||
9206 | */ |
||
9207 | public function countOverallMilitaryFlights($filters = array()) |
||
9217 | |||
9218 | |||
9219 | |||
9220 | /** |
||
9221 | * Counts all airlines that have flown over |
||
9222 | * |
||
9223 | * @return Integer the number of airlines |
||
9224 | * |
||
9225 | */ |
||
9226 | public function countOverallAirlines($filters = array()) |
||
9236 | |||
9237 | |||
9238 | /** |
||
9239 | * Counts all hours of today |
||
9240 | * |
||
9241 | * @return Array the hour list |
||
9242 | * |
||
9243 | */ |
||
9244 | public function countAllHoursFromToday($filters = array()) |
||
9281 | |||
9282 | /** |
||
9283 | * Gets all the spotter information based on calculated upcoming flights |
||
9284 | * |
||
9285 | * @return Array the spotter information |
||
9286 | * |
||
9287 | */ |
||
9288 | public function getUpcomingFlights($limit = '', $sort = '', $filters = array()) |
||
9360 | |||
9361 | |||
9362 | /** |
||
9363 | * Gets the Barrie Spotter ID based on the FlightAware ID |
||
9364 | * |
||
9365 | * @return Integer the Barrie Spotter ID |
||
9366 | q * |
||
9367 | */ |
||
9368 | public function getSpotterIDBasedOnFlightAwareID($flightaware_id) |
||
9385 | |||
9386 | |||
9387 | /** |
||
9388 | * Parses a date string |
||
9389 | * |
||
9390 | * @param String $dateString the date string |
||
9391 | * @param String $timezone the timezone of a user |
||
9392 | * @return Array the time information |
||
9393 | * |
||
9394 | */ |
||
9395 | public function parseDateString($dateString, $timezone = '') |
||
9425 | |||
9426 | |||
9427 | |||
9428 | |||
9429 | /** |
||
9430 | * Parses the direction degrees to working |
||
9431 | * |
||
9432 | * @param Float $direction the direction in degrees |
||
9433 | * @return Array the direction information |
||
9434 | * |
||
9435 | */ |
||
9436 | public function parseDirection($direction = 0) |
||
9511 | |||
9512 | |||
9513 | /** |
||
9514 | * Gets the aircraft registration |
||
9515 | * |
||
9516 | * @param String $flightaware_id the flight aware id |
||
9517 | * @return String the aircraft registration |
||
9518 | * |
||
9519 | */ |
||
9520 | |||
9521 | public function getAircraftRegistration($flightaware_id) |
||
9545 | |||
9546 | |||
9547 | /** |
||
9548 | * Gets the aircraft registration from ModeS |
||
9549 | * |
||
9550 | * @param String $aircraft_modes the flight ModeS in hex |
||
9551 | * @return String the aircraft registration |
||
9552 | * |
||
9553 | */ |
||
9554 | public function getAircraftRegistrationBymodeS($aircraft_modes) |
||
9571 | |||
9572 | /** |
||
9573 | * Gets the aircraft type from ModeS |
||
9574 | * |
||
9575 | * @param String $aircraft_modes the flight ModeS in hex |
||
9576 | * @return String the aircraft type |
||
9577 | * |
||
9578 | */ |
||
9579 | public function getAircraftTypeBymodeS($aircraft_modes) |
||
9596 | |||
9597 | /** |
||
9598 | * Gets Countrie from latitude/longitude |
||
9599 | * |
||
9600 | * @param Float $latitude latitute of the flight |
||
9601 | * @param Float $longitude longitute of the flight |
||
9602 | * @return String the countrie |
||
9603 | */ |
||
9604 | public function getCountryFromLatitudeLongitude($latitude,$longitude) |
||
9638 | |||
9639 | /** |
||
9640 | * converts the registration code using the country prefix |
||
9641 | * |
||
9642 | * @param String $registration the aircraft registration |
||
9643 | * @return String the aircraft registration |
||
9644 | * |
||
9645 | */ |
||
9646 | public function convertAircraftRegistration($registration) |
||
9695 | |||
9696 | /** |
||
9697 | * Country from the registration code |
||
9698 | * |
||
9699 | * @param String $registration the aircraft registration |
||
9700 | * @return String the country |
||
9701 | * |
||
9702 | */ |
||
9703 | public function countryFromAircraftRegistration($registration) |
||
9756 | |||
9757 | /** |
||
9758 | * Set a new highlight value for a flight |
||
9759 | * |
||
9760 | * @param String $flightaware_id flightaware_id from spotter_output table |
||
9761 | * @param String $highlight New highlight value |
||
9762 | */ |
||
9763 | public function setHighlightFlight($flightaware_id,$highlight) { |
||
9769 | |||
9770 | /** |
||
9771 | * Gets the short url from bit.ly |
||
9772 | * |
||
9773 | * @param String $url the full url |
||
9774 | * @return String the bit.ly url |
||
9775 | * |
||
9776 | */ |
||
9777 | public function getBitlyURL($url) |
||
9800 | |||
9801 | |||
9802 | public function getOrderBy() |
||
9809 | |||
9810 | /* |
||
9811 | public function importFromFlightAware() |
||
9812 | { |
||
9813 | global $globalFlightAwareUsername, $globalFlightAwarePassword, $globalLatitudeMax, $globalLatitudeMin, $globalLongitudeMax, $globalLongitudeMin, $globalAirportIgnore; |
||
9814 | $Spotter = new Spotter($this->db); |
||
9815 | $SpotterLive = new SpotterLive($this->db); |
||
9816 | $options = array( |
||
9817 | 'trace' => true, |
||
9818 | 'exceptions' => 0, |
||
9819 | 'login' => $globalFlightAwareUsername, |
||
9820 | 'password' => $globalFlightAwarePassword, |
||
9821 | ); |
||
9822 | $client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options); |
||
9823 | $params = array('query' => '{range lat '.$globalLatitudeMin.' '.$globalLatitudeMax.'} {range lon '.$globalLongitudeMax.' '.$globalLongitudeMin.'} {true inAir}', 'howMany' => '15', 'offset' => '0'); |
||
9824 | $result = $client->SearchBirdseyeInFlight($params); |
||
9825 | $dataFound = false; |
||
9826 | $ignoreImport = false; |
||
9827 | if (isset($result->SearchBirdseyeInFlightResult)) |
||
9828 | { |
||
9829 | if (is_array($result->SearchBirdseyeInFlightResult->aircraft)) |
||
9830 | { |
||
9831 | foreach($result->SearchBirdseyeInFlightResult->aircraft as $aircraft) |
||
9832 | { |
||
9833 | if (!strstr($aircraft->origin, 'L ') && !strstr($aircraft->destination, 'L ')) |
||
9834 | { |
||
9835 | foreach($globalAirportIgnore as $airportIgnore) |
||
9836 | { |
||
9837 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
9838 | { |
||
9839 | $ignoreImport = true; |
||
9840 | } |
||
9841 | } |
||
9842 | if ($ignoreImport == false) |
||
9843 | { |
||
9844 | $flightaware_id = $aircraft->faFlightID; |
||
9845 | $ident = $aircraft->ident; |
||
9846 | $aircraft_type = $aircraft->type; |
||
9847 | $departure_airport = $aircraft->origin; |
||
9848 | $arrival_airport = $aircraft->destination; |
||
9849 | $latitude = $aircraft->latitude; |
||
9850 | $longitude = $aircraft->longitude; |
||
9851 | $waypoints = $aircraft->waypoints; |
||
9852 | $altitude = $aircraft->altitude; |
||
9853 | $heading = $aircraft->heading; |
||
9854 | $groundspeed = $aircraft->groundspeed; |
||
9855 | $dataFound = true; |
||
9856 | //gets the callsign from the last hour |
||
9857 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
9858 | //change the departure/arrival airport to NA if its not available |
||
9859 | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
||
9860 | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
||
9861 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
9862 | if($last_hour_ident == "") |
||
9863 | { |
||
9864 | //adds the spotter data for the archive |
||
9865 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
9866 | } |
||
9867 | |||
9868 | //adds the spotter LIVE data |
||
9869 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
9870 | } |
||
9871 | } |
||
9872 | $ignoreImport = false; |
||
9873 | } |
||
9874 | } else { |
||
9875 | if (!strstr($result->SearchBirdseyeInFlightResult->aircraft->origin, 'L ') && !strstr($result->SearchBirdseyeInFlightResult->aircraft->destination, 'L ')) |
||
9876 | { |
||
9877 | foreach($globalAirportIgnore as $airportIgnore) |
||
9878 | { |
||
9879 | foreach($globalAirportIgnore as $airportIgnore) |
||
9880 | { |
||
9881 | if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore) |
||
9882 | { |
||
9883 | $ignoreImport = true; |
||
9884 | } |
||
9885 | } |
||
9886 | if ($ignoreImport == false) |
||
9887 | { |
||
9888 | $flightaware_id = $result->SearchBirdseyeInFlightResult->aircraft->faFlightID; |
||
9889 | $ident = $result->SearchBirdseyeInFlightResult->aircraft->ident; |
||
9890 | $aircraft_type = $result->SearchBirdseyeInFlightResult->aircraft->type; |
||
9891 | $departure_airport = $result->SearchBirdseyeInFlightResult->aircraft->origin; |
||
9892 | $arrival_airport = $result->SearchBirdseyeInFlightResult->aircraft->destination; |
||
9893 | $latitude = $result->SearchBirdseyeInFlightResult->aircraft->latitude; |
||
9894 | $longitude = $result->SearchBirdseyeInFlightResult->aircraft->longitude; |
||
9895 | $waypoints = $result->SearchBirdseyeInFlightResult->aircraft->waypoints; |
||
9896 | $altitude = $result->SearchBirdseyeInFlightResult->aircraft->altitude; |
||
9897 | $heading = $result->SearchBirdseyeInFlightResult->aircraft->heading; |
||
9898 | $groundspeed = $result->SearchBirdseyeInFlightResult->aircraft->groundspeed; |
||
9899 | $dataFound = true; |
||
9900 | //gets the callsign from the last hour |
||
9901 | $last_hour_ident = $this->getIdentFromLastHour($ident); |
||
9902 | //change the departure/arrival airport to NA if its not available |
||
9903 | if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; } |
||
9904 | if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; } |
||
9905 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
||
9906 | if($last_hour_ident == "") |
||
9907 | { |
||
9908 | //adds the spotter data for the archive |
||
9909 | $Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
9910 | } |
||
9911 | //adds the spotter LIVE data |
||
9912 | $SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
9913 | } |
||
9914 | $ignoreImport = false; |
||
9915 | } |
||
9916 | } |
||
9917 | } |
||
9918 | } |
||
9919 | } |
||
9920 | */ |
||
9921 | |||
9922 | // Update flights data when new data in DB |
||
9923 | public function updateFieldsFromOtherTables() |
||
10009 | |||
10010 | // Update arrival airports for data already in DB |
||
10011 | public function updateArrivalAirports() |
||
10052 | |||
10053 | public function closestAirports($origLat,$origLon,$dist = 10) { |
||
10074 | } |
||
10075 | /* |
||
10087 | ?> |