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