Completed
Push — master ( 341b08...8d07fb )
by Yannick
31:49
created

getCoordArchiveSpotterDataByIdDate()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 3
nop 3
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
class SpotterArchive {
3
	public $global_query = "SELECT spotter_archive.* FROM spotter_archive";
4
	public $db;
5
6
	public function __construct($dbc = null) {
7
		$Connection = new Connection($dbc);
8
		$this->db = $Connection->db;
9
		if ($this->db === null) die('Error: No DB connection. (SpotterArchive)');
10
	}
11
12
	/**
13
	* Get SQL query part for filter used
14
	* @param Array $filter the filter
15
	* @return Array the SQL part
16
	*/
17
	public function getFilter($filter = array(),$where = false,$and = false) {
18
		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
19
		$filters = array();
20
		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
21
			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
22
				$filters = $globalStatsFilters[$globalFilterName];
23
			} else {
24
				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
25
			}
26
		}
27
		if (isset($filter[0]['source'])) {
28
			$filters = array_merge($filters,$filter);
29
		}
30
		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
31
		$filter_query_join = '';
32
		$filter_query_where = '';
33
		foreach($filters as $flt) {
34
			if (isset($flt['airlines']) && !empty($flt['airlines'])) {
35
				if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') {
36
					if (isset($flt['source'])) {
37
						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
38
					} else {
39
						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
40
					}
41
				}
42
			}
43
			if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) {
44
				if (isset($flt['source'])) {
45
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
46
				} else {
47
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
48
				}
49
			}
50
			if (isset($flt['idents']) && !empty($flt['idents'])) {
51
				if (isset($flt['source'])) {
52
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
53
				} else {
54
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
55
				}
56
			}
57
			if (isset($flt['registrations']) && !empty($flt['registrations'])) {
58
				if (isset($flt['source'])) {
59
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
60
				} else {
61
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
62
				}
63
			}
64
			if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents']) && isset($flt['registrations']) && empty($flt['registrations'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) {
65
				if (isset($flt['source'])) {
66
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saa ON saa.flightaware_id = spotter_archive_output.flightaware_id";
67
				}
68
			}
69
		}
70
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
71
			if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') {
72
				$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) saf ON saf.flightaware_id = spotter_archive_output.flightaware_id";
73
			}
74
		}
75
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
76
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive_output.flightaware_id ";
77
		}
78
		if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) {
79
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
80
		}
81
		if (isset($filter['source']) && !empty($filter['source'])) {
82
			if (count($filter['source']) == 1) {
83
				$filter_query_where .= " AND format_source = '".$filter['source'][0]."'";
84
			} else {
85
				$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
86
			}
87
		}
88
		if (isset($filter['ident']) && !empty($filter['ident'])) {
89
			$filter_query_where .= " AND ident = '".$filter['ident']."'";
90
		}
91
		if (isset($filter['id']) && !empty($filter['id'])) {
92
			$filter_query_where .= " AND flightaware_id = '".$filter['id']."'";
93
		}
94
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
95
			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
96
		}
97
		if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) {
98
			$filter_query_date = '';
99
			if (isset($filter['year']) && $filter['year'] != '') {
100
				if ($globalDBdriver == 'mysql') {
101
					$filter_query_date .= " AND YEAR(spotter_archive_output.date) = '".$filter['year']."'";
102
				} else {
103
					$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_archive_output.date) = '".$filter['year']."'";
104
				}
105
			}
106
			if (isset($filter['month']) && $filter['month'] != '') {
107
				if ($globalDBdriver == 'mysql') {
108
					$filter_query_date .= " AND MONTH(spotter_archive_output.date) = '".$filter['month']."'";
109
				} else {
110
					$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_archive_output.date) = '".$filter['month']."'";
111
				}
112
			}
113
			if (isset($filter['day']) && $filter['day'] != '') {
114
				if ($globalDBdriver == 'mysql') {
115
					$filter_query_date .= " AND DAY(spotter_archive_output.date) = '".$filter['day']."'";
116
				} else {
117
					$filter_query_date .= " AND EXTRACT(DAY FROM spotter_archive_output.date) = '".$filter['day']."'";
118
				}
119
			}
120
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id";
121
		}
122
		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
123
		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
124
		if ($filter_query_where != '') {
125
			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
126
		}
127
		$filter_query = $filter_query_join.$filter_query_where;
128
		return $filter_query;
129
	}
130
131
	// Spotter_archive
