OXID eShop CE  4.10.8
 All Classes Namespaces 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 
59  protected $_oRecommList = null;
60 
66  protected $_sSearchParamForHtml = null;
67 
73  protected $_sSearchParam = null;
74 
80  protected $_sSearchCatId = null;
81 
87  protected $_sSearchVendor = null;
88 
94  protected $_sSearchManufacturer = null;
95 
101  protected $_blSearchClass = null;
102 
108  protected $_oPageNavigation = null;
109 
116 
124  protected $_aSimilarRecommListIds = null;
125 
126 
135  public function init()
136  {
137  parent::init();
138 
139  $myConfig = $this->getConfig();
140 
141  // #1184M - special char search
142  $oConfig = oxRegistry::getConfig();
143  $sSearchParamForQuery = trim($oConfig->getRequestParameter('searchparam', true));
144 
145  // searching in category ?
146  $sInitialSearchCat = $this->_sSearchCatId = rawurldecode($oConfig->getRequestParameter('searchcnid'));
147 
148  // searching in vendor #671
149  $sInitialSearchVendor = rawurldecode($oConfig->getRequestParameter('searchvendor'));
150 
151  // searching in Manufacturer #671
152  $sManufacturerParameter = $oConfig->getRequestParameter('searchmanufacturer');
153  $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
154 
155  $this->_blEmptySearch = false;
156  if (!$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer) {
157  //no search string
158  $this->_aArticleList = null;
159  $this->_blEmptySearch = true;
160 
161  return false;
162  }
163 
164  // config allows to search in Manufacturers ?
165  if (!$myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
166  $sInitialSearchManufacturer = null;
167  }
168 
169  // searching ..
171  $oSearchHandler = oxNew('oxsearch');
172  $oSearchList = $oSearchHandler->getSearchArticles(
173  $sSearchParamForQuery,
174  $sInitialSearchCat,
175  $sInitialSearchVendor,
176  $sInitialSearchManufacturer,
177  $this->getSortingSql($this->getSortIdent())
178  );
179 
180  // list of found articles
181  $this->_aArticleList = $oSearchList;
182  $this->_iAllArtCnt = 0;
183 
184  // skip count calculation if no articles in list found
185  if ($oSearchList->count()) {
186  $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount(
187  $sSearchParamForQuery,
188  $sInitialSearchCat,
189  $sInitialSearchVendor,
190  $sInitialSearchManufacturer
191  );
192  }
193 
194  $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
195  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
196  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
197  }
198 
205  public function render()
206  {
207  parent::render();
208 
209  $oConfig = $this->getConfig();
210  if ($oConfig->getConfigParam('bl_rssSearch')) {
211  $oRss = oxNew('oxrssfeed');
212  $sSearch = $oConfig->getRequestParameter('searchparam', true);
213  $sCnid = $oConfig->getRequestParameter('searchcnid', true);
214  $sVendor = $oConfig->getRequestParameter('searchvendor', true);
215  $sManufacturer = $oConfig->getRequestParameter('searchmanufacturer', true);
216  $sSearchArticlesTitle = $oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer);
217  $sSearchArticlesUrl = $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer);
218  $this->addRssFeed($sSearchArticlesTitle, $sSearchArticlesUrl, 'searchArticles');
219  }
220 
221  // processing list articles
222  $this->_processListArticles();
223 
224  return $this->_sThisTemplate;
225  }
226 
231  protected function _processListArticles()
232  {
233  $sAddDynParams = $this->getAddUrlParams();
234  if ($sAddDynParams && ($aArtList = $this->getArticleList())) {
235  $blSeo = oxRegistry::getUtils()->seoIsActive();
236  foreach ($aArtList as $oArticle) {
237  // appending std and dynamic urls
238  if (!$blSeo) {
239  // only if seo is off..
240  $oArticle->appendStdLink($sAddDynParams);
241  }
242  $oArticle->appendLink($sAddDynParams);
243  }
244  }
245  }
246 
252  public function getAddUrlParams()
253  {
254  $sAddParams = parent::getAddUrlParams();
255  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
256  $oConfig = $this->getConfig();
257 
258  if ($sParam = $oConfig->getRequestParameter('searchparam', true)) {
259  $sAddParams .= "&amp;searchparam=" . rawurlencode($sParam);
260  }
261 
262  if ($sParam = $oConfig->getRequestParameter('searchcnid')) {
263  $sAddParams .= "&amp;searchcnid=$sParam";
264  }
265 
266  if ($sParam = rawurldecode($oConfig->getRequestParameter('searchvendor'))) {
267  $sAddParams .= "&amp;searchvendor=$sParam";
268  }
269 
270  if ($sParam = rawurldecode($oConfig->getRequestParameter('searchmanufacturer'))) {
271  $sAddParams .= "&amp;searchmanufacturer=$sParam";
272  }
273 
274  return $sAddParams;
275  }
276 
282  protected function _isSearchClass()
283  {
284  if ($this->_blSearchClass === null) {
285  $this->_blSearchClass = false;
286  if (strtolower($this->getConfig()->getRequestParameter('cl')) == 'search') {
287  $this->_blSearchClass = true;
288  }
289  }
290 
291  return $this->_blSearchClass;
292  }
293 
299  public function isEmptySearch()
300  {
301  return $this->_blEmptySearch;
302  }
303 
309  public function getArticleList()
310  {
311  return $this->_aArticleList;
312  }
313 
321  public function getSimilarRecommListIds()
322  {
323  if ($this->_aSimilarRecommListIds === null) {
324  $this->_aSimilarRecommListIds = false;
325 
326  $aList = $this->getArticleList();
327  if ($aList && $aList->count() > 0) {
328  $this->_aSimilarRecommListIds = $aList->arrayKeys();
329  }
330  }
331 
333  }
334 
340  public function getSearchParamForHtml()
341  {
342  if ($this->_sSearchParamForHtml === null) {
343  $this->_sSearchParamForHtml = false;
344  if ($this->_isSearchClass()) {
345  $this->_sSearchParamForHtml = $this->getConfig()->getRequestParameter('searchparam');
346  }
347  }
348 
350  }
351 
357  public function getSearchParam()
358  {
359  if ($this->_sSearchParam === null) {
360  $this->_sSearchParam = false;
361  if ($this->_isSearchClass()) {
362  $this->_sSearchParam = rawurlencode($this->getConfig()->getRequestParameter('searchparam', true));
363  }
364  }
365 
366  return $this->_sSearchParam;
367  }
368 
374  public function getSearchCatId()
375  {
376  if ($this->_sSearchCatId === null) {
377  $this->_sSearchCatId = false;
378  if ($this->_isSearchClass()) {
379  $this->_sSearchCatId = rawurldecode($this->getConfig()->getRequestParameter('searchcnid'));
380  }
381  }
382 
383  return $this->_sSearchCatId;
384  }
385 
391  public function getSearchVendor()
392  {
393  if ($this->_sSearchVendor === null) {
394  $this->_sSearchVendor = false;
395  if ($this->_isSearchClass()) {
396  // searching in vendor #671
397  $this->_sSearchVendor = rawurldecode($this->getConfig()->getRequestParameter('searchvendor'));
398  }
399  }
400 
401  return $this->_sSearchVendor;
402  }
403 
409  public function getSearchManufacturer()
410  {
411  if ($this->_sSearchManufacturer === null) {
412  $this->_sSearchManufacturer = false;
413  if ($this->_isSearchClass()) {
414  // searching in Manufacturer #671
415  $sManufacturerParameter = $this->getConfig()->getRequestParameter('searchmanufacturer');
416  $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
417  }
418  }
419 
421  }
422 
428  public function getPageNavigation()
429  {
430  if ($this->_oPageNavigation === null) {
431  $this->_oPageNavigation = false;
432  $this->_oPageNavigation = $this->generatePageNavigation();
433  }
434 
436  }
437 
438 
444  public function getActiveCategory()
445  {
446  return $this->getActSearch();
447  }
448 
454  public function getBreadCrumb()
455  {
456  $aPaths = array();
457  $aPath = array();
458 
459  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
460  $aPath['title'] = oxRegistry::getLang()->translateString('SEARCH', $iBaseLanguage, false);
461  $aPath['link'] = $this->getLink();
462  $aPaths[] = $aPath;
463 
464  return $aPaths;
465  }
466 
472  public function canSelectDisplayType()
473  {
474  return $this->getConfig()->getConfigParam('blShowListDisplayType');
475  }
476 
482  protected function _canRedirect()
483  {
484  return false;
485  }
486 
492  public function getArticleCount()
493  {
494  return $this->_iAllArtCnt;
495  }
496 
502  public function getTitle()
503  {
504  $sTitle = '';
505  $sTitle .= $this->getArticleCount();
506  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
507  $sTitle .= ' ' . oxRegistry::getLang()->translateString('HITS_FOR', $iBaseLanguage, false);
508  $sTitle .= ' "' . $this->getSearchParamForHtml() . '"';
509 
510  return $sTitle;
511  }
512 }