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

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