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