yii2-arangodb/panels/arangodb/models/ArangoDb.php

73 lines
1.6 KiB
PHP
Raw Normal View History

2014-08-05 13:28:36 +08:00
<?php
namespace devgroup\arangodb\panels\arangodb\models;
2014-08-12 14:33:20 +08:00
use yii;
2014-08-05 13:28:36 +08:00
use yii\data\ArrayDataProvider;
use yii\debug\components\search\Filter;
use yii\debug\models\search\Base;
class ArangoDb extends Base
{
/**
* @var integer query attribute input search value
*/
public $query;
2014-08-12 16:54:30 +08:00
public $type;
2014-08-05 13:28:36 +08:00
/**
* @inheritdoc
*/
public function rules()
{
return [
2014-08-12 16:54:30 +08:00
[['query', 'type'], 'safe'],
2014-08-05 13:28:36 +08:00
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
2014-08-12 16:54:30 +08:00
'type' => 'Type',
2014-08-05 13:28:36 +08:00
'query' => 'Query',
];
}
/**
* Returns data provider with filled models. Filter applied if needed.
*
* @param array $params an array of parameter values indexed by parameter names
* @param array $models data to return provider for
* @return \yii\data\ArrayDataProvider
*/
public function search($params, $models)
{
$dataProvider = new ArrayDataProvider([
'allModels' => $models,
'pagination' => false,
'sort' => [
2014-08-12 16:54:30 +08:00
'attributes' => ['duration', 'seq', 'query', 'type'],
2014-08-05 13:28:36 +08:00
'defaultOrder' => [
'duration' => SORT_DESC,
],
],
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$filter = new Filter();
2014-08-12 16:54:30 +08:00
$this->addCondition($filter, 'type', true);
2014-08-05 13:28:36 +08:00
$this->addCondition($filter, 'query', true);
$dataProvider->allModels = $filter->filter($models);
return $dataProvider;
}
}