[ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend() ; } ] ], ], ]; } public function actionIndex() { $this->checkProductsPointsSale() ; return $this->render('index') ; } public function actionAjaxInit() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $usersArray = User::findBy()->all() ; $pointsSaleArray = PointSale::searchAll() ; // distributions $firstDistribution = Distribution::searchOne([], [ 'orderby' => 'id ASC' ]) ; $lastDistribution = Distribution::searchOne([], [ 'orderby' => 'id DESC' ]) ; $firstYear = date('Y',strtotime($firstDistribution->date)) ; $lastYear = date('Y',strtotime($lastDistribution->date)) ; $distributionYearsArray = [] ; for($year = $firstYear; $year <= $lastYear; $year ++) { $distributionYearsArray[] = $year ; } $distributionsArray = Distribution::searchAll([ 'distribution.active' => 1 ], [ 'orderby' => 'date ASC', ]) ; $distributionsByMonthArray = [] ; foreach($distributionsArray as $distribution) { $month = date('Y-m', strtotime($distribution->date)) ; if(!isset($distributionsByMonthArray[$month])) { $distributionsByMonthArray[$month] = [ 'display' => 0, 'year' => date('Y',strtotime($distribution->date)), 'month' => strftime('%B', strtotime($distribution->date)), 'distributions' => [] ] ; } $distribution->date = strftime('%A %d %B %Y', strtotime($distribution->date)) ; $distributionsByMonthArray[$month]['distributions'][] = $distribution ; } return [ 'usersArray' => $usersArray, 'pointsSaleArray' => $pointsSaleArray, 'distributionYearsArray' => $distributionYearsArray, 'distributionsByMonthArray' => $distributionsByMonthArray ] ; } }