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

PointVenteController.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. use common\models\PointVenteUser ;
  12. /**
  13. * PointVenteController implements the CRUD actions for PointVente model.
  14. */
  15. class PointVenteController extends BackendController
  16. {
  17. public function behaviors()
  18. {
  19. return [
  20. 'verbs' => [
  21. 'class' => VerbFilter::className(),
  22. 'actions' => [
  23. ],
  24. ],
  25. 'access' => [
  26. 'class' => AccessControl::className(),
  27. 'rules' => [
  28. [
  29. 'allow' => true,
  30. 'roles' => ['@'],
  31. 'matchCallback' => function ($rule, $action) {
  32. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  33. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  34. }
  35. ],
  36. ],
  37. ],
  38. ];
  39. }
  40. /**
  41. * Lists all PointVente models.
  42. * @return mixed
  43. */
  44. public function actionIndex()
  45. {
  46. $dataProvider = new ActiveDataProvider([
  47. 'query' => PointVente::find()->where(['id_etablissement'=>Yii::$app->user->identity->id_etablissement])
  48. ]);
  49. return $this->render('index', [
  50. 'dataProvider' => $dataProvider,
  51. ]);
  52. }
  53. /**
  54. * Displays a single PointVente model.
  55. * @param integer $id
  56. * @return mixed
  57. */
  58. public function actionView($id)
  59. {
  60. return $this->render('view', [
  61. 'model' => $this->findModel($id),
  62. ]);
  63. }
  64. /**
  65. * Creates a new PointVente model.
  66. * If creation is successful, the browser will be redirected to the 'view' page.
  67. * @return mixed
  68. */
  69. public function actionCreate()
  70. {
  71. $model = new PointVente();
  72. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  73. $model->gestionPointFabrication() ;
  74. $model->gestionAccesRestreint() ;
  75. return $this->redirect(['index']);
  76. } else {
  77. return $this->render('update', array_merge($this->initForm(),[
  78. 'model' => $model,
  79. ]));
  80. }
  81. }
  82. /**
  83. * Updates an existing PointVente model.
  84. * If update is successful, the browser will be redirected to the 'view' page.
  85. * @param integer $id
  86. * @return mixed
  87. */
  88. public function actionUpdate($id)
  89. {
  90. $model = PointVente::find()
  91. ->with('pointVenteUser')
  92. ->where(['id' => $id])
  93. ->one() ;
  94. foreach($model->pointVenteUser as $u)
  95. {
  96. $model->users[] = $u->id_user ;
  97. $model->users_commentaire[$u->id_user] = $u->commentaire ;
  98. }
  99. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  100. $model->gestionPointFabrication() ;
  101. $model->gestionAccesRestreint() ;
  102. return $this->redirect(['index']);
  103. } else {
  104. return $this->render('update', array_merge($this->initForm($id),[
  105. 'model' => $model,
  106. ]));
  107. }
  108. }
  109. public function initForm($id = 0)
  110. {
  111. $users = User::find()->orderBy('nom ASC')->all() ;
  112. return [
  113. 'users' => $users
  114. ] ;
  115. }
  116. /**
  117. * Deletes an existing PointVente model.
  118. * If deletion is successful, the browser will be redirected to the 'index' page.
  119. * @param integer $id
  120. * @return mixed
  121. */
  122. public function actionDelete($id)
  123. {
  124. $this->findModel($id)->delete();
  125. PointVenteUser::deleteAll(['id_point_vente' => $id]) ;
  126. return $this->redirect(['index']);
  127. }
  128. /**
  129. * Finds the PointVente model based on its primary key value.
  130. * If the model is not found, a 404 HTTP exception will be thrown.
  131. * @param integer $id
  132. * @return PointVente the loaded model
  133. * @throws NotFoundHttpException if the model cannot be found
  134. */
  135. protected function findModel($id)
  136. {
  137. if (($model = PointVente::findOne($id)) !== null) {
  138. return $model;
  139. } else {
  140. throw new NotFoundHttpException('The requested page does not exist.');
  141. }
  142. }
  143. }