<?php
namespace app\controllers;

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

class StatisticsController extends Controller
{
    public $layout = '@app/views/layouts/backend/user';

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

    public function actionIndex(){
        $searchModel = new Statistics();
        $users = $searchModel->searchUsers(Yii::$app->request->queryParams);
        $auctions = $searchModel->searchAuctions(Yii::$app->request->queryParams);
        $categories = $searchModel->searchCategory(Yii::$app->request->queryParams);
        $subscriptions = $searchModel->subscriptions;
        $total = User::find()->count();
        return $this->render('index', [
            'users' => $users,
            'searchModel' => $searchModel,
            'total' => $total,
            'auctions' => $auctions,
            'categories' => $categories,
            'subscriptions' => $subscriptions
        ]);



    }

    public function actionUser()
    {
        $searchModel = new Statistics();

        $auctions = $searchModel->searchAuctions(Yii::$app->request->queryParams);
        $categories = $searchModel->searchCategory(Yii::$app->request->queryParams);
        $subscriptions = $searchModel->subscriptions;

        $userBiddings = $searchModel->userBiddings();
        //$userAuctions = $searchModel->searchUserAuctions();
        $userMailing = $searchModel->userMailing();


        return $this->render('user',[
            'userBiddings' => $userBiddings,
           // 'userAuctions' => $userAuctions,
            'userMailing' => $userMailing,

            'subscriptions' => $subscriptions,
            'auctions' => $auctions,
            'categories' => $categories,
        ]);
    }
}