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);
}
+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;
foreach($types as $type){
$template->types[$type->id()] == array(
'name' => $type->name(),
+ 'price' => $type->price(),
'tickets_left' => $type->left()
);
}