|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use common\models\Developpement;
- use common\models\DeveloppementPriorite;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
-
- /**
- * DeveloppementController implements the CRUD actions for Developpement model.
- */
- class DeveloppementController extends Controller {
-
- /**
- * @inheritdoc
- */
- public function behaviors() {
- return [
- '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;
- }
- ]
- ],
- ],
- ];
- }
-
- /**
- * Lists all Developpement models.
- * @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']);
- }
-
- 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.');
- }
- }
-
- }
|