report_conversion_rate.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !class_exists( "report_conversion_rate")) {
00007     class Report_conversion_rate extends report_base
00008     {
00014         protected $_sThisTemplate = "report_conversion_rate.tpl";
00015 
00021         public function drawReport()
00022         {
00023             $oDb = oxDb::getDb();
00024 
00025             $oSmarty    = $this->getSmarty();
00026             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
00027             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
00028 
00029             // orders
00030             if ( $oDb->getOne( "select * from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00031                 return true;
00032             }
00033 
00034             // orders
00035             if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to" ) ) {
00036                 return true;
00037             }
00038         }
00039 
00045         public function visitor_month()
00046         {
00047             $myConfig = $this->getConfig();
00048             $oDb = oxDb::getDb();
00049 
00050             $aDataX = array();
00051             $aDataY = array();
00052 
00053             $dTimeTo    = strtotime( oxConfig::getParameter( "time_to"));
00054             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00055             $dTimeFrom  = mktime( 23, 59, 59, date( "m", $dTimeTo)-12, date( "d", $dTimeTo), date( "Y", $dTimeTo));
00056             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00057 
00058             // orders
00059             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00060             $aTemp = array();
00061             for ( $i = 1; $i <= 12; $i++)
00062                 $aTemp[date( "m/Y", mktime( 23, 59, 59, date( "m", $dTimeFrom)+$i, date( "d", $dTimeFrom), date( "Y", $dTimeFrom)) )] = 0;
00063 
00064             $rs = $oDb->execute( $sSQL);
00065             $blData = false;
00066             if ($rs != false && $rs->recordCount() > 0) {
00067                 while (!$rs->EOF) {
00068                     $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00069                     $rs->moveNext();
00070                     $blData = true;
00071                 }
00072             }
00073 
00074             $aDataX2  = array();
00075             $aDataX3  = array();
00076             if ($blData) {
00077                 foreach ( $aTemp as $key => $value) {
00078                     $aDataX[$key]   = $value;
00079                     $aDataX2[$key]  = 0;
00080                     $aDataX3[$key]  = 0;
00081                     $aDataY[]       = $key;
00082                 }
00083             }
00084             // orders
00085             $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00086             $aTemp = array();
00087             $rs = $oDb->execute( $sSQL);
00088             if ($rs != false && $rs->recordCount() > 0) {
00089                 while (!$rs->EOF) {
00090                     $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00091                     $rs->moveNext();
00092                 }
00093             }
00094 
00095             foreach ( $aTemp as $key => $value) {
00096                 if (isset($aDataX2[$key]))
00097                     $aDataX2[$key] = $value;
00098             }
00099 
00100             header ("Content-type: image/png" );
00101 
00102             // New graph with a drop shadow
00103             $graph = new Graph(800, 600, "auto");
00104 
00105             $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00106 
00107             // Use a "text" X-scale
00108             $graph->setScale("textlin");
00109             $graph->setY2Scale("lin");
00110             $graph->y2axis->setColor("red");
00111 
00112             // Label align for X-axis
00113             $graph->xaxis->setLabelAlign('center', 'top', 'right');
00114 
00115             // Label align for Y-axis
00116             $graph->yaxis->setLabelAlign('right', 'bottom');
00117 
00118             $graph->setShadow();
00119             // Description
00120             $graph->xaxis->setTickLabels( $aDataY);
00121 
00122 
00123             // Set title and subtitle
00124             $graph->title->set("Monat");
00125 
00126             // Use built in font
00127             $graph->title->setFont(FF_FONT1, FS_BOLD);
00128 
00129             $aDataFinalX = array();
00130             foreach ( $aDataX as $dData)
00131                 $aDataFinalX[] = $dData;
00132 
00133             // Create the bar plot
00134             $l2plot=new LinePlot($aDataFinalX);
00135             $l2plot->setColor("navy");
00136             $l2plot->setWeight(2);
00137             $l2plot->setLegend("Besucher");
00138             //$l1plot->SetBarCenter();
00139             $l2plot->value->setColor("navy");
00140             $l2plot->value->setFormat('% d');
00141             $l2plot->value->hideZero();
00142             $l2plot->value->show();
00143 
00144             $aDataFinalX2 = array();
00145             foreach ( $aDataX2 as $dData)
00146                 $aDataFinalX2[] = $dData;
00147 
00148             // Create the bar plot
00149             $l3plot=new LinePlot($aDataFinalX2);
00150             $l3plot->setColor("orange");
00151             $l3plot->setWeight(2);
00152             $l3plot->setLegend("Bestellungen");
00153             //$l1plot->SetBarCenter();
00154             $l3plot->value->setColor('orange');
00155             $l3plot->value->setFormat('% d');
00156             $l3plot->value->hideZero();
00157             $l3plot->value->show();
00158 
00159             //conversion rate graph
00160             $l1datay = array();
00161             for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
00162                 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
00163                     $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
00164                 } else
00165                     $l1datay[] = 0;
00166             }
00167 
00168             $l1plot=new LinePlot($l1datay);
00169             $l1plot->setColor("red");
00170             $l1plot->setWeight(2);
00171             $l1plot->setLegend("Conversion rate (%)");
00172             $l1plot->value->setColor('red');
00173             $l1plot->value->setFormat('% 0.2f%%');
00174             $l1plot->value->hideZero();
00175             $l1plot->value->show();
00176 
00177             // Create the grouped bar plot1
00178             $graph->addY2( $l1plot );
00179             $graph->add( $l2plot );
00180             $graph->add( $l3plot );
00181 
00182             // Finally output the  image
00183             $graph->stroke();
00184 
00185         }
00186 
00192         public function visitor_week()
00193         {
00194             $myConfig = $this->getConfig();
00195             $oDb = oxDb::getDb();
00196 
00197             $aDataX = array();
00198             $aDataY = array();
00199 
00200             $dTimeTo    = strtotime( oxConfig::getParameter( "time_to"));
00201             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00202             $dTimeFrom  = strtotime( oxConfig::getParameter( "time_from"));
00203             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00204 
00205             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid order by oxtime";
00206             $aTemp = array();
00207             $rs = $oDb->execute( $sSQL);
00208             $blData = false;
00209             if ($rs != false && $rs->recordCount() > 0) {
00210                 while (!$rs->EOF) {
00211                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00212                     $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00213                     $rs->moveNext();
00214                     $blData = true;
00215                 }
00216             }
00217 
00218             $aDataX2  = array();
00219             $aDataX3  = array();
00220             if ($blData) {
00221                 // initializing one week before current..
00222                 reset( $aTemp );
00223                 $iCurrKey = ( (int) key( $aTemp ) ) - 1;
00224                 $aDataX[$iCurrKey] = 0;
00225                 $aDataX2[$iCurrKey] = 0;
00226                 $aDataX3[$iCurrKey] = 0;
00227                 $aDataY[] = "KW ".$iCurrKey;
00228 
00229                 foreach ( $aTemp as $key => $value) {
00230                     $aDataX[$key]   = $value;
00231                     $aDataX2[$key]  = 0;
00232                     $aDataX3[$key]  = 0;
00233                     $aDataY[]       = "KW ".$key;
00234                 }
00235             }
00236 
00237             // buyer
00238             $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00239             $aTemp = array();
00240             $rs = $oDb->execute( $sSQL);
00241             if ($rs != false && $rs->recordCount() > 0) {
00242                 while (!$rs->EOF) {
00243                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00244                     $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00245                     $rs->moveNext();
00246                 }
00247             }
00248 
00249             foreach ( $aTemp as $key => $value) {
00250                 if (isset($aDataX2[$key]))
00251                     $aDataX2[$key] = $value;
00252             }
00253 
00254             // newcustomer
00255             $sSQL = "select oxtime, oxsessid from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid order by oxtime";
00256             $aTemp = array();
00257             $rs = $oDb->execute( $sSQL);
00258             if ($rs != false && $rs->recordCount() > 0) {
00259                 while (!$rs->EOF) {
00260                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00261                     $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00262                     $rs->moveNext();
00263                 }
00264             }
00265 
00266             foreach ( $aTemp as $key => $value) {
00267                 if (isset($aDataX3[$key]))
00268                     $aDataX3[$key] = $value;
00269             }
00270 
00271             header ("Content-type: image/png" );
00272 
00273             // New graph with a drop shadow
00274             $graph = new Graph( max( 800, count( $aDataX) * 80), 600);
00275 
00276             $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00277 
00278             // Use a "text" X-scale
00279             $graph->setScale("textlin");
00280             $graph->setY2Scale("lin");
00281             $graph->y2axis->setColor("red");
00282 
00283             // Label align for X-axis
00284             $graph->xaxis->setLabelAlign('center', 'top', 'right');
00285 
00286             // Label align for Y-axis
00287             $graph->yaxis->setLabelAlign('right', 'bottom');
00288 
00289             $graph->setShadow();
00290             // Description
00291             $graph->xaxis->setTickLabels( $aDataY);
00292 
00293 
00294             // Set title and subtitle
00295             $graph->title->set("Woche");
00296 
00297             // Use built in font
00298             $graph->title->setFont(FF_FONT1, FS_BOLD);
00299 
00300             $aDataFinalX = array();
00301             foreach ( $aDataX as $dData)
00302                 $aDataFinalX[] = $dData;
00303 
00304             // Create the bar plot
00305             $l2plot=new LinePlot($aDataFinalX);
00306             $l2plot->setColor("navy");
00307             $l2plot->setWeight(2);
00308             $l2plot->setLegend("Besucher");
00309             $l2plot->value->setColor("navy");
00310             $l2plot->value->setFormat('% d');
00311             $l2plot->value->hideZero();
00312             $l2plot->value->show();
00313 
00314             $aDataFinalX2 = array();
00315             foreach ( $aDataX2 as $dData)
00316                 $aDataFinalX2[] = $dData;
00317 
00318             // Create the bar plot
00319             $l3plot=new LinePlot($aDataFinalX2);
00320             $l3plot->setColor("orange");
00321             $l3plot->setWeight(2);
00322             $l3plot->setLegend("Bestellungen");
00323             //$l1plot->SetBarCenter();
00324             $l3plot->value->setColor("orange");
00325             $l3plot->value->setFormat('% d');
00326             $l3plot->value->hideZero();
00327             $l3plot->value->show();
00328 
00329             //conversion rate graph
00330             $l1datay = array();
00331             for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
00332                 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
00333                     $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
00334                 } else
00335                     $l1datay[] = 0;
00336             }
00337             $l1plot=new LinePlot($l1datay);
00338             $l1plot->setColor("red");
00339             $l1plot->setWeight(2);
00340             $l1plot->setLegend("Conversion rate (%)");
00341             $l1plot->value->setColor('red');
00342             $l1plot->value->setFormat('% 0.4f%%');
00343             $l1plot->value->hideZero();
00344             $l1plot->value->show();
00345 
00346             // Create the grouped bar plot
00347             $graph->addY2($l1plot);
00348             $graph->add($l2plot);
00349             $graph->add($l3plot);
00350 
00351             // Finally output the  image
00352             $graph->stroke();
00353         }
00354     }
00355 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5