[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getLogic()->getUserContainer()->getSolver()->hasAccessBackend(); } ], [ 'actions' => ['change-producer'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::getCurrentStatus() == User::STATUS_ADMIN ; } ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } /** * Affiche le tableau de bord du backend avec les dernières commandes * réalisée, les dernières inscriptions, la liste des clients ayant un crédit * négatif etc. * * @return mixed */ public function actionIndex() { // commandes $optionDashboardNumberDistributions = Producer::getConfig('option_dashboard_number_distributions') ; $dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3 ; $optionDashboardDateStart = Producer::getConfig('option_dashboard_date_start') ; $optionDashboardDateEnd = Producer::getConfig('option_dashboard_date_end') ; $queryDistributions = DistributionModel::find()->with('order') ; if($optionDashboardDateStart || $optionDashboardDateEnd) { if($optionDashboardDateStart) { $queryDistributions->andWhere(['>=', 'distribution.date', $optionDashboardDateStart]) ; } if($optionDashboardDateEnd) { $queryDistributions->andWhere(['<=', 'distribution.date', $optionDashboardDateEnd]) ; } } else { $queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]) ; } $distributionsArray = $queryDistributions->andWhere([ 'distribution.id_producer' => GlobalParam::getCurrentProducerId(), 'distribution.active' => 1 ]) ->orderBy('date ASC') ->limit($dashboardNumberDistributions) ->all(); // dernières commandes $paramsOrders = [] ; if($optionDashboardDateStart || $optionDashboardDateEnd) { $conditionsOrders = '' ; if($optionDashboardDateStart) { $conditionsOrders .= 'distribution.date >= :date_start' ; $paramsOrders[':date_start'] = $optionDashboardDateStart; } if($optionDashboardDateEnd) { if($optionDashboardDateStart) { $conditionsOrders .= ' AND ' ; } $conditionsOrders .= 'distribution.date <= :date_end' ; $paramsOrders[':date_end'] = $optionDashboardDateEnd ; } } else { $conditionsOrders = 'distribution.date >= :date_start' ; $paramsOrders[':date_start'] = date('Y-m-d 00:00:00') ; } $ordersArray = Order::searchAll([],[ 'orderby' => 'date DESC', 'conditions' => $conditionsOrders.' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', 'params' => $paramsOrders, ]); // clients $usersArray = User::findBy() ->orderBy('created_at DESC') ->limit(5) ->all(); $usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) ->andWhere('user_producer.credit < 0') ->all(); // paramètres $producer = GlobalParam::getCurrentProducer(); $productsCount = Product::searchCount() ; $pointsSaleCount = PointSale::searchCount() ; return $this->render('index', [ 'distributionsArray' => $distributionsArray, 'ordersArray' => $ordersArray, 'usersArray' => $usersArray, 'usersNegativeCredit' => $usersNegativeCredit, 'producer' => $producer, 'productsCount' => $productsCount, 'pointsSaleCount' => $pointsSaleCount ]); } /** * Affiche la page de connexion. * * @return mixed */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', [ 'model' => $model, ]); } } /** * Déconnecte l'utilisateur et le redirige à la page d'accueil. * * @return mixed */ public function actionLogout() { Yii::$app->user->logout(); return $this->goHome(); } /** * Change le producteur courant de l'utilisateur connecté. * Permet de passer d'un producteur à un autre en tant qu'administrateur. * * @param integer $id */ public function actionChangeProducer($id) { Yii::$app->user->identity->id_producer = $id; Yii::$app->user->identity->save(); $this->redirect(['site/index']); } }