[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::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 $distributionsArray = Distribution::find() ->with('order') ->where(['>=', 'distribution.date', date('Y-m-d')]) ->andWhere([ 'distribution.id_producer' => GlobalParam::getCurrentProducerId(), 'distribution.active' => 1 ]) ->orderBy('date ASC') ->limit(3) ->all(); // dernières commandes $ordersArray = Order::searchAll([],[ 'orderby' => 'date DESC', 'conditions' => 'distribution.date > :date 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' => [':date' => date('Y-m-d 00:00:00')], ]); // clients $nbUsers = User::searchCount(); $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, 'nbUsers' => $nbUsers, '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']); } }