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