Code Duplication    Length = 20-20 lines in 4 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 2 locations

@@ 561-580 (lines=20) @@
558
		return $trainers;
559
	}
560
561
	public function getTrainerLevelRanking() {
562
		$exclue = "";
563
		if (!empty(self::$config->system->trainer_blacklist)) {
564
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
565
		}
566
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
567
		$result = $this->mysqli->query($req);
568
		$levelData = array();
569
		while ($data = $result->fetch_object()) {
570
			$levelData[$data->level] = $data->count;
571
		}
572
		for ($i = 5; $i <= 40; $i++) {
573
			if (!isset($levelData[$i])) {
574
				$levelData[$i] = 0;
575
			}
576
		}
577
		# sort array again
578
		ksort($levelData);
579
		return $levelData;
580
	}
581
582
	public function getActivePokemon($trainer_name) {
583
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, TO_TIMESTAMP(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
@@ 608-627 (lines=20) @@
605
		return $pokemon;
606
	}
607
608
	public function getTrainerLevelCount($team_id) {
609
		$exclue = "";
610
		if (!empty(self::$config->system->trainer_blacklist)) {
611
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
612
		}
613
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
614
		$result = $this->mysqli->query($req);
615
		$levelData = array();
616
		while ($data = $result->fetch_object()) {
617
			$levelData[$data->level] = $data->count;
618
		}
619
		for ($i = 5; $i <= 40; $i++) {
620
			if (!isset($levelData[$i])) {
621
				$levelData[$i] = 0;
622
			}
623
		}
624
		# sort array again
625
		ksort($levelData);
626
		return $levelData;
627
	}
628
629
630
	/////////

core/process/queries/QueryManagerMysqlMonocleAlternate.php 2 locations

@@ 556-575 (lines=20) @@
553
		return $trainers;
554
	}
555
556
	public function getTrainerLevelRanking() {
557
		$exclue = "";
558
		if (!empty(self::$config->system->trainer_blacklist)) {
559
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
560
		}
561
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
562
		$result = $this->mysqli->query($req);
563
		$levelData = array();
564
		while ($data = $result->fetch_object()) {
565
			$levelData[$data->level] = $data->count;
566
		}
567
		for ($i = 5; $i <= 40; $i++) {
568
			if (!isset($levelData[$i])) {
569
				$levelData[$i] = 0;
570
			}
571
		}
572
		# sort array again
573
		ksort($levelData);
574
		return $levelData;
575
	}
576
577
	public function getActivePokemon($trainer_name) {
578
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
@@ 603-622 (lines=20) @@
600
		return $pokemon;
601
	}
602
603
	public function getTrainerLevelCount($team_id) {
604
		$exclue = "";
605
		if (!empty(self::$config->system->trainer_blacklist)) {
606
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
607
		}
608
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
609
		$result = $this->mysqli->query($req);
610
		$levelData = array();
611
		while ($data = $result->fetch_object()) {
612
			$levelData[$data->level] = $data->count;
613
		}
614
		for ($i = 5; $i <= 40; $i++) {
615
			if (!isset($levelData[$i])) {
616
				$levelData[$i] = 0;
617
			}
618
		}
619
		# sort array again
620
		ksort($levelData);
621
		return $levelData;
622
	}
623
624
625
	/////////