Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

138 linhas
3.6KB

  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_boulangerie'=>Yii::$app->user->identity->id])
  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. }