Let race colours be stored in the database.
authorCMDR furrycat <elite@furrycat.net>
Sun, 5 Jun 2016 09:37:13 +0000 (05:37 -0400)
committerCMDR furrycat <elite@furrycat.net>
Sun, 5 Jun 2016 09:37:13 +0000 (05:37 -0400)
propel/build/classes/buckyball/Race.php
propel/schema.xml

index 52f1977..ac1da2c 100644 (file)
@@ -24,6 +24,12 @@ class Race extends BaseRace
     'average_lap' => array('fastest average lap', 'ByAverageLap', 1 << 5)
   );
 
+  private static $COLOURS = array('#808080', '#000000');
+
+  function Colours() {
+    return self::$COLOURS;
+  }
+
   function Prizes() {
     return self::$PRIZES;
   }
@@ -84,4 +90,24 @@ class Race extends BaseRace
     return $ret;
   }
 
+  function getColours($strict = false) {
+    $colour1 = $this->getColour1();
+    $colour2 = $this->getColour2();
+    if ($strict && (! $colour1 || ! $colour2)) return null;
+    if (! $colour1) $colour1 = self::Colours()[0];
+    if (! $colour2) $colour2 = self::Colours()[1];
+    return array($colour1, $colour2);
+  }
+
+  function getFlag() {
+    $colours = $this->getColours(true);
+    if (! $colours) return '';
+    $style = "background-image: linear-gradient(-45deg, $colours[0] 0%, $colours[0] 50%, $colours[1] 50%, $colours[1] 100%);";
+    return "&nbsp;<span style=\"$style\">&nbsp;&nbsp;&nbsp;&nbsp;</span>";
+  }
+
+  function getLink() {
+    return parent::getLink() . $this->getFlag();
+  }
+
 }
index c8bad27..0377b0e 100644 (file)
     <column name="name" type="varchar" size="64" required="true"/>
     <column name="allotted_time" type="integer" required="false"/>
     <column name="prizes" type="integer" required="false"/>
+    <column name="colour1" type="char" size="7" required="false"/>
+    <column name="colour2" type="char" size="7" required="false"/>
     <unique name="name">
       <unique-column name="name"/>
     </unique>