A fix in the model and a simple view for attachments.

This commit is contained in:
James Cole
2015-07-18 21:12:34 +02:00
parent 6a9574bab9
commit 359fab315f
4 changed files with 52 additions and 2 deletions

View File

@@ -35,7 +35,8 @@ class General extends Twig_Extension
$this->formatAmountPlain(),
$this->formatJournal(),
$this->balance(),
$this->getAccountRole()
$this->getAccountRole(),
$this->formatFilesize()
];
}
@@ -66,6 +67,27 @@ class General extends Twig_Extension
return 'FireflyIII\Support\Twig\General';
}
protected function formatFilesize()
{
return new Twig_SimpleFilter(
'filesize', function ($size) {
$size = intval($size);
// less than one GB, more than one MB
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
return round($size / (1024 * 1024), 2) . ' MB';
}
// less than one MB
if ($size < (1024 * 1024)) {
return round($size / 1024, 2) . ' KB';
}
return $size . ' bytes';
}
);
}
/**
* @return Twig_SimpleFilter
*/