132
	public function addSpotterArchiveData($flightaware_id = '', $ident = '', $registration = '', $airline_name = '', $airline_icao = '', $airline_country = '', $airline_type = '', $aircraft_icao = '', $aircraft_shadow = '', $aircraft_name = '', $aircraft_manufacturer = '', $departure_airport_icao = '', $departure_airport_name = '', $departure_airport_city = '', $departure_airport_country = '', $departure_airport_time = '',$arrival_airport_icao = '', $arrival_airport_name = '', $arrival_airport_city ='', $arrival_airport_country = '', $arrival_airport_time = '', $route_stop = '', $date = '',$latitude = '', $longitude = '', $waypoints = '', $altitude = '', $real_altitude = '',$heading = '', $ground_speed = '', $squawk = '', $ModeS = '', $pilot_id = '', $pilot_name = '',$verticalrate = '',$format_source = '', $source_name = '', $over_country = '') {
133
		require_once(dirname(__FILE__).'/class.Spotter.php');
134
		if ($over_country == '') {
135
			$Spotter = new Spotter($this->db);
136
			$data_country = $Spotter->getCountryFromLatitudeLongitude($latitude,$longitude);
137
			if (!empty($data_country)) $country = $data_country['iso2'];
138
			else $country = '';
139
		} else $country = $over_country;
140
		if ($airline_type === NULL) $airline_type ='';
141
142
		//if ($country == '') echo "\n".'************ UNKNOW COUNTRY ****************'."\n";
143
		//else echo "\n".'*/*/*/*/*/*/*/ Country : '.$country.' */*/*/*/*/*/*/*/*/'."\n";
144
145
		// Route is not added in spotter_archive
146
		$query  = "INSERT INTO spotter_archive (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, departure_airport_time,arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, arrival_airport_time, route_stop, date,latitude, longitude, waypoints, altitude, heading, ground_speed, squawk, ModeS, pilot_id, pilot_name, verticalrate,format_source,over_country,source_name,real_altitude)
147
		          VALUES (:flightaware_id, :ident, :registration, :airline_name, :airline_icao, :airline_country, :airline_type, :aircraft_icao, :aircraft_shadow, :aircraft_name, :aircraft_manufacturer, :departure_airport_icao, :departure_airport_name, :departure_airport_city, :departure_airport_country, :departure_airport_time,:arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :arrival_airport_time, :route_stop, :date,:latitude, :longitude, :waypoints, :altitude, :heading, :ground_speed, :squawk, :ModeS, :pilot_id, :pilot_name, :verticalrate, :format_source, :over_country, :source_name,:real_altitude)";
148
149
		$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_shadow' => $aircraft_shadow, ':aircraft_name' => $aircraft_name, ':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, ':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':arrival_airport_time' => $arrival_airport_time, ':route_stop' => $route_stop, ':date' => $date,':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':ground_speed' => $ground_speed, ':squawk' => $squawk, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':over_country' => $country, ':source_name' => $source_name,':real_altitude' => $real_altitude);
150
		try {
151
			$sth = $this->db->prepare($query);
152
			$sth->execute($query_values);
153
			$sth->closeCursor();
154
		} catch(PDOException $e) {
155
			return "error : ".$e->getMessage();
156
		}
157
		return "success";
158
	}
159
160
161
	/**
162
	* Gets all the spotter information based on a particular callsign
163
	*
164
	* @return Array the spotter information
165
	*
166
	*/
167
	public function getLastArchiveSpotterDataByIdent($ident) {
168
		$Spotter = new Spotter($this->db);
169
		date_default_timezone_set('UTC');
170
171
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
172
		//$query  = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
173
		$query  = "SELECT spotter_archive.* FROM spotter_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1";
174
175
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident));
176
177
		return $spotter_array;
178
	}
179
180
181
	/**
182
	* Gets last the spotter information based on a particular id
183
	*
184
	* @return Array the spotter information
185
	*
186
	*/
187
	public function getLastArchiveSpotterDataById($id) {
188
		$Spotter = new Spotter($this->db);
189
		date_default_timezone_set('UTC');
190
		$id = filter_var($id, FILTER_SANITIZE_STRING);
191
		//$query  = SpotterArchive->$global_query." WHERE spotter_archive.flightaware_id = :id";
192
		//$query  = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
193
		$query  = "SELECT * FROM spotter_archive WHERE flightaware_id = :id ORDER BY date DESC LIMIT 1";
194
195
//              $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id));
196
		/*
197
		try {
198
		      $Connection = new Connection();
199
		      $sth = Connection->$db->prepare($query);
200
		      $sth->execute(array(':id' => $id));
201
		} catch(PDOException $e) {
202
		      return "error";
203
		}
204
		$spotter_array = $sth->fetchAll(PDO->FETCH_ASSOC);
205
		*/
206
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id));
207
208
		return $spotter_array;
209
	}
210
211
	/**
212
	* Gets all the spotter information based on a particular id
213
	*
214
	* @return Array the spotter information
215
	*
216
	*/
217
	public function getAllArchiveSpotterDataById($id) {
218
		date_default_timezone_set('UTC');
219
		$id = filter_var($id, FILTER_SANITIZE_STRING);
220
		$query  = $this->global_query." WHERE spotter_archive.flightaware_id = :id ORDER BY date";
221
222
//              $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id));
223
224
		try {
225
			$sth = $this->db->prepare($query);
226
			$sth->execute(array(':id' => $id));
227
		} catch(PDOException $e) {
228
			echo $e->getMessage();
229
			die;
230
		}
231
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
232
233
		return $spotter_array;
234
	}
235
236
	/**
237
	* Gets coordinate & time spotter information based on a particular id
238
	*
239
	* @return Array the spotter information
240
	*
241
	*/
242
	public function getCoordArchiveSpotterDataById($id) {
243
		date_default_timezone_set('UTC');
244
		$id = filter_var($id, FILTER_SANITIZE_STRING);
245
		$query  = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER by spotter_archive.date ASC";
246
		try {
247
			$sth = $this->db->prepare($query);
248
			$sth->execute(array(':id' => $id));
249
		} catch(PDOException $e) {
250
			echo $e->getMessage();
251
			die;
252
		}
253
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
254
		return $spotter_array;
255
	}
256
257
	/**
258
	* Gets coordinate & time spotter information based on a particular id
259
	*
260
	* @return Array the spotter information
261
	*
262
	*/
