Code Duplication    Length = 6-10 lines in 14 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 14 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-111 (lines=9) @@
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
	}
112
113
	function getRecentAll() {
114
		$req = "SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
@@ 150-158 (lines=9) @@
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
	}
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
@@ 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
	public function getPokemonCount($pokemon_id) {
286
		$req = "SELECT count, last_seen, latitude, longitude
@@ 285-292 (lines=8) @@
282
		return $data;
283
	}
284
285
	public function getPokemonCount($pokemon_id) {
286
		$req = "SELECT count, last_seen, latitude, longitude
287
					FROM pokemon_stats
288
					WHERE pid = ".$pokemon_id;
289
		$result = pg_query($this->db, $req);
290
		$data = pg_fetch_object($result);
291
		return $data;
292
	}
293
294
	public function getRaidCount($pokemon_id) {
295
		$req = "SELECT count, last_seen, latitude, longitude
@@ 294-301 (lines=8) @@
291
		return $data;
292
	}
293
294
	public function getRaidCount($pokemon_id) {
295
		$req = "SELECT count, last_seen, latitude, longitude
296
					FROM raid_stats
297
					WHERE pid = ".$pokemon_id;
298
		$result = pg_query($this->db, $req);
299
		$data = pg_fetch_object($result);
300
		return $data;
301
	}
302
303
304
	///////////////
@@ 309-314 (lines=6) @@
306
	//////////////
307
308
309
	function getTotalPokestops() {
310
		$req = "SELECT COUNT(*) as total FROM pokestops";
311
		$result = pg_query($this->db, $req);
312
		$data = pg_fetch_object($result);
313
		return $data;
314
	}
315
316
	public function getAllPokestops() {
317
		$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";
@@ 346-354 (lines=9) @@
343
		return $datas;
344
	}
345
346
	function getOwnedAndPoints($team_id) {
347
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
348
        			FROM forts f
349
					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))
350
        			WHERE fs.team = '" . $team_id . "'";
351
		$result = pg_query($this->db, $req);
352
		$data = pg_fetch_object($result);
353
		return $data;
354
	}
355
356
	function getAllGyms() {
357
		$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
@@ 368-377 (lines=10) @@
365
		return $gyms;
366
	}
367
368
	public function getGymData($gym_id) {
369
		$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
370
			FROM forts f
371
			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))
372
			WHERE f.id ='".$gym_id."'
373
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
374
		$result = pg_query($this->db, $req);
375
		$data = pg_fetch_object($result);
376
		return $data;
377
	}
378
379
	public function getGymDefenders($gym_id) {
380
		$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
@@ 676-681 (lines=6) @@
673
	}
674
675
676
	public function getCaptchaCount() {
677
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
678
		$result = pg_query($this->db, $req);
679
		$data = pg_fetch_object($result);
680
		return $data;
681
	}
682
683
	public function getNestData() {
684
		$pokemon_exclude_sql = "";