report_searchstrings.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if (!class_exists("report_searchstrings")) {
00007     class Report_searchstrings extends report_base
00008     {
00009 
00015         protected $_sThisTemplate = "report_searchstrings.tpl";
00016 
00022         public function render()
00023         {
00024             $oDb = oxDb::getDb();
00025 
00026             $aDataX = array();
00027             $aDataY = array();
00028 
00029             $oSmarty = $this->getSmarty();
00030             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_from'])));
00031             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_to'])));
00032 
00033             $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and " .
00034                     "oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
00035             $rs = $oDb->execute($sSQL);
00036             if ($rs != false && $rs->recordCount() > 0) {
00037                 while (!$rs->EOF) {
00038                     if ($rs->fields[1]) {
00039                         $aDataX[] = $rs->fields[0];
00040                         $aDataY[] = $rs->fields[1];
00041                     }
00042                     $rs->moveNext();
00043                 }
00044             }
00045             $iMax = 0;
00046             for ($iCtr = 0; $iCtr < count($aDataX); $iCtr++) {
00047                 if ($iMax < $aDataX[$iCtr]) {
00048                     $iMax = $aDataX[$iCtr];
00049                 }
00050             }
00051 
00052             $aPoints = array();
00053             $aPoints["0"] = 0;
00054             $aAligns["0"] = 'report_searchstrings_scale_aligns_left"';
00055             $iTenth = strlen($iMax) - 1;
00056             if ($iTenth < 1) {
00057                 $iScaleMax = $iMax;
00058                 $aPoints["" . (round(($iMax / 2))) . ""] = $iMax / 2;
00059                 $aAligns["" . (round(($iMax / 2))) . ""] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 3) . '"';
00060                 $aPoints["" . $iMax . ""] = $iMax;
00061                 $aAligns["" . $iMax . ""] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 3) . '"';
00062             } else {
00063                 $iDeg = bcpow(10, $iTenth);
00064                 //$iScaleMax = $iDeg * (round($iMax/$iDeg));
00065                 $iScaleMax = $iMax;
00066                 $ctr = 0;
00067                 for ($iCtr = 10; $iCtr > 0; $iCtr--) {
00068                     $aPoints["" . (round(($ctr))) . ""] = $ctr += $iScaleMax / 10;
00069                     $aAligns["" . (round(($ctr))) . ""] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 10) . '"';
00070                 }
00071                 $aAligns["" . (round(($ctr))) . ""] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 10) . '"';
00072             }
00073 
00074             $aAligns["0"] .= ' width="' . (720 / count($aAligns)) . '"';
00075 
00076             for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
00077                 $aDataVals[$aDataY[$iCtr]] = round($aDataX[$iCtr] / $iMax * 100);
00078             }
00079 
00080             if (count($aDataY) > 0) {
00081                 $oSmarty->assign("drawStat", true);
00082             } else {
00083                 $oSmarty->assign("drawStat", false);
00084             }
00085 
00086             $oSmarty->assign("classes", array($aAligns));
00087             $oSmarty->assign("allCols", count($aAligns));
00088             $oSmarty->assign("cols", count($aAligns));
00089             $oSmarty->assign("percents", array($aDataVals));
00090             $oSmarty->assign("y", $aDataY);
00091 
00092             return parent::render();
00093         }
00094 
00098         public function graph1()
00099         {
00100             $myConfig = $this->getConfig();
00101             $oDb = oxDb::getDb();
00102 
00103             $aDataX = array();
00104             $aDataY = array();
00105 
00106             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
00107             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
00108 
00109             $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
00110             $rs = $oDb->execute($sSQL);
00111             if ($rs != false && $rs->recordCount() > 0) {
00112                 while (!$rs->EOF) {
00113                     if ($rs->fields[1]) {
00114                         $aDataX[] = $rs->fields[0];
00115                         $aDataY[] = $rs->fields[1];
00116                     }
00117                     $rs->moveNext();
00118                 }
00119             }
00120 
00121             header("Content-type: image/png");
00122 
00123             // New graph with a drop shadow
00124             $graph = new Graph(800, max(640, 20 * count($aDataX)));
00125             $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
00126 
00127             // Use a "text" X-scale
00128             $graph->setScale("textlin");
00129 
00130             $top = 60;
00131             $bottom = 30;
00132             $left = 80;
00133             $right = 30;
00134             $graph->set90AndMargin($left, $right, $top, $bottom);
00135 
00136             // Label align for X-axis
00137             $graph->xaxis->setLabelAlign('right', 'center', 'right');
00138 
00139             // Label align for Y-axis
00140             $graph->yaxis->setLabelAlign('center', 'bottom');
00141 
00142             $graph->setShadow();
00143             // Description
00144             $graph->xaxis->setTickLabels($aDataY);
00145 
00146             // Set title and subtitle
00147             $graph->title->set("Suchw�rter");
00148 
00149             // Use built in font
00150             $graph->title->setFont(FF_FONT1, FS_BOLD);
00151 
00152             // Create the bar plot
00153             $bplot = new BarPlot($aDataX);
00154             $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00155             $bplot->setLegend("Hits");
00156 
00157             $graph->add($bplot);
00158 
00159             // Finally output the  image
00160             $graph->stroke();
00161         }
00162     }
00163 }