| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Rule.php | 
					
						
							| 
									
										
										
										
											2020-02-16 13:56:52 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  | use Twig\Extension\AbstractExtension; | 
					
						
							|  |  |  | use Twig\TwigFunction; | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class Rule. | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  | class Rule extends AbstractExtension | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |     public function getFunctions(): array | 
					
						
							| 
									
										
										
										
											2016-08-26 08:21:31 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             $this->allJournalTriggers(), | 
					
						
							|  |  |  |             $this->allRuleTriggers(), | 
					
						
							|  |  |  |             $this->allActionTriggers(), | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2016-08-26 08:21:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  |     public function allJournalTriggers(): TwigFunction | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  |         return new TwigFunction( | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |             'allJournalTriggers', | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |             static function () { | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |                 return [ | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |                     'store-journal'     => (string) trans('firefly.rule_trigger_store_journal'), | 
					
						
							|  |  |  |                     'update-journal'    => (string) trans('firefly.rule_trigger_update_journal'), | 
					
						
							|  |  |  |                     'manual-activation' => (string) trans('firefly.rule_trigger_manual'), | 
					
						
							| 
									
										
										
										
											2017-11-15 11:33:07 +01:00
										 |  |  |                 ]; | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2016-01-15 17:38:09 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  |     public function allRuleTriggers(): TwigFunction | 
					
						
							| 
									
										
										
										
											2016-01-15 17:38:09 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-12-28 09:44:56 +01:00
										 |  |  |         return new TwigFunction( | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |             'allRuleTriggers', | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |             static function () { | 
					
						
							| 
									
										
										
										
											2022-03-20 07:42:39 +01:00
										 |  |  |                 $ruleTriggers     = array_keys(config('search.operators')); | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |                 $possibleTriggers = []; | 
					
						
							|  |  |  |                 foreach ($ruleTriggers as $key) { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |                     if ('user_action' !== $key) { | 
					
						
							| 
									
										
										
										
											2024-12-22 20:37:54 +01:00
										 |  |  |                         $possibleTriggers[$key] = (string) trans('firefly.rule_trigger_'.$key.'_choice'); | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2016-01-15 08:13:19 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-07-27 05:03:37 +02:00
										 |  |  |                 unset($ruleTriggers); | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |                 asort($possibleTriggers); | 
					
						
							| 
									
										
										
										
											2016-01-15 08:13:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 10:52:29 +01:00
										 |  |  |                 return $possibleTriggers; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-01-15 08:13:19 +01:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2016-01-15 17:38:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |     public function allActionTriggers(): TwigFunction | 
					
						
							| 
									
										
										
										
											2016-01-15 17:38:09 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |         return new TwigFunction( | 
					
						
							|  |  |  |             'allRuleActions', | 
					
						
							|  |  |  |             static function () { | 
					
						
							|  |  |  |                 // array of valid values for actions
 | 
					
						
							| 
									
										
										
										
											2024-12-22 20:37:54 +01:00
										 |  |  |                 $ruleActions     = array_keys(\Config::get('firefly.rule-actions')); | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |                 $possibleActions = []; | 
					
						
							|  |  |  |                 foreach ($ruleActions as $key) { | 
					
						
							| 
									
										
										
										
											2024-12-22 20:37:54 +01:00
										 |  |  |                     $possibleActions[$key] = (string) trans('firefly.rule_action_'.$key.'_choice'); | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 unset($ruleActions); | 
					
						
							|  |  |  |                 asort($possibleActions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return $possibleActions; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2016-01-15 08:10:22 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-28 21:50:20 +01:00
										 |  |  | } |