/** * Collects and renders visitor/week report data */ public function visitor_week() { $myConfig = $this->getConfig(); $oDb = oxDb::getDb(); $aDataX = array(); $aDataX2 = array(); $aDataX3 = array(); $aDataY = array(); $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to")))); $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from")))); $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid order by oxtime"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } // initializing list($iFrom, $iTo) = $this->getWeekRange(); for ($i = $iFrom; $i < $iTo; $i++) { $aDataX[$i] = 0; $aDataX2[$i] = 0; $aDataX3[$i] = 0; $aDataY[] = "KW " . $i; } foreach ($aTemp as $key => $value) { $aDataX[$key] = $value; $aDataX2[$key] = 0; $aDataX3[$key] = 0; $aDataY[] = "KW " . $key; } // buyer $sSQL = "select oxorderdate from oxorder where oxorderdate >= {$sTimeFrom} and oxorderdate <= {$sTimeTo} order by oxorderdate"; $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { $sKey = oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0])); if (isset($aDataX2[$sKey])) { $aDataX2[$sKey]++; } $rs->moveNext(); } } // newcustomer $sSQL = "select oxtime, oxsessid from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid order by oxtime"; $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { $sKey = oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0])); if (isset($aDataX3[$sKey])) { $aDataX3[$sKey]++; } $rs->moveNext(); } } header("Content-type: image/png"); // New graph with a drop shadow $graph = new Graph(max(800, count($aDataX) * 80), 600); $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME); // Use a "text" X-scale $graph->setScale("textlin"); $graph->setY2Scale("lin"); $graph->y2axis->setColor("red"); // Label align for X-axis $graph->xaxis->setLabelAlign('center', 'top', 'right'); // Label align for Y-axis $graph->yaxis->setLabelAlign('right', 'bottom'); $graph->setShadow(); // Description $graph->xaxis->setTickLabels($aDataY); // Set title and subtitle $graph->title->set("Woche"); // Use built in font $graph->title->setFont(FF_FONT1, FS_BOLD); $aDataFinalX = array(); foreach ($aDataX as $dData) { $aDataFinalX[] = $dData; } // Create the bar plot $l2plot = new LinePlot($aDataFinalX); $l2plot->setColor("navy"); $l2plot->setWeight(2); $l2plot->setLegend("Besucher"); $l2plot->value->setColor("navy"); $l2plot->value->setFormat('% d'); $l2plot->value->hideZero(); $l2plot->value->show(); $aDataFinalX2 = array(); foreach ($aDataX2 as $dData) { $aDataFinalX2[] = $dData; } // Create the bar plot $l3plot = new LinePlot($aDataFinalX2); $l3plot->setColor("orange"); $l3plot->setWeight(2); $l3plot->setLegend("Bestellungen"); //$l1plot->SetBarCenter(); $l3plot->value->setColor("orange"); $l3plot->value->setFormat('% d'); $l3plot->value->hideZero(); $l3plot->value->show(); //conversion rate graph $l1datay = array(); for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) { if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) { $l1datay[] = 100 / ($aDataFinalX[$iCtr] / $aDataFinalX2[$iCtr]); } else { $l1datay[] = 0; } } $l1plot = new LinePlot($l1datay); $l1plot->setColor("red"); $l1plot->setWeight(2); $l1plot->setLegend("Conversion rate (%)"); $l1plot->value->setColor('red'); $l1plot->value->setFormat('% 0.4f%%'); $l1plot->value->hideZero(); $l1plot->value->show(); // Create the grouped bar plot $graph->addY2($l1plot); $graph->add($l2plot); $graph->add($l3plot); // Finally output the image $graph->stroke(); }
/** * Returns predefined graph object * * @param int $iXSize graph image x size * @param int $iYSize graph image y size * @param string $sBackgroundImg background filler image (full path) [oxConfig::getImageDir( true ) ."/reportbgrnd.jpg"] * @param string $sScaleType graph scale type ["textlin"] * * @return Graph */ public function getGraph($iXSize, $iYSize, $sBackgroundImg = null, $sScaleType = "textlin") { $sBackgroundImg = $sBackgroundImg ? $sBackgroundImg : $this->getConfig()->getImageDir(true) . "/reportbgrnd.jpg"; // New graph with a drop shadow $oGraph = new Graph($iXSize, $iYSize); $oGraph->setBackgroundImage($sBackgroundImg, BGIMG_FILLFRAME); // Use a "text" X-scale $oGraph->setScale($sScaleType); // Label align for X-axis $oGraph->xaxis->setLabelAlign('center', 'top', 'right'); // Label align for Y-axis $oGraph->yaxis->setLabelAlign('right', 'bottom'); // shadow $oGraph->setShadow(); // Use built in font $oGraph->title->setFont(FF_FONT1, FS_BOLD); return $oGraph; }
/** * Current week top search strings report */ public function graph1() { $myConfig = $this->getConfig(); $oDb = oxDb::getDb(); $aDataX = array(); $aDataY = array(); $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from")))); $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to")))); $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxparameter order by nrof desc"; $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { if ($rs->fields[1]) { $aDataX[] = $rs->fields[0]; $aDataY[] = $rs->fields[1]; } $rs->moveNext(); } } header("Content-type: image/png"); // New graph with a drop shadow $graph = new Graph(800, max(640, 20 * count($aDataX))); $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME); // Use a "text" X-scale $graph->setScale("textlin"); $top = 60; $bottom = 30; $left = 80; $right = 30; $graph->set90AndMargin($left, $right, $top, $bottom); // Label align for X-axis $graph->xaxis->setLabelAlign('right', 'center', 'right'); // Label align for Y-axis $graph->yaxis->setLabelAlign('center', 'bottom'); $graph->setShadow(); // Description $graph->xaxis->setTickLabels($aDataY); // Set title and subtitle $graph->title->set("Suchw�rter"); // Use built in font $graph->title->setFont(FF_FONT1, FS_BOLD); // Create the bar plot $bplot = new BarPlot($aDataX); $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER); $bplot->setLegend("Hits"); $graph->add($bplot); // Finally output the image $graph->stroke(); }
/** * Collects and renders visitor/week report data */ public function visitor_week() { $myConfig = $this->getConfig(); $oDb = oxDb::getDb(); $aDataX = array(); $aDataY = array(); $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to")))); $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from")))); $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid order by oxtime"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } // initializing list($iFrom, $iTo) = $this->getWeekRange(); for ($i = $iFrom; $i < $iTo; $i++) { $aDataX[$i] = 0; $aDataX2[$i] = 0; $aDataX3[$i] = 0; $aDataY[] = "KW " . $i; } foreach ($aTemp as $key => $value) { $aDataX[$key] = $value; $aDataX2[$key] = 0; $aDataX3[$key] = 0; $aDataY[] = "KW " . $key; } // buyer $sSQL = "select oxorderdate from oxorder where oxorderdate >= {$sTimeFrom} and oxorderdate <= {$sTimeTo} order by oxorderdate"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } foreach ($aTemp as $key => $value) { $aDataX2[$key] = $value; } // newcustomer $sSQL = "select oxcreate from oxuser where oxcreate >= {$sTimeFrom} and oxcreate <= {$sTimeTo} order by oxcreate"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } foreach ($aTemp as $key => $value) { $aDataX3[$key] = $value; } header("Content-type: image/png"); // New graph with a drop shadow $graph = new Graph(max(800, count($aDataX) * 80), 600); $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME); // Use a "text" X-scale $graph->setScale("textlin"); // Label align for X-axis $graph->xaxis->setLabelAlign('center', 'top', 'right'); // Label align for Y-axis $graph->yaxis->setLabelAlign('right', 'bottom'); $graph->setShadow(); // Description $graph->xaxis->setTickLabels($aDataY); // Set title and subtitle $graph->title->set("Woche"); // Use built in font $graph->title->setFont(FF_FONT1, FS_BOLD); $aDataFinalX = array(); foreach ($aDataX as $dData) { $aDataFinalX[] = $dData; } // Create the bar plot $bplot = new BarPlot($aDataFinalX); $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER); $bplot->setLegend("Besucher"); $aDataFinalX2 = array(); foreach ($aDataX2 as $dData) { $aDataFinalX2[] = $dData; } // Create the bar plot $bplot2 = new BarPlot($aDataFinalX2); $bplot2->setFillColor("orange"); $bplot2->setLegend("Kaeufer"); $aDataFinalX3 = array(); foreach ($aDataX3 as $dData) { $aDataFinalX3[] = $dData; } // Create the bar plot $bplot3 = new BarPlot($aDataFinalX3); $bplot3->setFillColor("silver"); $bplot3->setLegend("Neukunden"); // Create the grouped bar plot $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3)); $graph->add($gbplot); // Finally output the image $graph->stroke(); }