Augmented type class
authorRichard Whitehouse <richardwhiuk@richardwhiuk.com>
Thu, 3 Feb 2011 16:43:16 +0000 (16:43 +0000)
committerRichard Whitehouse <richardwhiuk@richardwhiuk.com>
Thu, 3 Feb 2011 16:43:16 +0000 (16:43 +0000)
index.php
pages/index.php

index 3061d50110b58513b2f3b34fa7b4be01a40a8289..b4c5c5953453a806ba5c1d5e2c0510e0754882b6 100644 (file)
--- 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;
index e20981d8dc27aa6c4061bcedc963cb4c60a7fb3e..0bdd559f23a7d5e06c31fa27e06c0b1bc240ebe8 100644 (file)
@@ -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()
                                );
                        }