[ '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 développements. * * @return mixed */ public function actionIndex($statut = Developpement::STATUT_OPEN) { $dataProvider = new ActiveDataProvider([ 'query' => Developpement::find()->with(['developpementPriorite', 'developpementPrioriteCurrentEtablissement'])->where(['statut' => $statut])->orderBy('date DESC'), ]); return $this->render('index', [ 'dataProvider' => $dataProvider, 'statut' => $statut ]); } /** * Creates a new Developpement model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Developpement(); if ($model->load(Yii::$app->request->post())) { $model->date = date('Y-m-d H:i:s'); $model->setDateLivraison(); if ($model->save()) { Yii::$app->getSession()->setFlash('success', 'Développement ajouté'); return $this->redirect(['index']); } } else { return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing Developpement model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { $model->setDateLivraison(); if ($model->save()) { Yii::$app->getSession()->setFlash('success', 'Développement modifié'); return $this->redirect(['index']); } } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing Developpement model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', 'Développement supprimé'); return $this->redirect(['index']); } /** * Définit une priorité pour un développement. * * @param integer $id_developpement * @param string $priorite */ public function actionPriorite($id_developpement, $priorite = null) { $developpement_priorite = DeveloppementPriorite::find() ->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) ->one(); if (in_array($priorite, [DeveloppementPriorite::PRIORITE_HAUTE, DeveloppementPriorite::PRIORITE_NORMALE, DeveloppementPriorite::PRIORITE_BASSE])) { if ($developpement_priorite) { $developpement_priorite->priorite = $priorite; $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement; } else { $developpement_priorite = new DeveloppementPriorite; $developpement_priorite->id_developpement = $id_developpement; $developpement_priorite->priorite = $priorite; $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement; } $developpement_priorite->save(); } else { if ($developpement_priorite) { $developpement_priorite->delete(); } } $this->redirect(['index']); } /** * Finds the Developpement model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Developpement the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Developpement::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }