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