Your IP : 216.73.216.79


Current Path : /var/www/html/sprm/backend/models/
Upload File :
Current File : /var/www/html/sprm/backend/models/CorruptionOffendersSearch.php.backup.20210106

<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\CorruptionOffenders;

/**
 * CorruptionOffendersSearch represents the model behind the search form of `backend\models\CorruptionOffenders`.
 */
class CorruptionOffendersSearch extends CorruptionOffenders {

    public $keyword;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['id', 'created_by', 'updated_by'], 'integer'],
            [['keyword', 'ic_no', 'case_no', 'name', 'summary_charges', 'court', 'judge', 'prosecuting', 'defendant', 'offense', 'punishment', 'gender', 'citizen', 'state', 'category', 'employer', 'occupation', 'sentencing_date', 'past_conviction', 'appeal', 'img_url', 'created_at', 'updated_at'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios() {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params) {
        $query = CorruptionOffenders::find();

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $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;
        }

        // grid filtering conditions
        $query->orFilterWhere(['like', 'ic_no', $this->keyword])
                ->orFilterWhere(['like', 'case_no', $this->keyword])
                ->orFilterWhere(['like', 'name', $this->keyword])
                ->orFilterWhere(['like', 'summary_charges', $this->keyword])
                ->orFilterWhere(['like', 'court', $this->keyword])
                ->orFilterWhere(['like', 'judge', $this->keyword])
                ->orFilterWhere(['like', 'prosecuting', $this->keyword])
                ->orFilterWhere(['like', 'defendant', $this->keyword])
                ->orFilterWhere(['like', 'offense', $this->keyword])
                ->orFilterWhere(['like', 'punishment', $this->keyword])
                ->orFilterWhere(['like', 'gender', $this->keyword])
                ->orFilterWhere(['like', 'citizen', $this->keyword])
                ->orFilterWhere(['like', 'state', $this->keyword])
                ->orFilterWhere(['like', 'category', $this->keyword])
                ->orFilterWhere(['like', 'employer', $this->keyword])
                ->orFilterWhere(['like', 'occupation', $this->keyword])
                ->orFilterWhere(['like', 'past_conviction', $this->keyword])
                ->orFilterWhere(['like', 'appeal', $this->keyword]);

        return $dataProvider;
    }

}