Code Duplication    Length = 39-43 lines in 2 locations

require/class.Spotter.php 2 locations

@@ 3344-3382 (lines=39) @@
3341
	* @return Array the pilots list
3342
	*
3343
	*/
3344
	public function countAllPilots($limit = true, $olderthanmonths = 0, $sincedate = '')
3345
	{
3346
		global $globalDBdriver;
3347
		$query  = "SELECT DISTINCT spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count
3348
		 			FROM spotter_output
3349
					WHERE spotter_output.pilot_id <> '' ";
3350
                if ($olderthanmonths > 0) {
3351
            		if ($globalDBdriver == 'mysql') {
3352
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
3353
			} else {
3354
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
3355
			}
3356
		}
3357
                if ($sincedate != '') {
3358
            		if ($globalDBdriver == 'mysql') {
3359
				$query .= "AND date > '".$sincedate."' ";
3360
			} else {
3361
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
3362
			}
3363
		}
3364
		$query .= "GROUP BY spotter_output.pilot_id,spotter_output.pilot_name ORDER BY pilot_count DESC";
3365
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3366
      
3367
		
3368
		$sth = $this->db->prepare($query);
3369
		$sth->execute();
3370
      
3371
		$airline_array = array();
3372
		$temp_array = array();
3373
        
3374
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3375
		{
3376
			$temp_array['pilot_name'] = $row['pilot_name'];
3377
			$temp_array['pilot_id'] = $row['pilot_id'];
3378
			$temp_array['pilot_count'] = $row['pilot_count'];
3379
			$airline_array[] = $temp_array;
3380
		}
3381
		return $airline_array;
3382
	}
3383
	
3384
	 /**
3385
	* Gets all owner that have flown over
@@ 3988-4030 (lines=43) @@
3985
	* @return Array the aircraft list
3986
	*
3987
	*/
3988
	public function countAllAircraftTypes($limit = true,$olderthanmonths = 0,$sincedate = '')
3989
	{
3990
		global $globalDBdriver;
3991
		$query  = "SELECT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
3992
                    FROM spotter_output
3993
                    WHERE spotter_output.aircraft_name  <> '' AND spotter_output.aircraft_icao  <> '' ";
3994
                if ($olderthanmonths > 0) {
3995
            		if ($globalDBdriver == 'mysql') {
3996
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
3997
			} else {
3998
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
3999
			}
4000
                }
4001
                if ($sincedate != '') {
4002
            		if ($globalDBdriver == 'mysql') {
4003
				$query .= "AND date > '".$sincedate."' ";
4004
			} else {
4005
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
4006
			}
4007
		}
4008
4009
                //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
4010
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
4011
                $query .= "GROUP BY spotter_output.aircraft_icao, spotter_output.aircraft_name ORDER BY aircraft_icao_count DESC";
4012
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
4013
      
4014
		
4015
		$sth = $this->db->prepare($query);
4016
		$sth->execute();
4017
4018
		$aircraft_array = array();
4019
		$temp_array = array();
4020
        
4021
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4022
		{
4023
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4024
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4025
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4026
4027
			$aircraft_array[] = $temp_array;
4028
		}
4029
		return $aircraft_array;
4030
	}
4031
4032
4033
	/**