<?php

namespace api\models\search;

use common\models\HisRequest;
use yii\data\ActiveDataProvider;
use Yii;

class HisRequestSearch extends HisRequest
{
    /*public function rules()
    {
        return [];
    }

    public function scenarios()
    {
        return Model::scenarios();
    }*/

    public function search($params)
    {
        $query = HisRequest::find()->where(['username' => Yii::$app->user->identity->username]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => [
                    'id' => SORT_DESC
                ]
            ]
        ]);

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

        $query->andFilterWhere([
            'id' => $this->id
        ]);

        return $dataProvider;
    }
}
