firefly-iii/app/Support/Twig/Rule.php

107 lines
2.5 KiB
PHP
Raw Normal View History

2016-01-15 01:10:22 -06:00
<?php
/**
* Rule.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2016-01-15 01:10:22 -06:00
namespace FireflyIII\Support\Twig;
2016-01-15 01:13:19 -06:00
use Config;
2016-01-15 01:10:22 -06:00
use Twig_Extension;
use Twig_SimpleFunction;
/**
* Class Rule
*
2016-01-15 01:10:22 -06:00
* @package FireflyIII\Support\Twig
*/
class Rule extends Twig_Extension
{
2016-01-15 01:10:22 -06:00
/**
* @return Twig_SimpleFunction
2016-01-15 01:10:22 -06:00
*/
2016-04-05 15:00:03 -05:00
public function allJournalTriggers(): Twig_SimpleFunction
2016-01-15 01:10:22 -06:00
{
return new Twig_SimpleFunction(
2016-01-15 01:10:22 -06:00
'allJournalTriggers', function () {
return [
'store-journal' => trans('firefly.rule_trigger_store_journal'),
'update-journal' => trans('firefly.rule_trigger_update_journal'),
];
}
);
}
2016-01-15 01:10:22 -06:00
/**
* @return Twig_SimpleFunction
*/
2016-04-05 15:00:03 -05:00
public function allRuleTriggers(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
2016-01-15 01:13:19 -06:00
'allRuleTriggers', function () {
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
$possibleTriggers = [];
foreach ($ruleTriggers as $key) {
if ($key != 'user_action') {
$possibleTriggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
}
}
unset($key, $ruleTriggers);
return $possibleTriggers;
}
);
}
/**
* @return Twig_SimpleFunction
*/
2016-04-05 15:00:03 -05:00
public function allActionTriggers(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'allRuleActions', function () {
2016-01-15 01:13:19 -06:00
// array of valid values for actions
$ruleActions = array_keys(Config::get('firefly.rule-actions'));
$possibleActions = [];
foreach ($ruleActions as $key) {
$possibleActions[$key] = trans('firefly.rule_action_' . $key . '_choice');
}
unset($key, $ruleActions);
return $possibleActions;
}
);
}
/**
* @return array
*/
2016-04-05 15:00:03 -05:00
public function getFunctions(): array
{
return [
$this->allJournalTriggers(),
$this->allRuleTriggers(),
$this->allActionTriggers(),
];
2016-01-15 01:13:19 -06:00
2016-01-15 01:10:22 -06:00
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
2016-04-05 15:00:03 -05:00
public function getName(): string
2016-01-15 01:10:22 -06:00
{
return 'FireflyIII\Support\Twig\Rule';
}
}