Search.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\timeline;
  8. use yii\debug\components\search\Filter;
  9. use yii\debug\components\search\matchers\GreaterThanOrEqual;
  10. use yii\debug\models\search\Base;
  11. use yii\debug\panels\TimelinePanel;
  12. /**
  13. * Search model for timeline data.
  14. *
  15. * @author Dmitriy Bashkarev <dmitriy@bashkarev.com>
  16. * @since 2.0.8
  17. */
  18. class Search extends Base
  19. {
  20. /**
  21. * @var string attribute search
  22. */
  23. public $category;
  24. /**
  25. * @var integer attribute search
  26. */
  27. public $duration = 0;
  28. /**
  29. * @inheritdoc
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['category', 'duration'], 'safe'],
  35. ];
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'duration' => 'Duration ≥'
  44. ];
  45. }
  46. /**
  47. * Returns data provider with filled models. Filter applied if needed.
  48. *
  49. * @param array $params $params an array of parameter values indexed by parameter names
  50. * @param TimeLinePanel $panel
  51. * @return DataProvider
  52. */
  53. public function search($params, $panel)
  54. {
  55. $models = $panel->models;
  56. $dataProvider = new DataProvider($panel, [
  57. 'allModels' => $models,
  58. 'sort' => [
  59. 'attributes' => ['category', 'timestamp']
  60. ],
  61. ]);
  62. if (!($this->load($params) && $this->validate())) {
  63. return $dataProvider;
  64. }
  65. $filter = new Filter();
  66. $this->addCondition($filter, 'category', true);
  67. if ($this->duration > 0) {
  68. $filter->addMatcher('duration', new GreaterThanOrEqual(['value' => $this->duration / 1000]));
  69. }
  70. $dataProvider->allModels = $filter->filter($models);
  71. return $dataProvider;
  72. }
  73. }