report_top_viewed_products.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !class_exists( "report_top_viewed_products")) {
00008     class Report_top_viewed_products extends report_base
00009     {
00015         protected $_sThisTemplate = "report_top_viewed_products.tpl";
00016 
00022         public function graphToText()
00023         {
00024             $aDataX = array();
00025             $aDataY = array();
00026 
00027             $oSmarty = oxUtilsView::getInstance()->getSmarty();
00028             $sTime_from = date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) );
00029             $sTime_to   = date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) );
00030 
00031             $sSQL = "select count(*) as nrof, oxarticles.oxtitle from oxlogs, oxarticles where oxlogs.oxclass = 'details' and oxlogs.oxanid = oxarticles.oxid  and oxlogs.oxtime >= '$sTime_from' and oxlogs.oxtime <= '$sTime_to' group by oxlogs.oxanid order by nrof desc limit 0, 25";
00032             $rs = oxDb::getDb()->execute( $sSQL);
00033             if ($rs != false && $rs->recordCount() > 0) {
00034                 while (!$rs->EOF) {
00035                     if ( $rs->fields[1]) {
00036                         $aDataX[] = $rs->fields[0];
00037                         $aDataY[] = $rs->fields[1];
00038                     }
00039                     $rs->moveNext();
00040                 }
00041             }
00042             $iMax = 0;
00043             for ($iCtr = 0; $iCtr < count($aDataX); $iCtr++) {
00044                 if ($iMax < $aDataX[$iCtr])
00045                     $iMax = $aDataX[$iCtr];
00046             }
00047 
00048             $aPoints = array();
00049             $aPoints[0] = 0;
00050             $aAligns[0] = 'report_searchstrings_scale_aligns_left"';
00051             $iTenth = strlen($iMax) - 1;
00052             if ($iTenth < 1) {
00053                 $iScaleMax = $iMax;
00054                 $aPoints[(round(($iMax/2)))] = $iMax/2;
00055                 $aAligns[(round(($iMax/2)))] = 'report_searchstrings_scale_aligns_center" width="'.(720/3).'"';
00056                 $aPoints[$iMax] = $iMax;
00057                 $aAligns[$iMax] = 'report_searchstrings_scale_aligns_right" width="'.(720/3).'"';
00058             } else {
00059                 $iDeg = bcpow(10, $iTenth);
00060                 //$iScaleMax = $iDeg * (round($iMax/$iDeg));
00061                 $iScaleMax = $iMax;
00062                 $ctr = 0;
00063                 for ($iCtr = 10; $iCtr>0; $iCtr-- ) {
00064                     $aPoints[(round(($ctr)))] = $ctr += $iScaleMax / 10;
00065                     $aAligns[(round(($ctr)))] = 'report_searchstrings_scale_aligns_center" width="'.(720/10).'"';
00066                 }
00067                 $aAligns[(round(($ctr)))] = 'report_searchstrings_scale_aligns_right" width="'.(720/10).'"';
00068             }
00069 
00070             $aAligns[0] .= ' width="'.(720/count($aAligns)).'"';
00071 
00072             $aDataVals  = array();
00073 
00074             for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
00075                 $aDataVals[$iCtr]['pc'] = round($aDataX[$iCtr]/$iMax*100);
00076                 $aDataVals[$iCtr]['nm'] = $aDataY[$iCtr];
00077             }
00078 
00079             if (count($aDataY) > 0 )
00080                 $oSmarty->assign( "drawStat", true);
00081             else
00082                 $oSmarty->assign( "drawStat", false);
00083 
00084             $oSmarty->assign( "classes", array ( $aAligns ) );
00085             $oSmarty->assign( "allCols", count( $aAligns ) );
00086             $oSmarty->assign( "cols", count( $aAligns ) );
00087             $oSmarty->assign( "percents", array ( $aDataVals ));
00088             $oSmarty->assign( "y", $aDataY);
00089         }
00090 
00096         public function graph1()
00097         {
00098             $myConfig = $this->getConfig();
00099             $aDataX = array();
00100             $aDataY = array();
00101 
00102             $sTime_from = date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from")));
00103             $sTime_to   = date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to")));
00104 
00105             $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= '$sTime_from' and oxtime <= '$sTime_to' group by oxparameter order by nrof desc";
00106             $rs = oxDb::getDb()->execute( $sSQL);
00107             if ($rs != false && $rs->recordCount() > 0) {
00108                 while (!$rs->EOF) {
00109                     if ( $rs->fields[1]) {
00110                         $aDataX[] = $rs->fields[0];
00111                         $aDataY[] = $rs->fields[1];
00112                     }
00113                     $rs->moveNext();
00114                 }
00115             }
00116 
00117             header ("Content-type: image/png" );
00118 
00119             // New graph with a drop shadow
00120             $graph = new Graph(800, max( 640, 20*count($aDataX)));
00121             $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00122 
00123             // Use a "text" X-scale
00124             $graph->setScale("textlin");
00125 
00126             $top = 60;
00127             $bottom = 30;
00128             $left = 80;
00129             $right = 30;
00130             $graph->set90AndMargin($left, $right, $top, $bottom);
00131 
00132             // Label align for X-axis
00133             $graph->xaxis->setLabelAlign('right', 'center', 'right');
00134 
00135             // Label align for Y-axis
00136             $graph->yaxis->setLabelAlign('center', 'bottom');
00137 
00138             $graph->setShadow();
00139             // Description
00140             $graph->xaxis->setTickLabels( $aDataY);
00141             //print_r($aDataY);
00142 
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 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5