Code Duplication    Length = 6-11 lines in 12 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 12 locations

@@ 76-81 (lines=6) @@
73
	// Homepage
74
	/////////////
75
76
	function getTotalPokemon() {
77
		$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())";
78
		$result = pg_query($this->db, $req);
79
		$data = pg_fetch_object($result);
80
		return $data;
81
	}
82
83
	function getTotalLures() {
84
		$data = (object) array("total" => 0);
@@ 88-93 (lines=6) @@
85
		return $data;
86
	}
87
88
	function getTotalGyms() {
89
		$req = "SELECT COUNT(*) AS total FROM forts";
90
		$result = pg_query($this->db, $req);
91
		$data = pg_fetch_object($result);
92
		return $data;
93
	}
94
95
	function getTotalRaids() {
96
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())";
@@ 95-100 (lines=6) @@
92
		return $data;
93
	}
94
95
	function getTotalRaids() {
96
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())";
97
		$result = pg_query($this->db, $req);
98
		$data = pg_fetch_object($result);
99
		return $data;
100
	}
101
102
103
	function getTotalGymsForTeam($team_id) {
@@ 103-108 (lines=6) @@
100
	}
101
102
103
	function getTotalGymsForTeam($team_id) {
104
		$req = "SELECT COUNT(*) AS total 
105
					FROM forts f
106
					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))
107
					WHERE team = '$team_id'";
108
		$result = pg_query($this->db, $req);
109
		$data = pg_fetch_object($result);
110
		return $data;
111
	}
@@ 150-155 (lines=6) @@
147
	// Single Pokemon
148
	///////////////////
149
150
	function getGymsProtectedByPokemon($pokemon_id) {
151
		$req = "SELECT COUNT(f.id) AS total 
152
					FROM forts f
153
					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))
154
					WHERE guard_pokemon_id = '".$pokemon_id."'";
155
		$result = pg_query($this->db, $req);
156
		$data = pg_fetch_object($result);
157
		return $data;
158
	}
@@ 160-169 (lines=10) @@
157
		return $data;
158
	}
159
160
	function getPokemonLastSeen($pokemon_id) {
161
		$req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
162
                FROM sightings
163
                WHERE pokemon_id = '".$pokemon_id."'
164
                ORDER BY expire_timestamp DESC
165
                LIMIT 1 OFFSET 0";
166
		$result = pg_query($this->db, $req);
167
		$data = pg_fetch_object($result);
168
		return $data;
169
	}
170
171
	function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) {
172
		$req = "SELECT expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS distime, pokemon_id as pokemon_id, TO_TIMESTAMP(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
@@ 272-277 (lines=6) @@
269
		return $spawns;
270
	}
271
272
	public function getPokemonSliderMinMax() {
273
		$req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings";
274
		$result = pg_query($this->db, $req);
275
		$data = pg_fetch_object($result);
276
		return $data;
277
	}
278
279
	public function getMapsCoords() {
280
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
@@ 279-284 (lines=6) @@
276
		return $data;
277
	}
278
279
	public function getMapsCoords() {
280
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
281
		$result = pg_query($this->db, $req);
282
		$data = pg_fetch_object($result);
283
		return $data;
284
	}
285
286
287
	///////////////
@@ 292-297 (lines=6) @@
289
	//////////////
290
291
292
	function getTotalPokestops() {
293
		$req = "SELECT COUNT(*) as total FROM pokestops";
294
		$result = pg_query($this->db, $req);
295
		$data = pg_fetch_object($result);
296
		return $data;
297
	}
298
299
	public function getAllPokestops() {
300
		$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, EXTRACT(EPOCH FROM NOW()) AS now, null AS lure_expiration_real FROM pokestops";
@@ 329-337 (lines=9) @@
326
		return $datas;
327
	}
328
329
	function getOwnedAndPoints($team_id) {
330
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
331
        			FROM forts f
332
					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))
333
        			WHERE fs.team = '" . $team_id . "'";
334
		$result = pg_query($this->db, $req);
335
		$data = pg_fetch_object($result);
336
		return $data;
337
	}
338
339
	function getAllGyms() {
340
		$req = "SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level 
@@ 351-361 (lines=11) @@
348
		return $gyms;
349
	}
350
351
	public function getGymData($gym_id) {
352
		$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, TO_TIMESTAMP(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp	
353
			FROM forts f
354
			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))
355
			WHERE f.id ='".$gym_id."'
356
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
357
		$result = pg_query($this->db, $req);
358
		$data = pg_fetch_object($result);
359
		return $data;
360
	}
361
362
	public function getGymDefenders($gym_id) {
363
		$req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
364
			FROM gym_defenders 
@@ 693-698 (lines=6) @@
690
		return $data;
691
	}
692
693
	public function getCaptchaCount() {
694
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
695
		$result = pg_query($this->db, $req);
696
		$data = pg_fetch_object($result);
697
		return $data;
698
	}
699
700
	public function getNestData() {
701
		$pokemon_exclude_sql = "";