OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
report_searchstrings.php
Go to the documentation of this file.
1 <?php
2 
3 if ( !class_exists( "report_searchstrings")) {
7 class Report_searchstrings extends report_base
8 {
14  protected $_sThisTemplate = "report_searchstrings.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, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
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  for ($iCtr = 0; $iCtr < count($aDataY); $iCtr++) {
74  $aDataVals[$aDataY[$iCtr]] = round($aDataX[$iCtr]/$iMax*100);
75  }
76 
77  if (count($aDataY) > 0 )
78  $oSmarty->assign( "drawStat", true);
79  else
80  $oSmarty->assign( "drawStat", false);
81 
82  $oSmarty->assign( "classes", array ( $aAligns ));
83  $oSmarty->assign( "allCols", count( $aAligns ) );
84  $oSmarty->assign( "cols", count( $aAligns ) );
85  $oSmarty->assign( "percents", array ( $aDataVals ));
86  $oSmarty->assign( "y", $aDataY);
87 
88  return parent::render();
89  }
90 
96  public function graph1()
97  {
98  $myConfig = $this->getConfig();
99  $oDb = oxDb::getDb();
100 
101  $aDataX = array();
102  $aDataY = array();
103 
104  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from"))) );
105  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to"))) );
106 
107  $sSQL = "select count(*) as nrof, oxparameter from oxlogs where oxclass = 'search' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxparameter order by nrof desc";
108  $rs = $oDb->execute( $sSQL);
109  if ($rs != false && $rs->recordCount() > 0) {
110  while (!$rs->EOF) {
111  if ( $rs->fields[1]) {
112  $aDataX[] = $rs->fields[0];
113  $aDataY[] = $rs->fields[1];
114  }
115  $rs->moveNext();
116  }
117  }
118 
119  header ("Content-type: image/png" );
120 
121  // New graph with a drop shadow
122  $graph = new Graph(800, max( 640, 20*count($aDataX)));
123  $graph->setBackgroundImage( $myConfig->getImageDir(true)."/reportbgrnd.jpg", BGIMG_FILLFRAME);
124 
125  // Use a "text" X-scale
126  $graph->setScale("textlin");
127 
128  $top = 60;
129  $bottom = 30;
130  $left = 80;
131  $right = 30;
132  $graph->set90AndMargin($left, $right, $top, $bottom);
133 
134  // Label align for X-axis
135  $graph->xaxis->setLabelAlign('right', 'center', 'right');
136 
137  // Label align for Y-axis
138  $graph->yaxis->setLabelAlign('center', 'bottom');
139 
140  $graph->setShadow();
141  // Description
142  $graph->xaxis->setTickLabels( $aDataY);
143 
144  // Set title and subtitle
145  $graph->title->set("Suchw�rter");
146 
147  // Use built in font
148  $graph->title->setFont(FF_FONT1, FS_BOLD);
149 
150  // Create the bar plot
151  $bplot = new BarPlot( $aDataX);
152  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
153  $bplot->setLegend("Hits");
154 
155  $graph->add($bplot);
156 
157  // Finally output the image
158  $graph->stroke();
159  }
160 }
161 }