namespace app\models\search; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use app\models\EligibleApplicant; use yii\db\Query; class EligibleApplicantSearch extends EligibleApplicant { public function rules() { return [ [['registration_number', 'surname', 'other_names', 'fac_code', 'faculty_name', 'email', 'status_description', 'phone', 'category_description', 'type'], 'safe'], ]; } public function scenarios() { return Model::scenarios(); } public function search($params) { // Create a Query instance for the reference numbers $queryRefNos = (new Query()) ->select(new \yii\db\Expression('DISTINCT application_ref_no AS ref_nos')) ->from('cs_carsticker_application'); $refNos = $queryRefNos->column(); $integerValues = array_map('intval', $refNos); $query = EligibleApplicant::find()->andWhere(['IN', 'registration_number', $integerValues]); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { return $dataProvider; } // Grid filtering conditions $query->andFilterWhere([ 'registration_number' => $this->registration_number, 'status_description' => $this->status_description, ]); // Additional grid filtering conditions $query->andFilterWhere(['like', 'registration_number', $this->registration_number]) ->andFilterWhere(['like', 'surname', $this->surname]) ->andFilterWhere(['like', 'other_names', $this->other_names]) ->andFilterWhere(['like', 'fac_code', $this->fac_code]) ->andFilterWhere(['like', 'faculty_name', $this->faculty_name]) ->andFilterWhere(['like', 'email', $this->email]) ->andFilterWhere(['like', 'status_description', $this->status_description]) ->andFilterWhere(['like', 'phone', $this->phone]) ->andFilterWhere(['like', 'category_description', $this->category_description]) ->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; } }