EventlogSearch.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use app\models\Eventlog;
  7. /**
  8. * EventlogSearch represents the model behind the search form about `app\models\Eventlog`.
  9. */
  10. class EventlogSearch extends Eventlog
  11. {
  12. /**
  13. * @inheritdoc
  14. */
  15. public $at_org;
  16. public $name;
  17. public function rules()
  18. {
  19. return [
  20. [['id', 'user_id', 'auk_id'], 'integer'],
  21. [['ip', 'action', 'at_org','name','date'], 'safe'],
  22. ];
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function scenarios()
  28. {
  29. // bypass scenarios() implementation in the parent class
  30. return Model::scenarios();
  31. }
  32. /**
  33. * Creates data provider instance with search query applied
  34. *
  35. * @param array $params
  36. *
  37. * @return ActiveDataProvider
  38. */
  39. public function search($params)
  40. {
  41. $query = Eventlog::find();
  42. $query->joinWith('user');
  43. $query->joinWith('auctions');
  44. $query->joinWith('lots');
  45. $dataProvider = new ActiveDataProvider([
  46. 'query' => $query,
  47. 'sort'=> ['defaultOrder' => ['id'=>SORT_DESC]],
  48. ]);
  49. $dataProvider->sort->attributes['at_org'] = [
  50. 'asc' => ['user.at_org' => SORT_ASC],
  51. 'desc' => ['user.at_org' => SORT_DESC],
  52. ];
  53. $dataProvider->sort->attributes['name'] = [
  54. 'asc' => ['lots.name' => SORT_ASC],
  55. 'desc' => ['lots.name' => SORT_DESC],
  56. ];
  57. //$dataProvider->sort['defaultOrder'] = ['eventlog.id' => SORT_DESC];
  58. $this->load($params);
  59. if (!$this->validate()) {
  60. // uncomment the following line if you do not want to return any records when validation fails
  61. // $query->where('0=1');
  62. return $dataProvider;
  63. }
  64. $query->andFilterWhere([
  65. //'id' => $this->id,
  66. //'user_id' => $this->user_id,
  67. 'auk_id' => $this->auk_id,
  68. //'date' => $this->date,
  69. ]);
  70. $query->andFilterWhere(['like', 'ip', $this->ip])
  71. ->andFilterWhere(['like', 'at_org', $this->at_org])
  72. ->andFilterWhere(['like', 'lots.name', $this->name])
  73. ->andFilterWhere(['like', 'action', $this->action])
  74. ->andFilterWhere(['like', 'eventlog.date', $this->date]);
  75. return $dataProvider;
  76. }
  77. }