Your IP : 216.73.216.79


Current Path : /var/www/html/ebook/backend/modules/contentApplication/models/
Upload File :
Current File : /var/www/html/ebook/backend/modules/contentApplication/models/ContentApplicationSearch.php

<?php

namespace backend\modules\contentApplication\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\contentApplication\models\ContentApplication;

/**
 * ContentApplicationSearch represents the model behind the search form of `backend\modules\contentApplication\models\ContentApplication`.
 */
class ContentApplicationSearch extends ContentApplication {

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['application_id', 'created_by', 'updated_by'], 'integer'],
            [['application_cat', 'application_status', 'application_url', 'application_img', 'created_at', 'updated_at', 'application_title', 'application_sort'], '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 = ContentApplication::find()
                ->innerJoin('content_application_translation', 'content_application_translation.application_translation_parent_id=content_application.application_id')
                ->where(['=', 'content_application_translation.application_translation_main', '1']);

        $this->load($params);

        // add conditions that should always apply here
        $status_pagination = 10;
        if (!empty($this->application_cat))
            $status_pagination = false;

        $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $status_pagination,]]);
        $dataProvider->setSort(['defaultOrder' => ['application_cat' => SORT_ASC, 'application_sort' => SORT_ASC]]);



        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', 'application_cat', $this->application_cat])
                ->andFilterWhere(['like', 'application_status', $this->application_status])
                ->andFilterWhere(['like', 'application_url', $this->application_url])
                ->andFilterWhere(['like', 'application_img', $this->application_img])
                ->andFilterWhere(['=', 'application_sort', $this->application_sort]);
        $query->andFilterWhere(['LIKE', 'application_translation_title', $this->application_title]);

        return $dataProvider;
    }

}