263
	public function getCoordArchiveSpotterDataByIdDate($id,$begindate,$enddate) {
264
		date_default_timezone_set('UTC');
265
		$id = filter_var($id, FILTER_SANITIZE_STRING);
266
		$query  = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.date BETWEEN '".$begindate."' AND '".$enddate."' ORDER by spotter_archive.date ASC";
267
		try {
268
			$sth = $this->db->prepare($query);
269
			$sth->execute(array(':id' => $id));
270
		} catch(PDOException $e) {
271
			echo $e->getMessage();
272
			die;
273
		}
274
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
275
		return $spotter_array;
276
	}
277
278
279
	/**
280
	* Gets altitude information based on a particular callsign
281
	*
282
	* @return Array the spotter information
283
	*
284
	*/
285
	public function getAltitudeArchiveSpotterDataByIdent($ident) {
286
287
		date_default_timezone_set('UTC');
288
289
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
290
		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
291
292
		try {
293
			$sth = $this->db->prepare($query);
294
			$sth->execute(array(':ident' => $ident));
295
		} catch(PDOException $e) {
296
			echo $e->getMessage();
297
			die;
298
		}
299
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
300
301
		return $spotter_array;
302
	}
303
304
	/**
305
	* Gets altitude information based on a particular id
306
	*
307
	* @return Array the spotter information
308
	*
309
	*/
310
	public function getAltitudeArchiveSpotterDataById($id) {
311
312
		date_default_timezone_set('UTC');
313
314
		$id = filter_var($id, FILTER_SANITIZE_STRING);
315
		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
316
317
		try {
318
			$sth = $this->db->prepare($query);
319
			$sth->execute(array(':id' => $id));
320
		} catch(PDOException $e) {
321
			echo $e->getMessage();
322
			die;
323
		}
324
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
325
326
		return $spotter_array;
327
	}
328
329
	/**
330
	* Gets altitude & speed information based on a particular id
331
	*
332
	* @return Array the spotter information
333
	*
334
	*/
335
	public function getAltitudeSpeedArchiveSpotterDataById($id) {
336
		date_default_timezone_set('UTC');
337
		$id = filter_var($id, FILTER_SANITIZE_STRING);
338
		$query  = "SELECT spotter_archive.altitude, spotter_archive.real_altitude,spotter_archive.ground_speed, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER BY date";
339
		try {
340
			$sth = $this->db->prepare($query);
341
			$sth->execute(array(':id' => $id));
342
		} catch(PDOException $e) {
343
			echo $e->getMessage();
344
			die;
345
		}
346
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
347
		return $spotter_array;
348
	}
349
350
	/**
351
	* Gets altitude information based on a particular callsign
352
	*
353
	* @return Array the spotter information
354
	*
355
	*/
356
	public function getLastAltitudeArchiveSpotterDataByIdent($ident) {
357
		date_default_timezone_set('UTC');
358
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
359
		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
360
//                $query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident";
361
		try {
362
			$sth = $this->db->prepare($query);
363
			$sth->execute(array(':ident' => $ident));
364
		} catch(PDOException $e) {
365
			echo $e->getMessage();
366
			die;
367
		}
368
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
369
		return $spotter_array;
370
	}
371
372
373
374
	/**
375
	 * Gets all the archive spotter information
376
	 *
377
	 * @return Array the spotter information
378
	 *
379
	 */
380
	public function getSpotterArchiveData($ident,$flightaware_id,$date) {
381
		$Spotter = new Spotter($this->db);
382
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
383
		$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.flightaware_id = :flightaware_id AND l.date LIKE :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
384
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':flightaware_id' => $flightaware_id,':date' => $date.'%'));
385
		return $spotter_array;
386
	}
387
388
	public function deleteSpotterArchiveTrackData() {
389
		global $globalArchiveKeepTrackMonths, $globalDBdriver;
390
		if ($globalDBdriver == 'mysql') {
391
			$query = 'DELETE FROM spotter_archive WHERE spotter_archive.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepTrackMonths.' MONTH) LIMIT 10000';
392
		} else {
393
			$query = "DELETE FROM spotter_archive WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive WHERE spotter_archive.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepTrackMonths." MONTH' LIMIT 10000)";
394
		}
395
		try {
396
			$sth = $this->db->prepare($query);
397
			$sth->execute();
398
		} catch(PDOException $e) {
399
			echo $e->getMessage();
400
			die;
401
		}
402
	}
403
404
	/**
405
	    * Gets Minimal Live Spotter data
406
	    *
407
	    * @return Array the spotter information
408
	    *
409
	    */
410
	public function getMinLiveSpotterData($begindate,$enddate,$filter = array()) {
411
		global $globalDBdriver, $globalLiveInterval;
412
		date_default_timezone_set('UTC');
413
		//$filter_query = $this->getFilter($filter,true,true);
414
415
		$filter_query = '';
416
		if (isset($filter['source']) && !empty($filter['source'])) {
417
			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
418
		}
419
		// Use spotter_output also ?
420
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
421
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
422
		}
423
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
424
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
425
		}
426
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
427
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
428
		}
