From 56c20b586882537185078240296184a9a6fa2577 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 3 Feb 2011 16:43:16 +0000 Subject: [PATCH] Augmented type class --- index.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ pages/index.php | 1 + 2 files changed, 52 insertions(+) diff --git a/index.php b/index.php index 3061d50..b4c5c59 100644 --- a/index.php +++ b/index.php @@ -119,6 +119,32 @@ class Type { return $this->id; } + public function name(){ + if(!isset($this->name)){ + throw new Exception('Invalid Operation'); + } + return $this->name; + } + + public function price(){ + if(!isset($this->price)){ + throw new Exception('Invalid Operation'); + } + return $this->price; + } + + public function left(){ + if(!isset($this->left)){ + $count = Ticket::Get_Free_Count_By_Type($this); + if($count > 0){ + $this->left = true; + } else { + $this->left = false; + } + } + return $this->left; + } + public static function Get_All(){ $query = 'SELECT `id`,`name`,`price` FROM `type`'; $stmt = Ticketing::Get()->database()->prepare($query); @@ -134,6 +160,31 @@ class Type { } +class Ticket { + + private $id; + private $type; + private $status; + + // STATUS: 0 - FREE, 1 - ALLOCATED, 2 - SOLD + + public static function Get_Free_Count_By_Type($type){ + if($type instanceof Type){ + $type = $type->id(); + } + $query = 'SELECT COUNT(*) FROM `ticket` WHERE `type` = ?'; + $stmt = Ticketing::Get()->database()->prepare($query); + $stmt->bind_param('i', $type); + $stmt->execute(); + $stmt->bind_result($count); + if($stmt->fetch() == null){ + throw new Exception('No rows for count!'); + } + return $count; + } + +} + class Order { private $id; diff --git a/pages/index.php b/pages/index.php index e20981d..0bdd559 100644 --- a/pages/index.php +++ b/pages/index.php @@ -59,6 +59,7 @@ class Page_Index extends Page { foreach($types as $type){ $template->types[$type->id()] == array( 'name' => $type->name(), + 'price' => $type->price(), 'tickets_left' => $type->left() ); } -- 2.34.1