Code Duplication    Length = 39-40 lines in 7 locations

require/class.Spotter.php 7 locations

@@ 7152-7190 (lines=39) @@
7149
	* @return Array the month list
7150
	*
7151
	*/
7152
	public function countAllMonths()
7153
	{
7154
		global $globalTimezone, $globalDBdriver;
7155
		if ($globalTimezone != '') {
7156
			date_default_timezone_set($globalTimezone);
7157
			$datetime = new DateTime();
7158
			$offset = $datetime->format('P');
7159
		} else $offset = '+00:00';
7160
7161
		if ($globalDBdriver == 'mysql') {
7162
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
7163
								FROM spotter_output 
7164
								GROUP BY year_name, month_name 
7165
								ORDER BY date_count DESC";
7166
		} else {
7167
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count
7168
								FROM spotter_output 
7169
								GROUP BY year_name, month_name 
7170
								ORDER BY date_count DESC";
7171
		}
7172
      
7173
		
7174
		$sth = $this->db->prepare($query);
7175
		$sth->execute(array(':offset' => $offset));
7176
      
7177
		$date_array = array();
7178
		$temp_array = array();
7179
        
7180
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7181
		{
7182
			$temp_array['month_name'] = $row['month_name'];
7183
			$temp_array['year_name'] = $row['year_name'];
7184
			$temp_array['date_count'] = $row['date_count'];
7185
7186
			$date_array[] = $temp_array;
7187
		}
7188
7189
		return $date_array;
7190
	}
7191
7192
	/**
7193
	* Counts all military month
@@ 7198-7237 (lines=40) @@
7195
	* @return Array the month list
7196
	*
7197
	*/
7198
	public function countAllMilitaryMonths()
7199
	{
7200
		global $globalTimezone, $globalDBdriver;
7201
		if ($globalTimezone != '') {
7202
			date_default_timezone_set($globalTimezone);
7203
			$datetime = new DateTime();
7204
			$offset = $datetime->format('P');
7205
		} else $offset = '+00:00';
7206
7207
		if ($globalDBdriver == 'mysql') {
7208
			$query  = "SELECT YEAR(CONVERT_TZ(s.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(s.date,'+00:00', :offset)) AS month_name, count(*) as date_count
7209
								FROM spotter_output s
7210
								WHERE s.airline_type = 'military'
7211
								GROUP BY year_name, month_name 
7212
								ORDER BY date_count DESC";
7213
		} else {
7214
			$query  = "SELECT EXTRACT(YEAR FROM s.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM s.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count
7215
								FROM spotter_output s
7216
								WHERE s.airline_type = 'military'
7217
								GROUP BY year_name, month_name 
7218
								ORDER BY date_count DESC";
7219
		}
7220
		
7221
		$sth = $this->db->prepare($query);
7222
		$sth->execute(array(':offset' => $offset));
7223
      
7224
		$date_array = array();
7225
		$temp_array = array();
7226
        
7227
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7228
		{
7229
			$temp_array['month_name'] = $row['month_name'];
7230
			$temp_array['year_name'] = $row['year_name'];
7231
			$temp_array['date_count'] = $row['date_count'];
7232
7233
			$date_array[] = $temp_array;
7234
		}
7235
7236
		return $date_array;
7237
	}
7238
	
7239
	/**
7240
	* Counts all month owners
@@ 7245-7284 (lines=40) @@
7242
	* @return Array the month list
7243
	*
7244
	*/
7245
	public function countAllMonthsOwners()
7246
	{
7247
		global $globalTimezone, $globalDBdriver;
7248
		if ($globalTimezone != '') {
7249
			date_default_timezone_set($globalTimezone);
7250
			$datetime = new DateTime();
7251
			$offset = $datetime->format('P');
7252
		} else $offset = '+00:00';
7253
7254
		if ($globalDBdriver == 'mysql') {
7255
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct owner_name) as date_count
7256
								FROM spotter_output 
7257
								WHERE owner_name <> ''
7258
								GROUP BY year_name, month_name
7259
								ORDER BY date_count DESC";
7260
		} else {
7261
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct owner_name) as date_count
7262
								FROM spotter_output 
7263
								WHERE owner_name <> ''
7264
								GROUP BY year_name, month_name
7265
								ORDER BY date_count DESC";
7266
		}
7267
		
7268
		$sth = $this->db->prepare($query);
7269
		$sth->execute(array(':offset' => $offset));
7270
      
7271
		$date_array = array();
7272
		$temp_array = array();
7273
        
7274
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7275
		{
7276
			$temp_array['month_name'] = $row['month_name'];
7277
			$temp_array['year_name'] = $row['year_name'];
7278
			$temp_array['date_count'] = $row['date_count'];
7279
7280
			$date_array[] = $temp_array;
7281
		}
7282
7283
		return $date_array;
7284
	}
7285
7286
	/**
7287
	* Counts all month pilot
@@ 7292-7331 (lines=40) @@
7289
	* @return Array the month list
7290
	*
7291
	*/
7292
	public function countAllMonthsPilots()
7293
	{
7294
		global $globalTimezone, $globalDBdriver;
7295
		if ($globalTimezone != '') {
7296
			date_default_timezone_set($globalTimezone);
7297
			$datetime = new DateTime();
7298
			$offset = $datetime->format('P');
7299
		} else $offset = '+00:00';
7300
7301
		if ($globalDBdriver == 'mysql') {
7302
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct pilot_id) as date_count
7303
								FROM spotter_output 
7304
								WHERE pilot_id <> '' AND pilot_id IS NOT NULL
7305
								GROUP BY year_name, month_name
7306
								ORDER BY date_count DESC";
7307
		} else {
7308
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct pilot_id) as date_count
7309
								FROM spotter_output 