429
430
		if ($globalDBdriver == 'mysql') {
431
			$query  = 'SELECT spotter_archive.date,spotter_archive.flightaware_id, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
432
			          FROM spotter_archive
433
			          INNER JOIN (SELECT * FROM aircraft) a on spotter_archive.aircraft_icao = a.icao
434
			          WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".'
435
			          '.$filter_query.' ORDER BY flightaware_id';
436
		} else {
437
			$query  = 'SELECT spotter_archive.flightaware_id, spotter_archive.date, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
438
			          FROM spotter_archive
439
			          INNER JOIN (SELECT * FROM aircraft) a on spotter_archive.aircraft_icao = a.icao
440
			          WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".'
441
			          '.$filter_query.' ORDER BY flightaware_id';
442
		}
443
		//echo $query;
444
		try {
445
			$sth = $this->db->prepare($query);
446
			$sth->execute();
447
		} catch(PDOException $e) {
448
			echo $e->getMessage();
449
			die;
450
		}
451
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
452
		return $spotter_array;
453
	}
454
455
	/**
456
	    * Gets Minimal Live Spotter data
457
	    *
458
	    * @return Array the spotter information
459
	    *
460
	    */
461
	public function getMinLiveSpotterDataPlayback($begindate,$enddate,$filter = array()) {
462
		global $globalDBdriver, $globalLiveInterval;
463
		date_default_timezone_set('UTC');
464
465
		//$filter_query = $this->getFilter($filter,true,true);
466
467
		$filter_query = '';
468
		if (isset($filter['source']) && !empty($filter['source'])) {
469
			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
470
		}
471
		// Use spotter_output also ?
472
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
473
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
474
		}
475
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
476
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
477
		}
478
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
479
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
480
		}
481
482
483
		//if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
484
		if ($globalDBdriver == 'mysql') {
485
			/*
486
			$query  = 'SELECT a.aircraft_shadow, spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk
487
				    FROM spotter_archive
488
				    INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive.aircraft_icao = a.icao';
489
			*/
490
			$query  = 'SELECT a.aircraft_shadow, spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk
491
			          FROM spotter_archive_output
492
			          LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive_output.aircraft_icao = a.icao
493
			          WHERE (spotter_archive_output.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".')
494
			          '.$filter_query.' GROUP BY spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao, spotter_archive_output.arrival_airport_icao, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow';
495
496
		} else {
497
			//$query  = 'SELECT spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow FROM spotter_archive_output INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive_output l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_archive_output.flightaware_id = s.flightaware_id AND spotter_archive_output.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao';
498
			/*
499
			 $query  = 'SELECT spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow
500
			 	    FROM spotter_archive_output
501
			 	    INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao
502
			 	    WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".'
503
			 	    '.$filter_query.' GROUP BY spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao, spotter_archive_output.arrival_airport_icao, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow';
504
			 */
505
			$query  = 'SELECT DISTINCT spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow
506
			          FROM spotter_archive_output
507
			          INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao
508
			          WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".'
509
			          '.$filter_query.' LIMIT 200 OFFSET 0';
510
//                        	    .' GROUP BY spotter_output.flightaware_id, spotter_output.ident, spotter_output.aircraft_icao, spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao, spotter_output.latitude, spotter_output.longitude, spotter_output.altitude, spotter_output.heading, spotter_output.ground_speed, spotter_output.squawk, a.aircraft_shadow';
511
512
		}
513
		//echo $query;
514
		try {
515
			$sth = $this->db->prepare($query);
516
			$sth->execute();
517
		} catch(PDOException $e) {
518
			echo $e->getMessage();
519
			die;
520
		}
521
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
522
523
		return $spotter_array;
524
	}
525
526
	/**
527
	   * Gets count Live Spotter data
528
	   *
529
	   * @return Array the spotter information
530
	   *
531
	   */
532
	public function getLiveSpotterCount($begindate,$enddate,$filter = array()) {
533
		global $globalDBdriver, $globalLiveInterval;
534
		date_default_timezone_set('UTC');
535
536
		$filter_query = '';
537
		if (isset($filter['source']) && !empty($filter['source'])) {
538
			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
539
		}
540
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
541
			$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_archive.flightaware_id ";
542
		}
543
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
544
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
545
		}
546
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
547
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
548
		}
549
550
		//if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
551
		if ($globalDBdriver == 'mysql') {
552
			$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb
553
			         FROM spotter_archive l
554
			         WHERE (l.date BETWEEN DATE_SUB('."'".$begindate."'".',INTERVAL '.$globalLiveInterval.' SECOND) AND '."'".$begindate."'".')'.$filter_query;
555
		} else {
556
			$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."' - INTERVAL '".$globalLiveInterval." SECONDS' AND "."'".$enddate."'".')'.$filter_query;
557
		}
558
		//echo $query;
559
		try {
560
			$sth = $this->db->prepare($query);
561
			$sth->execute();
562
		} catch(PDOException $e) {
563
			echo $e->getMessage();
564
			die;
565
		}
566
		$result = $sth->fetch(PDO::FETCH_ASSOC);
567
		$sth->closeCursor();
568
		return $result['nb'];
569
570
	}
571
572
573
574
	// Spotter_Archive_output
575
576
	/**
577
	* Gets all the spotter information
578
	*
579
	* @return Array the spotter information
580
	*
581
	*/
