[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; } ], [ 'actions' => ['change-etablissement'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return Yii::$app->user->identity->status == USER::STATUS_ADMIN ; } ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['post'], ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } public function actionIndex() { // commandes $productions = Production::find() ->with('commande') ->where(['>=','production.date',date('Y-m-d')]) ->andWhere([ 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement, 'production.actif' => 1 ]) ->orderBy('date ASC') ->limit(5) ->all() ; // produits $nb_produits = Produit::count() ; $produits = Produit::find() ->where([ 'id_etablissement' => Yii::$app->user->identity->id_etablissement ]) ->orderBy('id DESC') ->limit(5) ->all() ; // points de vente $nb_points_vente = PointVente::count() ; $points_vente = PointVente::find() ->where([ 'id_etablissement' => Yii::$app->user->identity->id_etablissement ]) ->orderBy('id DESC') ->limit(5) ->all() ; // clients $nb_clients = User::findBy()->count(); $clients = User::findBy() ->orderBy('created_at DESC') ->limit(5) ->all(); // paramètres $etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; return $this->render('index',[ 'productions' => $productions, 'nb_produits' => $nb_produits, 'produits' => $produits, 'nb_points_vente' => $nb_points_vente, 'points_vente' => $points_vente, 'clients' => $clients, 'nb_clients' => $nb_clients, 'etablissement' => $etablissement, ]); } 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, ]); } } public function actionLogout() { Yii::$app->user->logout(); return $this->goHome(); } public function actionChangeEtablissement($id) { Yii::$app->user->identity->id_etablissement = $id ; Yii::$app->user->identity->save() ; $this->redirect(['site/index']) ; } }