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,
@@ 271-276 (lines=6) @@
268
		return $spawns;
269
	}
270
271
	public function getPokemonSliderMinMax() {
272
		$req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings";
273
		$result = pg_query($this->db, $req);
274
		$data = pg_fetch_object($result);
275
		return $data;
276
	}
277
278
	public function getMapsCoords() {
279
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
@@ 278-283 (lines=6) @@
275
		return $data;
276
	}
277
278
	public function getMapsCoords() {
279
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
280
		$result = pg_query($this->db, $req);
281
		$data = pg_fetch_object($result);
282
		return $data;
283
	}
284
285
286
	///////////////
@@ 291-296 (lines=6) @@
288
	//////////////
289
290
291
	function getTotalPokestops() {
292
		$req = "SELECT COUNT(*) as total FROM pokestops";
293
		$result = pg_query($this->db, $req);
294
		$data = pg_fetch_object($result);
295
		return $data;
296
	}
297
298
	public function getAllPokestops() {
299
		$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";
@@ 328-336 (lines=9) @@
325
		return $datas;
326
	}
327
328
	function getOwnedAndPoints($team_id) {
329
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
330
        			FROM forts f
331
					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))
332
        			WHERE fs.team = '" . $team_id . "'";
333
		$result = pg_query($this->db, $req);
334
		$data = pg_fetch_object($result);
335
		return $data;
336
	}
337
338
	function getAllGyms() {
339
		$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
@@ 350-360 (lines=11) @@
347
		return $gyms;
348
	}
349
350
	public function getGymData($gym_id) {
351
		$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
352
			FROM forts f
353
			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))
354
			WHERE f.id ='".$gym_id."'
355
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
356
		$result = pg_query($this->db, $req);
357
		$data = pg_fetch_object($result);
358
		return $data;
359
	}
360
361
	public function getGymDefenders($gym_id) {
362
		$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
363
			FROM gym_defenders
@@ 692-697 (lines=6) @@
689
		return $data;
690
	}
691
692
	public function getCaptchaCount() {
693
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
694
		$result = pg_query($this->db, $req);
695
		$data = pg_fetch_object($result);
696
		return $data;
697
	}
698
699
	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) {
700
		$pokemon_exclude_sql = "";