582
	public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '', $filters=array()) {
583
		global $globalTimezone, $globalDBdriver;
584
		require_once(dirname(__FILE__).'/class.Translation.php');
585
		$Translation = new Translation($this->db);
586
		$Spotter = new Spotter($this->db);
587
588
		date_default_timezone_set('UTC');
589
590
		$query_values = array();
591
		$additional_query = '';
592
		$limit_query = '';
593
		$filter_query = $this->getFilter($filters);
594
		if ($q != "") {
595
			if (!is_string($q)) {
596
				return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterArchive::searchSpotterData of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
597
			} else {
598
599
				$q_array = explode(" ", $q);
600
601
				foreach ($q_array as $q_item) {
602
					$additional_query .= " AND (";
603
					$additional_query .= "(spotter_archive_output.spotter_id like '%".$q_item."%') OR ";
604
					$additional_query .= "(spotter_archive_output.aircraft_icao like '%".$q_item."%') OR ";
605
					$additional_query .= "(spotter_archive_output.aircraft_name like '%".$q_item."%') OR ";
606
					$additional_query .= "(spotter_archive_output.aircraft_manufacturer like '%".$q_item."%') OR ";
607
					$additional_query .= "(spotter_archive_output.airline_icao like '%".$q_item."%') OR ";
608
					$additional_query .= "(spotter_archive_output.airline_name like '%".$q_item."%') OR ";
609
					$additional_query .= "(spotter_archive_output.airline_country like '%".$q_item."%') OR ";
610
					$additional_query .= "(spotter_archive_output.departure_airport_icao like '%".$q_item."%') OR ";
611
					$additional_query .= "(spotter_archive_output.departure_airport_name like '%".$q_item."%') OR ";
612
					$additional_query .= "(spotter_archive_output.departure_airport_city like '%".$q_item."%') OR ";
613
					$additional_query .= "(spotter_archive_output.departure_airport_country like '%".$q_item."%') OR ";
614
					$additional_query .= "(spotter_archive_output.arrival_airport_icao like '%".$q_item."%') OR ";
615
					$additional_query .= "(spotter_archive_output.arrival_airport_name like '%".$q_item."%') OR ";
616
					$additional_query .= "(spotter_archive_output.arrival_airport_city like '%".$q_item."%') OR ";
617
					$additional_query .= "(spotter_archive_output.arrival_airport_country like '%".$q_item."%') OR ";
618
					$additional_query .= "(spotter_archive_output.registration like '%".$q_item."%') OR ";
619
					$additional_query .= "(spotter_archive_output.owner_name like '%".$q_item."%') OR ";
620
					$additional_query .= "(spotter_archive_output.pilot_id like '%".$q_item."%') OR ";
621
					$additional_query .= "(spotter_archive_output.pilot_name like '%".$q_item."%') OR ";
622
					$additional_query .= "(spotter_archive_output.ident like '%".$q_item."%') OR ";
623
					$translate = $Translation->ident2icao($q_item);
624
					if ($translate != $q_item) $additional_query .= "(spotter_archive_output.ident like '%".$translate."%') OR ";
625
					$additional_query .= "(spotter_archive_output.highlight like '%".$q_item."%')";
626
					$additional_query .= ")";
627
				}
628
			}
629
		}
630
631
		if ($registration != "") {
632
			$registration = filter_var($registration,FILTER_SANITIZE_STRING);
633
			if (!is_string($registration)) {
634
				return array();
635
			} else {
636
				$additional_query .= " AND (spotter_archive_output.registration = '".$registration."')";
637
			}
638
		}
639
640
		if ($aircraft_icao != "") {
641
			$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
642
			if (!is_string($aircraft_icao)) {
643
				return array();
644
			} else {
645
				$additional_query .= " AND (spotter_archive_output.aircraft_icao = '".$aircraft_icao."')";
646
			}
647
		}
648
649
		if ($aircraft_manufacturer != "") {
650
			$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
651
			if (!is_string($aircraft_manufacturer)) {
652
				return array();
653
			} else {
654
				$additional_query .= " AND (spotter_archive_output.aircraft_manufacturer = '".$aircraft_manufacturer."')";
655
			}
656
		}
657
658
		if ($highlights == "true") {
659
			if (!is_string($highlights)) {
660
				return array();
661
			} else {
662
				$additional_query .= " AND (spotter_archive_output.highlight <> '')";
663
			}
664
		}
665
666
		if ($airline_icao != "") {
667
			$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
668
			if (!is_string($airline_icao)) {
669
				return array();
670
			} else {
671
				$additional_query .= " AND (spotter_archive_output.airline_icao = '".$airline_icao."')";
672
			}
673
		}
674
675
		if ($airline_country != "") {
676
			$airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING);
677
			if (!is_string($airline_country)) {
678
				return array();
679
			} else {
680
				$additional_query .= " AND (spotter_archive_output.airline_country = '".$airline_country."')";
681
			}
682
		}
683
684
		if ($airline_type != "") {
685
			$airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING);
686
			if (!is_string($airline_type)) {
687
				return array();
688
			} else {
689
				if ($airline_type == "passenger") {
690
					$additional_query .= " AND (spotter_archive_output.airline_type = 'passenger')";
691
				}
692
				if ($airline_type == "cargo") {
693
					$additional_query .= " AND (spotter_archive_output.airline_type = 'cargo')";
694
				}
695
				if ($airline_type == "military") {
696
					$additional_query .= " AND (spotter_archive_output.airline_type = 'military')";
697
				}
698
			}
699
		}
700
701
		if ($airport != "") {
702
			$airport = filter_var($airport,FILTER_SANITIZE_STRING);
703
			if (!is_string($airport)) {
704
				return array();
705
			} else {
706
				$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = '".$airport."') OR (spotter_archive_output.arrival_airport_icao = '".$airport."'))";
