AuctionsSearch.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. /**
  7. * AuctionsSearch represents the model behind the search form about `app\models\Auctions`.
  8. */
  9. class AuctionsSearch extends Auctions
  10. {
  11. public $lot;
  12. /**
  13. * @inheritdoc
  14. */
  15. public function rules()
  16. {
  17. return [
  18. [['id', 'user_id', 'lot_id', 'date_start', 'bidding_date', 'last_price', 'last_user', 'last_date'], 'integer'],
  19. [['userName', 'name'], 'safe'],
  20. [['lot'], 'string']
  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. $query = Auctions::find();
  41. $dataProvider = new ActiveDataProvider([
  42. 'query' => $query,
  43. 'sort' => [
  44. 'defaultOrder' => ['id' => SORT_DESC],
  45. ]
  46. ]);
  47. $this->load($params);
  48. if (!$this->validate()) {
  49. return $dataProvider;
  50. }
  51. $query->joinWith(['lot', 'user']);
  52. $query->andFilterWhere([
  53. 'date_start' => $this->date_start,
  54. 'bidding_date' => $this->date_stop,
  55. 'last_price' => $this->last_price,
  56. 'last_user' => $this->last_user,
  57. 'last_date' => $this->last_date,
  58. ]);
  59. $query->andFilterWhere(['like', 'lots.name', $this->lot]);
  60. $query->andFilterWhere(['like', 'auctions.name', $this->name]);
  61. //$query->andFilterWhere(['like','lots.start_price',$this->lot]);
  62. return $dataProvider;
  63. }
  64. }