Code Duplication    Length = 55-55 lines in 2 locations

require/class.Spotter.php 2 locations

@@ 5708-5762 (lines=55) @@
5705
	* @return Array the airport list
5706
	*
5707
	*/
5708
	public function countAllArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false)
5709
	{
5710
		global $globalDBdriver;
5711
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
5712
								FROM spotter_output 
5713
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' ";
5714
                if ($olderthanmonths > 0) {
5715
            		if ($globalDBdriver == 'mysql') {
5716
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5717
			} else {
5718
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5719
			}
5720
                if ($sincedate != '') {
5721
            		if ($globalDBdriver == 'mysql') {
5722
				$query .= "AND date > '".$sincedate."' ";
5723
			} else {
5724
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5725
			}
5726
		}
5727
            		if ($globalDBdriver == 'mysql') {
5728
				$query .= "AND date > '".$sincedate."' ";
5729
			} else {
5730
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5731
			}
5732
		}
5733
5734
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5735
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5736
                $query .= "GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country
5737
					ORDER BY airport_arrival_icao_count DESC";
5738
		if ($limit) $query .= " LIMIT 10";
5739
      
5740
		
5741
		$sth = $this->db->prepare($query);
5742
		$sth->execute();
5743
      
5744
		$airport_array = array();
5745
		$temp_array = array();
5746
        
5747
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5748
		{
5749
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5750
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5751
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5752
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5753
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5754
          
5755
			if ($icaoaskey) {
5756
				$icao = $row['arrival_airport_icao'];
5757
				$airport_array[$icao] = $temp_array;
5758
			} else $airport_array[] = $temp_array;
5759
		}
5760
5761
		return $airport_array;
5762
	}
5763
	
5764
	/**
5765
	* Gets all detected arrival airports of the airplanes that have flown over
@@ 5770-5824 (lines=55) @@
5767
	* @return Array the airport list
5768
	*
5769
	*/
5770
	public function countAllDetectedArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false)
5771
	{
5772
		global $globalDBdriver;
5773
		$query  = "SELECT DISTINCT spotter_output.real_arrival_airport_icao as arrival_airport_icao, COUNT(spotter_output.real_arrival_airport_icao) AS airport_arrival_icao_count, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country 
5774
			FROM spotter_output, airport 
5775
                    WHERE spotter_output.real_arrival_airport_icao <> '' AND spotter_output.real_arrival_airport_icao <> 'NA' AND airport.icao = spotter_output.real_arrival_airport_icao ";
5776
                if ($olderthanmonths > 0) {
5777
            		if ($globalDBdriver == 'mysql') {
5778
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5779
			} else {
5780
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5781
			}
5782
                if ($sincedate != '') {
5783
            		if ($globalDBdriver == 'mysql') {
5784
				$query .= "AND date > '".$sincedate."' ";
5785
			} else {
5786
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5787
			}
5788
		}
5789
            		if ($globalDBdriver == 'mysql') {
5790
				$query .= "AND date > '".$sincedate."' ";
5791
			} else {
5792
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5793
			}
5794
		}
5795
5796
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5797
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5798
                $query .= "GROUP BY spotter_output.real_arrival_airport_icao, airport.name, airport.city, airport.country
5799
					ORDER BY airport_arrival_icao_count DESC";
5800
		if ($limit) $query .= " LIMIT 10";
5801
      
5802
		
5803
		$sth = $this->db->prepare($query);
5804
		$sth->execute();
5805
      
5806
		$airport_array = array();
5807
		$temp_array = array();
5808
        
5809
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5810
		{
5811
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5812
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5813
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5814
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5815
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5816
          
5817
			if ($icaoaskey) {
5818
				$icao = $row['arrival_airport_icao'];
5819
				$airport_array[$icao] = $temp_array;
5820
			} else $airport_array[] = $temp_array;
5821
		}
5822
5823
		return $airport_array;
5824
	}
5825
	
5826
	
5827