Skip to content

Commit

Permalink
PlanetGateway expansion/replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
thekabal committed Jul 6, 2020
1 parent a10ed6c commit 4d4f67e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 52 deletions.
17 changes: 7 additions & 10 deletions admin/planet_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

echo "<h2>" . $langvars['l_admin_planet_editor'] . "</h2>";
echo "<form accept-charset='utf-8' action='admin.php' method='post'>";
if (empty($planet))
if (empty($planet_id))
{
echo "<select size='15' name='planet'>";
$res = $db->Execute("SELECT planet_id, name, sector_id FROM {$db->prefix}planets ORDER BY sector_id");
Expand All @@ -48,15 +48,12 @@
{
if (empty($operation))
{
// Get planet info from database
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet, \PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

echo "<table border='0' cellspacing='2' cellpadding='2'>";
echo "<tr><td><tt>" . $langvars['l_admin_planet_id'] . "</tt></td><td><font color='#6f0'>" . $planet . "</font></td>";
echo "<tr><td><tt>" . $langvars['l_admin_planet_id'] . "</tt></td><td><font color='#6f0'>" . $planet_id . "</font></td>";
echo "<td align='right'><tt>" . $langvars['l_admin_sector_id'] . "</tt><input type='text' size='5' name='sector_id' value=\"" . $row['sector_id'] . "\"></td>";
echo "<td align='right'><tt>" . $langvars['l_admin_defeated'] . "</tt><input type='checkbox' name='defeated' value='ON' " . \Tki\Checked::check($row['defeated']) . "></td></tr>";
echo "<tr><td><tt>" . $langvars['l_admin_planet_name'] . "</tt></td><td><input type='text' size='15' name='name' value=\"" . $row['name'] . "\"></td>";
Expand Down Expand Up @@ -108,7 +105,7 @@
echo "</table>";

echo "<br>";
echo "<input type='hidden' name='planet' value='" . $planet . "'>";
echo "<input type='hidden' name='planet' value='" . $planet_id . "'>";
echo "<input type='hidden' name='operation' value='save'>";
echo "<input type='submit' size='1' value='" . $langvars['l_save'] . "'>";
}
Expand All @@ -118,7 +115,7 @@
$_defeated = empty($defeated) ? "N" : "Y";
$_base = empty($base) ? "N" : "Y";
$_sells = empty($sells) ? "N" : "Y";
$planupdate = $db->Execute("UPDATE {$db->prefix}planets SET sector_id = ?, defeated = ?, name = ?, base = ?, sells = ?, owner = ?, organics = ?, ore = ?, goods = ?, energy = ?, team = ?, colonists = ?,credits = ? ,fighters = ?, torps = ?, prod_organics= ? , prod_ore = ?, prod_goods = ?, prod_energy = ?, prod_fighters = ?, prod_torp = ? WHERE planet_id = ?", array($sector_id, $_defeated, $name, $_base, $_sells, $owner, $organics, $ore, $goods, $energy, $team, $colonists, $credits, $fighters, $torps, $prod_organics, $prod_ore, $prod_goods, $prod_energy, $prod_fighters, $prod_torp, $planet));
$planupdate = $db->Execute("UPDATE {$db->prefix}planets SET sector_id = ?, defeated = ?, name = ?, base = ?, sells = ?, owner = ?, organics = ?, ore = ?, goods = ?, energy = ?, team = ?, colonists = ?,credits = ? ,fighters = ?, torps = ?, prod_organics= ? , prod_ore = ?, prod_goods = ?, prod_energy = ?, prod_fighters = ?, prod_torp = ? WHERE planet_id = ?", array($sector_id, $_defeated, $name, $_base, $_sells, $owner, $organics, $ore, $goods, $energy, $team, $colonists, $credits, $fighters, $torps, $prod_organics, $prod_ore, $prod_goods, $prod_energy, $prod_fighters, $prod_torp, $planet_id));
Tki\Db::logDbErrors($pdo_db, $planupdate, __LINE__, __FILE__);
if (!$planupdate)
{
Expand Down
15 changes: 5 additions & 10 deletions classes/Bases.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public function buildBase(\PDO $pdo_db, array $langvars, int $planet_id, int $se
$players_gateway = new Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls
$playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);

$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, \PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

// Error out and return if the Player isn't the owner of the Planet
// Verify player owns the planet which is to have the base created on.
Expand Down Expand Up @@ -88,11 +86,8 @@ public function buildBase(\PDO $pdo_db, array $langvars, int $planet_id, int $se
\Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__);

// Refresh Planet Info
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, \PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

// Notify User Of Base Results
echo $langvars['l_planet_bbuild'] . "<br><br>";
Expand Down
8 changes: 3 additions & 5 deletions classes/KabalToPlanet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ class KabalToPlanet
{
public static function planet(\PDO $pdo_db, $db, int $planet_id, Reg $tkireg, array $playerinfo, array $langvars): void
{
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id"; // Get target planet information
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, \PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

$sql = "SELECT * FROM ::prefix::ships WHERE ship_id=:ship_id"; // Get target player information
$stmt = $pdo_db->prepare($sql);
Expand Down
15 changes: 14 additions & 1 deletion classes/Planets/PlanetsGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(\PDO $pdo_db) // Create the this->pdo_db object
$this->pdo_db = $pdo_db;
}

public function selectPlanetInfo(int $sector_id): array
public function selectPlanetInfo(int $sector_id)
{
$sql = "SELECT * FROM ::prefix::planets WHERE sector_id = :sector_id";
$stmt = $this->pdo_db->prepare($sql);
Expand All @@ -45,4 +45,17 @@ public function selectPlanetInfo(int $sector_id): array
$planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found.
}

public function selectPlanetInfoByPlanet(int $planet_id)
{
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id = :planet_id";
$stmt = $this->pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, \PDO::PARAM_INT);
$stmt->execute();
\Tki\Db::logDbErrors($this->pdo_db, $sql, __LINE__, __FILE__); // Log any errors, if there are any

// A little magic here. If it couldn't select a planet in the sector, the following call will return false - which is what we want for "no planet found".
$planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
return $planetinfo; // FUTURE: Eventually we want this to return a planet object instead, for now, planetinfo array or false for no planet found.
}
}
8 changes: 4 additions & 4 deletions move.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
$login = new Tki\Login();
$login->checkLogin($pdo_db, $lang, $tkireg, $template);

// Database driven language entries
$langvars = Tki\Translate::load($pdo_db, $lang, array('move', 'common',
'global_includes', 'global_funcs', 'combat', 'footer', 'news'));

$title = $langvars['l_move_title'];

$header = new Tki\Header();
$header->display($pdo_db, $lang, $template, $title);

$sector = (int) filter_input(INPUT_GET, 'sector', FILTER_SANITIZE_NUMBER_INT);

// Database driven language entries
$langvars = Tki\Translate::load($pdo_db, $lang, array('move', 'common',
'global_includes', 'global_funcs', 'combat', 'footer', 'news'));

// Get playerinfo from database
$players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls
$playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);
Expand Down
16 changes: 6 additions & 10 deletions planet.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@
$sectors_gateway = new \Tki\Sectors\SectorsGateway($pdo_db); // Build a sector gateway object to handle the SQL calls
$sectorinfo = $sectors_gateway->selectSectorInfo($playerinfo['sector']);

$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);
$num_planets = count($planetinfo);

