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 FROM fort_sightings WHERE team = '$team_id'";
105
		$result = pg_query($this->db, $req);
106
		$data = pg_fetch_object($result);
107
		return $data;
108
	}
109
110
	function getRecentAll() {
111
		$req = "SELECT DISTINCT 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,
@@ 147-152 (lines=6) @@
144
	// Single Pokemon
145
	///////////////////
146
147
	function getGymsProtectedByPokemon($pokemon_id) {
148
		$req = "SELECT COUNT(DISTINCT(fort_id)) AS total FROM fort_sightings 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,
@@ 266-271 (lines=6) @@
263
		return $spawns;
264
	}
265
266
	public function getPokemonSliderMinMax() {
267
		$req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings";
268
		$result = pg_query($this->db, $req);
269
		$data = pg_fetch_object($result);
270
		return $data;
271
	}
272
273
	public function getMapsCoords() {
274
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
@@ 273-278 (lines=6) @@
270
		return $data;
271
	}
272
273
	public function getMapsCoords() {
274
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
275
		$result = pg_query($this->db, $req);
276
		$data = pg_fetch_object($result);
277
		return $data;
278
	}
279
280
281
	///////////////
@@ 286-291 (lines=6) @@
283
	//////////////
284
285
286
	function getTotalPokestops() {
287
		$req = "SELECT COUNT(*) as total FROM pokestops";
288
		$result = pg_query($this->db, $req);
289
		$data = pg_fetch_object($result);
290
		return $data;
291
	}
292
293
	public function getAllPokestops() {
294
		$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";
@@ 320-328 (lines=9) @@
317
		return $datas;
318
	}
319
320
	function getOwnedAndPoints($team_id) {
321
		$req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points
322
        			FROM fort_sightings fs
323
        			JOIN gym_defenders gd ON fs.fort_id = gd.fort_id
324
        			WHERE fs.team = '" . $team_id . "'";
325
		$result = pg_query($this->db, $req);
326
		$data = pg_fetch_object($result);
327
		return $data;
328
	}
329
330
	function getAllGyms() {
331
		$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 FROM forts f LEFT JOIN fort_sightings fs ON f.id = fs.fort_id;";
@@ 340-350 (lines=11) @@
337
		return $gyms;
338
	}
339
340
	public function getGymData($gym_id) {
341
		$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, SUM(gd.cp) as total_cp	
342
			FROM fort_sightings fs
343
			LEFT JOIN forts f ON f.id = fs.fort_id
344
			LEFT JOIN gym_defenders gd ON f.id = gd.fort_id
345
			WHERE f.id ='".$gym_id."'
346
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
347
		$result = pg_query($this->db, $req);
348
		$data = pg_fetch_object($result);
349
		return $data;
350
	}
351
352
	public function getGymDefenders($gym_id) {
353
		$req = "SELECT DISTINCT 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
@@ 467-472 (lines=6) @@
464
		return $data;
465
	}
466
467
	public function getCaptchaCount() {
468
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
469
		$result = pg_query($this->db, $req);
470
		$data = pg_fetch_object($result);
471
		return $data;
472
	}
473
474
	public function getNestData() {
475
		$pokemon_exclude_sql = "";