detail.php 1.49 KB
Newer Older
1 2 3
<?php
use yii\helpers\Html;
use yii\grid\GridView;
Tobias Munk committed
4

5 6 7 8 9 10 11 12
?>
<h1>Database Queries</h1>

<?php

echo GridView::widget([
	'dataProvider' => $dataProvider,
	'id' => 'db-panel-detailed-grid',
13
	'options' => ['class' => 'detail-grid-view'],
14 15 16 17
	'filterModel' => $searchModel,
	'filterUrl' => $panel->getUrl(),
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
18 19 20 21 22 23 24 25
		[
			'attribute' => 'seq',
			'label' => 'Time',
			'value' => function ($data) {
				$timeInSeconds = $data['timestamp'] / 1000;
				$millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000);
				return date('H:i:s.', $timeInSeconds) . sprintf('%03d', $millisecondsDiff);
			},
26 27 28
			'headerOptions' => [
				'class' => 'sort-numerical'
			]
29
		],
30 31
		[
			'attribute' => 'duration',
Mark committed
32
			'value' => function ($data) {
33
				return sprintf('%.1f ms', $data['duration']);
34
			},
35 36 37
			'options' => [
				'width' => '10%',
			],
38 39 40
			'headerOptions' => [
				'class' => 'sort-numerical'
			]
41 42 43
		],
		[
			'attribute' => 'type',
Mark committed
44
			'value' => function ($data) {
45
				return Html::encode(mb_strtoupper($data['type'], 'utf8'));
46 47 48 49
			},
		],
		[
			'attribute' => 'query',
Mark committed
50
			'value' => function ($data) {
51 52 53 54 55 56
				$query = Html::encode($data['query']);

				if (!empty($data['trace'])) {
					$query .= Html::ul($data['trace'], [
						'class' => 'trace',
						'item' => function ($trace) {
Mark committed
57
							return "<li>{$trace['file']} ({$trace['line']})</li>";
58 59 60 61 62 63 64
						},
					]);
				}
				return $query;
			},
			'format' => 'html',
			'options' => [
65
				'width' => '60%',
66 67 68 69
			],
		]
	],
]);
70
?>