You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\modules\pages\forms;
|
|
|
|
|
|
|
|
use yii\base\Model;
|
|
|
|
use yii\data\ActiveDataProvider;
|
|
|
|
use common\modules\pages\entities\Page;
|
|
|
|
|
|
|
|
class PageSearch extends Model
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
public $name;
|
|
|
|
public $slug;
|
|
|
|
public $title;
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[['id'], 'integer'],
|
|
|
|
[['name', 'slug', 'title'], 'safe'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
* @return ActiveDataProvider
|
|
|
|
*/
|
|
|
|
public function search(array $params): ActiveDataProvider
|
|
|
|
{
|
|
|
|
$query = Page::find()->typePublic()->andWhere(['>', 'depth', 0]);
|
|
|
|
|
|
|
|
$dataProvider = new ActiveDataProvider([
|
|
|
|
'query' => $query,
|
|
|
|
'sort' => [
|
|
|
|
'defaultOrder' => ['lft' => SORT_ASC]
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->load($params);
|
|
|
|
|
|
|
|
if (!$this->validate()) {
|
|
|
|
$query->where('0=1');
|
|
|
|
return $dataProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query->andFilterWhere([
|
|
|
|
'id' => $this->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$query
|
|
|
|
->andFilterWhere(['like', 'name', $this->name])
|
|
|
|
->andFilterWhere(['like', 'slug', $this->slug])
|
|
|
|
->andFilterWhere(['like', 'title', $this->title]);
|
|
|
|
|
|
|
|
return $dataProvider;
|
|
|
|
}
|
|
|
|
}
|