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

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5