report_top_clicked_categories.php

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