. */ declare(strict_types=1); namespace FireflyIII\Support\Twig; use Config; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; /** * Class Rule. */ class Rule extends AbstractExtension { /** * @return TwigFunction */ public function allActionTriggers(): TwigFunction { return new TwigFunction( 'allRuleActions', static function () { // array of valid values for actions $ruleActions = array_keys(Config::get('firefly.rule-actions')); $possibleActions = []; foreach ($ruleActions as $key) { $possibleActions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice'); } unset($ruleActions); asort($possibleActions); return $possibleActions; } ); } /** * @return TwigFunction */ public function allJournalTriggers(): TwigFunction { return new TwigFunction( 'allJournalTriggers', static function () { return [ 'store-journal' => (string)trans('firefly.rule_trigger_store_journal'), 'update-journal' => (string)trans('firefly.rule_trigger_update_journal'), ]; } ); } /** * @return TwigFunction */ public function allRuleTriggers(): TwigFunction { return new TwigFunction( 'allRuleTriggers', static function () { $ruleTriggers = array_keys(Config::get('firefly.rule-triggers')); $possibleTriggers = []; foreach ($ruleTriggers as $key) { if ('user_action' !== $key) { $possibleTriggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice'); } } unset($ruleTriggers); asort($possibleTriggers); return $possibleTriggers; } ); } /** * @return array */ public function getFunctions(): array { return [ $this->allJournalTriggers(), $this->allRuleTriggers(), $this->allActionTriggers(), ]; } }