47 lines
1.3 KiB
PHP
47 lines
1.3 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']);
|
|
|
|
$accounts = $user ? (new AccountRepository())->getList('*', ['user_id' => $user->id, 'is_delete' => 0], '`order`') : [];
|
|
|
|
$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 ?: [],
|
|
'total' => $total,
|
|
]);
|
|
}
|
|
}
|