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