<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\filters\AccessControl;
use app\models\User;
use app\models\MasUserGroup;

class DashboardController extends Controller
{
    public $layout = 'main';

    public function behaviors(): array
    {
        return [
            'access' => [
                'class' => AccessControl::class,
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
        ];
    }

    public function actionIndex(): string
    {
        $totalUsers  = User::find()->where(['is_active' => 'Y'])->count();
        $totalGroups = MasUserGroup::find()->where(['is_active' => 'Y'])->count();
        $recentUsers = User::find()->orderBy(['id' => SORT_DESC])->limit(5)->all();

        return $this->render('index', [
            'totalUsers'  => $totalUsers,
            'totalGroups' => $totalGroups,
            'recentUsers' => $recentUsers,
        ]);
    }
}
