Add systems and stations.
authorCMDR furrycat <elite@furrycat.net>
Fri, 8 Jan 2016 15:52:38 +0000 (10:52 -0500)
committerCMDR furrycat <elite@furrycat.net>
Fri, 8 Jan 2016 15:55:12 +0000 (10:55 -0500)
lib/header.php
lib/station.php [new file with mode: 0644]
lib/system.php [new file with mode: 0644]
propel/build/classes/buckyball/Station.php [new file with mode: 0644]
propel/schema.xml

index 8788241..f17ad4e 100644 (file)
@@ -5,7 +5,7 @@
 <body>
 <?php
   echo "<p>Buckyball Racing Club";
-  foreach (array("competitor", "hull", "ship", "system", "race", "raikogram", "entry") as $what) {
+  foreach (array("competitor", "hull", "ship", "system", "station", "race", "raikogram", "entry") as $what) {
     $title = preg_replace('/y$/', 'ie', $what);
     echo " | <a href=\"?module=$what\">" . ucfirst($title) . "s</a>";
   }
diff --git a/lib/station.php b/lib/station.php
new file mode 100644 (file)
index 0000000..caf5b68
--- /dev/null
@@ -0,0 +1,74 @@
+<h2>Stations</h2>
+<?php
+
+  function add_station($system_id, $type, $name) {
+    if (! $name) {
+      echo "<p>Missing station name!</p>\n";
+      return false;
+    }
+    $orbital = 0 + (! ($type & Station::OrbitalFlag()));
+    $large_pad = 0 + (! ($type & Station::LargePadFlag()));
+
+    $station = new Station;
+    $station->setSystemId($system_id);
+    $station->setOrbital($orbital);
+    $station->setLargePad($large_pad);
+    $station->setName($name);
+    try {
+      $station->save();
+      return true;
+    }
+    catch (Exception $e) {
+      echo "<p>Error adding station: " . $e->getMessage() . "</p>\n";
+    }
+    return false;
+  }
+
+  function module_station($action) {
+    if ($_POST['add_station']) {
+      if (add_station($_POST["system_id"], $_POST["type"], $_POST["name"])) unset($_POST);
+    }
+
+    $q = new StationQuery;
+    $q->joinWith('Station.System');
+    $stations = $q->orderBy('System.Name')->orderByName()->find();
+    foreach ($stations as $station) {
+      $station_name = $station->getName();
+      $system_name = $station->getSystem()->getName();
+      $type = $station->getType();
+      echo "<p><strong>$station_name</strong> $type in <em>$system_name</em></p>\n";
+    }
+
+    echo "<hr>\n";
+    $sq = new SystemQuery;
+    $systems = $sq->orderByName()->find();
+    if (! count($systems)) {
+      echo "<p>Add systems before adding stations.</p>\n";
+      return;
+    }
+    form();
+    echo "<p>Add a new station: ";
+    echo "<a href=\"?module=system\">System:</a> <select name=\"system_id\">";
+    option("system_id", 0, "");
+    foreach ($systems as $system) {
+      $id = $system->getId();
+      $name = $system->getName();
+      option("system_id", $id, $name);
+    }
+    echo "</select>\n";
+    echo "type: <select name=\"type\">\n";
+    /* Flags are what the station DOESN'T have! */
+    option("type", 0, "Starport");
+    option("type", Station::LargePadFlag(), "Outpost");
+    option("type", Station::OrbitalFlag(), "Base");
+    option("type", Station::LargePadFlag() | Station::OrbitalFlag(), "Settlement");
+    echo "</select>\n";
+    input("name", $_POST["name"]);
+    echo "</select>\n";
+
+    submit("add_station", "Add");
+    echo "</p>\n";
+    end_form();
+  }
+?>
+
diff --git a/lib/system.php b/lib/system.php
new file mode 100644 (file)
index 0000000..57027f1
--- /dev/null
@@ -0,0 +1,43 @@
+<h2>Systems</h2>
+<?php
+
+  function add_system($system_name) {
+    if (! $system_name) {
+      echo "<p>Missing system name!</p>\n";
+      return false;
+    }
+    $system = new System;
+    $system->setName($system_name);
+    try {
+      $system->save();
+      return true;
+    }
+    catch (Exception $e) {
+      echo "<p>Error adding system: " . $e->getMessage() . "</p>\n";
+    }
+    return false;
+  }
+
+  function module_system($action) {
+    if ($_POST['add_system']) {
+      if (add_system($_POST["system_name"])) unset($_POST);
+    }
+
+    $q = new SystemQuery;
+    $systems = $q->orderByName()->find();
+    if (! count($systems)) echo "<p>No systems</p>\n";
+    foreach ($systems as $system) {
+      $system_name = $system->getName();
+      echo "<p><strong>$system_name</strong></p>\n";
+    }
+
+    echo "<hr>\n";
+    form();
+    echo "<p>Add a new system: ";
+    input("system_name", $_POST['system_name']);
+    submit("add_system", "Add");
+    echo "</p>\n";
+    end_form();
+  }
+
+?>
diff --git a/propel/build/classes/buckyball/Station.php b/propel/build/classes/buckyball/Station.php
new file mode 100644 (file)
index 0000000..c9c4571
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+
+
+/**
+ * Skeleton subclass for representing a row from the 'station' table.
+ *
+ *
+ *
+ * You should add additional methods to this class to meet the
+ * application requirements.  This class will only be generated as
+ * long as it does not already exist in the output directory.
+ *
+ * @package    propel.generator.buckyball
+ */
+class Station extends BaseStation
+{
+  function LargePadFlag() { return 1; }
+  function OrbitalFlag() { return 2; }
+
+  function getType() {
+    if ($this->getOrbital()) {
+      if ($this->getLargePad()) return "Starport";
+      else return "Outpost";
+    }
+    else {
+      if ($this->getLargePad()) return "Base";
+      else return "Settlement";
+    }
+  }
+}
index 23b8ffc..510b77c 100644 (file)
@@ -73,6 +73,8 @@
     <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
     <column name="system_id" type="integer" required="true"/>
     <column name="name" type="varchar" size="64" required="true"/>
+    <column name="orbital" type="boolean" default="true" required="true"/>
+    <column name="large_pad" type="boolean" default="true" required="true"/>
     <unique name="system_station">
       <unique-column name="system_id"/>
       <unique-column name="name"/>