OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
report_top_viewed_products.php
Go to the documentation of this file.
1 <?php
2 
3 if (!class_exists("report_top_viewed_products")) {
9  class Report_top_viewed_products extends report_base
10  {
11 
17  protected $_sThisTemplate = "report_top_viewed_products.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, oxarticles.oxtitle from oxlogs, oxarticles " .
36  "where oxlogs.oxclass = 'details' and oxlogs.oxanid = oxarticles.oxid " .
37  "and oxlogs.oxtime >= $sTimeFrom and oxlogs.oxtime <= $sTimeTo group by oxlogs.oxanid " .
38  "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  $iTenth = strlen($iMax) - 1;
60  if ($iTenth < 1) {
61  $iScaleMax = $iMax;
62  $aPoints[(round(($iMax / 2)))] = $iMax / 2;
63  $aAligns[(round(($iMax / 2)))] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 3) . '"';
64  $aPoints[$iMax] = $iMax;
65  $aAligns[$iMax] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 3) . '"';
66  } else {
67  $iDeg = bcpow(10, $iTenth);
68  //$iScaleMax = $iDeg * (round($iMax/$iDeg));
69  $iScaleMax = $iMax;
70  $ctr = 0;
71  for ($iCtr = 10; $iCtr > 0; $iCtr--) {
72  $aPoints[(round(($ctr)))] = $ctr += $iScaleMax / 10;
73  $aAligns[(round(($ctr)))] = 'report_searchstrings_scale_aligns_center" width="' . (720 / 10) . '"';
74  }
75  $aAligns[(round(($ctr)))] = 'report_searchstrings_scale_aligns_right" width="' . (720 / 10) . '"';
76  }
77 
78  $aAligns[0] .= ' width="' . (720 / count($aAligns)) . '"';
79 
80  $aDataVals = array();
81 
82  for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
83  $aDataVals[$iCtr]['pc'] = round($aDataX[$iCtr] / $iMax * 100);
84  $aDataVals[$iCtr]['nm'] = $aDataY[$iCtr];
85  }
86 
87  if (count($aDataY) > 0) {
88  $oSmarty->assign("drawStat", true);
89  } else {
90  $oSmarty->assign("drawStat", false);
91  }
92 
93  $oSmarty->assign("classes", array($aAligns));
94  $oSmarty->assign("allCols", count($aAligns));
95  $oSmarty->assign("cols", count($aAligns));
96  $oSmarty->assign("percents", array($aDataVals));
97  $oSmarty->assign("y", $aDataY);
98 
99  return parent::render();
100  }
101 
105  public function graph1()
106  {
107  $myConfig = $this->getConfig();
108  $oDb = oxDb::getDb();
109 
110  $aDataX = array();
111  $aDataY = array();
112 
113  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
114  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
115 
116  $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
117  $rs = $oDb->execute($sSQL);
118  if ($rs != false && $rs->recordCount() > 0) {
119  while (!$rs->EOF) {
120  if ($rs->fields[1]) {
121  $aDataX[] = $rs->fields[0];
122  $aDataY[] = $rs->fields[1];
123  }
124  $rs->moveNext();
125  }
126  }
127 
128  header("Content-type: image/png");
129 
130  // New graph with a drop shadow
131  $graph = new Graph(800, max(640, 20 * count($aDataX)));
132  $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
133 
134  // Use a "text" X-scale
135  $graph->setScale("textlin");
136 
137  $top = 60;
138  $bottom = 30;
139  $left = 80;
140  $right = 30;
141  $graph->set90AndMargin($left, $right, $top, $bottom);
142 
143  // Label align for X-axis
144  $graph->xaxis->setLabelAlign('right', 'center', 'right');
145 
146  // Label align for Y-axis
147  $graph->yaxis->setLabelAlign('center', 'bottom');
148 
149  $graph->setShadow();
150  // Description
151  $graph->xaxis->setTickLabels($aDataY);
152  //print_r($aDataY);
153 
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 }