AuclotsController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\controllers;
  3. use app\models\Bills;
  4. use Yii;
  5. use app\models\Auclots;
  6. use app\models\Files;
  7. use yii\data\ActiveDataProvider;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. use yii\web\UploadedFile;
  12. /**
  13. * AuclotsController implements the CRUD actions for Auclots model.
  14. */
  15. class AuclotsController extends Controller
  16. {
  17. public function behaviors()
  18. {
  19. return [
  20. 'verbs' => [
  21. 'class' => VerbFilter::className(),
  22. 'actions' => [
  23. 'delete' => ['post'],
  24. ],
  25. ],
  26. ];
  27. }
  28. /**
  29. * Lists all Auclots models.
  30. * @return mixed
  31. */
  32. public function init()
  33. {
  34. if(Yii::$app->user->isGuest)
  35. {
  36. return $this->redirect('/user/login');
  37. }
  38. if(@!Yii::$app->user->identity->confirmed_at && (@Yii::$app->user->identity->role == 1)){
  39. return $this->redirect('/registration/organizer');
  40. }
  41. $this->layout = '@app/views/layouts/backend/user';
  42. parent::init();
  43. }
  44. public function actionIndex()
  45. {
  46. $dataProvider = new ActiveDataProvider([
  47. 'query' => Auclots::find()->where(['user_id'=>Yii::$app->user->identity->id])->orderBy('id DESC'),
  48. ]);
  49. return $this->render('index', [
  50. 'dataProvider' => $dataProvider,
  51. ]);
  52. }
  53. /**
  54. * Displays a single Auclots 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 Auclots 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 Auclots();
  72. if (Yii::$app->request->post()) {
  73. $files = new Files();
  74. $dogovor = UploadedFile::getInstance($files, 'file');
  75. if(isset($dogovor))
  76. {
  77. $dogovor->name = $files->transliteration($dogovor->name);
  78. $path = Yii::$app->params['uploadPath'].$dogovor->name;
  79. $dogovor->saveAs($path);
  80. $model->dogovor_id = $files->saveFile([
  81. 'name'=>$dogovor->name,
  82. 'path'=>Yii::$app->params['uploadPath'],
  83. 'user_id'=>Yii::$app->user->identity->id,
  84. 'auction_id'=>'null',
  85. 'lot_id'=>$model->id,
  86. 'type' => 'NULL'
  87. ]);
  88. }
  89. }
  90. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  91. Yii::$app->session->setFlash('success', Yii::t('app', 'AuctionCreated ID'));
  92. return $this->redirect(['index']);
  93. } else {
  94. return $this->render('create', ['model' => $model]);
  95. }
  96. }
  97. /**
  98. * Updates an existing Auclots model.
  99. * If update is successful, the browser will be redirected to the 'view' page.
  100. * @param integer $id
  101. * @return mixed
  102. */
  103. public function actionUpdate($id)
  104. {
  105. $model = $this->findModel($id);
  106. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  107. return $this->redirect(['view', 'id' => $model->id]);
  108. } else {
  109. return $this->render('update', [
  110. 'model' => $model,
  111. ]);
  112. }
  113. }
  114. /**
  115. * Deletes an existing Auclots model.
  116. * If deletion is successful, the browser will be redirected to the 'index' page.
  117. * @param integer $id
  118. * @return mixed
  119. */
  120. public function actionDelete($id)
  121. {
  122. $this->findModel($id)->delete();
  123. return $this->redirect(['index']);
  124. }
  125. /**
  126. * Finds the Auclots model based on its primary key value.
  127. * If the model is not found, a 404 HTTP exception will be thrown.
  128. * @param integer $id
  129. * @return Auclots the loaded model
  130. * @throws NotFoundHttpException if the model cannot be found
  131. */
  132. protected function findModel($id)
  133. {
  134. if (($model = Auclots::findOne($id)) !== null) {
  135. return $model;
  136. } else {
  137. throw new NotFoundHttpException('The requested page does not exist.');
  138. }
  139. }
  140. }