Finally added a format helper, which has been long intended. There may be still be conversion issues, it hasn't been tested much.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@77 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
66
site/views/helpers/format.php
Normal file
66
site/views/helpers/format.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
class FormatHelper extends AppHelper {
|
||||
|
||||
static $time;
|
||||
static $number;
|
||||
|
||||
function __construct() {
|
||||
App::import('Helper', array('Time', 'Number'));
|
||||
self::$time = new TimeHelper;
|
||||
self::$number = new NumberHelper;
|
||||
}
|
||||
|
||||
function currency($amount) {
|
||||
if (!isset($amount))
|
||||
return null;
|
||||
|
||||
return (isset($amount)
|
||||
? self::$number->currency($amount)
|
||||
: null);
|
||||
|
||||
/* if ($money < 0) */
|
||||
/* return "($ " . number_format(-1*$money, 2) . ")"; */
|
||||
/* else */
|
||||
/* return "$ " . number_format($money, 2); */
|
||||
}
|
||||
|
||||
function date($date) {
|
||||
$date_fmt = 'm/d/Y';
|
||||
return (isset($date)
|
||||
? self::$time->format($date_fmt, $date)
|
||||
//? date_format(date_create($date), $date_fmt)
|
||||
: null);
|
||||
}
|
||||
|
||||
function datetime($datetime) {
|
||||
if (!$date) return null;
|
||||
return self::$time->nice($datetime);
|
||||
}
|
||||
|
||||
function phone($phone) {
|
||||
if (!isset($phone))
|
||||
return null;
|
||||
|
||||
$phone = preg_replace("/\D/", "", $phone);
|
||||
if(strlen($phone) == 7)
|
||||
return preg_replace("/(\d{3})(\d{4})/", "$1-$2", $phone);
|
||||
elseif(strlen($phone) == 10)
|
||||
return preg_replace("/(\d{3})(\d{3})(\d{4})/", "$1-$2-$3", $phone);
|
||||
else
|
||||
return $phone;
|
||||
}
|
||||
|
||||
function comment($comment) {
|
||||
if (isset($comment) && is_array($comment)) {
|
||||
foreach (array_keys($comment) AS $k) {
|
||||
if (!$comment[$k])
|
||||
unset($comment[$k]);
|
||||
}
|
||||
return implode('; ', $comment);
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user