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.

Db.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\debug\models\search;
  8. use yii\data\ArrayDataProvider;
  9. use yii\debug\components\search\Filter;
  10. /**
  11. * Search model for current request database queries.
  12. *
  13. * @author Qiang Xue <qiang.xue@gmail.com>
  14. * @author Mark Jebri <mark.github@yandex.ru>
  15. * @since 2.0
  16. */
  17. class Db extends Base
  18. {
  19. /**
  20. * @var string type of the input search value
  21. */
  22. public $type;
  23. /**
  24. * @var integer query attribute input search value
  25. */
  26. public $query;
  27. /**
  28. * @inheritdoc
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['type', 'query'], 'safe'],
  34. ];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'type' => 'Type',
  43. 'query' => 'Query',
  44. ];
  45. }
  46. /**
  47. * Returns data provider with filled models. Filter applied if needed.
  48. *
  49. * @param array $models data to return provider for
  50. * @return \yii\data\ArrayDataProvider
  51. */
  52. public function search($models)
  53. {
  54. $dataProvider = new ArrayDataProvider([
  55. 'allModels' => $models,
  56. 'pagination' => false,
  57. 'sort' => [
  58. 'attributes' => ['duration', 'seq', 'type', 'query'],
  59. ],
  60. ]);
  61. if (!$this->validate()) {
  62. return $dataProvider;
  63. }
  64. $filter = new Filter();
  65. $this->addCondition($filter, 'type', true);
  66. $this->addCondition($filter, 'query', true);
  67. $dataProvider->allModels = $filter->filter($models);
  68. return $dataProvider;
  69. }
  70. }