7310
								WHERE pilot_id <> '' AND pilot_id IS NOT NULL
7311
								GROUP BY year_name, month_name
7312
								ORDER BY date_count DESC";
7313
		}
7314
		
7315
		$sth = $this->db->prepare($query);
7316
		$sth->execute(array(':offset' => $offset));
7317
      
7318
		$date_array = array();
7319
		$temp_array = array();
7320
        
7321
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7322
		{
7323
			$temp_array['month_name'] = $row['month_name'];
7324
			$temp_array['year_name'] = $row['year_name'];
7325
			$temp_array['date_count'] = $row['date_count'];
7326
7327
			$date_array[] = $temp_array;
7328
		}
7329
7330
		return $date_array;
7331
	}
7332
	
7333
7334
	/**
@@ 7340-7379 (lines=40) @@
7337
	* @return Array the month list
7338
	*
7339
	*/
7340
	public function countAllMonthsAirlines()
7341
	{
7342
		global $globalTimezone, $globalDBdriver;
7343
		if ($globalTimezone != '') {
7344
			date_default_timezone_set($globalTimezone);
7345
			$datetime = new DateTime();
7346
			$offset = $datetime->format('P');
7347
		} else $offset = '+00:00';
7348
7349
		if ($globalDBdriver == 'mysql') {
7350
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct airline_icao) as date_count
7351
								FROM spotter_output 
7352
								WHERE airline_icao <> '' 
7353
								GROUP BY year_name, month_name
7354
								ORDER BY date_count DESC";
7355
		} else {
7356
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct airline_icao) as date_count
7357
								FROM spotter_output 
7358
								WHERE airline_icao <> '' 
7359
								GROUP BY year_name, month_name
7360
								ORDER BY date_count DESC";
7361
		}
7362
		
7363
		$sth = $this->db->prepare($query);
7364
		$sth->execute(array(':offset' => $offset));
7365
      
7366
		$date_array = array();
7367
		$temp_array = array();
7368
        
7369
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7370
		{
7371
			$temp_array['month_name'] = $row['month_name'];
7372
			$temp_array['year_name'] = $row['year_name'];
7373
			$temp_array['date_count'] = $row['date_count'];
7374
7375
			$date_array[] = $temp_array;
7376
		}
7377
7378
		return $date_array;
7379
	}
7380
	
7381
	/**
7382
	* Counts all month aircraft
@@ 7387-7426 (lines=40) @@
7384
	* @return Array the month list
7385
	*
7386
	*/
7387
	public function countAllMonthsAircrafts()
7388
	{
7389
		global $globalTimezone, $globalDBdriver;
7390
		if ($globalTimezone != '') {
7391
			date_default_timezone_set($globalTimezone);
7392
			$datetime = new DateTime();
7393
			$offset = $datetime->format('P');
7394
		} else $offset = '+00:00';
7395
7396
		if ($globalDBdriver == 'mysql') {
7397
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct aircraft_icao) as date_count
7398
								FROM spotter_output 
7399
								WHERE aircraft_icao <> '' 
7400
								GROUP BY year_name, month_name
7401
								ORDER BY date_count DESC";
7402
		} else {
7403
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct aircraft_icao) as date_count
7404
								FROM spotter_output 
7405
								WHERE aircraft_icao <> '' 
7406
								GROUP BY year_name, month_name
7407
								ORDER BY date_count DESC";
7408
		}
7409
		
7410
		$sth = $this->db->prepare($query);
7411
		$sth->execute(array(':offset' => $offset));
7412
      
7413
		$date_array = array();
7414
		$temp_array = array();
7415
        
7416
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7417
		{
7418
			$temp_array['month_name'] = $row['month_name'];
7419
			$temp_array['year_name'] = $row['year_name'];
7420
			$temp_array['date_count'] = $row['date_count'];
7421
7422
			$date_array[] = $temp_array;
7423
		}
7424
7425
		return $date_array;
7426
	}
7427
	
7428
7429
	/**
@@ 7435-7474 (lines=40) @@
7432
	* @return Array the month list
7433
	*
7434
	*/
7435
	public function countAllMonthsRealArrivals()
7436
	{
7437
		global $globalTimezone, $globalDBdriver;
7438
		if ($globalTimezone != '') {
7439
			date_default_timezone_set($globalTimezone);
7440
			$datetime = new DateTime();
7441
			$offset = $datetime->format('P');
7442
		} else $offset = '+00:00';
7443
7444
		if ($globalDBdriver == 'mysql') {
7445
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(real_arrival_airport_icao) as date_count
7446
								FROM spotter_output 
7447
								WHERE real_arrival_airport_icao <> '' 
7448
								GROUP BY year_name, month_name
7449
								ORDER BY date_count DESC";
7450
		} else {
7451
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(real_arrival_airport_icao) as date_count
7452
								FROM spotter_output 
7453
								WHERE real_arrival_airport_icao <> '' 
7454
								GROUP BY year_name, month_name
7455
								ORDER BY date_count DESC";
7456
		}
7457
		
7458
		$sth = $this->db->prepare($query);
7459
		$sth->execute(array(':offset' => $offset));
7460
      
7461
		$date_array = array();
7462
		$temp_array = array();
7463
        
7464
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7465
		{
7466
			$temp_array['month_name'] = $row['month_name'];
7467
			$temp_array['year_name'] = $row['year_name'];
7468
			$temp_array['date_count'] = $row['date_count'];
7469
7470
			$date_array[] = $temp_array;
7471
		}
7472
7473
		return $date_array;
7474
	}
7475
	
7476
7477