if (!$planetinfo)
{
Expand Down Expand Up @@ -441,11 +440,8 @@
Tki\Db::logDbErrors($pdo_db, $update1b, __LINE__, __FILE__);

// Refresh Planet Info
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(PDO::FETCH_ASSOC);
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

// Notify User Of Base Results
echo $langvars['l_planet_bbuild'] . "<br><br>";
Expand Down
9 changes: 3 additions & 6 deletions planet2.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,9 @@
$players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls
$playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);

// Get the Planet Info
$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id AND planet_id > 0 LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

// Check to see if it returned valid planet info.
if ($planetinfo === false)
Expand Down
8 changes: 3 additions & 5 deletions planet3.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@
$players_gateway = new \Tki\Players\PlayersGateway($pdo_db); // Build a player gateway object to handle the SQL calls
$playerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);

$sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':planet_id', $planet_id, PDO::PARAM_INT);
$stmt->execute();
$planetinfo = $stmt->fetch(PDO::FETCH_ASSOC);
// Get planetinfo from database
$planets_gateway = new \Tki\Planets\PlanetsGateway($pdo_db); // Build a planet gateway object to handle the SQL calls
$planetinfo = $planets_gateway->selectPlanetInfoByPlanet($planet_id);

// Check to see if it returned valid planet info.
if ($planetinfo === false)
Expand Down
2 changes: 1 addition & 1 deletion planet_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$preptype = $_GET['preptype'];
}

$sort = null;
$sort = '';
if (array_key_exists('sort', $_GET))
{
$sort = $_GET['sort'];
Expand Down

0 comments on commit 4d4f67e

Please sign in to comment.