From 3ad3a78c607890352af8e96f874e4d7fd647ad4d Mon Sep 17 00:00:00 2001
From: thekabal <thekabal@gmail.com>
Date: Sun, 11 Mar 2018 21:02:02 -0600
Subject: [PATCH] Implement SectorGateway

---
 beacon.php         | 7 ++-----
 check_fighters.php | 7 ++-----
 check_mines.php    | 7 ++-----
 lrscan.php         | 9 +++------
 main.php           | 3 +--
 5 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/beacon.php b/beacon.php
index 987d032fd..cb74118e0 100644
--- a/beacon.php
+++ b/beacon.php
@@ -37,11 +37,8 @@
 $playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);
 
 // Get sectorinfo from database
-$sql = "SELECT * FROM ::prefix::universe WHERE sector_id=:sector_id LIMIT 1";
-$stmt = $pdo_db->prepare($sql);
-$stmt->bindParam(':sector_id', $playerinfo['sector'], PDO::PARAM_INT);
-$stmt->execute();
-$sectorinfo = $stmt->fetch(PDO::FETCH_ASSOC);
+$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
+$sectorinfo = $sectors_gateway->selectSectorInfo($playerinfo['sector']);
 
 $allowed_rsw = "N";
 
diff --git a/check_fighters.php b/check_fighters.php
index 2855a0a6d..df3483852 100644
--- a/check_fighters.php
+++ b/check_fighters.php
@@ -21,11 +21,8 @@
 $langvars = Tki\Translate::load($pdo_db, $lang, array('check_fighters', 'common', 'global_includes', 'global_funcs', 'combat', 'footer', 'news', 'regional'));
 
 // Get sectorinfo from database
-$sql = "SELECT * FROM ::prefix::universe WHERE sector_id=:sector_id LIMIT 1";
-$stmt = $pdo_db->prepare($sql);
-$stmt->bindParam(':sector_id', $sector, PDO::PARAM_INT);
-$stmt->execute();
-$sectorinfo = $stmt->fetch(PDO::FETCH_ASSOC);
+$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
+$sectorinfo = $sectors_gateway->selectSectorInfo($sector);
 
 $result3 = $db->Execute("SELECT * FROM {$db->prefix}sector_defense WHERE sector_id = ? and defense_type ='F' ORDER BY quantity DESC;", array($sector));
 Tki\Db::logDbErrors($pdo_db, $result3, __LINE__, __FILE__);
diff --git a/check_mines.php b/check_mines.php
index 2a95df3ea..d6a790b47 100644
--- a/check_mines.php
+++ b/check_mines.php
@@ -21,11 +21,8 @@
 $langvars = Tki\Translate::load($pdo_db, $lang, array('check_mines', 'common', 'global_includes', 'combat', 'footer', 'news'));
 
 // Get sectorinfo from database
-$sql = "SELECT * FROM ::prefix::universe WHERE sector_id=:sector_id LIMIT 1";
-$stmt = $pdo_db->prepare($sql);
-$stmt->bindParam(':sector_id', $sector, PDO::PARAM_INT);
-$stmt->execute();
-$sectorinfo = $stmt->fetch(PDO::FETCH_ASSOC);
+$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
+$sectorinfo = $sectors_gateway->selectSectorInfo($sector);
 
 // Put the defense information into the array defenseinfo
 $result3 = $db->Execute("SELECT * FROM {$db->prefix}sector_defense WHERE sector_id = ? and defense_type ='M'", array($sector));
diff --git a/lrscan.php b/lrscan.php
index ebd4a7ffc..08c966fcf 100644
--- a/lrscan.php
+++ b/lrscan.php
@@ -124,12 +124,9 @@
         $row2 = $result2->fields;
         $num_ships = $row2['count'];
 
-        // Get sectorinfo from database
-        $sql = "SELECT * FROM ::prefix::universe WHERE sector_id=:sector_id LIMIT 1";
-        $stmt = $pdo_db->prepare($sql);
-        $stmt->bindParam(':sector_id', $row['link_dest'], PDO::PARAM_INT);
-        $stmt->execute();
-        $sectorinfo = $stmt->fetch(PDO::FETCH_ASSOC);
+        // Pull sector info from database
+        $sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
+        $sectorinfo = $sectors_gateway->selectSectorInfo($row['link_dest']);
 
         // Get port type and discover the presence of a planet in scanned sector
         $result3 = $db->Execute("SELECT planet_id FROM {$db->prefix}planets WHERE sector_id = ?;", array($row['link_dest']));
diff --git a/main.php b/main.php
index 98f22f1cc..3448c7e2c 100644
--- a/main.php
+++ b/main.php
@@ -52,10 +52,9 @@
     die();
 }
 
-
 // Pull sector info from database
 $sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
-$sectorinfo = $sectors_gateway->selectsectorInfo($playerinfo['sector']);
+$sectorinfo = $sectors_gateway->selectSectorInfo($playerinfo['sector']);
 
 if ($playerinfo['on_planet'] == "Y")
 {