[ 'class' => VerbFilter::className(), 'actions' => [ ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; } ], ], ], ]; } /** * Liste les points de vente. * * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider([ 'query' => PointVente::find()->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) ]); return $this->render('index', [ 'dataProvider' => $dataProvider, ]); } /** * Crée un point de vente. * * @return mixed */ public function actionCreate() { $model = new PointVente(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->gestionPointFabrication(); $model->gestionAccesRestreint(); return $this->redirect(['index']); } else { return $this->render('update', array_merge($this->initForm(), [ 'model' => $model, ])); } } /** * Modifie un point de vente. * * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = PointVente::find() ->with('pointVenteUser') ->where(['id' => $id]) ->one(); foreach ($model->pointVenteUser as $u) { $model->users[] = $u->id_user; $model->users_commentaire[$u->id_user] = $u->commentaire; } if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->gestionPointFabrication(); $model->gestionAccesRestreint(); return $this->redirect(['index']); } else { return $this->render('update', array_merge($this->initForm($id), [ 'model' => $model, ])); } } /** * Initialise le formulaire de création/modification. * * @param integer $id * @return mixed */ public function initForm($id = 0) { $users = User::findBy() ->orderBy('nom ASC') ->all(); return [ 'users' => $users ]; } /** * Supprime un point de vente et redirige vers la liste des points de vente. * * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); PointVenteUser::deleteAll(['id_point_vente' => $id]); ProductionPointVente::deleteAll(['id_point_vente' => $id]) ; return $this->redirect(['index']); } /** * Recherche un point de vente en fonction de son ID. * * @param integer $id * @return PointVente * @throws NotFoundHttpException si le modèle n'est pas trouvé */ protected function findModel($id) { if (($model = PointVente::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }