Ysurac /
FlightAirMap
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | //$global_query = "SELECT spotter_live.* FROM spotter_live"; |
||
| 3 | |||
| 4 | class SpotterLive { |
||
| 5 | public $db; |
||
| 6 | static $global_query = "SELECT spotter_live.* FROM spotter_live"; |
||
| 7 | |||
| 8 | public function __construct($dbc = null) { |
||
| 9 | $Connection = new Connection($dbc); |
||
| 10 | $this->db = $Connection->db(); |
||
| 11 | } |
||
| 12 | |||
| 13 | |||
| 14 | /** |
||
| 15 | * Get SQL query part for filter used |
||
| 16 | * @param Array $filter the filter |
||
| 17 | * @return Array the SQL part |
||
| 18 | */ |
||
| 19 | public function getFilter($filter = array(),$where = false,$and = false) { |
||
| 20 | global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver; |
||
| 21 | $filters = array(); |
||
| 22 | if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
||
| 23 | if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
||
| 24 | $filters = $globalStatsFilters[$globalFilterName]; |
||
| 25 | } else { |
||
| 26 | $filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | if (isset($filter[0]['source'])) { |
||
| 30 | $filters = array_merge($filters,$filter); |
||
| 31 | } |
||
| 32 | if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
||
| 33 | $filter_query_join = ''; |
||
| 34 | $filter_query_where = ''; |
||
| 35 | foreach($filters as $flt) { |
||
| 36 | if (isset($flt['airlines']) && !empty($flt['airlines'])) { |
||
| 37 | if ($flt['airlines'][0] != '') { |
||
| 38 | if (isset($flt['source'])) { |
||
| 39 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id"; |
||
| 40 | } else { |
||
| 41 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id"; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) { |
||
| 46 | if (isset($flt['source'])) { |
||
| 47 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id"; |
||
| 48 | } else { |
||
| 49 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id"; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | if (isset($flt['idents']) && !empty($flt['idents'])) { |
||
| 53 | if (isset($flt['source'])) { |
||
| 54 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id"; |
||
| 55 | } else { |
||
| 56 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id"; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | if (isset($flt['registrations']) && !empty($flt['registrations'])) { |
||
| 60 | if (isset($flt['source'])) { |
||
| 61 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id"; |
||
| 62 | } else { |
||
| 63 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id"; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) { |
||
| 67 | if (isset($flt['source'])) { |
||
| 68 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) ssf ON ssf.flightaware_id = spotter_live.flightaware_id"; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
||
| 73 | if ($filter['airlines'][0] != '') { |
||
| 74 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) sai ON sai.flightaware_id = spotter_live.flightaware_id"; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | if (isset($filter['alliance']) && !empty($filter['alliance'])) { |
||
| 78 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN (SELECT icao FROM airlines WHERE alliance = '".$filter['alliance']."')) sal ON sal.flightaware_id = spotter_live.flightaware_id "; |
||
| 79 | } |
||
| 80 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
||
| 81 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
||
| 82 | } |
||
| 83 | if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
||
| 84 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) sp ON sp.flightaware_id = spotter_live.flightaware_id"; |
||
| 85 | } |
||
| 86 | if (isset($filter['source']) && !empty($filter['source'])) { |
||
| 87 | $filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; |
||
| 88 | } |
||
| 89 | if (isset($filter['ident']) && !empty($filter['ident'])) { |
||
| 90 | $filter_query_where .= " AND ident = '".$filter['ident']."'"; |
||
| 91 | } |
||
| 92 | if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) { |
||
| 93 | $filter_query_date = ''; |
||
| 94 | |||
| 95 | if (isset($filter['year']) && $filter['year'] != '') { |
||
| 96 | if ($globalDBdriver == 'mysql') { |
||
| 97 | $filter_query_date .= " AND YEAR(spotter_output.date) = '".$filter['year']."'"; |
||
| 98 | } else { |
||
| 99 | $filter_query_date .= " AND EXTRACT(YEAR FROM spotter_output.date) = '".$filter['year']."'"; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | if (isset($filter['month']) && $filter['month'] != '') { |
||
| 103 | if ($globalDBdriver == 'mysql') { |
||
| 104 | $filter_query_date .= " AND MONTH(spotter_output.date) = '".$filter['month']."'"; |
||
| 105 | } else { |
||
| 106 | $filter_query_date .= " AND EXTRACT(MONTH FROM spotter_output.date) = '".$filter['month']."'"; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | if (isset($filter['day']) && $filter['day'] != '') { |
||
| 110 | if ($globalDBdriver == 'mysql') { |
||
| 111 | $filter_query_date .= " AND DAY(spotter_output.date) = '".$filter['day']."'"; |
||
| 112 | } else { |
||
| 113 | $filter_query_date .= " AND EXTRACT(DAY FROM spotter_output.date) = '".$filter['day']."'"; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_live.flightaware_id"; |
||
| 117 | } |
||
| 118 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
||
| 119 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
||
| 120 | } |
||
| 121 | if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
||
| 122 | elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
||
| 123 | if ($filter_query_where != '') { |
||
| 124 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
||
| 125 | } |
||
| 126 | $filter_query = $filter_query_join.$filter_query_where; |
||
| 127 | return $filter_query; |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Gets all the spotter information based on the latest data entry |
||
| 132 | * |
||
| 133 | * @return Array the spotter information |
||
| 134 | * |
||
| 135 | */ |
||
| 136 | public function getLiveSpotterData($limit = '', $sort = '', $filter = array()) |
||
| 137 | { |
||
| 138 | global $globalDBdriver, $globalLiveInterval; |
||
| 139 | $Spotter = new Spotter($this->db); |
||
| 140 | date_default_timezone_set('UTC'); |
||
| 141 | |||
| 142 | $filter_query = $this->getFilter($filter); |
||
| 143 | $limit_query = ''; |
||
| 144 | if ($limit != '') |
||
| 145 | { |
||
| 146 | $limit_array = explode(',', $limit); |
||
| 147 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 148 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 149 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 150 | { |
||
| 151 | $limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0]; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | $orderby_query = ''; |
||
| 155 | if ($sort != '') |
||
| 156 | { |
||
| 157 | $search_orderby_array = $this->getOrderBy(); |
||
| 158 | if (isset($search_orderby_array[$sort]['sql'])) |
||
| 159 | { |
||
| 160 | $orderby_query = ' '.$search_orderby_array[$sort]['sql']; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 165 | if ($globalDBdriver == 'mysql') { |
||
| 166 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
||
| 167 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query; |
||
| 168 | } else { |
||
| 169 | $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query.$orderby_query; |
||
| 170 | } |
||
| 171 | $spotter_array = $Spotter->getDataFromDB($query.$limit_query,array(),'',true); |
||
| 172 | |||
| 173 | return $spotter_array; |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Gets Minimal Live Spotter data |
||
| 178 | * |
||
| 179 | * @return Array the spotter information |
||
| 180 | * |
||
| 181 | */ |
||
| 182 | public function getMinLiveSpotterData($filter = array()) |
||
| 183 | { |
||
| 184 | global $globalDBdriver, $globalLiveInterval; |
||
| 185 | date_default_timezone_set('UTC'); |
||
| 186 | |||
| 187 | $filter_query = $this->getFilter($filter,true,true); |
||
| 188 | |||
| 189 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 190 | if ($globalDBdriver == 'mysql') { |
||
| 191 | // $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$globalLiveInterval." SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
||
| 192 | // $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
||
| 193 | // $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query; |
||
| 194 | /* |
||
| 195 | $query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 196 | FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0"; |
||
| 197 | */ |
||
| 198 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 199 | FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0"; |
||
| 200 | |||
| 201 | // $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date ORDER BY spotter_live.date GROUP BY spotter_live.flightaware_id'.$filter_query; |
||
| 202 | |||
| 203 | //$query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
||
| 204 | } else { |
||
| 205 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
||
| 206 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
||
| 207 | //$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
||
| 208 | /* |
||
| 209 | $query = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 210 | FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
||
| 211 | */ |
||
| 212 | |||
| 213 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 214 | FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
||
| 215 | |||
| 216 | |||
| 217 | } |
||
| 218 | // $spotter_array = Spotter->getDataFromDB($query.$limit_query); |
||
| 219 | // echo $query; |
||
| 220 | |||
| 221 | try { |
||
| 222 | $sth = $this->db->prepare($query); |
||
| 223 | $sth->execute(); |
||
| 224 | } catch(PDOException $e) { |
||
| 225 | echo $e->getMessage(); |
||
| 226 | die; |
||
| 227 | } |
||
| 228 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 229 | |||
| 230 | return $spotter_array; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Gets Minimal Live Spotter data since xx seconds |
||
| 235 | * |
||
| 236 | * @return Array the spotter information |
||
| 237 | * |
||
| 238 | */ |
||
| 239 | public function getMinLastLiveSpotterData($filter = array()) |
||
| 240 | { |
||
| 241 | global $globalDBdriver, $globalLiveInterval; |
||
| 242 | date_default_timezone_set('UTC'); |
||
| 243 | |||
| 244 | $filter_query = $this->getFilter($filter,true,true); |
||
| 245 | |||
| 246 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 247 | if ($globalDBdriver == 'mysql') { |
||
| 248 | /* |
||
| 249 | $query = 'SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 250 | FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,engine_type, engine_count, wake_category,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
||
| 251 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
||
| 252 | */ |
||
| 253 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 254 | FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
||
| 255 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
||
| 256 | } else { |
||
| 257 | /* |
||
| 258 | $query = "SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 259 | FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,engine_type, engine_count, wake_category, icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
||
| 260 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
||
| 261 | */ |
||
| 262 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 263 | FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
||
| 264 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
||
| 265 | // echo $query; |
||
| 266 | } |
||
| 267 | |||
| 268 | try { |
||
| 269 | $sth = $this->db->prepare($query); |
||
| 270 | $sth->execute(); |
||
| 271 | } catch(PDOException $e) { |
||
| 272 | echo $e->getMessage(); |
||
| 273 | die; |
||
| 274 | } |
||
| 275 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 276 | return $spotter_array; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Gets number of latest data entry |
||
| 281 | * |
||
| 282 | * @return String number of entry |
||
| 283 | * |
||
| 284 | */ |
||
| 285 | public function getLiveSpotterCount($filter = array()) |
||
| 286 | { |
||
| 287 | global $globalDBdriver, $globalLiveInterval; |
||
| 288 | $filter_query = $this->getFilter($filter,true,true); |
||
| 289 | |||
| 290 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 291 | if ($globalDBdriver == 'mysql') { |
||
| 292 | //$query = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query; |
||
| 293 | $query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
||
| 294 | } else { |
||
| 295 | //$query = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query; |
||
| 296 | $query = "SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
||
| 297 | } |
||
| 298 | try { |
||
| 299 | $sth = $this->db->prepare($query); |
||
| 300 | $sth->execute(); |
||
| 301 | } catch(PDOException $e) { |
||
| 302 | echo $e->getMessage(); |
||
| 303 | die; |
||
| 304 | } |
||
| 305 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 306 | $sth->closeCursor(); |
||
| 307 | return $result['nb']; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Gets all the spotter information based on the latest data entry and coord |
||
| 312 | * |
||
| 313 | * @return Array the spotter information |
||
| 314 | * |
||
| 315 | */ |
||
| 316 | public function getLiveSpotterDatabyCoord($coord, $filter = array()) |
||
| 317 | { |
||
| 318 | global $globalDBdriver, $globalLiveInterval; |
||
| 319 | $Spotter = new Spotter($this->db); |
||
| 320 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 321 | $filter_query = $this->getFilter($filter); |
||
| 322 | |||
| 323 | if (is_array($coord)) { |
||
| 324 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 325 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 326 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 327 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 328 | } else return array(); |
||
| 329 | if ($globalDBdriver == 'mysql') { |
||
| 330 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query; |
||
| 331 | } else { |
||
| 332 | $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." GROUP BY spotter_live.flightaware_id".$filter_query; |
||
| 333 | |||
| 334 | } |
||
| 335 | $spotter_array = $Spotter->getDataFromDB($query); |
||
| 336 | return $spotter_array; |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Gets all the spotter information based on the latest data entry and coord |
||
| 341 | * |
||
| 342 | * @return Array the spotter information |
||
| 343 | * |
||
| 344 | */ |
||
| 345 | public function getMinLiveSpotterDatabyCoord($coord, $filter = array()) |
||
| 346 | { |
||
| 347 | global $globalDBdriver, $globalLiveInterval; |
||
| 348 | $Spotter = new Spotter($this->db); |
||
| 349 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
||
| 350 | $filter_query = $this->getFilter($filter,true,true); |
||
| 351 | |||
| 352 | if (is_array($coord)) { |
||
| 353 | $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 354 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 355 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 356 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 357 | } else return array(); |
||
| 358 | if ($globalDBdriver == 'mysql') { |
||
| 359 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 360 | FROM spotter_live |
||
| 361 | INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
||
| 362 | FROM spotter_live l |
||
| 363 | WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date |
||
| 364 | AND l.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND l.longitude BETWEEN '.$minlong.' AND '.$maxlong.' |
||
| 365 | GROUP BY l.flightaware_id |
||
| 366 | ) s on spotter_live.flightaware_id = s.flightaware_id |
||
| 367 | AND spotter_live.date = s.maxdate'.$filter_query.' spotter_live.latitude <> 0 AND spotter_live.longitude <> 0'; |
||
| 368 | } else { |
||
| 369 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
||
| 370 | FROM spotter_live |
||
| 371 | INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
||
| 372 | FROM spotter_live l |
||
| 373 | WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date |
||
| 374 | AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." |
||
| 375 | AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." |
||
| 376 | GROUP BY l.flightaware_id |
||
| 377 | ) s on spotter_live.flightaware_id = s.flightaware_id |
||
| 378 | AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
||
| 379 | } |
||
| 380 | try { |
||
| 381 | $sth = $this->db->prepare($query); |
||
| 382 | $sth->execute(); |
||
| 383 | } catch(PDOException $e) { |
||
| 384 | echo $e->getMessage(); |
||
| 385 | die; |
||
| 386 | } |
||
| 387 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 388 | return $spotter_array; |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Gets all the spotter information based on a user's latitude and longitude |
||
| 393 | * |
||
| 394 | * @return Array the spotter information |
||
| 395 | * |
||
| 396 | */ |
||
| 397 | public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
||
| 398 | { |
||
| 399 | $Spotter = new Spotter($this->db); |
||
| 400 | date_default_timezone_set('UTC'); |
||
| 401 | if ($lat != '') { |
||
| 402 | if (!is_numeric($lat)) { |
||
| 403 | return false; |
||
| 404 | } |
||
| 405 | } |
||
| 406 | if ($lng != '') |
||
| 407 | { |
||
| 408 | if (!is_numeric($lng)) |
||
| 409 | { |
||
| 410 | return false; |
||
|
0 ignored issues
–
show
|
|||
| 411 | } |
||
| 412 | } |
||
| 413 | |||
| 414 | if ($radius != '') |
||
| 415 | { |
||
| 416 | if (!is_numeric($radius)) |
||
| 417 | { |
||
| 418 | return false; |
||
| 419 | } |
||
| 420 | } |
||
| 421 | $additional_query = ''; |
||
| 422 | if ($interval != '') |
||
| 423 | { |
||
| 424 | if (!is_string($interval)) |
||
| 425 | { |
||
| 426 | //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
||
| 427 | return false; |
||
| 428 | } else { |
||
| 429 | if ($interval == '1m') |
||
| 430 | { |
||
| 431 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
||
| 432 | } else if ($interval == '15m'){ |
||
| 433 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
||
| 434 | } |
||
| 435 | } |
||
| 436 | } else { |
||
| 437 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
||
| 438 | } |
||
| 439 | |||
| 440 | $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
||
| 441 | WHERE spotter_live.latitude <> '' |
||
| 442 | AND spotter_live.longitude <> '' |
||
| 443 | ".$additional_query." |
||
| 444 | HAVING distance < :radius |
||
| 445 | ORDER BY distance"; |
||
| 446 | |||
| 447 | $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius)); |
||
| 448 | |||
| 449 | return $spotter_array; |
||
| 450 | } |
||
| 451 | |||
| 452 | |||
| 453 | /** |
||
| 454 | * Gets all the spotter information based on a particular callsign |
||
| 455 | * |
||
| 456 | * @return Array the spotter information |
||
| 457 | * |
||
| 458 | */ |
||
| 459 | public function getLastLiveSpotterDataByIdent($ident) |
||
| 460 | { |
||
| 461 | $Spotter = new Spotter($this->db); |
||
| 462 | date_default_timezone_set('UTC'); |
||
| 463 | |||
| 464 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
||
| 465 | $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 GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
||
| 466 | |||
| 467 | $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true); |
||
| 468 | |||
| 469 | return $spotter_array; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Gets all the spotter information based on a particular callsign |
||
| 474 | * |
||
| 475 | * @return Array the spotter information |
||
| 476 | * |
||
| 477 | */ |
||
| 478 | public function getDateLiveSpotterDataByIdent($ident,$date) |
||
| 479 | { |
||
| 480 | $Spotter = new Spotter($this->db); |
||
| 481 | date_default_timezone_set('UTC'); |
||
| 482 | |||
| 483 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
||
| 484 | $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.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
||
| 485 | |||
| 486 | $date = date('c',$date); |
||
| 487 | $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
||
| 488 | |||
| 489 | return $spotter_array; |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Gets last spotter information based on a particular callsign |
||
| 494 | * |
||
| 495 | * @return Array the spotter information |
||
| 496 | * |
||
| 497 | */ |
||
| 498 | public function getLastLiveSpotterDataById($id) |
||
| 499 | { |
||
| 500 | $Spotter = new Spotter($this->db); |
||
| 501 | date_default_timezone_set('UTC'); |
||
| 502 | |||
| 503 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
||
| 504 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
||
| 505 | |||
| 506 | $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true); |
||
| 507 | |||
| 508 | return $spotter_array; |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Gets last spotter information based on a particular callsign |
||
| 513 | * |
||
| 514 | * @return Array the spotter information |
||
| 515 | * |
||
| 516 | */ |
||
| 517 | public function getDateLiveSpotterDataById($id,$date) |
||
| 518 | { |
||
| 519 | $Spotter = new Spotter($this->db); |
||
| 520 | date_default_timezone_set('UTC'); |
||
| 521 | |||
| 522 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
||
| 523 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
||
| 524 | $date = date('c',$date); |
||
| 525 | $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true); |
||
| 526 | |||
| 527 | return $spotter_array; |
||
| 528 | } |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Gets altitude information based on a particular callsign |
||
| 532 | * |
||
| 533 | * @return Array the spotter information |
||
| 534 | * |
||
| 535 | */ |
||
| 536 | public function getAltitudeLiveSpotterDataByIdent($ident) |
||
| 537 | { |
||
| 538 | |||
| 539 | date_default_timezone_set('UTC'); |
||
| 540 | |||
| 541 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
||
| 542 | $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
||
| 543 | |||
| 544 | try { |
||
| 545 | |||
| 546 | $sth = $this->db->prepare($query); |
||
| 547 | $sth->execute(array(':ident' => $ident)); |
||
| 548 | } catch(PDOException $e) { |
||
| 549 | echo $e->getMessage(); |
||
| 550 | die; |
||
| 551 | } |
||
| 552 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 553 | |||
| 554 | return $spotter_array; |
||
| 555 | } |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Gets all the spotter information based on a particular id |
||
| 559 | * |
||
| 560 | * @return Array the spotter information |
||
| 561 | * |
||
| 562 | */ |
||
| 563 | public function getAllLiveSpotterDataById($id,$liveinterval = false) |
||
| 564 | { |
||
| 565 | global $globalDBdriver, $globalLiveInterval; |
||
| 566 | date_default_timezone_set('UTC'); |
||
| 567 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
||
| 568 | //$query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
||
| 569 | if ($globalDBdriver == 'mysql') { |
||
| 570 | $query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
||
| 571 | if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
||
| 572 | $query .= ' ORDER BY date'; |
||
| 573 | } else { |
||
| 574 | $query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
||
| 575 | if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
||
| 576 | $query .= ' ORDER BY date'; |
||
| 577 | } |
||
| 578 | |||
| 579 | try { |
||
| 580 | $sth = $this->db->prepare($query); |
||
| 581 | $sth->execute(array(':id' => $id)); |
||
| 582 | } catch(PDOException $e) { |
||
| 583 | echo $e->getMessage(); |
||
| 584 | die; |
||
| 585 | } |
||
| 586 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 587 | return $spotter_array; |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * Gets all the spotter information based on a particular ident |
||
| 592 | * |
||
| 593 | * @return Array the spotter information |
||
| 594 | * |
||
| 595 | */ |
||
| 596 | public function getAllLiveSpotterDataByIdent($ident) |
||
| 597 | { |
||
| 598 | date_default_timezone_set('UTC'); |
||
| 599 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
||
| 600 | $query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
||
| 601 | try { |
||
| 602 | |||
| 603 | $sth = $this->db->prepare($query); |
||
| 604 | $sth->execute(array(':ident' => $ident)); |
||
| 605 | } catch(PDOException $e) { |
||
| 606 | echo $e->getMessage(); |
||
| 607 | die; |
||
| 608 | } |
||
| 609 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 610 | return $spotter_array; |
||
| 611 | } |
||
| 612 | |||
| 613 | |||
| 614 | /** |
||
| 615 | * Deletes all info in the table |
||
| 616 | * |
||
| 617 | * @return String success or false |
||
| 618 | * |
||
| 619 | */ |
||
| 620 | public function deleteLiveSpotterData() |
||
| 621 | { |
||
| 622 | global $globalDBdriver; |
||
| 623 | if ($globalDBdriver == 'mysql') { |
||
| 624 | //$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
||
| 625 | $query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
||
| 626 | //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
||
| 627 | } else { |
||
| 628 | $query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
||
| 629 | } |
||
| 630 | |||
| 631 | try { |
||
| 632 | |||
| 633 | $sth = $this->db->prepare($query); |
||
| 634 | $sth->execute(); |
||
| 635 | } catch(PDOException $e) { |
||
| 636 | return "error"; |
||
| 637 | } |
||
| 638 | |||
| 639 | return "success"; |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Deletes all info in the table for aircraft not seen since 2 HOUR |
||
| 644 | * |
||
| 645 | * @return String success or false |
||
| 646 | * |
||
| 647 | */ |
||
| 648 | public function deleteLiveSpotterDataNotUpdated() |
||
| 649 | { |
||
| 650 | global $globalDBdriver, $globalDebug; |
||
| 651 | if ($globalDBdriver == 'mysql') { |
||
| 652 | //$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0'; |
||
| 653 | $query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0"; |
||
| 654 | try { |
||
| 655 | |||
| 656 | $sth = $this->db->prepare($query); |
||
| 657 | $sth->execute(); |
||
| 658 | } catch(PDOException $e) { |
||
| 659 | return "error"; |
||
| 660 | } |
||
| 661 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
||
| 662 | $i = 0; |
||
| 663 | $j =0; |
||
| 664 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 665 | foreach($all as $row) |
||
| 666 | { |
||
| 667 | $i++; |
||
| 668 | $j++; |
||
| 669 | if ($j == 30) { |
||
| 670 | if ($globalDebug) echo "."; |
||
| 671 | try { |
||
| 672 | |||
| 673 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
||
| 674 | $sth->execute(); |
||
| 675 | } catch(PDOException $e) { |
||
| 676 | return "error"; |
||
| 677 | } |
||
| 678 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
||
| 679 | $j = 0; |
||
| 680 | } |
||
| 681 | $query_delete .= "'".$row['flightaware_id']."',"; |
||
| 682 | } |
||
| 683 | if ($i > 0) { |
||
| 684 | try { |
||
| 685 | |||
| 686 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
||
| 687 | $sth->execute(); |
||
| 688 | } catch(PDOException $e) { |
||
| 689 | return "error"; |
||
| 690 | } |
||
| 691 | } |
||
| 692 | return "success"; |
||
| 693 | } elseif ($globalDBdriver == 'pgsql') { |
||
| 694 | //$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0"; |
||
| 695 | //$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
||
| 696 | $query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)"; |
||
| 697 | try { |
||
| 698 | |||
| 699 | $sth = $this->db->prepare($query); |
||
| 700 | $sth->execute(); |
||
| 701 | } catch(PDOException $e) { |
||
| 702 | return "error"; |
||
| 703 | } |
||
| 704 | /* $query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
||
| 705 | $i = 0; |
||
| 706 | $j =0; |
||
| 707 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
| 708 | foreach($all as $row) |
||
| 709 | { |
||
| 710 | $i++; |
||
| 711 | $j++; |
||
| 712 | if ($j == 100) { |
||
| 713 | if ($globalDebug) echo "."; |
||
| 714 | try { |
||
| 715 | |||
| 716 | $sth = $this->db->query(substr($query_delete,0,-1).")"); |
||
| 717 | //$sth->execute(); |
||
| 718 | } catch(PDOException $e) { |
||
| 719 | return "error"; |
||
| 720 | } |
||
| 721 | $query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
||
| 722 | $j = 0; |
||
| 723 | } |
||
| 724 | $query_delete .= "'".$row['flightaware_id']."',"; |
||
| 725 | } |
||
| 726 | if ($i > 0) { |
||
| 727 | try { |
||
| 728 | |||
| 729 | $sth = $this->db->query(substr($query_delete,0,-1).")"); |
||
| 730 | //$sth->execute(); |
||
| 731 | } catch(PDOException $e) { |
||
| 732 | return "error"; |
||
| 733 | } |
||
| 734 | } |
||
| 735 | */ |
||
| 736 | return "success"; |
||
| 737 | } |
||
| 738 | } |
||
| 739 | |||
| 740 | /** |
||
| 741 | * Deletes all info in the table for an ident |
||
| 742 | * |
||
| 743 | * @return String success or false |
||
| 744 | * |
||
| 745 | */ |
||
| 746 | public function deleteLiveSpotterDataByIdent($ident) |
||
| 747 | { |
||
| 748 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
||
| 749 | $query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
||
| 750 | |||
| 751 | try { |
||
| 752 | |||
| 753 | $sth = $this->db->prepare($query); |
||
| 754 | $sth->execute(array(':ident' => $ident)); |
||
| 755 | } catch(PDOException $e) { |
||
| 756 | return "error"; |
||
| 757 | } |
||
| 758 | |||
| 759 | return "success"; |
||
| 760 | } |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Deletes all info in the table for an id |
||
| 764 | * |
||
| 765 | * @return String success or false |
||
| 766 | * |
||
| 767 | */ |
||
| 768 | public function deleteLiveSpotterDataById($id) |
||
| 769 | { |
||
| 770 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
||
| 771 | $query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
||
| 772 | |||
| 773 | try { |
||
| 774 | |||
| 775 | $sth = $this->db->prepare($query); |
||
| 776 | $sth->execute(array(':id' => $id)); |
||
| 777 | } catch(PDOException $e) { |
||
| 778 | return "error"; |
||
| 779 | } |
||
| 780 | |||
| 781 | return "success"; |
||
| 782 | } |
||
| 783 | |||
| 784 | |||
| 785 | /** |
||
| 786 | * Gets the aircraft ident within the last hour |
||
| 787 | * |
||
| 788 | * @return String the ident |
||
| 789 | * |
||
| 790 | */ |
||
| 791 | public function getIdentFromLastHour($ident) |
||
| 792 | { |
||
| 793 | global $globalDBdriver, $globalTimezone; |
||
| 794 | if ($globalDBdriver == 'mysql') { |
||
| 795 | $query = 'SELECT spotter_live.ident FROM spotter_live |
||
| 796 | WHERE spotter_live.ident = :ident |
||
| 797 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
||
| 798 | AND spotter_live.date < UTC_TIMESTAMP()'; |
||
| 799 | $query_data = array(':ident' => $ident); |
||
| 800 | } else { |
||
| 801 | $query = "SELECT spotter_live.ident FROM spotter_live |
||
| 802 | WHERE spotter_live.ident = :ident |
||
| 803 | AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
||
| 804 | AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
||
| 805 | $query_data = array(':ident' => $ident); |
||
| 806 | } |
||
| 807 | |||
| 808 | $sth = $this->db->prepare($query); |
||
| 809 | $sth->execute($query_data); |
||
| 810 | $ident_result=''; |
||
| 811 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 812 | { |
||
| 813 | $ident_result = $row['ident']; |
||
| 814 | } |
||
| 815 | return $ident_result; |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Check recent aircraft |
||
| 820 | * |
||
| 821 | * @return String the ident |
||
| 822 | * |
||
| 823 | */ |
||
| 824 | public function checkIdentRecent($ident) |
||
| 825 | { |
||
| 826 | global $globalDBdriver, $globalTimezone; |
||
| 827 | if ($globalDBdriver == 'mysql') { |
||
| 828 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
||
| 829 | WHERE spotter_live.ident = :ident |
||
| 830 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
||
| 831 | // AND spotter_live.date < UTC_TIMESTAMP()"; |
||
| 832 | $query_data = array(':ident' => $ident); |
||
| 833 | } else { |
||
| 834 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
||
| 835 | WHERE spotter_live.ident = :ident |
||
| 836 | AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'"; |
||
| 837 | // AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
||
| 838 | $query_data = array(':ident' => $ident); |
||
| 839 | } |
||
| 840 | |||
| 841 | $sth = $this->db->prepare($query); |
||
| 842 | $sth->execute($query_data); |
||
| 843 | $ident_result=''; |
||
| 844 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 845 | { |
||
| 846 | $ident_result = $row['flightaware_id']; |
||
| 847 | } |
||
| 848 | return $ident_result; |
||
| 849 | } |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Check recent aircraft by id |
||
| 853 | * |
||
| 854 | * @return String the ident |
||
| 855 | * |
||
| 856 | */ |
||
| 857 | public function checkIdRecent($id) |
||
| 858 | { |
||
| 859 | global $globalDBdriver, $globalTimezone; |
||
| 860 | if ($globalDBdriver == 'mysql') { |
||
| 861 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
||
| 862 | WHERE spotter_live.flightaware_id = :id |
||
| 863 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; |
||
| 864 | // AND spotter_live.date < UTC_TIMESTAMP()"; |
||
| 865 | $query_data = array(':id' => $id); |
||
| 866 | } else { |
||
| 867 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
||
| 868 | WHERE spotter_live.flightaware_id = :id |
||
| 869 | AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'"; |
||
| 870 | // AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
||
| 871 | $query_data = array(':id' => $id); |
||
| 872 | } |
||
| 873 | |||
| 874 | $sth = $this->db->prepare($query); |
||
| 875 | $sth->execute($query_data); |
||
| 876 | $ident_result=''; |
||
| 877 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 878 | { |
||
| 879 | $ident_result = $row['flightaware_id']; |
||
| 880 | } |
||
| 881 | return $ident_result; |
||
| 882 | } |
||
| 883 | |||
| 884 | /** |
||
| 885 | * Check recent aircraft by ModeS |
||
| 886 | * |
||
| 887 | * @return String the ModeS |
||
| 888 | * |
||
| 889 | */ |
||
| 890 | public function checkModeSRecent($modes) |
||
| 891 | { |
||
| 892 | global $globalDBdriver, $globalTimezone; |
||
| 893 | if ($globalDBdriver == 'mysql') { |
||
| 894 | $query = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
||
| 895 | WHERE spotter_live.ModeS = :modes |
||
| 896 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
||
| 897 | // AND spotter_live.date < UTC_TIMESTAMP()"; |
||
| 898 | $query_data = array(':modes' => $modes); |
||
| 899 | } else { |
||
| 900 | $query = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
||
| 901 | WHERE spotter_live.ModeS = :modes |
||
| 902 | AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '30 MINUTE'"; |
||
| 903 | // // AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
||
| 904 | $query_data = array(':modes' => $modes); |
||
| 905 | } |
||
| 906 | |||
| 907 | $sth = $this->db->prepare($query); |
||
| 908 | $sth->execute($query_data); |
||
| 909 | $ident_result=''; |
||
| 910 | while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
||
| 911 | { |
||
| 912 | //$ident_result = $row['spotter_live_id']; |
||
| 913 | $ident_result = $row['flightaware_id']; |
||
| 914 | } |
||
| 915 | return $ident_result; |
||
| 916 | } |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Adds a new spotter data |
||
| 920 | * |
||
| 921 | * @param String $flightaware_id the ID from flightaware |
||
| 922 | * @param String $ident the flight ident |
||
| 923 | * @param String $aircraft_icao the aircraft type |
||
| 924 | * @param String $departure_airport_icao the departure airport |
||
| 925 | * @param String $arrival_airport_icao the arrival airport |
||
| 926 | * @return String success or false |
||
| 927 | * |
||
| 928 | */ |
||
| 929 | public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $altitude_real = '',$heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '') |
||
| 930 | { |
||
| 931 | global $globalURL, $globalArchive, $globalDebug; |
||
| 932 | $Common = new Common(); |
||
| 933 | date_default_timezone_set('UTC'); |
||
| 934 | |||
| 935 | //getting the airline information |
||
| 936 | if ($ident != '') |
||
| 937 | { |
||
| 938 | if (!is_string($ident)) |
||
| 939 | { |
||
| 940 | return false; |
||
| 941 | } |
||
| 942 | } |
||
| 943 | |||
| 944 | //getting the aircraft information |
||
| 945 | if ($aircraft_icao != '') |
||
| 946 | { |
||
| 947 | if (!is_string($aircraft_icao)) |
||
| 948 | { |
||
| 949 | return false; |
||
| 950 | } |
||
| 951 | } |
||
| 952 | //getting the departure airport information |
||
| 953 | if ($departure_airport_icao != '') |
||
| 954 | { |
||
| 955 | if (!is_string($departure_airport_icao)) |
||
| 956 | { |
||
| 957 | return false; |
||
| 958 | } |
||
| 959 | } |
||
| 960 | |||
| 961 | //getting the arrival airport information |
||
| 962 | if ($arrival_airport_icao != '') |
||
| 963 | { |
||
| 964 | if (!is_string($arrival_airport_icao)) |
||
| 965 | { |
||
| 966 | return false; |
||
| 967 | } |
||
| 968 | } |
||
| 969 | |||
| 970 | |||
| 971 | if ($latitude != '') |
||
| 972 | { |
||
| 973 | if (!is_numeric($latitude)) |
||
| 974 | { |
||
| 975 | return false; |
||
| 976 | } |
||
| 977 | } else return ''; |
||
| 978 | |||
| 979 | if ($longitude != '') |
||
| 980 | { |
||
| 981 | if (!is_numeric($longitude)) |
||
| 982 | { |
||
| 983 | return false; |
||
| 984 | } |
||
| 985 | } else return ''; |
||
| 986 | |||
| 987 | if ($waypoints != '') |
||
| 988 | { |
||
| 989 | if (!is_string($waypoints)) |
||
| 990 | { |
||
| 991 | return false; |
||
| 992 | } |
||
| 993 | } |
||
| 994 | |||
| 995 | if ($altitude != '') |
||
| 996 | { |
||
| 997 | if (!is_numeric($altitude)) |
||
| 998 | { |
||
| 999 | return false; |
||
| 1000 | } |
||
| 1001 | } else $altitude = 0; |
||
| 1002 | |||
| 1003 | if ($heading != '') |
||
| 1004 | { |
||
| 1005 | if (!is_numeric($heading)) |
||
| 1006 | { |
||
| 1007 | return false; |
||
| 1008 | } |
||
| 1009 | } else $heading = 0; |
||
| 1010 | |||
| 1011 | if ($groundspeed != '') |
||
| 1012 | { |
||
| 1013 | if (!is_numeric($groundspeed)) |
||
| 1014 | { |
||
| 1015 | return false; |
||
| 1016 | } |
||
| 1017 | } else $groundspeed = 0; |
||
| 1018 | date_default_timezone_set('UTC'); |
||
| 1019 | if ($date == '') $date = date("Y-m-d H:i:s", time()); |
||
| 1020 | |||
| 1021 | |||
| 1022 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
||
| 1023 | $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
||
| 1024 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
||
| 1025 | $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1026 | $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
||
| 1027 | $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1028 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1029 | $waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
||
| 1030 | $altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1031 | $heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
||
| 1032 | $groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
||
| 1033 | $squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
||
| 1034 | $route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
||
| 1035 | $ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
||
| 1036 | $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
||
| 1037 | $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
||
| 1038 | $format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
||
| 1039 | $source_name = filter_var($source_name,FILTER_SANITIZE_STRING); |
||
| 1040 | $over_country = filter_var($over_country,FILTER_SANITIZE_STRING); |
||
| 1041 | $verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
||
| 1042 | |||
| 1043 | $airline_name = ''; |
||
| 1044 | $airline_icao = ''; |
||
| 1045 | $airline_country = ''; |
||
| 1046 | $airline_type = ''; |
||
| 1047 | $aircraft_shadow = ''; |
||
| 1048 | $aircraft_type = ''; |
||
| 1049 | $aircraft_manufacturer = ''; |
||
| 1050 | |||
| 1051 | |||
| 1052 | |||
| 1053 | $aircraft_name = ''; |
||
| 1054 | $departure_airport_name = ''; |
||
| 1055 | $departure_airport_city = ''; |
||
| 1056 | $departure_airport_country = ''; |
||
| 1057 | |||
| 1058 | $arrival_airport_name = ''; |
||
| 1059 | $arrival_airport_city = ''; |
||
| 1060 | $arrival_airport_country = ''; |
||
| 1061 | |||
| 1062 | |||
| 1063 | if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
||
| 1064 | if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
||
| 1065 | if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
||
| 1066 | if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
||
| 1067 | |||
| 1068 | $query = ''; |
||
| 1069 | if ($globalArchive) { |
||
| 1070 | if ($globalDebug) echo '-- Delete previous data -- '; |
||
| 1071 | $query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;'; |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | $query .= 'INSERT INTO spotter_live (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, 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, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
||
| 1075 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,: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,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)'; |
||
| 1076 | |||
| 1077 | $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_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,':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source,':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country); |
||
| 1078 | try { |
||
| 1079 | |||
| 1080 | $sth = $this->db->prepare($query); |
||
| 1081 | $sth->execute($query_values); |
||
| 1082 | } catch(PDOException $e) { |
||
| 1083 | return "error : ".$e->getMessage(); |
||
| 1084 | } |
||
| 1085 | if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) { |
||
| 1086 | if ($globalDebug) echo '(Add to SBS archive : '; |
||
| 1087 | $SpotterArchive = new SpotterArchive($this->db); |
||
| 1088 | $result = $SpotterArchive->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, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
||
| 1089 | if ($globalDebug) echo $result.')'; |
||
| 1090 | } |
||
| 1091 | return "success"; |
||
| 1092 | |||
| 1093 | } |
||
| 1094 | |||
| 1095 | public function getOrderBy() |
||
| 1096 | { |
||
| 1097 | $orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC")); |
||
| 1098 | return $orderby; |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | } |
||
| 1102 | |||
| 1103 | |||
| 1104 | ?> |
||
| 1105 |
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:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.