Code Duplication    Length = 14-16 lines in 5 locations

core/process/queries/QueryManagerMysqlMonocleAlternate.php 2 locations

@@ 392-406 (lines=15) @@
389
	// Raids
390
	///////////
391
392
	public function getAllRaids($page) {
393
		$limit = " LIMIT ".($page * 10).",10";
394
		$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
395
					FROM forts f
396
					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))
397
				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
398
					WHERE r.time_end > UNIX_TIMESTAMP()
399
					ORDER BY r.level DESC, r.time_battle" . $limit;
400
		$result = $this->mysqli->query($req);
401
		$raids = array();
402
		while ($data = $result->fetch_object()) {
403
			$raids[] = $data;
404
		}
405
		return $raids;
406
	}
407
408
409
@@ 501-514 (lines=14) @@
498
		return array("last_page" => $last_page, "data" => $history);
499
	}
500
501
	private function getHistoryForGymPokemon($gym_id, $last_modified)
502
	{
503
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
504
					FROM gym_history_defenders ghd
505
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
506
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
507
					ORDER BY gd.deployment_time";
508
		$result = $this->mysqli->query($req);
509
		$pokemons = array();
510
		while ($data = $result->fetch_object()) {
511
			$pokemons[$data->defender_id] = $data;
512
		}
513
		return $pokemons;
514
	}
515
516
517

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 = "";
@@ 599-612 (lines=14) @@
596
		return $data;
597
	}
598
599
	private function getTrainerActivePokemon($trainer_name){
600
		$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
601
					FROM gympokemon INNER JOIN
602
					(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
603
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
604
					WHERE gympokemon.trainer_name='".$trainer_name."'
605
					ORDER BY gympokemon.cp DESC)";
606
		$result = $this->mysqli->query($req);
607
		$pokemons = array();
608
		while ($data = $result->fetch_object()) {
609
			$pokemons[] = $data;
610
		}
611
		return $pokemons;
612
	}
613
614
	private function getTrainerInactivePokemon($trainer_name){
615
		$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
@@ 614-627 (lines=14) @@
611
		return $pokemons;
612
	}
613
614
	private function getTrainerInactivePokemon($trainer_name){
615
		$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
616
					FROM gympokemon LEFT JOIN
617
					(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
618
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
619
					WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
620
					ORDER BY gympokemon.cp DESC)";
621
		$result = $this->mysqli->query($req);
622
		$pokemons = array();
623
		while ($data = $result->fetch_object()) {
624
			$pokemons[] = $data;
625
		}
626
		return $pokemons;
627
	}
628
629
630
	/////////