コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Estimate::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['estimate.id' => $this->id, 'estimate.client_id' => $this->client_id, 'estimate.user_id' => $this->user_id, 'estimate.status' => $this->status, 'estimate.request_date' => $this->request_date, 'estimate.sent_date' => $this->sent_date, 'estimate.total' => $this->total, 'estimate.cost' => $this->cost, 'estimate.total_checked' => $this->total_checked, 'estimate.cost_checked' => $this->cost_checked, 'estimate.us' => $this->us, 'estimate.deleted' => $this->deleted]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     $joinWith = ['client' => function ($query) {
         if ($this->clientName) {
             $query->where(['like', 'name', $this->clientName]);
         }
     }];
     if ($this->sampleDelivered) {
         array_push($joinWith, 'entriesWithSampleDelivered');
     }
     $query->joinWith($joinWith)->active();
     return $dataProvider;
 }