Files
pmgr/views/helpers/format.php
abijah 73ea4fa86c Added a formatting method to print the age of a datetime object, and modified the lease view to use it. I anticipate customizing the function to be more fuzzy and less precise.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@89 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-10 17:06:35 +00:00

73 lines
1.6 KiB
PHP

<?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 '-';
//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 (!$datetime) 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;
}
function age($datetime) {
return $time->timeAgoInWords($datetime,
array('end' => '+99 years'));
}
}