/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query2 = new Query(); if (isset($_GET['CallHistorySearch'])) { $monthStart = substr($_GET['CallHistorySearch']['start_time'], 5, 2); $monthEnd = substr($_GET['CallHistorySearch']['end_time'], 5, 2); $yearStart = substr($_GET['CallHistorySearch']['start_time'], 0, 4); $yearEnd = substr($_GET['CallHistorySearch']['end_time'], 0, 4); // cek interval month if ($monthStart == $monthEnd) { $obj = new CallHistory(); $obj->setSuffixTable($yearStart . $monthStart); $query = $obj->find(); } else { $obj = new CallHistory(); $obj->setSuffixTable($yearStart . $monthStart); $query = $obj->find()->union($query2->select('*')->from('tbl_call_history_' . $yearEnd . $monthEnd), true); /* $obj = new CallHistory(); $obj->setSuffixTable($yearStart.$monthStart); $query = new Query(); $query2 = new Query();*/ /*echo 'tbl_call_history_'.$yearStart.$monthStart; echo 'tbl_call_history_'.$yearEnd.$monthEnd; die();*/ $query->select('*')->from('tbl_csall_history_' . $yearStart . $monthStart); $query2->select('*')->from('tbl_call_history_' . $yearEnd . $monthEnd); $query->union($query2, true); } } else { // value default not result data $obj = new CallHistory(); $obj->setSuffixTable('201509'); $query = $obj->find(); } /*$query = CallHistory::find()->union( $query2->select('*') ->from('tbl_call_history_201512') ,true);*/ $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['forcePageParam' => false, 'pageSizeParam' => false, 'pageSize' => 10]]); $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(['J' => $this->J, 'Al' => $this->Al, 'duration' => $this->duration, 'Bl' => $this->Bl]); $query->andFilterWhere(['like', 'Anumber', $this->Anumber])->andFilterWhere(['like', 'Bnumber', $this->Bnumber])->andFilterWhere(['like', 'Zon', $this->Zon])->andFilterWhere(['like', 'Trunk1', $this->Trunk1])->andFilterWhere(['like', 'Trunk2', $this->Trunk2])->andFilterWhere(['like', 'setup_time', $this->setup_time])->andFilterWhere(['between', 'start_time', $this->start_time, $this->end_time]); // ->andFilterWhere(['like', 'setup_time', $this->setup_time]); // echo "<pre>"; // print_r($query); return $dataProvider; }
/** * Finds the CallHistory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CallHistory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CallHistory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }