OXID eShop CE  4.9.9
 All Classes 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")) {
7  class Report_top_viewed_products extends report_base
8  {
9 
15  protected $_sThisTemplate = "report_top_viewed_products.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, oxarticles.oxtitle from oxlogs, oxarticles " .
34  "where oxlogs.oxclass = 'details' and oxlogs.oxanid = oxarticles.oxid " .
35  "and oxlogs.oxtime >= $sTimeFrom and oxlogs.oxtime <= $sTimeTo group by oxlogs.oxanid " .
36  "order by nrof desc limit 0, 25";
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  $aDataVals = array();
79 
80  for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
81  $aDataVals[$iCtr]['pc'] = round($aDataX[$iCtr] / $iMax * 100);
82  $aDataVals[$iCtr]['nm'] = $aDataY[$iCtr];
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  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
112  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
113 
114  $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
115  $rs = $oDb->execute($sSQL);
116  if ($rs != false && $rs->recordCount() > 0) {
117  while (!$rs->EOF) {
118  if ($rs->fields[1]) {
119  $aDataX[] = $rs->fields[0];
120  $aDataY[] = $rs->fields[1];
121  }
122  $rs->moveNext();
123  }
124  }
125 
126  header("Content-type: image/png");
127 
128  // New graph with a drop shadow
129  $graph = new Graph(800, max(640, 20 * count($aDataX)));
130  $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
131 
132  // Use a "text" X-scale
133  $graph->setScale("textlin");
134 
135  $top = 60;
136  $bottom = 30;
137  $left = 80;
138  $right = 30;
139  $graph->set90AndMargin($left, $right, $top, $bottom);
140 
141  // Label align for X-axis
142  $graph->xaxis->setLabelAlign('right', 'center', 'right');
143 
144  // Label align for Y-axis
145  $graph->yaxis->setLabelAlign('center', 'bottom');
146 
147  $graph->setShadow();
148  // Description
149  $graph->xaxis->setTickLabels($aDataY);
150  //print_r($aDataY);
151 
152 
153  // Set title and subtitle
154  $graph->title->set("Suchw�rter");
155 
156  // Use built in font
157  $graph->title->setFont(FF_FONT1, FS_BOLD);
158 
159  // Create the bar plot
160  $bplot = new BarPlot($aDataX);
161  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
162  $bplot->setLegend("Hits");
163 
164  $graph->add($bplot);
165 
166  // Finally output the image
167  $graph->stroke();
168  }
169  }
170 }