<?php

namespace backend\models;

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

/**
 * BookMarkSearch represents the model behind the search form about `backend\models\BookMark`.
 */
class BookMarkSearch extends BookMark
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'bookId', 'chapterIndex', 'chapterId', 'quotePosition'], 'integer'],
        ];
    }

    /**
     * @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 = BookMark::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'bookId' => $this->bookId,
            'chapterIndex' => $this->chapterIndex,
            'chapterId' => $this->chapterId,
            'quotePosition' => $this->quotePosition,
        ]);

        return $dataProvider;
    }
}
