No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

85 líneas
1.9KB

  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 $params an array of parameter values indexed by parameter names
  50. * @param array $models data to return provider for
  51. * @return \yii\data\ArrayDataProvider
  52. */
  53. public function search($params, $models)
  54. {
  55. $dataProvider = new ArrayDataProvider([
  56. 'allModels' => $models,
  57. 'pagination' => false,
  58. 'sort' => [
  59. 'attributes' => ['duration', 'seq', 'type', 'query'],
  60. 'defaultOrder' => [
  61. 'duration' => SORT_DESC,
  62. ],
  63. ],
  64. ]);
  65. if (!($this->load($params) && $this->validate())) {
  66. return $dataProvider;
  67. }
  68. $filter = new Filter();
  69. $this->addCondition($filter, 'type', true);
  70. $this->addCondition($filter, 'query', true);
  71. $dataProvider->allModels = $filter->filter($models);
  72. return $dataProvider;
  73. }
  74. }