707
			}
708
		}
709
710
		if ($airport_country != "") {
711
			$airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING);
712
			if (!is_string($airport_country)) {
713
				return array();
714
			} else {
715
				$additional_query .= " AND ((spotter_archive_output.departure_airport_country = '".$airport_country."') OR (spotter_archive_output.arrival_airport_country = '".$airport_country."'))";
716
			}
717
		}
718
719
		if ($callsign != "") {
720
			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
721
			if (!is_string($callsign)) {
722
				return array();
723
			} else {
724
				$translate = $Translation->ident2icao($callsign);
725
				if ($translate != $callsign) {
726
					$additional_query .= " AND (spotter_archive_output.ident = :callsign OR spotter_archive_output.ident = :translate)";
727
					$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate));
728
				} else {
729
					$additional_query .= " AND (spotter_archive_output.ident = '".$callsign."')";
730
				}
731
			}
732
		}
733
734
		if ($owner != "") {
735
			$owner = filter_var($owner,FILTER_SANITIZE_STRING);
736
			if (!is_string($owner)) {
737
				return array();
738
			} else {
739
				$additional_query .= " AND (spotter_archive_output.owner_name = '".$owner."')";
740
			}
741
		}
742
743
		if ($pilot_name != "") {
744
			$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
745
			if (!is_string($pilot_name)) {
746
				return array();
747
			} else {
748
				$additional_query .= " AND (spotter_archive_output.pilot_name = '".$pilot_name."')";
749
			}
750
		}
751
752
		if ($pilot_id != "") {
753
			$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT);
754
			if (!is_string($pilot_id)) {
755
				return array();
756
			} else {
757
				$additional_query .= " AND (spotter_archive_output.pilot_id = '".$pilot_id."')";
758
			}
759
		}
760
761
		if ($departure_airport_route != "") {
762
			$departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING);
763
			if (!is_string($departure_airport_route)) {
764
				return array();
765
			} else {
766
				$additional_query .= " AND (spotter_archive_output.departure_airport_icao = '".$departure_airport_route."')";
767
			}
768
		}
769
770
		if ($arrival_airport_route != "") {
771
			$arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING);
772
			if (!is_string($arrival_airport_route)) {
773
				return array();
774
			} else {
775
				$additional_query .= " AND (spotter_archive_output.arrival_airport_icao = '".$arrival_airport_route."')";
776
			}
777
		}
778
779
		if ($altitude != "") {
780
			$altitude_array = explode(",", $altitude);
781
782
			$altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
783
			$altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
784
785
786
			if ($altitude_array[1] != "") {
787
				$altitude_array[0] = substr($altitude_array[0], 0, -2);
788
				$altitude_array[1] = substr($altitude_array[1], 0, -2);
789
				$additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' ";
790
			} else {
791
				$altitude_array[0] = substr($altitude_array[0], 0, -2);
792
				$additional_query .= " AND altitude <= '".$altitude_array[0]."' ";
793
			}
794
		}
795
796
		if ($date_posted != "") {
797
			$date_array = explode(",", $date_posted);
798
			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
799
			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
800
			if ($globalTimezone != '') {
801
				date_default_timezone_set($globalTimezone);
802
				$datetime = new DateTime();
803
				$offset = $datetime->format('P');
804
			} else $offset = '+00:00';
805
			if ($date_array[1] != "") {
806
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
807
				$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1]));
808
				if ($globalDBdriver == 'mysql') {
809
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' ";
810
				} else {
811
					$additional_query .= " AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." >= CAST('".$date_array[0]."' AS TIMESTAMP) AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." <= CAST('".$date_array[1]."' AS TIMESTAMP) ";
812
				}
813
			} else {
814
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
815
				if ($globalDBdriver == 'mysql') {
816
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' ";
817
				} else {
818
					$additional_query .= " AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." >= CAST('".$date_array[0]."' AS TIMESTAMP) ";
819
				}
820
			}
821
		}
822
		if ($limit != "") {
823
			$limit_array = explode(",", $limit);
824
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
825
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
826
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
827
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
828
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
829
			}
830
		}
831
		if ($origLat != "" && $origLon != "" && $dist != "") {
832
			$dist = number_format($dist*0.621371,2,'.','');
833
			$query="SELECT spotter_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(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
834
			       FROM spotter_archive_output, spotter_archive WHERE spotter_output_archive.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/ABS(cos(radians($origLat))*69)) and ($origLon+$dist/ABS(cos(radians($origLat))*69)) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69))
835
			       AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(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." ORDER BY distance";
836
		} else {
837
			if ($sort != "") {
838
				$search_orderby_array = $Spotter->getOrderBy();
839
				$orderby_query = $search_orderby_array[$sort]['sql'];
840
			} else {
841
				$orderby_query = " ORDER BY spotter_archive_output.date DESC";
842
			}
843
			if ($includegeodata == "true") {
844
				$additional_query .= " AND (spotter_archive_output.waypoints <> '')";
845
			}
846
847
			$query  = "SELECT spotter_archive_output.* FROM spotter_archive_output
848
			          WHERE spotter_archive_output.ident <> ''
849
			          ".$additional_query."
850
			          ".$filter_query.$orderby_query;
851
		}
852
		$spotter_array = $Spotter->getDataFromDB($query, $query_values,$limit_query);
