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