選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DeveloppementController.php 5.1KB

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