Found how to store UsersIn :)

This commit is contained in:
Phyks 2013-09-07 23:56:31 +02:00
parent 6558ec10d2
commit 346ba92334
2 changed files with 77 additions and 3 deletions

View File

@ -1,13 +1,13 @@
<?php <?php
// TODO : Handle users_in
require_once('data/config.php'); require_once('data/config.php');
require_once('Storage.class.php'); require_once('Storage.class.php');
require_once('UsersIn.class.php');
class Invoice extends Storage { class Invoice extends Storage {
protected $id = 0, $date, $users_in, $guests, $buyer, $amount, $what; protected $id = 0, $date, $users_in, $buyer, $amount, $what;
// date is a DateTime object // date is a DateTime object
// buyer is a User object // buyer is a User object
// guests is an array with same keys as users_in // users_in is a UsersIn objects
protected $TABLE_NAME = "Invoices"; protected $TABLE_NAME = "Invoices";
protected $fields = array( protected $fields = array(
'id'=>'key', 'id'=>'key',
@ -19,6 +19,7 @@
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$users_in = new UsersIn();
} }
// Getters // Getters
@ -39,6 +40,10 @@
return $this->buyer; return $this->buyer;
} }
public function getUsersIn() {
return $this->users_in;
}
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
} }
@ -50,6 +55,7 @@
// Setters // Setters
// ======= // =======
public function setId($id) { public function setId($id) {
$this->users_in->setId($id);
$this->id = (int) $id; $this->id = (int) $id;
} }
@ -75,6 +81,11 @@
$this->what = $what; $this->what = $what;
} }
public function setUsersIn($users_in) {
// Note : users_in in param is an array with users in listed and guests for each user
$this->users_in->set($users_in);
}
// Maps htmlspecialchars on the class before display // Maps htmlspecialchars on the class before display
// ================================================= // =================================================
public function secureDisplay() { public function secureDisplay() {

63
inc/UsersIn.class.php Normal file
View File

@ -0,0 +1,63 @@
<?php
//TODO : load() and save() overload
require_once('data/config.php');
require_once('Storage.class.php');
class UsersIn extends Storage {
protected $invoice_id = 0, $users_list;
//users_list is an array of users_id and number of guest per user
protected $TABLE_NAME = "Users_in";
protected $fields = array(
'invoice_id'=>'int',
'user_id'=>'int',
'guests'=>'int'
);
public function __construct() {
parent::__construct();
$users_list = array();
}
// Getters
// =======
public function getInvoiceId() {
return $this->invoice_id;
}
public function get() {
return $this->users_list;
}
// Setters
// =======
public function setInvoiceId($id) {
$this->invoice_id = (int) $id;
}
public function set($users_in) {
$this->users_list = $users_in;
}
// Maps htmlspecialchars on the class before display
// =================================================
public function secureDisplay() {
$this->invoice_id = (int) $this->invoice_id;
$temp_array = array();
foreach($this->users_list as $user=>$guests) {
$temp_array[(int) $user] = (int) $guests;
}
$this->users_in = $temp_array;
return $this;
}
// Restores object from array
// ==========================
public function sessionRestore($data, $serialized = false) {
// TODO ***
if($serialized) {
$data = unserialize($data);
}
}
}