Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\modules\leads\models;
  4.  
  5. use yii\base\Model;
  6. use yii\data\ActiveDataProvider;
  7.  
  8. /**
  9. * LeadInfoSearch represents the model behind the search form about `app\modules\lead_info\models\LeadInfo`.
  10. */
  11. class LeadInfoSearch extends LeadInfo
  12. {
  13.  
  14. public $user_id;
  15. public $date_from;
  16. public $date_to;
  17. /**
  18. * @inheritdoc
  19. */
  20. public function rules()
  21. {
  22. return [
  23. [['id','partner_id', 'aff_id', 'ga_cid','isRemoved', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign','count_orders', 'count_sells', 'total_lessons'], 'integer'],
  24. [['source', 'conv_url','user_id','product_id', 'promocode_id', 'lead_channel_id', 'lead_landing_id', 'lead_form_id'], 'safe'],
  25. [['date_from', 'date_to', 'create_time'], 'date'],
  26. ];
  27. }
  28.  
  29. /**
  30. * @inheritdoc
  31. */
  32. public function scenarios()
  33. {
  34. // bypass scenarios() implementation in the parent class
  35. return Model::scenarios();
  36. }
  37.  
  38. /**
  39. * Creates data provider instance with search query applied
  40. *
  41. * @param array $params
  42. *
  43. * @return ActiveDataProvider
  44. */
  45. public function search($params)
  46. {
  47. $query = LeadInfo::find();
  48.  
  49. // add conditions that should always apply here
  50.  
  51. $dataProvider = new ActiveDataProvider([
  52. 'query' => $query,
  53. ]);
  54.  
  55. $this->load($params);
  56.  
  57.  
  58.  
  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.  
  65.  
  66. $query->joinWith('leadForm');
  67. $query->joinWith('leadLanding');
  68. $query->joinWith('leadChannel');
  69. $query->joinWith('promocode');
  70. $query->joinWith('product');
  71. $query->joinWith('user');
  72.  
  73. // grid filtering conditions
  74. $query->andFilterWhere([
  75. 'id' => $this->id,
  76. 'create_time' => $this->create_time,
  77. 'user.username' => $this->user->username,
  78. 'product.name' => $this->product->name,
  79. 'lead_channel.name' => $this->leadChannel->name,
  80. 'partner_id' => $this->partner_id,
  81. 'aff_id' => $this->aff_id,
  82. 'lead_landing.name' => $this->leadLanding->name,
  83. 'lead_form.name' => $this->leadForm->name,
  84. 'ga_cid' => $this->ga_cid,
  85. 'utm_medium' => $this->utm_medium,
  86. 'utm_term' => $this->utm_term,
  87. 'utm_content' => $this->utm_content,
  88. 'utm_campaign' => $this->utm_campaign,
  89. 'promocode.promo_name' => $this->promocode->promo_name,
  90. 'count_orders' => $this->count_orders,
  91. 'count_sells' => $this->count_sells,
  92. 'total_lessons' => $this->total_lessons,
  93. 'isRemoved' => 1,
  94. ]);
  95.  
  96.  
  97.  
  98.  
  99. $query->andFilterWhere(['like', 'source', $this->source])
  100. ->andFilterWhere(['like', 'conv_url', $this->conv_url])
  101. ->andFilterWhere(['like', 'lead_channel.name', $this->lead_channel_id])
  102. ->andFilterWhere(['like', 'lead_landing.name', $this->lead_landing_id])
  103. ->andFilterWhere(['like', 'lead_form.name', $this->lead_form_id])
  104. ->andFilterWhere(['like', 'product.name', $this->product_id])
  105. ->andFilterWhere(['like', 'promocode.promo_name', $this->promocode_id])
  106. ->andFilterWhere(['like', 'user.username', $this->user_id])
  107.  
  108. // ->andFilterWhere(['>=', 'create_time', $this->date_from ? strtotime($this->date_from . ' 00:00:00') : null])
  109. // ->andFilterWhere(['<=', 'create_time', $this->date_to ? strtotime($this->date_to . ' 23:59:59') : null]);
  110. ->andFilterWhere(['>=', 'create_time', $this->date_from])
  111. ->andFilterWhere(['<=', 'create_time', $this->date_to]);
  112.  
  113.  
  114.  
  115. ;
  116.  
  117. return $dataProvider;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement