diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index cbfc8c48ac..899b93e8b9 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -27,9 +27,11 @@ use Carbon\Carbon; use Eloquent; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\RuleGroup; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; use RuntimeException; @@ -93,12 +95,51 @@ class ExpandedForm return $this->currencyField($name, 'amount-small', $value, $options); } + /** + * @param string $name + * @param $selected + * @param null $options + * + * @return string + * @throws \Throwable + */ + public function assetAccountCheckList(string $name, $options = null): string + { + $options = $options ?? []; + $label = $this->label($name, $options); + $options = $this->expandOptionArray($name, $label, $options); + $classes = $this->getHolderClasses($name); + $selected = request()->old($name) ?? []; + + // get all asset accounts: + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $assetAccounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); + $grouped = []; + // group accounts: + /** @var Account $account */ + foreach ($assetAccounts as $account) { + $role = $repository->getMetaValue($account, 'accountRole'); + if (null === $role) { + $role = 'no_account_type'; // @codeCoverageIgnore + } + $key = (string)trans('firefly.opt_group_' . $role); + $grouped[$key][$account->id] = $account->name; + } + + unset($options['class']); + $html = view('form.assetAccountCheckList', compact('classes','selected', 'name', 'label', 'options', 'grouped'))->render(); + + return $html; + } + /** * @param string $name * @param null $value * @param array $options * * @return string + * @throws \Throwable */ public function assetAccountList(string $name, $value = null, array $options = []): string { @@ -193,19 +234,10 @@ class ExpandedForm * @param array $options * * @return string + * @throws \Throwable */ public function currencyList(string $name, $value = null, array $options = []): string { - // properties for cache - $cache = new CacheProperties; - $cache->addProperty('exp-form-currency-list'); - $cache->addProperty($name); - $cache->addProperty($value); - $cache->addProperty($options); - - if ($cache->has()) { - return $cache->get(); - } /** @var CurrencyRepositoryInterface $currencyRepos */ $currencyRepos = app(CurrencyRepositoryInterface::class); @@ -217,7 +249,6 @@ class ExpandedForm $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')'; } $res = $this->select($name, $array, $value, $options); - $cache->store($res); return $res; } @@ -351,28 +382,6 @@ class ExpandedForm return $selectList; } - /** - * @param string $name - * @param array $list - * @param null $selected - * @param array $options - * - * @return string - * @throws \Throwable - */ - public function multiCheckbox(string $name, array $list = [], $selected = null, array $options = []): string - { - $label = $this->label($name, $options); - $options = $this->expandOptionArray($name, $label, $options); - $classes = $this->getHolderClasses($name); - $selected = $this->fillFieldValue($name, $selected); - - unset($options['class']); - $html = view('form.multiCheckbox', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render(); - - return $html; - } - /** * @param string $name * @param array $list @@ -516,6 +525,31 @@ class ExpandedForm return $html; } + /** + * @param string $name + * @param null $value + * @param array $options + * + * @return string + * @throws \Throwable + */ + public function ruleGroupList(string $name, $value = null, array $options = []): string + { + /** @var RuleGroupRepositoryInterface $groupRepos */ + $groupRepos = app(RuleGroupRepositoryInterface::class); + + // get all currencies: + $list = $groupRepos->get(); + $array = []; + /** @var RuleGroup $group */ + foreach ($list as $group) { + $array[$group->id] = $group->title; + } + $res = $this->select($name, $array, $value, $options); + + return $res; + } + /** * @param string $name * @param array $list diff --git a/config/twigbridge.php b/config/twigbridge.php index 63b6398f22..2e2b1d98c7 100644 --- a/config/twigbridge.php +++ b/config/twigbridge.php @@ -188,7 +188,7 @@ return [ 'is_safe' => [ 'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount', - 'number', 'assetAccountList','amountNoCurrency','currencyList' + 'number', 'assetAccountList','amountNoCurrency','currencyList','ruleGroupList','assetAccountCheckList' ], ], 'Form' => [ diff --git a/resources/views/form/assetAccountCheckList.twig b/resources/views/form/assetAccountCheckList.twig index 39776e2be0..129dc11356 100644 --- a/resources/views/form/assetAccountCheckList.twig +++ b/resources/views/form/assetAccountCheckList.twig @@ -2,18 +2,20 @@
- {% for value,description in list %} - {% set options = options|merge({'id': 'ffInput_'~name~'_'~value}) %} -
- -
+ {% for groupName, accounts in grouped %} + {{ groupName }}
+ {% for id, account in accounts %} +
+ +
+ {% endfor %} {% endfor %} {% include 'form/help' %} {% include 'form/feedback' %}