function printQueryLog() { include_once 'ImpPhp/ImpTable.php'; uasort($this->queryLog, create_function('$a,$b', 'return strcmp($b["Count"], $a["Count"]);')); $d = array(); $TotalQueries = 0; foreach ($this->queryLog as $k => $v) { $d[] = array("Query" => $k, 'Count' => $v['Count'], 'Time' => round($v['Time'] * 1000000), 'Cost' => round($v['Time'] * 1000000 / $v['Count'])); $TotalQueries += $v['Count']; } assert($TotalQueries == $this->queryCount); $className = get_class($this); $QueryTable = new ImpTable($d); $QueryTable->JSRenderQueue = $className . '_Table_Generators'; $QueryTable->DefaultSortKey = 'Time'; $QueryTable->DefaultSortOrder = 'Descending'; $QueryTable->AutoSort(); $QueryTable->Attributes['id'] = $className . '_Queries'; $QueryTable->Attributes['class'] = 'ImpPhp Debug'; $QueryTable->Caption = $className . ': ' . number_format($TotalQueries) . ' queries in ' . number_format($this->cummulativeQueryTime, 3) . ' seconds'; $QueryTable->ColumnHeaders = array('Query' => array('label' => 'SQL Statement'), 'Count' => array('label' => 'Count', 'formatter' => 'YAHOO.widget.DataTable.formatNumber'), 'Time' => array('label' => 'Time (µs)', 'formatter' => 'YAHOO.widget.DataTable.formatNumber'), 'Cost' => array('label' => 'Cost', 'formatter' => 'YAHOO.widget.DataTable.formatNumber')); ?> <script type="text/javascript" charset="utf-8"> <?php echo $QueryTable->JSRenderQueue; ?> = new Array(); </script> <a href="#" class="<?php echo $QueryTable->Attributes['class']; ?> " style="position: fixed; bottom: 0; text-align: center; width: 100%; padding: 1em 0; background-color: lightgrey; color: black;" onclick="this.style.display='none';document.getElementById('<?php echo $className; ?> _Queries').style.display='block';while(f = <?php echo $QueryTable->JSRenderQueue; ?> .shift()){ f(); }; return false"><?php echo $QueryTable->Caption; ?> (Show)</a> <style> #<?php echo $className; ?> _Queries { text-align: left; padding: 2pt; background-color: white; color: black; margin-top: 4em; display:none; } #<?php echo $className; ?> _Queries caption { font-weight: bold; text-align: center; background-color: #666699; margin: 0; } #<?php echo $className; ?> _Queries thead { background-color: lightgray; } #<?php echo $className; ?> _Queries a { color: inherit ! important; font-weight: inherit ! important; } #<?php echo $className; ?> _Queries th { padding: 2pt; padding-right: 1em; font-weight: bold; white-space: nowrap; border: none; } #<?php echo $className; ?> _Queries td { font-family: monospace; font-size: 9px; border: none; } #<?php echo $className; ?> _Queries tr:nth-child(odd) { background-color: lightgreen; } </style> <?php $QueryTable->generate(); }
<pre xml:space="preserve"> <script type="text/javascript" charset="utf-8"> my_preloaded_datasource = new YAHOO.util.DataSource("data.xml?"); my_preloaded_datasource.responseType = YAHOO.util.DataSource.TYPE_XML; my_preloaded_datasource.responseSchema = { resultNode:'row', fields: ["col1", "col2"] }; </script> <?php $externalDSTable = new ImpTable(); $externalDSTable->ColumnHeaders = array( array('key'=>"col1", "label" => "Column 1", "sortable" => false), array("key" => "col2", "label" => "Column 2", "sortable" => true) ); $externalDSTable->useData('DataSource', 'my_preloaded_datasource'); $externalDSTable->Caption = 'XML loaded from an existing YUI DataSource'; $externalDSTable->generate(); ?> </pre><?php $externalDSTable = new ImpTable(); $externalDSTable->ColumnHeaders = array(array('key' => "col1", "label" => "Column 1", "sortable" => false), array("key" => "col2", "label" => "Column 2", "sortable" => true)); $externalDSTable->useData('DataSource', 'my_preloaded_datasource'); $externalDSTable->Caption = 'XML loaded from an existing YUI DataSource'; $externalDSTable->generate(); ?> </div> </body> </html>