Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

162 lines
5.1KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use common\models\Developpement;
  6. use common\models\DeveloppementPriorite;
  7. use yii\data\ActiveDataProvider;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. use yii\filters\AccessControl;
  12. /**
  13. * DeveloppementController implements the CRUD actions for Developpement model.
  14. */
  15. class DeveloppementController extends Controller {
  16. /**
  17. * @inheritdoc
  18. */
  19. public function behaviors()
  20. {
  21. return [
  22. 'access' => [
  23. 'class' => AccessControl::className(),
  24. 'rules' => [
  25. [
  26. 'allow' => true,
  27. 'roles' => ['@'],
  28. 'matchCallback' => function ($rule, $action) {
  29. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  30. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  31. }
  32. ]
  33. ],
  34. ],
  35. ];
  36. }
  37. /**
  38. * Lists all Developpement models.
  39. * @return mixed
  40. */
  41. public function actionIndex() {
  42. $dataProvider = new ActiveDataProvider([
  43. 'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']),
  44. ]);
  45. return $this->render('index', [
  46. 'dataProvider' => $dataProvider,
  47. ]);
  48. }
  49. /**
  50. * Creates a new Developpement model.
  51. * If creation is successful, the browser will be redirected to the 'view' page.
  52. * @return mixed
  53. */
  54. public function actionCreate() {
  55. $model = new Developpement();
  56. if ($model->load(Yii::$app->request->post())) {
  57. $model->date = date('Y-m-d H:i:s') ;
  58. $model->setDateLivraison() ;
  59. if($model->save()) {
  60. Yii::$app->getSession()->setFlash('success','Développement ajouté') ;
  61. return $this->redirect(['index']);
  62. }
  63. } else {
  64. return $this->render('create', [
  65. 'model' => $model,
  66. ]);
  67. }
  68. }
  69. /**
  70. * Updates an existing Developpement model.
  71. * If update is successful, the browser will be redirected to the 'view' page.
  72. * @param integer $id
  73. * @return mixed
  74. */
  75. public function actionUpdate($id) {
  76. $model = $this->findModel($id);
  77. if ($model->load(Yii::$app->request->post())) {
  78. $model->setDateLivraison() ;
  79. if($model->save()) {
  80. Yii::$app->getSession()->setFlash('success','Développement modifié') ;
  81. return $this->redirect(['index']);
  82. }
  83. } else {
  84. return $this->render('update', [
  85. 'model' => $model,
  86. ]);
  87. }
  88. }
  89. /**
  90. * Deletes an existing Developpement model.
  91. * If deletion is successful, the browser will be redirected to the 'index' page.
  92. * @param integer $id
  93. * @return mixed
  94. */
  95. public function actionDelete($id) {
  96. $this->findModel($id)->delete();
  97. Yii::$app->getSession()->setFlash('success','Développement supprimé') ;
  98. return $this->redirect(['index']);
  99. }
  100. public function actionPriorite($id_developpement, $priorite = null) {
  101. $developpement_priorite = DeveloppementPriorite::find()
  102. ->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])
  103. ->one() ;
  104. if(in_array($priorite,
  105. [DeveloppementPriorite::PRIORITE_HAUTE,
  106. DeveloppementPriorite::PRIORITE_NORMALE,
  107. DeveloppementPriorite::PRIORITE_BASSE])) {
  108. if($developpement_priorite) {
  109. $developpement_priorite->priorite = $priorite ;
  110. $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
  111. }
  112. else {
  113. $developpement_priorite = new DeveloppementPriorite ;
  114. $developpement_priorite->id_developpement = $id_developpement ;
  115. $developpement_priorite->priorite = $priorite ;
  116. $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
  117. }
  118. $developpement_priorite->save() ;
  119. }
  120. else {
  121. if($developpement_priorite) {
  122. $developpement_priorite->delete() ;
  123. }
  124. }
  125. $this->redirect(['index']) ;
  126. }
  127. /**
  128. * Finds the Developpement model based on its primary key value.
  129. * If the model is not found, a 404 HTTP exception will be thrown.
  130. * @param integer $id
  131. * @return Developpement the loaded model
  132. * @throws NotFoundHttpException if the model cannot be found
  133. */
  134. protected function findModel($id) {
  135. if (($model = Developpement::findOne($id)) !== null) {
  136. return $model;
  137. } else {
  138. throw new NotFoundHttpException('The requested page does not exist.');
  139. }
  140. }
  141. }