Files
firefly-iii/app/Support/Twig/Journal.php

99 lines
2.4 KiB
PHP
Raw Normal View History

2015-05-01 22:44:35 +02:00
<?php
2016-02-05 12:08:25 +01:00
declare(strict_types = 1);
2015-05-01 22:44:35 +02:00
namespace FireflyIII\Support\Twig;
use FireflyIII\Models\TransactionJournal;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
2015-05-02 22:12:26 +02:00
2015-05-01 22:44:35 +02:00
/**
2015-05-02 11:32:45 +02:00
* Class Journal
2015-05-01 22:44:35 +02:00
*
* @package FireflyIII\Support\Twig
*/
2015-05-02 11:32:45 +02:00
class Journal extends Twig_Extension
2015-05-01 22:44:35 +02:00
{
2015-05-02 22:05:18 +02:00
/**
* @return array
*/
2016-02-06 15:01:26 +01:00
public function getFilters(): array
2015-05-01 22:44:35 +02:00
{
2015-06-06 17:40:41 +02:00
$filters = [$this->typeIcon()];
2015-05-01 22:44:35 +02:00
2015-06-06 17:40:41 +02:00
return $filters;
}
/**
* @return array
*/
2016-02-06 15:01:26 +01:00
public function getFunctions(): array
2015-06-06 17:40:41 +02:00
{
$functions = [
$this->invalidJournal(),
];
return $functions;
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
2016-02-06 15:01:26 +01:00
public function getName(): string
2015-06-06 17:40:41 +02:00
{
return 'FireflyIII\Support\Twig\Journals';
}
2016-02-06 15:01:26 +01:00
/**
* @return Twig_SimpleFunction
*/
protected function invalidJournal(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'invalidJournal', function (TransactionJournal $journal): bool {
if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) {
return true;
}
return false;
}
);
}
2015-06-06 17:40:41 +02:00
/**
* @return Twig_SimpleFilter
*/
2016-02-06 15:01:26 +01:00
protected function typeIcon(): Twig_SimpleFilter
2015-06-06 17:40:41 +02:00
{
return new Twig_SimpleFilter(
2016-02-06 15:01:26 +01:00
'typeIcon', function (TransactionJournal $journal): string {
2015-06-03 18:22:47 +02:00
switch (true) {
case $journal->isWithdrawal():
2015-06-23 21:14:21 +02:00
$txt = '<i class="fa fa-long-arrow-left fa-fw" title="' . trans('firefly.withdrawal') . '"></i>';
2015-06-03 18:22:47 +02:00
break;
case $journal->isDeposit():
2015-06-23 21:14:21 +02:00
$txt = '<i class="fa fa-long-arrow-right fa-fw" title="' . trans('firefly.deposit') . '"></i>';
2015-06-03 18:22:47 +02:00
break;
case $journal->isTransfer():
2015-06-03 18:22:47 +02:00
$txt = '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';
break;
case $journal->isOpeningBalance():
2015-06-23 21:14:21 +02:00
$txt = '<i class="fa-fw fa fa-ban" title="' . trans('firefly.openingBalance') . '"></i>';
2015-06-03 18:22:47 +02:00
break;
2015-05-17 09:35:49 +02:00
default:
2015-06-03 18:22:47 +02:00
$txt = '';
break;
2015-05-01 22:44:35 +02:00
}
2015-06-03 18:22:47 +02:00
return $txt;
2015-05-01 22:44:35 +02:00
}, ['is_safe' => ['html']]
);
}
}