Cleaning functions and putting it in tpl

This commit is contained in:
Phyks 2013-09-10 23:08:05 +02:00
parent 978b518f78
commit 70adda6248
5 changed files with 12 additions and 123 deletions

9
TODO
View File

@ -9,12 +9,3 @@ Manage paybacks :
================= =================
* TODO : Payback system (class should be ok) * TODO : Payback system (class should be ok)
* TODO : Global payback * TODO : Global payback
To test :
=========
* Connection form
* Remember me ?
* Edit notice
* Add / Edit user
* Change password
* Change settings

View File

@ -1,90 +0,0 @@
<?php
require_once('data/config.php');
require_once('Storage.class.php');
class Payback extends Storage {
protected $id = 0, $invoice_id, $amount, $from, $to;
protected $TABLE_NAME = "Paybacks";
protected $fields = array(
'id'=>'key',
'invoice_id'=>'int',
'amount'=>'float',
'from'=>'int',
'to'=>'int'
);
public function __construct() {
parent::__construct();
}
// Getters
// =======
public function getId() {
return (int) $this->id;
}
public function getInvoice() {
return (int) $this->invoice_id;
}
public function getAmount() {
return (float) $this->amount;
}
public function getFrom() {
return (int) $this->from;
}
public function getTo() {
return (int) $this->to;
}
// Setters
// =======
public function setId($id) {
$this->id = (int) $id;
}
public function setInvoice($invoice_id) {
$this->invoice_id = (int) $invoice_id;
}
public function setAmount($amount) {
$this->amount = (float) $amount;
}
public function setFrom($from) {
$this->from = (int) $from;
}
public function setTo($to) {
$this->to = (int) $to;
}
// Restores object from array
// ==========================
public function sessionRestore($data, $serialized = false) {
if($serialized)
$data = unserialize($data);
$this->setId($data['id']);
$this->setInvoice($data['invoice_id']);
$this->setAmount($data['amount']);
$this->setFrom($data['from']);
$this->setTo($data['to']);
}
// 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;
$this->from = (int) $this->from;
$this->to = (int) $this->to;
}
}

View File

@ -79,25 +79,3 @@
return $return; return $return;
} }
function formatUsersIn($users_in, $all_users) {
global $localized;
// TODO : Move this function to somewhere else ?
$return = '';
$users_in = $users_in->get();
$i = false;
foreach($users_in as $user_in=>$guests) {
if($i) { $return .= '<br/>'; } else { $i = true; }
$return .= $all_users[$user_in]->getDisplayName();
if($guests != 0) {
if($guests > 1)
$return .= ' ('.$guests.' '.$localized['guest'][LANG].'s)';
else
$return .= ' ('.$guests.' '.$localized['guest'][LANG].')';
}
}
return $return;
}

View File

@ -478,7 +478,7 @@ class RainTPL{
$value = "\$value$loop_level"; // value $value = "\$value$loop_level"; // value
//loop code //loop code
$compiled_code .= "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>"; $compiled_code .= "<?php $counter=-1; if( $var !== null && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>";
} }

View File

@ -42,7 +42,17 @@
<tr> <tr>
<td>{$value->getDate('d-m-Y A')}</td> <td>{$value->getDate('d-m-Y A')}</td>
<td>{$users[$value->getBuyer()]->getDisplayName()}</td> <td>{$users[$value->getBuyer()]->getDisplayName()}</td>
<td>{function="formatUsersIn($value->getUsersIn(), $users)"}</td> <td>
{loop="$value->getUsersIn()->get()"}
{$users[$key2]->getDisplayName()}
{if condition="$value2 > 1"}
({$value2} guests)
{elseif condition="$value2 == 1"}
({$value2} guest)
{/if}
<br/>
{/loop}
</td>
<td>{$value->getAmount()}</td> <td>{$value->getAmount()}</td>
<td>{$value->getWhat()}</td> <td>{$value->getWhat()}</td>
<td><a href="index.php?do=edit_invoice&id={$value->getId()}">Edit</a></td> <td><a href="index.php?do=edit_invoice&id={$value->getId()}">Edit</a></td>