report_top_viewed_products.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !class_exists( "report_top_viewed_products")) {
00007 class Report_top_viewed_products extends report_base
00008 {
00014     protected $_sThisTemplate = "report_top_viewed_products.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, oxarticles.oxtitle from oxlogs, oxarticles where oxlogs.oxclass = 'details' and oxlogs.oxanid = oxarticles.oxid  and oxlogs.oxtime >= $sTimeFrom and oxlogs.oxtime <= $sTimeTo group by oxlogs.oxanid order by nrof desc limit 0, 25";
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         $aDataVals  = array();
00074 
00075         for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
00076             $aDataVals[$iCtr]['pc'] = round($aDataX[$iCtr]/$iMax*100);
00077             $aDataVals[$iCtr]['nm'] = $aDataY[$iCtr];
00078         }
00079 
00080         if (count($aDataY) > 0 )
00081             $oSmarty->assign( "drawStat", true);
00082         else
00083             $oSmarty->assign( "drawStat", false);
00084 
00085         $oSmarty->assign( "classes", array ( $aAligns ) );
00086         $oSmarty->assign( "allCols", count( $aAligns ) );
00087         $oSmarty->assign( "cols", count( $aAligns ) );
00088         $oSmarty->assign( "percents", array ( $aDataVals ));
00089         $oSmarty->assign( "y", $aDataY);
00090 
00091         return parent::render();
00092     }
00093 
00099     public function graph1()
00100     {
00101         $myConfig = $this->getConfig();
00102         $oDb = oxDb::getDb();
00103 
00104         $aDataX = array();
00105         $aDataY = array();
00106 
00107         $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from" ) ) ) );
00108         $sTimeTo   = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to" ) ) ) );
00109 
00110         $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
00111         $rs = $oDb->execute( $sSQL);
00112         if ($rs != false && $rs->recordCount() > 0) {
00113             while (!$rs->EOF) {
00114                 if ( $rs->fields[1]) {
00115                     $aDataX[] = $rs->fields[0];
00116                     $aDataY[] = $rs->fields[1];
00117                 }
00118                 $rs->moveNext();
00119             }
00120         }
00121 
00122         header ("Content-type: image/png" );
00123 
00124         // New graph with a drop shadow
00125         $graph = new Graph(800, max( 640, 20*count($aDataX)));
00126         $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00127 
00128         // Use a "text" X-scale
00129         $graph->setScale("textlin");
00130 
00131         $top = 60;
00132         $bottom = 30;
00133         $left = 80;
00134         $right = 30;
00135         $graph->set90AndMargin($left, $right, $top, $bottom);
00136 
00137         // Label align for X-axis
00138         $graph->xaxis->setLabelAlign('right', 'center', 'right');
00139 
00140         // Label align for Y-axis
00141         $graph->yaxis->setLabelAlign('center', 'bottom');
00142 
00143         $graph->setShadow();
00144         // Description
00145         $graph->xaxis->setTickLabels( $aDataY);
00146         //print_r($aDataY);
00147 
00148 
00149         // Set title and subtitle
00150         $graph->title->set("Suchw�rter");
00151 
00152         // Use built in font
00153         $graph->title->setFont(FF_FONT1, FS_BOLD);
00154 
00155         // Create the bar plot
00156         $bplot = new BarPlot( $aDataX);
00157         $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00158         $bplot->setLegend("Hits");
00159 
00160         $graph->add($bplot);
00161 
00162         // Finally output the  image
00163         $graph->stroke();
00164     }
00165 }
00166 }