RequisitesController.php 3.9 KB

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