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