Code Duplication    Length = 6-10 lines in 14 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 14 locations

@@ 77-82 (lines=6) @@
74
    // Homepage
75
    /////////////
76
77
    public function getTotalPokemon()
78
    {
79
        $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())';
80
        $result = pg_query($this->db, $req);
81
        $data = pg_fetch_object($result);
82
83
        return $data;
84
    }
85
@@ 93-98 (lines=6) @@
90
        return $data;
91
    }
92
93
    public function getTotalGyms()
94
    {
95
        $req = 'SELECT COUNT(*) AS total FROM forts';
96
        $result = pg_query($this->db, $req);
97
        $data = pg_fetch_object($result);
98
99
        return $data;
100
    }
101
@@ 102-107 (lines=6) @@
99
        return $data;
100
    }
101
102
    public function getTotalRaids()
103
    {
104
        $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())';
105
        $result = pg_query($this->db, $req);
106
        $data = pg_fetch_object($result);
107
108
        return $data;
109
    }
110
@@ 111-119 (lines=9) @@
108
        return $data;
109
    }
110
111
    public function getTotalGymsForTeam($team_id)
112
    {
113
        $req = "SELECT COUNT(*) AS total
114
					FROM forts f
115
					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))
116
					WHERE team = '$team_id'";
117
        $result = pg_query($this->db, $req);
118
        $data = pg_fetch_object($result);
119
120
        return $data;
121
    }
122
@@ 164-172 (lines=9) @@
161
    // Single Pokemon
162
    ///////////////////
163
164
    public function getGymsProtectedByPokemon($pokemon_id)
165
    {
166
        $req = "SELECT COUNT(f.id) AS total
167
					FROM forts f
168
					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))
169
					WHERE guard_pokemon_id = '".$pokemon_id."'";
170
        $result = pg_query($this->db, $req);
171
        $data = pg_fetch_object($result);
172
173
        return $data;
174
    }
175
@@ 176-185 (lines=10) @@
173
        return $data;
174
    }
175
176
    public function getPokemonLastSeen($pokemon_id)
177
    {
178
        $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
179
                FROM sightings
180
                WHERE pokemon_id = '".$pokemon_id."'
181
                ORDER BY expire_timestamp DESC
182
                LIMIT 1 OFFSET 0";
183
        $result = pg_query($this->db, $req);
184
        $data = pg_fetch_object($result);
185
186
        return $data;
187
    }
188
@@ 299-304 (lines=6) @@
296
        return $spawns;
297
    }
298
299
    public function getPokemonSliderMinMax()
300
    {
301
        $req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings';
302
        $result = pg_query($this->db, $req);
303
        $data = pg_fetch_object($result);
304
305
        return $data;
306
    }
307
@@ 308-313 (lines=6) @@
305
        return $data;
306
    }
307
308
    public function getMapsCoords()
309
    {
310
        $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
311
        $result = pg_query($this->db, $req);
312
        $data = pg_fetch_object($result);
313
314
        return $data;
315
    }
316
@@ 317-324 (lines=8) @@
314
        return $data;
315
    }
316
317
    public function getPokemonCount($pokemon_id)
318
    {
319
        $req = 'SELECT count, last_seen, latitude, longitude
320
					FROM pokemon_stats
321
					WHERE pid = '.$pokemon_id;
322
        $result = pg_query($this->db, $req);
323
        $data = pg_fetch_object($result);
324
325
        return $data;
326
    }
327
@@ 328-335 (lines=8) @@
325
        return $data;
326
    }
327
328
    public function getRaidCount($pokemon_id)
329
    {
330
        $req = 'SELECT count, last_seen, latitude, longitude
331
					FROM raid_stats
332
					WHERE pid = '.$pokemon_id;
333
        $result = pg_query($this->db, $req);
334
        $data = pg_fetch_object($result);
335
336
        return $data;
337
    }
338
@@ 343-348 (lines=6) @@
340
    // Pokestops
341
    //////////////
342
343
    public function getTotalPokestops()
344
    {
345
        $req = 'SELECT COUNT(*) as total FROM pokestops';
346
        $result = pg_query($this->db, $req);
347
        $data = pg_fetch_object($result);
348
349
        return $data;
350
    }
351
@@ 384-392 (lines=9) @@
381
        return $datas;
382
    }
383
384
    public function getOwnedAndPoints($team_id)
385
    {
386
        $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
387
        			FROM forts f
388
					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))
389
        			WHERE fs.team = '".$team_id."'";
390
        $result = pg_query($this->db, $req);
391
        $data = pg_fetch_object($result);
392
393
        return $data;
394
    }
395
@@ 410-419 (lines=10) @@
407
        return $gyms;
408
    }
409
410
    public function getGymData($gym_id)
411
    {
412
        $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
413
			FROM forts f
414
			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))
415
			WHERE f.id ='".$gym_id."'
416
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
417
        $result = pg_query($this->db, $req);
418
        $data = pg_fetch_object($result);
419
420
        return $data;
421
    }
422
@@ 737-742 (lines=6) @@
734
        return $counts;
735
    }
736
737
    public function getCaptchaCount()
738
    {
739
        $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL';
740
        $result = pg_query($this->db, $req);
741
        $data = pg_fetch_object($result);
742
743
        return $data;
744
    }
745