Bicycle/App/Controller/IndexController.php
Egor Isaev cff643ebc5 dev
2026-08-12 17:08:46 +03:00

51 lines
1.5 KiB
PHP

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description IndexController.php
* @copyright (c) 03/06/2026
*/
namespace App\Controller;
use App\Repositories\AccountRepository;
use App\Repositories\UserRepository;
use Services\Auth;
use System\Classes\Controller;
use System\Classes\MyException;
/**
* Дашборд — главная страница после входа (защищена, см. $_auth_protection).
*/
class IndexController extends Controller
{
protected bool $_auth_protection = true;
/**
* @return string
* @throws MyException
*/
public function indexAction(): string
{
$auth_user = Auth::instance()->getUser();
$user = (new UserRepository())->getByLogin($auth_user['login']);
$account_repo = new AccountRepository();
$accounts = $user ? $account_repo->getList('*', ['user_id' => $user->id, 'is_delete' => 0], '`order`') : [];
$archived_accounts = $user ? $account_repo->getList('*', ['user_id' => $user->id, 'is_delete' => 1], 'title') : [];
$total = array_sum(array_map(
static fn ($account) => $account->include_in_total && $account->currency === 'RUB' ? (float)$account->summa : 0,
$accounts ?: []
));
return $this->render('index', [
'user' => $auth_user,
'accounts' => $accounts ?: [],
'archived_accounts' => $archived_accounts ?: [],
'total' => $total,
]);
}
}