Code Duplication    Length = 35-42 lines in 2 locations

require/class.Spotter.php 2 locations

@@ 3295-3336 (lines=42) @@
3292
	* @return Array the airline list
3293
	*
3294
	*/
3295
	public function countAllAirlines($limit = true, $olderthanmonths = 0, $sincedate = '')
3296
	{
3297
		global $globalDBdriver;
3298
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3299
		 			FROM spotter_output
3300
					WHERE spotter_output.airline_name <> '' AND spotter_output.airline_icao <> 'NA' ";
3301
                if ($olderthanmonths > 0) {
3302
            		if ($globalDBdriver == 'mysql') {
3303
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
3304
			} else {
3305
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
3306
			}
3307
		}
3308
                if ($sincedate != '') {
3309
            		if ($globalDBdriver == 'mysql') {
3310
				$query .= "AND date > '".$sincedate."' ";
3311
			} else {
3312
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
3313
			}
3314
		}
3315
        	$query .= "GROUP BY spotter_output.airline_name,spotter_output.airline_icao, spotter_output.airline_country ORDER BY airline_count DESC";
3316
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3317
      
3318
		
3319
		$sth = $this->db->prepare($query);
3320
		$sth->execute();
3321
      
3322
        $airline_array = array();
3323
		$temp_array = array();
3324
        
3325
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3326
		{
3327
			$temp_array['airline_name'] = $row['airline_name'];
3328
            $temp_array['airline_icao'] = $row['airline_icao'];
3329
            $temp_array['airline_count'] = $row['airline_count'];
3330
            $temp_array['airline_country'] = $row['airline_country'];
3331
          
3332
            $airline_array[] = $temp_array;
3333
		}
3334
3335
		return $airline_array;
3336
	}
3337
3338
	 /**
3339
	* Gets all pilots that have flown over
@@ 6962-6996 (lines=35) @@
6959
	* @return Array the callsign list
6960
	*
6961
	*/
6962
	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '')
6963
	{
6964
		global $globalDBdriver;
6965
		$query  = "SELECT DISTINCT spotter_output.ident, COUNT(spotter_output.ident) AS callsign_icao_count, spotter_output.airline_name, spotter_output.airline_icao  
6966
                    FROM spotter_output
6967
                    WHERE spotter_output.ident <> ''  ";
6968
		 if ($olderthanmonths > 0) {
6969
			if ($globalDBdriver == 'mysql') $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
6970
			else $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
6971
		}
6972
		if ($sincedate != '') {
6973
			if ($globalDBdriver == 'mysql') $query .= "AND date > '".$sincedate."' ";
6974
			else $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP) ";
6975
		}
6976
		$query .= "GROUP BY spotter_output.ident, spotter_output.airline_name, spotter_output.airline_icao ORDER BY callsign_icao_count DESC";
6977
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
6978
      		
6979
		$sth = $this->db->prepare($query);
6980
		$sth->execute();
6981
      
6982
		$callsign_array = array();
6983
		$temp_array = array();
6984
        
6985
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6986
		{
6987
			$temp_array['callsign_icao'] = $row['ident'];
6988
			$temp_array['airline_name'] = $row['airline_name'];
6989
			$temp_array['airline_icao'] = $row['airline_icao'];
6990
			$temp_array['callsign_icao_count'] = $row['callsign_icao_count'];
6991
          
6992
			$callsign_array[] = $temp_array;
6993
		}
6994
6995
		return $callsign_array;
6996
	}
6997
6998
6999