You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.6KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use common\models\Developpement;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. use yii\filters\AccessControl;
  11. /**
  12. * DeveloppementController implements the CRUD actions for Developpement model.
  13. */
  14. class DeveloppementController extends Controller {
  15. /**
  16. * @inheritdoc
  17. */
  18. public function behaviors()
  19. {
  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
  29. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  30. }
  31. ]
  32. ],
  33. ],
  34. ];
  35. }
  36. /**
  37. * Lists all Developpement models.
  38. * @return mixed
  39. */
  40. public function actionIndex() {
  41. $dataProvider = new ActiveDataProvider([
  42. 'query' => Developpement::find(),
  43. ]);
  44. return $this->render('index', [
  45. 'dataProvider' => $dataProvider,
  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. /**
  100. * Finds the Developpement model based on its primary key value.
  101. * If the model is not found, a 404 HTTP exception will be thrown.
  102. * @param integer $id
  103. * @return Developpement the loaded model
  104. * @throws NotFoundHttpException if the model cannot be found
  105. */
  106. protected function findModel($id) {
  107. if (($model = Developpement::findOne($id)) !== null) {
  108. return $model;
  109. } else {
  110. throw new NotFoundHttpException('The requested page does not exist.');
  111. }
  112. }
  113. }