Code Duplication    Length = 14-16 lines in 6 locations

core/process/queries/QueryManagerMysqlMonocleAlternate.php 2 locations

@@ 374-388 (lines=15) @@
371
	// Raids
372
	///////////
373
374
	public function getAllRaids($page) {
375
		$limit = " LIMIT ".($page * 10).",10";
376
		$req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude 
377
					FROM forts f
378
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
379
				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
380
					WHERE r.time_end > UNIX_TIMESTAMP() 
381
					ORDER BY r.level DESC, r.time_battle" . $limit;
382
		$result = $this->mysqli->query($req);
383
		$raids = array();
384
		while ($data = $result->fetch_object()) {
385
			$raids[] = $data;
386
		}
387
		return $raids;
388
	}
389
390
391
@@ 484-497 (lines=14) @@
481
		return array("last_page" => $last_page, "data" => $history);
482
	}
483
484
	private function getHistoryForGymPokemon($gym_id, $last_modified)
485
	{
486
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
487
					FROM gym_history_defenders ghd
488
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
489
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
490
					ORDER BY gd.deployment_time";
491
		$result = $this->mysqli->query($req);
492
		$pokemons = array();
493
		while ($data = $result->fetch_object()) {
494
			$pokemons[$data->defender_id] = $data;
495
		}
496
		return $pokemons;
497
	}
498
499
500

core/process/queries/QueryManagerMysqlRocketmap.php 3 locations

@@ 160-175 (lines=16) @@
157
		return $data;
158
	}
159
160
	function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) {
161
		$req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude,
162
							cp, individual_attack, individual_defense, individual_stamina,
163
							ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form
164
							FROM pokemon
165
							WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
166
							ORDER BY $top_order_by $top_direction, disappear_time DESC
167
							LIMIT 0,50";
168
169
		$result = $this->mysqli->query($req);
170
		$top = array();
171
		while ($data = $result->fetch_object()) {
172
			$top[] = $data;
173
		}
174
		return $top;
175
	}
176
177
	function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) {
178
		$trainer_blacklist = "";
@@ 581-594 (lines=14) @@
578
		return $data;
579
	}
580
581
	private function getTrainerActivePokemon($trainer_name){
582
		$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, filtered_gymmember.gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '1' AS active
583
					FROM gympokemon INNER JOIN
584
					(SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
585
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
586
					WHERE gympokemon.trainer_name='".$trainer_name."'
587
					ORDER BY gympokemon.cp DESC)";
588
		$result = $this->mysqli->query($req);
589
		$pokemons = array();
590
		while ($data = $result->fetch_object()) {
591
			$pokemons[] = $data;
592
		}
593
		return $pokemons;
594
	}
595
596
	private function getTrainerInactivePokemon($trainer_name){
597
		$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '0' AS active
@@ 596-609 (lines=14) @@
593
		return $pokemons;
594
	}
595
596
	private function getTrainerInactivePokemon($trainer_name){
597
		$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '0' AS active
598
					FROM gympokemon LEFT JOIN
599
					(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
600
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
601
					WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
602
					ORDER BY gympokemon.cp DESC)";
603
		$result = $this->mysqli->query($req);
604
		$pokemons = array();
605
		while ($data = $result->fetch_object()) {
606
			$pokemons[] = $data;
607
		}
608
		return $pokemons;
609
	}
610
611
612
	/////////

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 1 location

@@ 469-482 (lines=14) @@
466
		return array("last_page" => $last_page, "data" => $history);
467
	}
468
469
	private function getHistoryForGymPokemon($gym_id, $last_modified)
470
	{
471
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
472
					FROM gym_history_defenders ghd
473
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
474
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
475
					ORDER BY gd.deployment_time";
476
		$result = $this->mysqli->query($req);
477
		$pokemons = array();
478
		while ($data = $result->fetch_object()) {
479
			$pokemons[$data->defender_id] = $data;
480
		}
481
		return $pokemons;
482
	}
483
484
	///////////
485
	// Raids