SearchModel.php 2.0 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\httpclient\debug;
  8. use yii\data\ArrayDataProvider;
  9. use yii\debug\components\search\Filter;
  10. use yii\debug\models\search\Base;
  11. class SearchModel extends Base
  12. {
  13. /**
  14. * @var string type of the input search value
  15. */
  16. public $type;
  17. /**
  18. * @var string method of the input search value
  19. */
  20. public $method;
  21. /**
  22. * @var int request attribute input search value
  23. */
  24. public $request;
  25. /**
  26. * @inheritdoc
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['type', 'method', 'request'], 'safe'],
  32. ];
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'type' => 'Type',
  41. 'method' => 'Method',
  42. 'request' => 'Request',
  43. ];
  44. }
  45. /**
  46. * Returns data provider with filled models. Filter applied if needed.
  47. *
  48. * @param array $params an array of parameter values indexed by parameter names
  49. * @param array $models data to return provider for
  50. * @return \yii\data\ArrayDataProvider
  51. */
  52. public function search($params, $models)
  53. {
  54. $dataProvider = new ArrayDataProvider([
  55. 'allModels' => $models,
  56. 'pagination' => false,
  57. 'sort' => [
  58. 'attributes' => ['duration', 'seq', 'type', 'method', 'request'],
  59. 'defaultOrder' => [
  60. 'duration' => SORT_DESC,
  61. ],
  62. ],
  63. ]);
  64. if (!($this->load($params) && $this->validate())) {
  65. return $dataProvider;
  66. }
  67. $filter = new Filter();
  68. $this->addCondition($filter, 'type', true);
  69. $this->addCondition($filter, 'method', true);
  70. $this->addCondition($filter, 'request', true);
  71. $dataProvider->allModels = $filter->filter($models);
  72. return $dataProvider;
  73. }
  74. }