<?php

namespace frontend\controllers;

use Yii;
use yii\data\Pagination;
use common\models\UserAcountLog;

class AccountController extends _UserController {

    public function actionIndex() {
        $pagesize = (int) Yii::$app->request->get('pagesize', 10);
        $type = (int) Yii::$app->request->get('type');

        $query = UserAcountLog::find()->where(['c_user_id' => Yii::$app->user->getId()]);

        if ($type) {
            $query->andWhere(['c_type' => $type]);
        }

        $countQuery = clone $query;

        $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $pagesize]);
        $list = $query->offset($pages->offset)->limit($pages->limit)->orderby(['c_id' => SORT_ASC])->all();
        $var['type'] = $type;
        $var['pages'] = $pages;
        $var['list'] = $list;

        return $this->render('index', $var);
    }

}
