Code Duplication    Length = 20-20 lines in 5 locations

core/process/queries/QueryManagerMysqlMonocleAlternate.php 2 locations

@@ 574-593 (lines=20) @@
571
		return $trainers;
572
	}
573
574
	public function getTrainerLevelRanking() {
575
		$exclue = "";
576
		if (!empty(self::$config->system->trainer_blacklist)) {
577
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
578
		}
579
		$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";
580
		$result = $this->mysqli->query($req);
581
		$levelData = array();
582
		while ($data = $result->fetch_object()) {
583
			$levelData[$data->level] = $data->count;
584
		}
585
		for ($i = 5; $i <= 40; $i++) {
586
			if (!isset($levelData[$i])) {
587
				$levelData[$i] = 0;
588
			}
589
		}
590
		# sort array again
591
		ksort($levelData);
592
		return $levelData;
593
	}
594
595
	public function getActivePokemon($trainer_name) {
596
		$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
@@ 621-640 (lines=20) @@
618
		return $pokemon;
619
	}
620
621
	public function getTrainerLevelCount($team_id) {
622
		$exclue = "";
623
		if (!empty(self::$config->system->trainer_blacklist)) {
624
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
625
		}
626
		$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";
627
		$result = $this->mysqli->query($req);
628
		$levelData = array();
629
		while ($data = $result->fetch_object()) {
630
			$levelData[$data->level] = $data->count;
631
		}
632
		for ($i = 5; $i <= 40; $i++) {
633
			if (!isset($levelData[$i])) {
634
				$levelData[$i] = 0;
635
			}
636
		}
637
		# sort array again
638
		ksort($levelData);
639
		return $levelData;
640
	}
641
642
643
	/////////

core/process/queries/QueryManagerMysqlRocketmap.php 1 location

@@ 527-546 (lines=20) @@
524
		return $trainers;
525
	}
526
527
	public function getTrainerLevelCount($team_id) {
528
		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
529
		if (!empty(self::$config->system->trainer_blacklist)) {
530
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
531
		}
532
		$req .= " GROUP BY level";
533
		$result = $this->mysqli->query($req);
534
		$levelData = array();
535
		while ($data = $result->fetch_object()) {
536
			$levelData[$data->level] = $data->count;
537
		}
538
		for ($i = 5; $i <= 40; $i++) {
539
			if (!isset($levelData[$i])) {
540
				$levelData[$i] = 0;
541
			}
542
		}
543
		# sort array again
544
		ksort($levelData);
545
		return $levelData;
546
	}
547
548
	private function getTrainerData($trainer_name, $team, $page, $ranking) {
549
		$where = "";

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 2 locations

@@ 578-597 (lines=20) @@
575
		return $trainers;
576
	}
577
578
	public function getTrainerLevelRanking() {
579
		$exclue = "";
580
		if (!empty(self::$config->system->trainer_blacklist)) {
581
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
582
		}
583
		$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";
584
		$result = $this->mysqli->query($req);
585
		$levelData = array();
586
		while ($data = $result->fetch_object()) {
587
			$levelData[$data->level] = $data->count;
588
		}
589
		for ($i = 5; $i <= 40; $i++) {
590
			if (!isset($levelData[$i])) {
591
				$levelData[$i] = 0;
592
			}
593
		}
594
		# sort array again
595
		ksort($levelData);
596
		return $levelData;
597
	}
598
599
	public function getActivePokemon($trainer_name) {
600
		$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
@@ 625-644 (lines=20) @@
622
		return $pokemon;
623
	}
624
625
	public function getTrainerLevelCount($team_id) {
626
		$exclue = "";
627
		if (!empty(self::$config->system->trainer_blacklist)) {
628
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
629
		}
630
		$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";
631
		$result = $this->mysqli->query($req);
632
		$levelData = array();
633
		while ($data = $result->fetch_object()) {
634
			$levelData[$data->level] = $data->count;
635
		}
636
		for ($i = 5; $i <= 40; $i++) {
637
			if (!isset($levelData[$i])) {
638
				$levelData[$i] = 0;
639
			}
640
		}
641
		# sort array again
642
		ksort($levelData);
643
		return $levelData;
644
	}
645
646
647
	/////////