Your IP : 216.73.216.79


Current Path : /var/www/html/dosm/backend/models/
Upload File :
Current File : /var/www/html/dosm/backend/models/ContentPocketStatSearch.php

<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\ContentPocketStat;
use Yii;

/**
 * ContentPocketStatSearch represents the model behind the search form of `backend\modules\contentPhoto\models\ContentPhotoGallery`.
 */
class ContentPocketStatSearch extends ContentPocketStat {

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [[
            'pocketstat_title', 'pocketstat_status',
            'pocketstat_year', 'pocketstat_quarter', 'pocketstat_negeri', 'pocketstat_sort','sorting_status'
                ], '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 = ContentPocketStat::find()->orderBy(['pocketstat_sort' => SORT_ASC, 'pocketstat_year' => SORT_DESC]);

        // add conditions that should always apply here
        $pageSize = 10;
        if($this->sorting_status == 1)
            $pageSize = false;
        $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize,]]);
        $dataProvider->setSort(['defaultOrder' => ['pocketstat_sort' => SORT_ASC]]);
        $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->andFilterWhere(['like', 'pocketstat_title', $this->pocketstat_title])
                ->andFilterWhere(['=', 'pocketstat_year', $this->pocketstat_year])
                ->andFilterWhere(['=', 'pocketstat_quarter', $this->pocketstat_quarter])
                ->andFilterWhere(['=', 'pocketstat_negeri', $this->pocketstat_negeri])
                ->andFilterWhere(['=', 'pocketstat_status', $this->pocketstat_status])
                ->andFilterWhere(['=', 'pocketstat_sort', $this->pocketstat_sort]);

        $query->andWhere(['=', 'pocketstat_main', '1']);

        return $dataProvider;
    }

}