From: CMDR furrycat Events
+Missing event name!
Invalid event start time!
\n"; + return false; + } + $real_end_time = real_time($end_time); + if (is_null($real_end_time)) { + echo "Invalid event end time!
\n"; + return false; + } + if ($real_end_time < $real_start_time) { + echo "Event end time is earlier than start time!
\n"; + return false; + } + } + $event = new Event; + $event->setName($name); + if ($real_start_time) $event->setStartTime($real_start_time); + if ($real_end_time) $event->setEndTime($real_end_time); + try { + $event->save(); + return true; + } + catch (Exception $e) { + echo "Error adding event: " . $e->getMessage() . "
\n"; + } + return false; + } + + function show_event($event) { + echo "No races.
\n"; + return; + } + + foreach ($races as $race) { + echo "" . $race->getTitleLink() . "
\n"; + } + } + + function module_event($action) { + if ($_POST['add_event']) { + if (add_event($_POST["name"], $_POST["start_time"], $_POST["end_time"])) unset($_POST); + } + + $q = new EventQuery; + if ($action) $q->filterById($action); + $events = $q->find(); + if (! count($events)) echo "No events
\n"; + echo "" . $event->getLink() . "
\n"; + } + echo "Add a new event: "; + input("name", $_POST['name']); + echo " from "; + input("start_time", $_POST['start_time']); + echo " to "; + input("end_time", $_POST['start_time']); + submit("add_event", "Add"); + echo "
\n"; + end_form(); + } +?> diff --git a/lib/header.php b/lib/header.php index b31c7a7..3d0d0b2 100644 --- a/lib/header.php +++ b/lib/header.php @@ -11,7 +11,7 @@ \n"; $links = array(); - foreach (array("competitor", "manufacturer", "hull", "ship", "system", "station", "race", "raikogram", "entry") as $what) { + foreach (array("competitor", "manufacturer", "hull", "ship", "system", "station", "event", "race", "raikogram", "entry") as $what) { $title = preg_replace('/y$/', 'ie', $what); $links[] = ""; } diff --git a/lib/race.php b/lib/race.php index e8d5166..c17a3fe 100644 --- a/lib/race.php +++ b/lib/race.php @@ -437,9 +437,10 @@ return sqrt(($x * $x) + ($y * $y) + ($z * $z)); } - function do_race($name, $allotted_time, $posted) { + function do_race($name, $event_id, $allotted_time, $posted) { $race = new Race; $race->setName($name); + $race->setEventId($event_id); if ($allotted_time) $race->setAllottedTime($allotted_time); $optional = $posted['optional']; if (is_int($optional) && $optional > 0) $race->setWaypoints($optional); @@ -499,7 +500,7 @@ return true; } - function add_race($name, $allotted_time) { + function add_race($name, $event_id, $allotted_time) { $sq = new StationQuery; $sq->joinWith('Station.System'); $stations = $sq->orderBySystemId('desc')->orderByName()->find(); @@ -511,7 +512,11 @@ $posted[$k] = $v; } if (count($posted)) { - if (do_race($name, $allotted_time, $posted)) return true; + if (! $event_id) { + echo "Race not associated with an event.
\n"; + return false; + } + if (do_race($name, $event_id, $allotted_time, $posted)) return true; } form(); @@ -818,8 +823,8 @@ function module_race($action, $args) { global $race_colours; - if ($_POST['add_race']) { - if (add_race($_POST["name"], $_POST["allotted_time"])) unset($_POST); + if (array_key_exists("add_race", $_POST)) { + if (add_race($_POST["name"], $_POST["event_id"], $_POST["allotted_time"])) unset($_POST); } $methods = array( @@ -959,7 +964,7 @@ $white_fields[] = 'Raced'; if ($allotted_time) $white_fields[] = 'Total'; if ($race->getPrizes()) $orange_fields[] = 'Award'; - entry_header($sort, $format, $type, $blue_fields, $white_fields, $orange_fields, $race->getName(), $race->getColours(true)); + entry_header($sort, $format, $type, $blue_fields, $white_fields, $orange_fields, $race->getTitle(), $race->getColours(true)); $n = $position = $rank = 1; $shown = 0; $ship_entries = array(); @@ -1308,8 +1313,22 @@ echo "Add stations before adding races.
\n"; return; } + $eq = new EventQuery; + $events = $eq->orderByName()->find(); + if (! count($events)) { + echo "Add events before adding races.
\n"; + return; + } form(); echo "Add a new race: "; + echo "Event: \n"; input("name", $_POST["name"]); echo "allotted time (s): "; input("allotted_time", $_POST["allotted_time"]); diff --git a/propel/build/classes/buckyball/Event.php b/propel/build/classes/buckyball/Event.php new file mode 100644 index 0000000..0031c37 --- /dev/null +++ b/propel/build/classes/buckyball/Event.php @@ -0,0 +1,43 @@ +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 " "; + } + + function getLink() { + return parent::getLink() . $this->getFlag(); + } +} diff --git a/propel/build/classes/buckyball/Race.php b/propel/build/classes/buckyball/Race.php index ac1da2c..7b03044 100644 --- a/propel/build/classes/buckyball/Race.php +++ b/propel/build/classes/buckyball/Race.php @@ -24,12 +24,6 @@ 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; } @@ -91,23 +85,31 @@ class Race extends BaseRace } 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); + return $this->getEvent()->getColours($strict); } 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 " "; + return $this->getEvent()->getFlag(); + } + + function getName() { + $name = $this->getEvent()->getName(); + $class = $this->getClassName(); + if ($class) $name .= " $class"; + return $name; + } + + function getTitle() { + $class = $this->getClassName(); + if ($class) return $class; + return $this->getEvent()->getName(); } function getLink() { return parent::getLink() . $this->getFlag(); } + function getTitleLink() { + return parent::getLink($this->getTitle()) . $this->getFlag(); + } } diff --git a/propel/schema.xml b/propel/schema.xml index 97fc9dd..b67d69b 100644 --- a/propel/schema.xml +++ b/propel/schema.xml @@ -111,6 +111,23 @@ + +