OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
search.php
Go to the documentation of this file.
1 <?php
2 
7 class Search extends oxUBase
8 {
9 
15  protected $_iAllArtCnt = 0;
16 
22  protected $_iCntPages = null;
23 
29  protected $_sThisTemplate = 'page/search/search.tpl';
30 
36  protected $_sListType = 'search';
37 
43  protected $_blShowSorting = true;
44 
50  protected $_blEmptySearch = null;
51 
57  protected $_oRecommList = null;
58 
64  protected $_sSearchParamForHtml = null;
65 
71  protected $_sSearchParam = null;
72 
78  protected $_sSearchCatId = null;
79 
85  protected $_sSearchVendor = null;
86 
92  protected $_sSearchManufacturer = null;
93 
99  protected $_blSearchClass = null;
100 
106  protected $_oPageNavigation = null;
107 
114 
120  protected $_aSimilarRecommListIds = null;
121 
122 
131  public function init()
132  {
133  parent::init();
134 
135  $myConfig = $this->getConfig();
136 
137  // #1184M - special char search
138  $oConfig = oxRegistry::getConfig();
139  $sSearchParamForQuery = trim($oConfig->getRequestParameter('searchparam', true));
140 
141  // searching in category ?
142  $sInitialSearchCat = $this->_sSearchCatId = rawurldecode($oConfig->getRequestParameter('searchcnid'));
143 
144  // searching in vendor #671
145  $sInitialSearchVendor = rawurldecode($oConfig->getRequestParameter('searchvendor'));
146 
147  // searching in Manufacturer #671
148  $sManufacturerParameter = $oConfig->getRequestParameter('searchmanufacturer');
149  $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
150 
151  $this->_blEmptySearch = false;
152  if (!$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer) {
153  //no search string
154  $this->_aArticleList = null;
155  $this->_blEmptySearch = true;
156 
157  return false;
158  }
159 
160  // config allows to search in Manufacturers ?
161  if (!$myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
162  $sInitialSearchManufacturer = null;
163  }
164 
165  // searching ..
167  $oSearchHandler = oxNew('oxsearch');
168  $oSearchList = $oSearchHandler->getSearchArticles(
169  $sSearchParamForQuery,
170  $sInitialSearchCat,
171  $sInitialSearchVendor,
172  $sInitialSearchManufacturer,
173  $this->getSortingSql($this->getSortIdent())
174  );
175 
176  // list of found articles
177  $this->_aArticleList = $oSearchList;
178  $this->_iAllArtCnt = 0;
179 
180  // skip count calculation if no articles in list found
181  if ($oSearchList->count()) {
182  $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount(
183  $sSearchParamForQuery,
184  $sInitialSearchCat,
185  $sInitialSearchVendor,
186  $sInitialSearchManufacturer
187  );
188  }
189 
190  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
191  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
192  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
193  }
194 
201  public function render()
202  {
203  parent::render();
204 
205  $oConfig = $this->getConfig();
206  if ($oConfig->getConfigParam('bl_rssSearch')) {
207  $oRss = oxNew('oxrssfeed');
208  $sSearch = $oConfig->getRequestParameter('searchparam', true);
209  $sCnid = $oConfig->getRequestParameter('searchcnid', true);
210  $sVendor = $oConfig->getRequestParameter('searchvendor', true);
211  $sManufacturer = $oConfig->getRequestParameter('searchmanufacturer', true);
212  $sSearchArticlesTitle = $oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer);
213  $sSearchArticlesUrl = $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer);
214  $this->addRssFeed($sSearchArticlesTitle, $sSearchArticlesUrl, 'searchArticles');
215  }
216 
217  // processing list articles
218  $this->_processListArticles();
219 
220  return $this->_sThisTemplate;
221  }
222 
227  protected function _processListArticles()
228  {
229  $sAddDynParams = $this->getAddUrlParams();
230  if ($sAddDynParams && ($aArtList = $this->getArticleList())) {
231  $blSeo = oxRegistry::getUtils()->seoIsActive();
232  foreach ($aArtList as $oArticle) {
233  // appending std and dynamic urls
234  if (!$blSeo) {
235  // only if seo is off..
236  $oArticle->appendStdLink($sAddDynParams);
237  }
238  $oArticle->appendLink($sAddDynParams);
239  }
240  }
241  }
242 
248  public function getAddUrlParams()
249  {
250  $sAddParams = parent::getAddUrlParams();
251  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
252  $oConfig = $this->getConfig();
253 
254  if ($sParam = $oConfig->getRequestParameter('searchparam', true)) {
255  $sAddParams .= "&amp;searchparam=" . rawurlencode($sParam);
256  }
257 
258  if ($sParam = $oConfig->getRequestParameter('searchcnid')) {
259  $sAddParams .= "&amp;searchcnid=$sParam";
260  }
261 
262  if ($sParam = rawurldecode($oConfig->getRequestParameter('searchvendor'))) {
263  $sAddParams .= "&amp;searchvendor=$sParam";
264  }
265 
266  if ($sParam = rawurldecode($oConfig->getRequestParameter('searchmanufacturer'))) {
267  $sAddParams .= "&amp;searchmanufacturer=$sParam";
268  }
269 
270  return $sAddParams;
271  }
272 
278  protected function _isSearchClass()
279  {
280  if ($this->_blSearchClass === null) {
281  $this->_blSearchClass = false;
282  if (strtolower($this->getConfig()->getRequestParameter('cl')) == 'search') {
283  $this->_blSearchClass = true;
284  }
285  }
286 
287  return $this->_blSearchClass;
288  }
289 
295  public function isEmptySearch()
296  {
297  return $this->_blEmptySearch;
298  }
299 
305  public function getArticleList()
306  {
307  return $this->_aArticleList;
308  }
309 
315  public function getSimilarRecommListIds()
316  {
317  if ($this->_aSimilarRecommListIds === null) {
318  $this->_aSimilarRecommListIds = false;
319 
320  $aList = $this->getArticleList();
321  if ($aList && $aList->count() > 0) {
322  $this->_aSimilarRecommListIds = $aList->arrayKeys();
323  }
324  }
325 
327  }
328 
334  public function getSearchParamForHtml()
335  {
336  if ($this->_sSearchParamForHtml === null) {
337  $this->_sSearchParamForHtml = false;
338  if ($this->_isSearchClass()) {
339  $this->_sSearchParamForHtml = $this->getConfig()->getRequestParameter('searchparam');
340  }
341  }
342 
344  }
345 
351  public function getSearchParam()
352  {
353  if ($this->_sSearchParam === null) {
354  $this->_sSearchParam = false;
355  if ($this->_isSearchClass()) {
356  $this->_sSearchParam = rawurlencode($this->getConfig()->getRequestParameter('searchparam', true));
357  }
358  }
359 
360  return $this->_sSearchParam;
361  }
362 
368  public function getSearchCatId()
369  {
370  if ($this->_sSearchCatId === null) {
371  $this->_sSearchCatId = false;
372  if ($this->_isSearchClass()) {
373  $this->_sSearchCatId = rawurldecode($this->getConfig()->getRequestParameter('searchcnid'));
374  }
375  }
376 
377  return $this->_sSearchCatId;
378  }
379 
385  public function getSearchVendor()
386  {
387  if ($this->_sSearchVendor === null) {
388  $this->_sSearchVendor = false;
389  if ($this->_isSearchClass()) {
390  // searching in vendor #671
391  $this->_sSearchVendor = rawurldecode($this->getConfig()->getRequestParameter('searchvendor'));
392  }
393  }
394 
395  return $this->_sSearchVendor;
396  }
397 
403  public function getSearchManufacturer()
404  {
405  if ($this->_sSearchManufacturer === null) {
406  $this->_sSearchManufacturer = false;
407  if ($this->_isSearchClass()) {
408  // searching in Manufacturer #671
409  $sManufacturerParameter = $this->getConfig()->getRequestParameter('searchmanufacturer');
410  $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
411  }
412  }
413 
415  }
416 
422  public function getPageNavigation()
423  {
424  if ($this->_oPageNavigation === null) {
425  $this->_oPageNavigation = false;
426  $this->_oPageNavigation = $this->generatePageNavigation();
427  }
428 
430  }
431 
432 
438  public function getActiveCategory()
439  {
440  return $this->getActSearch();
441  }
442 
448  public function getBreadCrumb()
449  {
450  $aPaths = array();
451  $aPath = array();
452 
453  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
454  $aPath['title'] = oxRegistry::getLang()->translateString('SEARCH', $iBaseLanguage, false);
455  $aPath['link'] = $this->getLink();
456  $aPaths[] = $aPath;
457 
458  return $aPaths;
459  }
460 
466  public function canSelectDisplayType()
467  {
468  return $this->getConfig()->getConfigParam('blShowListDisplayType');
469  }
470 
476  protected function _canRedirect()
477  {
478  return false;
479  }
480 
486  public function getArticleCount()
487  {
488  return $this->_iAllArtCnt;
489  }
490 
496  public function getTitle()
497  {
498  $sTitle = '';
499  $sTitle .= $this->getArticleCount();
500  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
501  $sTitle .= ' ' . oxRegistry::getLang()->translateString('HITS_FOR', $iBaseLanguage, false);
502  $sTitle .= ' "' . $this->getSearchParamForHtml() . '"';
503 
504  return $sTitle;
505  }
506 }