BillsSearch.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use app\models\Bills;
  7. /**
  8. * BillsSearch represents the model behind the search form of `app\models\Bills`.
  9. */
  10. class BillsSearch extends Bills
  11. {
  12. public $user_at_org;
  13. public $auction_id;
  14. public function rules()
  15. {
  16. return [
  17. [['user_id', 'auction_id', 'bid_id'], 'integer'],
  18. [['type'], 'safe'],
  19. [['user_at_org'], 'string', 'max' => 255],
  20. [['payed'], 'in', 'range' => array_keys(Bills::payStatuses())],
  21. ];
  22. }
  23. public function search($params)
  24. {
  25. $query = Bills::find();
  26. $dataProvider = new ActiveDataProvider([
  27. 'query' => $query,
  28. 'sort' => [
  29. 'defaultOrder' => [
  30. 'payed' => SORT_ASC,
  31. ],
  32. ],
  33. ]);
  34. $this->load($params);
  35. if (!$this->validate()) {
  36. return $dataProvider;
  37. }
  38. $query->joinWith(['user', 'auction']);
  39. $query->andFilterWhere([
  40. 'user_id' => $this->user_id,
  41. 'bid_id' => $this->bid_id,
  42. 'bills.type' => $this->type,
  43. 'bills.payed' => $this->payed,
  44. ]);
  45. $query->andFilterWhere([
  46. 'bidding.auction_id' => $this->auction_id,
  47. ]);
  48. $query->andFilterWhere(['like', 'user.at_org', $this->user_at_org]);
  49. return $dataProvider;
  50. }
  51. }