OXID eShop CE  4.10.5
 All Classes Namespaces Files Functions Variables Pages
report_searchstrings.php
Go to the documentation of this file.
1 <?php
2 
3 if (!class_exists("report_searchstrings")) {
9  class Report_searchstrings extends report_base
10  {
11 
17  protected $_sThisTemplate = "report_searchstrings.tpl";
18 
24  public function render()
25  {
26  $oDb = oxDb::getDb();
27 
28  $aDataX = array();
29  $aDataY = array();
30 
31  $oSmarty = $this->getSmarty();
32  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_from'])));
33  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_to'])));
34 
35  $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and " .
36  "oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
37  $rs = $oDb->execute($sSQL);
38  if ($rs != false && $rs->recordCount() > 0) {
39  while (!$rs->EOF) {
40  if ($rs->fields[1]) {
41  $aDataX[] = $rs->fields[0];
42  $aDataY[] = $rs->fields[1];
43  }
44  $rs->moveNext();
45  }
46  }
47  $iMax = 0;
48  for ($iCtr = 0; $iCtr < count($aDataX); $iCtr++) {
49  if ($iMax < $aDataX[$iCtr]) {
50  $iMax = $aDataX[$iCtr];
51  }
52  }
53 
54  $aPoints = array();
55  $aPoints["0"] = 0;
56  $aAligns["0"] = 'report_searchstrings_scale_aligns_left"';
57  $iTenth = strlen($iMax) - 1;
58  if ($iTenth < 1) {
59  $iScaleMax = $iMax;
60  $aPoints["" . (round(($iMax / 2))) . ""] = $iMax / 2;
61  $aAligns["" . (round(($iMax / 2))) . ""] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 3) . '"';
62  $aPoints["" . $iMax . ""] = $iMax;
63  $aAligns["" . $iMax . ""] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 3) . '"';
64  } else {
65  $iDeg = bcpow(10, $iTenth);
66  //$iScaleMax = $iDeg * (round($iMax/$iDeg));
67  $iScaleMax = $iMax;
68  $ctr = 0;
69  for ($iCtr = 10; $iCtr > 0; $iCtr--) {
70  $aPoints["" . (round(($ctr))) . ""] = $ctr += $iScaleMax / 10;
71  $aAligns["" . (round(($ctr))) . ""] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 10) . '"';
72  }
73  $aAligns["" . (round(($ctr))) . ""] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 10) . '"';
74  }
75 
76  $aAligns["0"] .= ' width="' . (720 / count($aAligns)) . '"';
77 
78  for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
79  $aDataVals[$aDataY[$iCtr]] = round($aDataX[$iCtr] / $iMax * 100);
80  }
81 
82  if (count($aDataY) > 0) {
83  $oSmarty->assign("drawStat", true);
84  } else {
85  $oSmarty->assign("drawStat", false);
86  }
87 
88  $oSmarty->assign("classes", array($aAligns));
89  $oSmarty->assign("allCols", count($aAligns));
90  $oSmarty->assign("cols", count($aAligns));
91  $oSmarty->assign("percents", array($aDataVals));
92  $oSmarty->assign("y", $aDataY);
93 
94  return parent::render();
95  }
96 
100  public function graph1()
101  {
102  $myConfig = $this->getConfig();
103  $oDb = oxDb::getDb();
104 
105  $aDataX = array();
106  $aDataY = array();
107 
108  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
109  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
110 
111  $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
112  $rs = $oDb->execute($sSQL);
113  if ($rs != false && $rs->recordCount() > 0) {
114  while (!$rs->EOF) {
115  if ($rs->fields[1]) {
116  $aDataX[] = $rs->fields[0];
117  $aDataY[] = $rs->fields[1];
118  }
119  $rs->moveNext();
120  }
121  }
122 
123  header("Content-type: image/png");
124 
125  // New graph with a drop shadow
126  $graph = new Graph(800, max(640, 20 * count($aDataX)));
127  $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
128 
129  // Use a "text" X-scale
130  $graph->setScale("textlin");
131 
132  $top = 60;
133  $bottom = 30;
134  $left = 80;
135  $right = 30;
136  $graph->set90AndMargin($left, $right, $top, $bottom);
137 
138  // Label align for X-axis
139  $graph->xaxis->setLabelAlign('right', 'center', 'right');
140 
141  // Label align for Y-axis
142  $graph->yaxis->setLabelAlign('center', 'bottom');
143 
144  $graph->setShadow();
145  // Description
146  $graph->xaxis->setTickLabels($aDataY);
147 
148  // Set title and subtitle
149  $graph->title->set("Suchw�rter");
150 
151  // Use built in font
152  $graph->title->setFont(FF_FONT1, FS_BOLD);
153 
154  // Create the bar plot
155  $bplot = new BarPlot($aDataX);
156  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
157  $bplot->setLegend("Hits");
158 
159  $graph->add($bplot);
160 
161  // Finally output the image
162  $graph->stroke();
163  }
164  }
165 }