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.

134 líneas
3.3KB

  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 requests manifest data.
  12. *
  13. * @author Qiang Xue <qiang.xue@gmail.com>
  14. * @author Mark Jebri <mark.github@yandex.ru>
  15. * @since 2.0
  16. */
  17. class Debug extends Base
  18. {
  19. /**
  20. * @var string tag attribute input search value
  21. */
  22. public $tag;
  23. /**
  24. * @var string ip attribute input search value
  25. */
  26. public $ip;
  27. /**
  28. * @var string method attribute input search value
  29. */
  30. public $method;
  31. /**
  32. * @var integer ajax attribute input search value
  33. */
  34. public $ajax;
  35. /**
  36. * @var string url attribute input search value
  37. */
  38. public $url;
  39. /**
  40. * @var string status code attribute input search value
  41. */
  42. public $statusCode;
  43. /**
  44. * @var integer sql count attribute input search value
  45. */
  46. public $sqlCount;
  47. /**
  48. * @var integer total mail count attribute input search value
  49. */
  50. public $mailCount;
  51. /**
  52. * @var array critical codes, used to determine grid row options.
  53. */
  54. public $criticalCodes = [400, 404, 500];
  55. /**
  56. * @inheritdoc
  57. */
  58. public function rules()
  59. {
  60. return [
  61. [['tag', 'ip', 'method', 'ajax', 'url', 'statusCode', 'sqlCount', 'mailCount'], 'safe'],
  62. ];
  63. }
  64. /**
  65. * @inheritdoc
  66. */
  67. public function attributeLabels()
  68. {
  69. return [
  70. 'tag' => 'Tag',
  71. 'ip' => 'Ip',
  72. 'method' => 'Method',
  73. 'ajax' => 'Ajax',
  74. 'url' => 'url',
  75. 'statusCode' => 'Status code',
  76. 'sqlCount' => 'Query Count',
  77. 'mailCount' => 'Mail Count',
  78. ];
  79. }
  80. /**
  81. * Returns data provider with filled models. Filter applied if needed.
  82. * @param array $params an array of parameter values indexed by parameter names
  83. * @param array $models data to return provider for
  84. * @return \yii\data\ArrayDataProvider
  85. */
  86. public function search($params, $models)
  87. {
  88. $dataProvider = new ArrayDataProvider([
  89. 'allModels' => $models,
  90. 'sort' => [
  91. 'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount', 'mailCount'],
  92. ],
  93. 'pagination' => [
  94. 'pageSize' => 50,
  95. ],
  96. ]);
  97. if (!($this->load($params) && $this->validate())) {
  98. return $dataProvider;
  99. }
  100. $filter = new Filter();
  101. $this->addCondition($filter, 'tag', true);
  102. $this->addCondition($filter, 'ip', true);
  103. $this->addCondition($filter, 'method');
  104. $this->addCondition($filter, 'ajax');
  105. $this->addCondition($filter, 'url', true);
  106. $this->addCondition($filter, 'statusCode');
  107. $this->addCondition($filter, 'sqlCount');
  108. $this->addCondition($filter, 'mailCount');
  109. $dataProvider->allModels = $filter->filter($models);
  110. return $dataProvider;
  111. }
  112. /**
  113. * Checks if code is critical.
  114. *
  115. * @param integer $code
  116. * @return boolean
  117. */
  118. public function isCodeCritical($code)
  119. {
  120. return in_array($code, $this->criticalCodes);
  121. }
  122. }