bouffeatulm/inc/Paybacks.class.php

108 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2013-09-10 23:07:39 +02:00
<?php
require_once('data/config.php');
require_once('Storage.class.php');
class Payback extends Storage {
2013-09-11 00:51:45 +02:00
protected $id = 0, $date, $invoice_id, $amount, $from_user, $to_user;
2013-09-10 23:07:39 +02:00
protected $TABLE_NAME = "Paybacks";
protected $fields = array(
'id'=>'key',
'date'=>'date',
'invoice_id'=>'int',
2013-09-14 23:21:49 +02:00
'amount'=>'int',
2013-09-10 23:07:39 +02:00
'from_user'=>'int',
'to_user'=>'int'
);
public function __construct() {
parent::__construct();
}
// Getters
// =======
public function getId() {
return (int) $this->id;
}
public function getDate($format = 'd-m-Y H:i') {
if(!empty($this->date))
return $this->date->format($format);
else
return false;
}
public function getInvoice() {
return (int) $this->invoice_id;
}
public function getAmount() {
2013-09-14 23:21:49 +02:00
return (float) $this->amount / 100; // Amount is stored in cents
2013-09-10 23:07:39 +02:00
}
public function getFrom() {
2013-09-11 00:51:45 +02:00
return (int) $this->from_user;
2013-09-10 23:07:39 +02:00
}
public function getTo() {
2013-09-11 00:51:45 +02:00
return (int) $this->to_user;
2013-09-10 23:07:39 +02:00
}
// Setters
// =======
public function setId($id) {
$this->id = (int) $id;
}
public function setDate($minute, $hour, $day, $month, $year) {
$this->date = DateTime::createFromFormat('Y-n-j G:i', (int) $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute);
2013-09-10 23:07:39 +02:00
}
public function setInvoice($invoice_id) {
$this->invoice_id = (int) $invoice_id;
}
public function setAmount($amount) {
$amount = str_replace(',', '.', $amount);
2013-09-14 23:21:49 +02:00
$this->amount = (int) ($amount * 100); // Amount is stored in cents
2013-09-10 23:07:39 +02:00
}
public function setFrom($from) {
2013-09-11 00:51:45 +02:00
$this->from_user = (int) $from;
2013-09-10 23:07:39 +02:00
}
public function setTo($to) {
2013-09-11 00:51:45 +02:00
$this->to_user = (int) $to;
2013-09-10 23:07:39 +02:00
}
// Restores object from array
// ==========================
public function sessionRestore($data, $serialized = false) {
if($serialized)
$data = unserialize($data);
$this->setId($data['id']);
$this->setInvoice($data['invoice_id']);
2013-09-14 23:21:49 +02:00
$this->amount = (int) $data['amount'];
2013-09-11 00:51:45 +02:00
$this->setFrom($data['from_user']);
$this->setTo($data['to_user']);
2013-09-10 23:07:39 +02:00
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
}
// Maps htmlspecialchars on the class before display
// =================================================
public function secureDisplay() {
$this->id = (int) $this->id;
$this->invoice_id = (int) $this->invoice_id;
$this->amount = (float) $this->amount;
2013-09-11 00:51:45 +02:00
$this->from = (int) $this->from_user;
$this->to = (int) $this->to_user;
return $this;
2013-09-10 23:07:39 +02:00
}
}