class CustomTableGateway extends pdoext_TableGateway
{
private $user;
function __construct($table, $conn, $user)
{
$this->user = $user;
parent::__construct($table, $conn);
}
function insert($data)
{
$data['user_id'] = $this->user->getId();
parent::insert($data);
}
function update($data, $condition)
{
$condition['user_id'] = $this->user->getId();
parent::update($data, $condition);
}
function delete($condition)
{
$condition['user_id'] = $this->user->getId();
parent::delete($condition);
}
}
class Ticket_TableGateway extends CustomTableGateway
{
function __construct($conn, $user)
{
parent::__construct('ticket', $conn, $user);
}
function getFromId($id)
{
$result = parent::fecth($id);
return new Ticket($result);
}
function getAllTickets() {
$tickets = array();
$result = $this->conn->query('SELECT * FROM ticket');
foreach ($result as $r) {
$tickets[] = new Ticket($r);
}
return $tickets;
}
}
class User {
function getId() {
return 0;
}
}
$id = 1;
$gateway = new Ticket_TableGateway($conn, $user);
$ticket = $gateway->getFromId($id);
class Ticket {
private $data;
function __construct($result)
{
$this->data => $result;
}
// skulle save bare vaere her i ticket
function save($gateway) {
// normalize data if necessary
try {
$gateway->save($this->data);
} catch (Exception $e) {
throw $e;
}
}
// frygter lidt at komme til at lave magic get og set for en masse klasser
function __get($prop) {
return $this->data[$prop];
}
function __set($prop, $value) {
$this->data[$prop] = $value;
}
}