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.

PointVenteController.php 3.6KB

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