[ 'class' => VerbFilter::className(), 'actions' => [ ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend(); } ], ], ], ]; } /** * Liste les points de vente. * * @return mixed */ public function actionIndex() { $searchModel = new PointSaleSearch() ; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Crée un point de vente. * * @return mixed */ public function actionCreate() { $model = new PointSale(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->processPointProduction(); $model->processRestrictedAccess(); return $this->redirect(['index']); } else { return $this->render('create', array_merge($this->initForm(), [ 'model' => $model, ])); } } /** * Modifie un point de vente. * * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = PointSale::find() ->with('userPointSale') ->where(['id' => $id]) ->one(); foreach ($model->userPointSale as $userPointSale) { $model->users[] = $userPointSale->id_user; $model->users_comment[$userPointSale->id_user] = $userPointSale->comment; } if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->processPointProduction(); $model->processRestrictedAccess(); 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('name 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(); UserPointSale::deleteAll(['id_point_sale' => $id]); PointSaleDistribution::deleteAll(['id_point_sale' => $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 = PointSale::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }