PublishingSearch.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use app\models\Publishing;
  7. /**
  8. * PublishingSearch represents the model behind the search form about `app\models\Publishing`.
  9. */
  10. class PublishingSearch extends Publishing
  11. {
  12. public $userName;
  13. public $lotName;
  14. public $endBidding;
  15. public $statusName;
  16. public $main_search;
  17. public $status;
  18. public $org_name;
  19. public $name;
  20. public $type;
  21. public $category;
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules()
  26. {
  27. // $rules[] = [['status'], 'in', 'range' => array_keys((new Auctions())->statusNames)];
  28. // $rules[] = [['type'], 'in', 'range' => array_keys(Lots::$procurementMethodTypes)];
  29. return [
  30. [['id', 'user_id', 'lot_id', 'last_user', 'lot_num'], 'integer'],
  31. [['name', 'date_start', 'date_stop', 'last_date','userName','lotName','statusName','endBidding','lot_num','userName','statusName', 'status', 'type'], 'safe'],
  32. [['last_price'], 'number'],
  33. [['main_search', 'org_name', 'name', 'category'], 'string', 'max' => 255]
  34. ];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function scenarios()
  40. {
  41. // bypass scenarios() implementation in the parent class
  42. return Model::scenarios();
  43. }
  44. /**
  45. * Creates data provider instance with search query applied
  46. *
  47. * @param array $params
  48. *
  49. * @return ActiveDataProvider
  50. */
  51. public function search($params)
  52. {
  53. $query = Publishing::find()->orderBy('id DESC');;
  54. $dataProvider = new ActiveDataProvider([
  55. 'query' => $query,
  56. 'pagination' => [
  57. 'defaultPageSize' => 4,
  58. 'pageSize' => 4,
  59. ],
  60. 'sort' => [
  61. 'defaultOrder' => [
  62. 'id' => SORT_DESC
  63. ]
  64. ]
  65. ]);
  66. $this->load($params);
  67. if (!$this->validate()) {
  68. return $dataProvider;
  69. }
  70. $query->joinWith(['profile', 'user', 'lot']);
  71. $query->andFilterWhere([
  72. 'or',
  73. ['like', 'auctions.lot_num', $this->main_search],
  74. ['like', 'lots.name', $this->main_search],
  75. ]);
  76. $query->andFilterWhere(['like', 'auctions.type', $this->type]);
  77. $query->andFilterWhere(['like', 'auctions.status', $this->status]);
  78. $query->andFilterWhere(['like', 'lots.category_id', $this->category]);
  79. $query->andFilterWhere(['like', 'profile.at_org', $this->org_name]);
  80. $query
  81. ->andFilterWhere(['like', 'auctions.lot_num', $this->lot_num])
  82. ->andFilterWhere(['like', 'profile.at_org', $this->userName])
  83. ->andFilterWhere(['like', 'lots.bidding_date', $this->endBidding])
  84. ->andFilterWhere(['like', 'lots.name', $this->name]);
  85. return $dataProvider;
  86. }
  87. public function isClear(){
  88. return !$this->status
  89. && !$this->org_name
  90. && !$this->category
  91. && !$this->type
  92. && !$this->name;
  93. }
  94. }