Code Duplication    Length = 26-27 lines in 4 locations

require/class.Spotter.php 1 location

@@ 3212-3238 (lines=27) @@
3209
	* @return String the ident
3210
	*
3211
	*/
3212
	public function getIdentFromLastHour($ident)
3213
	{
3214
		global $globalDBdriver, $globalTimezone;
3215
		if ($globalDBdriver == 'mysql') {
3216
			$query  = "SELECT spotter_output.ident FROM spotter_output 
3217
								WHERE spotter_output.ident = :ident 
3218
								AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
3219
								AND spotter_output.date < UTC_TIMESTAMP()";
3220
			$query_data = array(':ident' => $ident);
3221
		} elseif ($globalDBdriver == 'pgsql') {
3222
			$query  = "SELECT spotter_output.ident FROM spotter_output 
3223
								WHERE spotter_output.ident = :ident 
3224
								AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
3225
								AND spotter_output.date < now() AT TIME ZONE 'UTC'";
3226
			$query_data = array(':ident' => $ident);
3227
    		}
3228
		
3229
		$sth = $this->db->prepare($query);
3230
		$sth->execute($query_data);
3231
    		$ident_result='';
3232
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3233
		{
3234
			$ident_result = $row['ident'];
3235
		}
3236
3237
		return $ident_result;
3238
	}
3239
	
3240
	
3241
	/**

require/class.SpotterLive.php 3 locations

@@ 567-592 (lines=26) @@
564
	* @return String the ident
565
	*
566
	*/
567
	public function getIdentFromLastHour($ident)
568
	{
569
		global $globalDBdriver, $globalTimezone;
570
		if ($globalDBdriver == 'mysql') {
571
			$query  = 'SELECT spotter_live.ident FROM spotter_live 
572
				WHERE spotter_live.ident = :ident 
573
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
574
				AND spotter_live.date < UTC_TIMESTAMP()';
575
			$query_data = array(':ident' => $ident);
576
		} elseif ($globalDBdriver == 'pgsql') {
577
			$query  = "SELECT spotter_live.ident FROM spotter_live 
578
				WHERE spotter_live.ident = :ident 
579
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
580
				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
581
			$query_data = array(':ident' => $ident);
582
		}
583
		
584
		$sth = $this->db->prepare($query);
585
		$sth->execute($query_data);
586
		$ident_result='';
587
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
588
		{
589
			$ident_result = $row['ident'];
590
		}
591
		return $ident_result;
592
        }
593
594
	/**
595
	* Check recent aircraft
@@ 600-625 (lines=26) @@
597
	* @return String the ident
598
	*
599
	*/
600
	public function checkIdentRecent($ident)
601
	{
602
		global $globalDBdriver, $globalTimezone;
603
		if ($globalDBdriver == 'mysql') {
604
			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
605
				WHERE spotter_live.ident = :ident 
606
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
607
//				AND spotter_live.date < UTC_TIMESTAMP()";
608
			$query_data = array(':ident' => $ident);
609
		} elseif ($globalDBdriver == 'pgsql') {
610
			$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
611
				WHERE spotter_live.ident = :ident 
612
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
613
//				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
614
			$query_data = array(':ident' => $ident);
615
		}
616
		
617
		$sth = $this->db->prepare($query);
618
		$sth->execute($query_data);
619
		$ident_result='';
620
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
621
		{
622
			$ident_result = $row['flightaware_id'];
623
		}
624
		return $ident_result;
625
        }
626
627
	/**
628
	* Check recent aircraft by ModeS
@@ 633-659 (lines=27) @@
630
	* @return String the ModeS
631
	*
632
	*/
633
	public function checkModeSRecent($modes)
634
	{
635
		global $globalDBdriver, $globalTimezone;
636
		if ($globalDBdriver == 'mysql') {
637
			$query  = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
638
				WHERE spotter_live.ModeS = :modes 
639
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
640
//				AND spotter_live.date < UTC_TIMESTAMP()";
641
			$query_data = array(':modes' => $modes);
642
		} elseif ($globalDBdriver == 'pgsql') {
643
			$query  = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
644
				WHERE spotter_live.ModeS = :modes 
645
				AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '30 MINUTE'";
646
//			//	AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
647
			$query_data = array(':modes' => $modes);
648
		}
649
		
650
		$sth = $this->db->prepare($query);
651
		$sth->execute($query_data);
652
		$ident_result='';
653
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
654
		{
655
			//$ident_result = $row['spotter_live_id'];
656
			$ident_result = $row['flightaware_id'];
657
		}
658
		return $ident_result;
659
        }
660
661
	/**
662
	* Adds a new spotter data