<?php

namespace app\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\ListOfHotels;

/**
 * ListOfHotelsSearch represents the model behind the search form of `app\models\ListOfHotels`.
 */
class ListOfHotelsSearch extends ListOfHotels
{
    /**
     * {@inheritdoc}
     */
    public $priceFrom;
    public function rules()
    {
        return [
            [['id', 'created_by', 'updated_by', 'comm_hall_type'], 'integer'],
            [['hotel_name', 'hotel_name_english', 'hotel_image', 'hotel_address', 'per_day_price', 'security_deposit', 'number_of_rooms', 'zone_id', 'ward_id', 'status', 'desc1', 'desc2', 'desc3', 'desc_title1', 'desc_title2', 'desc_title3', 'slider_image1', 'slider_image2', 'slider_image3', 'lat', 'lon', 'term_and_condition', '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)
    {
        //print '<pre>';
       // print_r($params);die;
        $query = ListOfHotels::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
            '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->andFilterWhere(['between', 'per_day_price',$this->priceFrom,$this->per_day_price]);
        $query->andFilterWhere([
            'id' => $this->id,
            'ward_id' => $this->ward_id,
            'zone_id' => $this->zone_id,
            'created_by' => $this->created_by,
            'created_at' => $this->created_at,
            'updated_by' => $this->updated_by,
            'updated_at' => $this->updated_at,
            'comm_hall_type' => $this->comm_hall_type,
        ]);

        $query->andFilterWhere(['like', 'hotel_name', $this->hotel_name])
            ->andFilterWhere(['like', 'hotel_name_english', $this->hotel_name_english])
            ->andFilterWhere(['like', 'hotel_image', $this->hotel_image])
            ->andFilterWhere(['like', 'hotel_address', $this->hotel_address])
            ->andFilterWhere(['like', 'per_day_price', $this->per_day_price])
            ->andFilterWhere(['like', 'security_deposit', $this->security_deposit])
            ->andFilterWhere(['like', 'number_of_rooms', $this->number_of_rooms])
            ->andFilterWhere(['like', 'zone_id', $this->zone_id])
            ->andFilterWhere(['like', 'ward_id', $this->ward_id])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'desc1', $this->desc1])
            ->andFilterWhere(['like', 'desc2', $this->desc2])
            ->andFilterWhere(['like', 'desc3', $this->desc3])
            ->andFilterWhere(['like', 'desc_title1', $this->desc_title1])
            ->andFilterWhere(['like', 'desc_title2', $this->desc_title2])
            ->andFilterWhere(['like', 'desc_title3', $this->desc_title3])
            ->andFilterWhere(['like', 'slider_image1', $this->slider_image1])
            ->andFilterWhere(['like', 'slider_image2', $this->slider_image2])
            ->andFilterWhere(['like', 'slider_image3', $this->slider_image3])
            ->andFilterWhere(['like', 'lat', $this->lat])
            ->andFilterWhere(['like', 'lon', $this->lon])
            ->andFilterWhere(['like', 'term_and_condition', $this->term_and_condition]);

        return $dataProvider;
    }
}
