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.

91 lines
2.1KB

  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 log.
  12. *
  13. * @author Qiang Xue <qiang.xue@gmail.com>
  14. * @author Mark Jebri <mark.github@yandex.ru>
  15. * @since 2.0
  16. */
  17. class Log extends Base
  18. {
  19. /**
  20. * @var string ip attribute input search value
  21. */
  22. public $level;
  23. /**
  24. * @var string method attribute input search value
  25. */
  26. public $category;
  27. /**
  28. * @var integer message attribute input search value
  29. */
  30. public $message;
  31. /**
  32. * @inheritdoc
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['level', 'message', 'category'], 'safe'],
  38. ];
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'level' => 'Level',
  47. 'category' => 'Category',
  48. 'message' => 'Message',
  49. ];
  50. }
  51. /**
  52. * Returns data provider with filled models. Filter applied if needed.
  53. *
  54. * @param array $params an array of parameter values indexed by parameter names
  55. * @param array $models data to return provider for
  56. * @return \yii\data\ArrayDataProvider
  57. */
  58. public function search($params, $models)
  59. {
  60. $dataProvider = new ArrayDataProvider([
  61. 'allModels' => $models,
  62. 'pagination' => false,
  63. 'sort' => [
  64. 'attributes' => ['time', 'level', 'category', 'message'],
  65. 'defaultOrder' => [
  66. 'time' => SORT_ASC,
  67. ],
  68. ],
  69. ]);
  70. if (!($this->load($params) && $this->validate())) {
  71. return $dataProvider;
  72. }
  73. $filter = new Filter();
  74. $this->addCondition($filter, 'level');
  75. $this->addCondition($filter, 'category', true);
  76. $this->addCondition($filter, 'message', true);
  77. $dataProvider->allModels = $filter->filter($models);
  78. return $dataProvider;
  79. }
  80. }