2019-08-10 08:09:44 -05:00
|
|
|
<?php
|
2019-10-01 23:37:26 -05:00
|
|
|
/**
|
|
|
|
* PiggyBankForm.php
|
2020-02-16 06:56:52 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2019-10-01 23:37:26 -05:00
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-08-17 05:09:03 -05:00
|
|
|
declare(strict_types=1);
|
2019-08-10 08:09:44 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Support\Form;
|
2021-09-18 03:26:12 -05:00
|
|
|
|
2019-08-10 08:09:44 -05:00
|
|
|
use FireflyIII\Models\PiggyBank;
|
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PiggyBankForm
|
|
|
|
*
|
2022-10-30 05:43:17 -05:00
|
|
|
* TODO cleanup and describe.
|
2019-08-10 08:09:44 -05:00
|
|
|
*/
|
|
|
|
class PiggyBankForm
|
|
|
|
{
|
|
|
|
use FormSupport;
|
2019-08-10 09:50:37 -05:00
|
|
|
|
2019-08-10 08:09:44 -05:00
|
|
|
/**
|
2022-10-30 05:43:17 -05:00
|
|
|
* TODO cleanup and describe
|
2019-08-10 09:50:37 -05:00
|
|
|
*
|
2022-12-29 12:42:26 -06:00
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
* @param array|null $options
|
2019-08-10 08:09:44 -05:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function piggyBankList(string $name, $value = null, array $options = null): string
|
|
|
|
{
|
|
|
|
// make repositories
|
|
|
|
/** @var PiggyBankRepositoryInterface $repository */
|
|
|
|
$repository = app(PiggyBankRepositoryInterface::class);
|
|
|
|
$piggyBanks = $repository->getPiggyBanksWithAmount();
|
2022-12-29 12:42:26 -06:00
|
|
|
$title = (string)trans('firefly.default_group_title_name');
|
2020-06-27 06:08:51 -05:00
|
|
|
$array = [];
|
|
|
|
$subList = [
|
|
|
|
0 => [
|
|
|
|
'group' => [
|
|
|
|
'title' => $title,
|
|
|
|
],
|
|
|
|
'piggies' => [
|
2022-12-29 12:42:26 -06:00
|
|
|
(string)trans('firefly.none_in_select_list'),
|
2020-06-27 06:08:51 -05:00
|
|
|
],
|
|
|
|
],
|
2019-08-10 08:09:44 -05:00
|
|
|
];
|
|
|
|
/** @var PiggyBank $piggy */
|
|
|
|
foreach ($piggyBanks as $piggy) {
|
2020-06-27 06:08:51 -05:00
|
|
|
$group = $piggy->objectGroups->first();
|
|
|
|
$groupTitle = null;
|
|
|
|
$groupOrder = 0;
|
|
|
|
if (null !== $group) {
|
|
|
|
$groupTitle = $group->title;
|
|
|
|
$groupOrder = $group->order;
|
|
|
|
}
|
|
|
|
$subList[$groupOrder] = $subList[$groupOrder] ?? [
|
2022-12-29 12:42:26 -06:00
|
|
|
'group' => [
|
|
|
|
'title' => $groupTitle,
|
|
|
|
],
|
|
|
|
'piggies' => [],
|
|
|
|
];
|
2020-06-27 06:08:51 -05:00
|
|
|
$subList[$groupOrder]['piggies'][$piggy->id] = $piggy->name;
|
|
|
|
}
|
|
|
|
ksort($subList);
|
|
|
|
foreach ($subList as $info) {
|
|
|
|
$groupTitle = $info['group']['title'];
|
|
|
|
$array[$groupTitle] = $info['piggies'];
|
2019-08-10 08:09:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->select($name, $array, $value, $options);
|
|
|
|
}
|
2019-08-17 05:09:03 -05:00
|
|
|
}
|