Code Duplication    Length = 6-10 lines in 14 locations

core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 14 locations

@@ 79-84 (lines=6) @@
76
    // Homepage
77
    /////////////
78
79
    public function getTotalPokemon()
80
    {
81
        $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())';
82
        $result = pg_query($this->db, $req);
83
        $data = pg_fetch_object($result);
84
85
        return $data;
86
    }
87
@@ 95-100 (lines=6) @@
92
        return $data;
93
    }
94
95
    public function getTotalGyms()
96
    {
97
        $req = 'SELECT COUNT(*) AS total FROM forts';
98
        $result = pg_query($this->db, $req);
99
        $data = pg_fetch_object($result);
100
101
        return $data;
102
    }
103
@@ 104-109 (lines=6) @@
101
        return $data;
102
    }
103
104
    public function getTotalRaids()
105
    {
106
        $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())';
107
        $result = pg_query($this->db, $req);
108
        $data = pg_fetch_object($result);
109
110
        return $data;
111
    }
112
@@ 113-121 (lines=9) @@
110
        return $data;
111
    }
112
113
    public function getTotalGymsForTeam($team_id)
114
    {
115
        $req = "SELECT COUNT(*) AS total
116
					FROM forts f
117
					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))
118
					WHERE team = '$team_id'";
119
        $result = pg_query($this->db, $req);
120
        $data = pg_fetch_object($result);
121
122
        return $data;
123
    }
124
@@ 166-174 (lines=9) @@
163
    // Single Pokemon
164
    ///////////////////
165
166
    public function getGymsProtectedByPokemon($pokemon_id)
167
    {
168
        $req = "SELECT COUNT(f.id) AS total
169
					FROM forts f
170
					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))
171
					WHERE guard_pokemon_id = '".$pokemon_id."'";
172
        $result = pg_query($this->db, $req);
173
        $data = pg_fetch_object($result);
174
175
        return $data;
176
    }
177
@@ 178-187 (lines=10) @@
175
        return $data;
176
    }
177
178
    public function getPokemonLastSeen($pokemon_id)
179
    {
180
        $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
181
                FROM sightings
182
                WHERE pokemon_id = '".$pokemon_id."'
183
                ORDER BY expire_timestamp DESC
184
                LIMIT 1 OFFSET 0";
185
        $result = pg_query($this->db, $req);
186
        $data = pg_fetch_object($result);
187
188
        return $data;
189
    }
190
@@ 301-306 (lines=6) @@
298
        return $spawns;
299
    }
300
301
    public function getPokemonSliderMinMax()
302
    {
303
        $req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings';
304
        $result = pg_query($this->db, $req);
305
        $data = pg_fetch_object($result);
306
307
        return $data;
308
    }
309
@@ 310-315 (lines=6) @@
307
        return $data;
308
    }
309
310
    public function getMapsCoords()
311
    {
312
        $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
313
        $result = pg_query($this->db, $req);
314
        $data = pg_fetch_object($result);
315
316
        return $data;
317
    }
318
@@ 319-326 (lines=8) @@
316
        return $data;
317
    }
318
319
    public function getPokemonCount($pokemon_id)
320
    {
321
        $req = 'SELECT count, last_seen, latitude, longitude
322
					FROM pokemon_stats
323
					WHERE pid = '.$pokemon_id;
324
        $result = pg_query($this->db, $req);
325
        $data = pg_fetch_object($result);
326
327
        return $data;
328
    }
329
@@ 344-351 (lines=8) @@
341
        return $array;
342
    }
343
344
    public function getRaidCount($pokemon_id)
345
    {
346
        $req = 'SELECT count, last_seen, latitude, longitude
347
					FROM raid_stats
348
					WHERE pid = '.$pokemon_id;
349
        $result = pg_query($this->db, $req);
350
        $data = pg_fetch_object($result);
351
352
        return $data;
353
    }
354
@@ 373-378 (lines=6) @@
370
    // Pokestops
371
    //////////////
372
373
    public function getTotalPokestops()
374
    {
375
        $req = 'SELECT COUNT(*) as total FROM pokestops';
376
        $result = pg_query($this->db, $req);
377
        $data = pg_fetch_object($result);
378
379
        return $data;
380
    }
381
@@ 414-422 (lines=9) @@
411
        return $datas;
412
    }
413
414
    public function getOwnedAndPoints($team_id)
415
    {
416
        $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
417
        			FROM forts f
418
					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))
419
        			WHERE fs.team = '".$team_id."'";
420
        $result = pg_query($this->db, $req);
421
        $data = pg_fetch_object($result);
422
423
        return $data;
424
    }
425
@@ 440-449 (lines=10) @@
437
        return $gyms;
438
    }
439
440
    public function getGymData($gym_id)
441
    {
442
        $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
443
			FROM forts f
444
			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))
445
			WHERE f.id ='".$gym_id."'
446
			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
447
        $result = pg_query($this->db, $req);
448
        $data = pg_fetch_object($result);
449
450
        return $data;
451
    }
452
@@ 751-756 (lines=6) @@
748
        return $counts;
749
    }
750
751
    public function getTotalPokemonIV()
752
    {
753
        $req = 'SELECT COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND cp IS NOT NULL';
754
        $result = pg_query($this->db, $req);
755
        $data = pg_fetch_object($result);
756
757
        return $data;
758
    }
759