<?php use BjyProfiler\Db\Profiler\Profiler; ?>
<div class="zdt-toolbar-entry">
    <div class="zdt-toolbar-preview">
        <img src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NzU1MkQ0QURDODkyMTFFMUE4RDU5MDZBOEM2RTM5QjYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NzU1MkQ0QUVDODkyMTFFMUE4RDU5MDZBOEM2RTM5QjYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo3NTUyRDRBQkM4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eHh9xiZS36//2lHR8fy9PR0eSAQUGMUZYhcAM6SteAmhsFebHt7OwyqPKWlpZ+bmpqCRqPxDujRmUwmhsUmU1hYSNCDD1tbW2kKbmzO+Xy+yc3NTS8chPh8Pg/2BP3rYExlSqVSKxQK9XjgRorXSCSSrCyLkYlyVU6JGgfUiI5Q/E7S7hD6KNU88DeJRj2kB/4HfX19X5OO4cxptVrVaNQcCF8mk2WftLoY2xA43+ns7HTabLYn8LfEjI+Pk5qaGiEW15B+FQi+jCKJ8EcWw3kWUmGOp4biRcFtEL87v9PpXMEIvoP5NffLIz8FGAAqeUQbl180BwAAAABJRU5ErkJggg==" alt="Database (Zend\Db)">
        <span class="zdt-toolbar-info">
            <?php if ($this->collector->hasProfiler()): ?>
                <?php echo $this->collector->getQueryCount(); ?> in <?php echo $this->ZendDeveloperToolsTime($this->collector->getQueryTime()); ?>
            <?php else: ?>
                N/A
            <?php endif; ?>
        </span>
    </div>
    <div class="zdt-toolbar-detail zdt-toolbar-dbquery-detail">
        <div class="zdt-toolbar-detail-inner">
            <?php if ($this->collector->hasProfiler()): ?>
                <span class="zdt-toolbar-info zdt-toolbar-info-heading">Quantity</span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">create</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->collector->getQueryCount(Profiler::INSERT); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">read</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->collector->getQueryCount(Profiler::SELECT); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">update</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->collector->getQueryCount(Profiler::UPDATE); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">delete</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->collector->getQueryCount(Profiler::DELETE); ?></span>
                </span>

                <span class="zdt-toolbar-info zdt-toolbar-info-heading zdt-toolbar-topspacing">Time</span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">create</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->ZendDeveloperToolsTime($this->collector->getQueryTime(Profiler::INSERT)); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">read</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->ZendDeveloperToolsTime($this->collector->getQueryTime(Profiler::SELECT)); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">update</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->ZendDeveloperToolsTime($this->collector->getQueryTime(Profiler::UPDATE)); ?></span>
                </span>
                <span class="zdt-toolbar-info">
                    <span class="zdt-detail-label">delete</span>
                    <span class="zdt-detail-value zdt-detail-value-right"><?php echo $this->ZendDeveloperToolsTime($this->collector->getQueryTime(Profiler::DELETE)); ?></span>
                </span>

                <span class="zdt-toolbar-info zdt-toolbar-info-heading zdt-toolbar-topspacing zdt-toolbar-dbquery-heading">Query Profiles</span>
                <span class="zdt-toolbar-info zdt-toolbar-dbquery">
                    <?php $profiler = $this->collector->getProfiler(); ?>
                    <?php foreach ($profiler->getQueryProfiles() as $profile): ?>
                        <?php $query = $profile->toArray(); ?>
                        <hr />
                        <span class="zdt-detail-label">SQL</span>
                        <span class="zdt-detail-value zdt-detail-dbquery zdt-detail-dbquery-sql">
                        <?php /* highlight UPPERCASE words in the query, which should mostly match SQL keywords */ ?>
                        <?php echo preg_replace('/([A-Z]+)/', '<span class="highlight">$1</span>', $this->escapeHtml($query['sql'])) ?>
                        </span>
                        <span class="clear"></span>
                        <?php if (isset($query['parameters']) && (is_array($query['parameters']) || ($query['parameters'] instanceof \Iterator && $query['parameters'] instanceof \Countable)) && count($query['parameters']) > 0): ?>
                            <span class="zdt-detail-label">Params</span>
                            <span class="zdt-detail-value zdt-detail-dbquery zdt-detail-dbquery-params">
                                <?php foreach ($query['parameters'] as $key => $value): ?>
                                    <?php echo $this->escapeHtml("{$key} => " . var_export($value, true)); ?><br />
                                <?php endforeach ?>
                            </span>
                            <span class="clear"></span>
                            <?php endif ?>
                        <span class="zdt-detail-label">Time</span>
                        <span class="zdt-detail-value zdt-detail-dbquery zdt-detail-dbquery-time">
                        <?php echo $this->escapeHtml($this->ZendDeveloperToolsTime($query['elapsed'])) ?>
                        </span>
                        <span class="clear"></span>
                    <?php endforeach; ?>
                </span>
            <?php else: ?>
                <span class="zdt-toolbar-info zdt-toolbar-info-heading">Error</span>
                <span class="zdt-toolbar-info">
                    You have to install or enable <a href="https://github.com/bjyoungblood/BjyProfiler">@bjyoungblood's Zend\Db Profiler</a> to use this feature.
                </span>
            <?php endif ?>
        </div>
    </div>
</div>
<style>
    .zdt-toolbar-entry .zdt-toolbar-detail .zdt-toolbar-detail-inner {
        padding: 5px;
        font-size: 11px;
        max-width: 600px;
        width: 600px;
        max-height: 400px;
        min-height: 100px;
        overflow-y: auto!important;
        overflow-x: hidden;
    }

    .zdt-toolbar-entry .zdt-toolbar-detail .zdt-toolbar-detail-inner .zdt-toolbar-dbquery {
        max-height: none!important;
    }

    .zdt-toolbar-entry .zdt-toolbar-detail .zdt-detail-dbquery {
        white-space: normal;
        width: 400px;
    }

    .zdt-toolbar-entry .zdt-toolbar-detail .zdt-detail-dbquery .highlight {
        color: #80DC09;
        font-weight: bold;
    }

    .zdt-toolbar-entry .zdt-toolbar-info .clear {
        clear: both;
        display: block;
    }

    .zdt-toolbar-entry .zdt-toolbar-detail .zdt-toolbar-dbquery hr {
        border: 0;
        border-top: 1px solid #80DC09;
        clear: both;
    }
</style>
