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