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