853
		return $spotter_array;
854
	}
855
856
	public function deleteSpotterArchiveData() {
857
		global $globalArchiveKeepMonths, $globalDBdriver;
858
		date_default_timezone_set('UTC');
859
		if ($globalDBdriver == 'mysql') {
860
			$query = 'DELETE FROM spotter_archive_output WHERE spotter_archive_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepMonths.' MONTH) LIMIT 10000';
861
		} else {
862
			$query = "DELETE FROM spotter_archive_output WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive_output WHERE spotter_archive_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepMonths." MONTH' LIMIT 10000)";
863
		}
864
		try {
865
			$sth = $this->db->prepare($query);
866
			$sth->execute();
867
		} catch(PDOException $e) {
868
			return "error";
869
		}
870
	}
871
872
	/**
873
	* Gets all the spotter information based on the callsign
874
	*
875
	* @return Array the spotter information
876
	*
877
	*/
878
	public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') {
879
		$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output";
880
881
		date_default_timezone_set('UTC');
882
		$Spotter = new Spotter($this->db);
883
884
		$query_values = array();
885
		$limit_query = '';
886
		$additional_query = '';
887
888
		if ($ident != "") {
889
			if (!is_string($ident)) {
890
				return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterArchive::getSpotterDataByIdent of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
891
			} else {
892
				$additional_query = " AND spotter_archive_output.ident = :ident";
893
				$query_values = array(':ident' => $ident);
894
			}
895
		}
896
897
		if ($limit != "") {
898
			$limit_array = explode(",", $limit);
899
900
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
901
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
902
903
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
904
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
905
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
906
			}
907
		}
908
909
		if ($sort != "") {
910
			$search_orderby_array = $Spotter->getOrderBy();
911
			$orderby_query = $search_orderby_array[$sort]['sql'];
912
		} else {
913
			$orderby_query = " ORDER BY spotter_archive_output.date DESC";
914
		}
915
916
		$query = $global_query." WHERE spotter_archive_output.ident <> '' ".$additional_query." ".$orderby_query;
917
918
		$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query);
919
920
		return $spotter_array;
921
	}
922
923
924
	/**
925
	* Gets all the spotter information based on the owner
926
	*
927
	* @return Array the spotter information
928
	*
929
	*/
930
	public function getSpotterDataByOwner($owner = '', $limit = '', $sort = '', $filter = array()) {
931
		$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output";
932
933
		date_default_timezone_set('UTC');
934
		$Spotter = new Spotter($this->db);
935
936
		$query_values = array();
937
		$limit_query = '';
938
		$additional_query = '';
939
		$filter_query = $this->getFilter($filter,true,true);
940
941
		if ($owner != "") {
942
			if (!is_string($owner)) {
943
				return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterArchive::getSpotterDataByOwner of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
944
			} else {
945
				$additional_query = " AND (spotter_archive_output.owner_name = :owner)";
946
				$query_values = array(':owner' => $owner);
947
			}
948
		}
949
950
		if ($limit != "") {
951
			$limit_array = explode(",", $limit);
952
953
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
954
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
955
956
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
957
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
958
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
959
			}
960
		}
961
962
		if ($sort != "") {
963
			$search_orderby_array = $Spotter->getOrderBy();
964
			$orderby_query = $search_orderby_array[$sort]['sql'];
965
		} else {
966
			$orderby_query = " ORDER BY spotter_archive_output.date DESC";
967
		}
968
969
		$query = $global_query.$filter_query." spotter_archive_output.owner_name <> '' ".$additional_query." ".$orderby_query;
970
971
		$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query);
972
973
		return $spotter_array;
974
	}
975
976
	/**
977
	* Gets all the spotter information based on the pilot
978
	*
979
	* @return Array the spotter information
980
	*
981
	*/
982
	public function getSpotterDataByPilot($pilot = '', $limit = '', $sort = '', $filter = array()) {
983
		$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output";
984
985
		date_default_timezone_set('UTC');
986
		$Spotter = new Spotter($this->db);
987
988
		$query_values = array();
989
		$limit_query = '';
990
		$additional_query = '';
991
		$filter_query = $this->getFilter($filter,true,true);
992
993
		if ($pilot != "") {
994
			$additional_query = " AND (spotter_archive_output.pilot_id = :pilot OR spotter_archive_output.pilot_name = :pilot)";
995
			$query_values = array(':pilot' => $pilot);
996
		}
997
998
		if ($limit != "") {
999
			$limit_array = explode(",", $limit);
1000
1001
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1002
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1003
1004
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
1005
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1006
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1007
			}
1008
		}
1009
1010
		if ($sort != "") {
1011
			$search_orderby_array = $Spotter->getOrderBy();
1012
			$orderby_query = $search_orderby_array[$sort]['sql'];
1013
		} else {
1014
			$orderby_query = " ORDER BY spotter_archive_output.date DESC";
1015
		}
1016
1017
		$query = $global_query.$filter_query." spotter_archive_output.pilot_name <> '' ".$additional_query." ".$orderby_query;
1018
1019
		$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query);
1020
1021
		return $spotter_array;
1022
	}
1023
1024
	/**
1025
	* Gets all number of flight over countries
1026
	*
1027
	* @return Array the airline country list
1028
	*
1029
	*/
1030
	public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') {
1031
		global $globalDBdriver;
1032
		/*
1033
		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb
1034
			    FROM countries c, spotter_archive s
1035
			    WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) ";
1036
		*/
