From d2b60726e7289c702ba466025ad34e2530c88e05 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 3 Feb 2011 16:31:23 +0000 Subject: [PATCH] more functionality in index --- index.php | 64 ++++++++++++++++++++++++++++++++++++++++++++- pages/index.php | 15 +++++++++++ templates/index.php | 16 ++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 1bc10e5..3061d50 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,19 @@ class Template { } + public function title(){ + return 'Review Orders'; + } + +} + +class Theme { + + public function display($template){ + + + } + } class Config { @@ -87,6 +100,40 @@ class Database extends mysqli { } +class Type { + + private $id; + private $name; + private $price; + + public function __construct($id, $name, $price){ + $this->id = $id; + $this->name = $name; + $this->price = $price; + } + + public function id(){ + if(!isset($this->id)){ + throw new Exception('Invalid Operation'); + } + return $this->id; + } + + public static function Get_All(){ + $query = 'SELECT `id`,`name`,`price` FROM `type`'; + $stmt = Ticketing::Get()->database()->prepare($query); + $stmt->execute(); + $stmt->bind_result($id, $name, $price); + $types = array(); + while($stmt->fetch()){ + $types[$id] = new Type($id, $name, $price); + } + $stmt->close(); + return $types; + } + +} + class Order { private $id; @@ -232,17 +279,32 @@ class Ticketing { return $this->template; } + private $theme; + + public function theme(){ + if(!isset($this->theme)){ + require_once('theme.php'); + $this->theme = new Theme_Impl(); + } + return $this->theme; + } + public function run(){ try { $this->page()->logic($this->template()); - $this->template()->display(); + $this->theme()->display($this->template()); } catch(Exception $e){ header('Content-type: text/plain'); print_r($e); exit; } } + public function url(){ + $args = func_get_args(); + return $this->config()->get('base') . implode('/', $args); + } + } Ticketing::Get()->run(); diff --git a/pages/index.php b/pages/index.php index 4e0a886..e20981d 100644 --- a/pages/index.php +++ b/pages/index.php @@ -50,6 +50,21 @@ class Page_Index extends Page { } + // Do we have any tickets left? + + $types = Type::Get_All(); + + $template->types = array(); + + foreach($types as $type){ + $template->types[$type->id()] == array( + 'name' => $type->name(), + 'tickets_left' => $type->left() + ); + } + + $templates->add = $system->url('add'); + $system->database()->commit(); diff --git a/templates/index.php b/templates/index.php index 036a849..801e7bb 100644 --- a/templates/index.php +++ b/templates/index.php @@ -2,5 +2,21 @@ class Template_Index extends Template { + public function display(){ +?> +
+previous) > 0){ ?> + + +
+

Current Order

+ +
+
+