2016-01-15 08:10:22 +01:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* Rule.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-01-15 08:10:22 +01:00
|
|
|
|
|
|
|
namespace FireflyIII\Support\Twig;
|
|
|
|
|
2016-01-15 08:13:19 +01:00
|
|
|
use Config;
|
2016-01-15 08:10:22 +01:00
|
|
|
use Twig_Extension;
|
|
|
|
use Twig_SimpleFunction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Rule
|
2016-01-15 17:38:09 +01:00
|
|
|
*
|
2016-01-15 08:10:22 +01:00
|
|
|
* @package FireflyIII\Support\Twig
|
|
|
|
*/
|
|
|
|
class Rule extends Twig_Extension
|
|
|
|
{
|
2016-01-15 17:38:09 +01:00
|
|
|
|
2016-08-26 08:21:31 +02:00
|
|
|
/**
|
|
|
|
* @return Twig_SimpleFunction
|
|
|
|
*/
|
|
|
|
public function allActionTriggers(): Twig_SimpleFunction
|
|
|
|
{
|
|
|
|
return new Twig_SimpleFunction(
|
|
|
|
'allRuleActions', function () {
|
|
|
|
// 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);
|
2017-09-03 10:16:45 +02:00
|
|
|
asort($possibleActions);
|
2016-08-26 08:21:31 +02:00
|
|
|
|
|
|
|
return $possibleActions;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-15 08:10:22 +01:00
|
|
|
/**
|
2016-01-15 17:38:09 +01:00
|
|
|
* @return Twig_SimpleFunction
|
2016-01-15 08:10:22 +01:00
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function allJournalTriggers(): Twig_SimpleFunction
|
2016-01-15 08:10:22 +01:00
|
|
|
{
|
2016-01-15 17:38:09 +01:00
|
|
|
return new Twig_SimpleFunction(
|
2016-01-15 08:10:22 +01:00
|
|
|
'allJournalTriggers', function () {
|
|
|
|
return [
|
|
|
|
'store-journal' => trans('firefly.rule_trigger_store_journal'),
|
|
|
|
'update-journal' => trans('firefly.rule_trigger_update_journal'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
2016-01-15 17:38:09 +01:00
|
|
|
}
|
2016-01-15 08:10:22 +01:00
|
|
|
|
2016-01-15 17:38:09 +01:00
|
|
|
/**
|
|
|
|
* @return Twig_SimpleFunction
|
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function allRuleTriggers(): Twig_SimpleFunction
|
2016-01-15 17:38:09 +01:00
|
|
|
{
|
|
|
|
return new Twig_SimpleFunction(
|
2016-01-15 08:13:19 +01:00
|
|
|
'allRuleTriggers', function () {
|
|
|
|
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
|
|
|
$possibleTriggers = [];
|
|
|
|
foreach ($ruleTriggers as $key) {
|
2017-07-15 16:41:07 +02:00
|
|
|
if ($key !== 'user_action') {
|
2016-01-15 08:13:19 +01:00
|
|
|
$possibleTriggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($key, $ruleTriggers);
|
2017-09-03 10:16:45 +02:00
|
|
|
asort($possibleTriggers);
|
2016-01-15 08:13:19 +01:00
|
|
|
|
|
|
|
return $possibleTriggers;
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
2016-01-15 17:38:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function getFunctions(): array
|
2016-01-15 17:38:09 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->allJournalTriggers(),
|
|
|
|
$this->allRuleTriggers(),
|
|
|
|
$this->allActionTriggers(),
|
|
|
|
];
|
2016-01-15 08:13:19 +01:00
|
|
|
|
2016-01-15 08:10:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the extension.
|
|
|
|
*
|
|
|
|
* @return string The extension name
|
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function getName(): string
|
2016-01-15 08:10:22 +01:00
|
|
|
{
|
|
|
|
return 'FireflyIII\Support\Twig\Rule';
|
|
|
|
}
|
2016-01-28 21:50:20 +01:00
|
|
|
}
|