1037
		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb
1038
		         FROM countries c, spotter_archive s
1039
		         WHERE c.iso2 = s.over_country ";
1040
		if ($olderthanmonths > 0) {
1041
			if ($globalDBdriver == 'mysql') {
1042
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
1043
			} else {
1044
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1045
			}
1046
		}
1047
		if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
1048
		$query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC";
1049
		if ($limit) $query .= " LIMIT 0,10";
1050
1051
1052
		$sth = $this->db->prepare($query);
1053
		$sth->execute();
1054
1055
		$flight_array = array();
1056
		$temp_array = array();
1057
1058
		while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1059
			$temp_array['flight_count'] = $row['nb'];
1060
			$temp_array['flight_country'] = $row['name'];
1061
			$temp_array['flight_country_iso3'] = $row['iso3'];
1062
			$temp_array['flight_country_iso2'] = $row['iso2'];
1063
			$flight_array[] = $temp_array;
1064
		}
1065
		return $flight_array;
1066
	}
1067
1068
	/**
1069
	* Gets all number of flight over countries
1070
	*
1071
	* @return Array the airline country list
1072
	*
1073
	*/
1074
	public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '') {
1075
		global $globalDBdriver;
1076
		/*
1077
		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb
1078
			    FROM countries c, spotter_archive s
1079
			    WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) ";
1080
		*/
1081
		$query = "SELECT o.airline_icao,c.name, c.iso3, c.iso2, count(c.name) as nb
1082
		         FROM countries c, spotter_archive s, spotter_output o
1083
		         WHERE c.iso2 = s.over_country AND o.airline_icao <> '' AND o.flightaware_id = s.flightaware_id ";
1084
		if ($olderthanmonths > 0) {
1085
			if ($globalDBdriver == 'mysql') {
1086
				$query .= 'AND s.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
1087
			} else {
1088
				$query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1089
			}
1090
		}
1091
		if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' ";
1092
		$query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC";
1093
		if ($limit) $query .= " LIMIT 0,10";
1094
1095
1096
		$sth = $this->db->prepare($query);
1097
		$sth->execute();
1098
1099
		$flight_array = array();
1100
		$temp_array = array();
1101
1102
		while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1103
			$temp_array['airline_icao'] = $row['airline_icao'];
1104
			$temp_array['flight_count'] = $row['nb'];
1105
			$temp_array['flight_country'] = $row['name'];
1106
			$temp_array['flight_country_iso3'] = $row['iso3'];
1107
			$temp_array['flight_country_iso2'] = $row['iso2'];
1108
			$flight_array[] = $temp_array;
1109
		}
1110
		return $flight_array;
1111
	}
1112
1113
	/**
1114
	* Gets last spotter information based on a particular callsign
1115
	*
1116
	* @return Array the spotter information
1117
	*
1118
	*/
1119
	public function getDateArchiveSpotterDataById($id,$date) {
1120
		$Spotter = new Spotter($this->db);
1121
		date_default_timezone_set('UTC');
1122
		$id = filter_var($id, FILTER_SANITIZE_STRING);
1123
		$query  = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1124
		$date = date('c',$date);
1125
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date));
1126
		return $spotter_array;
1127
	}
1128
1129
	/**
1130
	* Gets all the spotter information based on a particular callsign
1131
	*
1132
	* @return Array the spotter information
1133
	*
1134
	*/
1135
	public function getDateArchiveSpotterDataByIdent($ident,$date) {
1136
		$Spotter = new Spotter($this->db);
1137
		date_default_timezone_set('UTC');
1138
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1139
		$query  = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1140
		$date = date('c',$date);
1141
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
1142
		return $spotter_array;
1143
	}
1144
1145
	/**
1146
	* Gets all the spotter information based on the airport
1147
	*
1148
	* @return Array the spotter information
1149
	*
1150
	*/
1151
	public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) {
1152
		global $global_query;
1153
		$Spotter = new Spotter($this->db);
1154
		date_default_timezone_set('UTC');
1155
		$query_values = array();
1156
		$limit_query = '';
1157
		$additional_query = '';
1158
		$filter_query = $this->getFilter($filters,true,true);
1159
1160
		if ($airport != "") {
1161
			if (!is_string($airport)) {
1162
				return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterArchive::getSpotterDataByAirport of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1163
			} else {
1164
				$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = :airport) OR (spotter_archive_output.arrival_airport_icao = :airport))";
1165
				$query_values = array(':airport' => $airport);
1166
			}
1167
		}
1168
1169
		if ($limit != "") {
1170
			$limit_array = explode(",", $limit);
1171
1172
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1173
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1174
1175
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
1176
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1177
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1178
			}
1179
		}
1180
1181
		if ($sort != "") {
1182
			$search_orderby_array = $Spotter->getOrderBy();
1183
			$orderby_query = $search_orderby_array[$sort]['sql'];
1184
		} else {
1185
			$orderby_query = " ORDER BY spotter_archive_output.date DESC";
1186
		}
1187
1188
		$query = $global_query.$filter_query." spotter_archive_output.ident <> '' ".$additional_query." AND ((spotter_archive_output.departure_airport_icao <> 'NA') AND (spotter_archive_output.arrival_airport_icao <> 'NA')) ".$orderby_query;
1189
1190
		$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query);
1191
1192
		return $spotter_array;
1193
	}
1194
}
1195
?>