Code Duplication    Length = 6-10 lines in 14 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 14 locations

@@ 70-75 (lines=6) @@
67
	// Homepage
68
	/////////////
69
70
	function getTotalPokemon() {
71
		$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())";
72
		$result = pg_query($this->db, $req);
73
		$data = pg_fetch_object($result);
74
		return $data;
75
	}
76
77
	function getTotalLures() {
78
		$data = (object) array("total" => 0);
@@ 82-87 (lines=6) @@
79
		return $data;
80
	}
81
82
	function getTotalGyms() {
83
		$req = "SELECT COUNT(*) AS total FROM forts";
84
		$result = pg_query($this->db, $req);
85
		$data = pg_fetch_object($result);
86
		return $data;
87
	}
88
89
	function getTotalRaids() {
90
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())";
@@ 89-94 (lines=6) @@
86
		return $data;
87
	}
88
89
	function getTotalRaids() {
90
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())";
91
		$result = pg_query($this->db, $req);
92
		$data = pg_fetch_object($result);
93
		return $data;
94
	}
95
96
97
	function getTotalGymsForTeam($team_id) {
@@ 97-105 (lines=9) @@
94
	}
95
96
97
	function getTotalGymsForTeam($team_id) {
98
		$req = "SELECT COUNT(*) AS total
99
					FROM forts f
100
					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))
101
					WHERE team = '$team_id'";
102
		$result = pg_query($this->db, $req);
103
		$data = pg_fetch_object($result);
104
		return $data;
105
	}
106
107
	function getRecentAll() {
108
		$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,
@@ 144-152 (lines=9) @@
141
	// Single Pokemon
142
	///////////////////
143
144
	function getGymsProtectedByPokemon($pokemon_id) {
145
		$req = "SELECT COUNT(f.id) AS total
146
					FROM forts f
147
					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))
148
					WHERE guard_pokemon_id = '".$pokemon_id."'";
149
		$result = pg_query($this->db, $req);
150
		$data = pg_fetch_object($result);
151
		return $data;
152
	}
153
154
	function getPokemonLastSeen($pokemon_id) {
155
		$req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
@@ 154-163 (lines=10) @@
151
		return $data;
152
	}
153
154
	function getPokemonLastSeen($pokemon_id) {
155
		$req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
156
                FROM sightings
157
                WHERE pokemon_id = '".$pokemon_id."'
158
                ORDER BY expire_timestamp DESC
159
                LIMIT 1 OFFSET 0";
160
		$result = pg_query($this->db, $req);
161
		$data = pg_fetch_object($result);
162
		return $data;
163
	}
164
165
	function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) {
166
		$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,
@@ 265-270 (lines=6) @@
262
		return $spawns;
263
	}
264
265
	public function getPokemonSliderMinMax() {
266
		$req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings";
267
		$result = pg_query($this->db, $req);
268
		$data = pg_fetch_object($result);
269
		return $data;
270
	}
271
272
	public function getMapsCoords() {
273
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
@@ 272-277 (lines=6) @@
269
		return $data;
270
	}
271
272
	public function getMapsCoords() {
273
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
274
		$result = pg_query($this->db, $req);
275
		$data = pg_fetch_object($result);
276
		return $data;
277
	}
278
279
	public function getPokemonCount($pokemon_id) {
280
		$req = "SELECT count, last_seen, latitude, longitude
@@ 279-286 (lines=8) @@
276
		return $data;
277
	}
278
279
	public function getPokemonCount($pokemon_id) {
280
		$req = "SELECT count, last_seen, latitude, longitude
281
					FROM pokemon_stats
282
					WHERE pid = ".$pokemon_id;
283
		$result = pg_query($this->db, $req);
284
		$data = pg_fetch_object($result);
285
		return $data;
286
	}
287
288
	public function getRaidCount($pokemon_id) {
289
		$req = "SELECT count, last_seen, latitude, longitude
@@ 288-295 (lines=8) @@
285
		return $data;
286
	}
287
288
	public function getRaidCount($pokemon_id) {
289
		$req = "SELECT count, last_seen, latitude, longitude
290
					FROM raid_stats
291
					WHERE pid = ".$pokemon_id;
292
		$result = pg_query($this->db, $req);
293
		$data = pg_fetch_object($result);
294
		return $data;
295
	}
296
297
298
	///////////////
@@ 303-308 (lines=6) @@
300
	//////////////
301
302
303
	function getTotalPokestops() {
304
		$req = "SELECT COUNT(*) as total FROM pokestops";
305
		$result = pg_query($this->db, $req);
306
		$data = pg_fetch_object($result);
307
		return $data;
308
	}
309
310
	public function getAllPokestops() {
311
		$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";
@@ 340-348 (lines=9) @@
337
		return $datas;
338
	}
339
340
	function getOwnedAndPoints($team_id) {
341
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
342
        			FROM forts f
343
					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))
344
        			WHERE fs.team = '" . $team_id . "'";
345
		$result = pg_query($this->db, $req);
346
		$data = pg_fetch_object($result);
347
		return $data;
348
	}
349
350
	function getAllGyms() {
351
		$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
@@ 362-371 (lines=10) @@
359
		return $gyms;
360
	}
361
362
	public function getGymData($gym_id) {
363
		$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
364
			FROM forts f
365
			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))
366
			WHERE f.id ='".$gym_id."'
367
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
368
		$result = pg_query($this->db, $req);
369
		$data = pg_fetch_object($result);
370
		return $data;
371
	}
372
373
	public function getGymDefenders($gym_id) {
374
		$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
@@ 670-675 (lines=6) @@
667
	}
668
669
670
	public function getCaptchaCount() {
671
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
672
		$result = pg_query($this->db, $req);
673
		$data = pg_fetch_object($result);
674
		return $data;
675
	}
676
677
	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) {
678
		$pokemon_exclude_sql = "";