LotSearch.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use app\models\Lots;
  7. /**
  8. * LotSearch represents the model behind the search form about `app\models\Lots`.
  9. */
  10. class LotSearch extends Lots
  11. {
  12. /**
  13. * @inheritdoc
  14. */
  15. public function rules()
  16. {
  17. return [
  18. [['id', 'user_id', 'category_id', 'requisites_id', 'status','num'], 'integer'],
  19. [['aukname','name', 'description', 'address', 'delivery_time', 'delivery_term', 'requires', 'payment_term', 'payment_order', 'member_require', 'member_docs', 'notes', 'date', 'auction_date'], 'safe'],
  20. [['start_price', 'step'], 'number'],
  21. ];
  22. }
  23. /**
  24. * @inheritdoc
  25. */
  26. public function scenarios()
  27. {
  28. // bypass scenarios() implementation in the parent class
  29. return Model::scenarios();
  30. }
  31. /**
  32. * Creates data provider instance with search query applied
  33. *
  34. * @param array $params
  35. *
  36. * @return ActiveDataProvider
  37. */
  38. public function search($params)
  39. {
  40. if(Yii::$app->user->can('admin'))
  41. {
  42. $query = Lots::find()->orderBy('id DESC');
  43. }
  44. else
  45. {
  46. $query = Lots::find()->where(['user_id' => Yii::$app->user->identity->id])->orderBy('date DESC');
  47. }
  48. $dataProvider = new ActiveDataProvider([
  49. 'query' => $query,
  50. ]);
  51. $this->load($params);
  52. if (!$this->validate()) {
  53. // uncomment the following line if you do not want to return any records when validation fails
  54. // $query->where('0=1');
  55. return $dataProvider;
  56. }
  57. $query->andFilterWhere([
  58. 'id' => $this->id,
  59. 'aukname' => $this->aukname,
  60. 'start_price' => $this->start_price,
  61. 'step' => $this->step,
  62. 'docs_id' => $this->docs_id,
  63. 'delivery_time' => $this->delivery_time,
  64. 'category_id' => $this->category_id,
  65. 'requisites_id' => $this->requisites_id,
  66. 'dogovor_id' => $this->dogovor_id,
  67. 'date' => $this->date,
  68. 'auction_date' => $this->auction_date,
  69. 'status' => $this->status,
  70. ]);
  71. $query->andFilterWhere(['like', 'aukname', $this->aukname])
  72. ->andFilterWhere(['like', 'name', $this->name])
  73. ->andFilterWhere(['like', 'description', $this->description])
  74. ->andFilterWhere(['like', 'address', $this->address])
  75. ->andFilterWhere(['like', 'delivery_term', $this->delivery_term])
  76. ->andFilterWhere(['like', 'requires', $this->requires])
  77. ->andFilterWhere(['like', 'payment_term', $this->payment_term])
  78. ->andFilterWhere(['like', 'payment_order', $this->payment_order])
  79. ->andFilterWhere(['like', 'member_require', $this->member_require])
  80. ->andFilterWhere(['like', 'member_docs', $this->member_docs])
  81. ->andFilterWhere(['like', 'notes', $this->notes])
  82. ->andFilterWhere(['like', 'status', $this->status]);
  83. return $dataProvider;
  84. }
  85. }