OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
search.php
Go to the documentation of this file.
1 <?php
2 
7 class Search extends oxUBase
8 {
13  protected $_iAllArtCnt = 0;
14 
19  protected $_iCntPages = null;
20 
25  protected $_sThisTemplate = 'page/search/search.tpl';
26 
31  protected $_sListType = 'search';
32 
37  protected $_blShowSorting = true;
38 
43  protected $_blEmptySearch = null;
44 
49  protected $_oRecommList = null;
50 
55  protected $_sSearchParamForHtml = null;
56 
61  protected $_sSearchParam = null;
62 
67  protected $_sSearchCatId = null;
68 
73  protected $_sSearchVendor = null;
74 
79  protected $_sSearchManufacturer = null;
80 
85  protected $_blSearchClass = null;
86 
91  protected $_oPageNavigation = null;
92 
99 
105  protected $_aSimilarRecommListIds = null;
106 
107 
116  public function init()
117  {
118  parent::init();
119 
120  $myConfig = $this->getConfig();
121 
122  // #1184M - specialchar search
123  $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
124 
125  // searching in category ?
126  $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
127 
128  // searching in vendor #671
129  $sInitialSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
130 
131  // searching in Manufacturer #671
132  $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
133 
134  $this->_blEmptySearch = false;
135  if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
136  //no search string
137  $this->_aArticleList = null;
138  $this->_blEmptySearch = true;
139  return false;
140  }
141 
142  // config allows to search in Manufacturers ?
143  if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
144  $sInitialSearchManufacturer = null;
145  }
146 
147  // searching ..
148  $oSearchHandler = oxNew( 'oxsearch' );
149  $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( $this->getSortIdent() ) );
150 
151  // list of found articles
152  $this->_aArticleList = $oSearchList;
153  $this->_iAllArtCnt = 0;
154 
155  // skip count calculation if no articles in list found
156  if ( $oSearchList->count() ) {
157  $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
158  }
159 
160  $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
161  $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
162  $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
163  }
164 
171  public function render()
172  {
173  parent::render();
174 
175  $oConfig = $this->getConfig();
176  if ( $oConfig->getConfigParam( 'bl_rssSearch' ) ) {
177  $oRss = oxNew('oxrssfeed');
178  $sSearch = $oConfig->getRequestParameter( 'searchparam', true );
179  $sCnid = $oConfig->getRequestParameter( 'searchcnid', true );
180  $sVendor = $oConfig->getRequestParameter( 'searchvendor', true );
181  $sManufacturer = $oConfig->getRequestParameter( 'searchmanufacturer', true );
182  $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
183  }
184 
185  // processing list articles
186  $this->_processListArticles();
187 
188  return $this->_sThisTemplate;
189  }
190 
197  protected function _processListArticles()
198  {
199  $sAddDynParams = $this->getAddUrlParams();
200  if ( $sAddDynParams && ( $aArtList = $this->getArticleList() ) ) {
201  $blSeo = oxRegistry::getUtils()->seoIsActive();
202  foreach ( $aArtList as $oArticle ) {
203  // appending std and dynamic urls
204  if ( !$blSeo ) {
205  // only if seo is off..
206  $oArticle->appendStdLink( $sAddDynParams );
207  }
208  $oArticle->appendLink( $sAddDynParams );
209  }
210  }
211  }
212 
218  public function getAddUrlParams()
219  {
220  $sAddParams = parent::getAddUrlParams();
221  $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
222  $oConfig = $this->getConfig();
223 
224  if ( $sParam = $oConfig->getRequestParameter( 'searchparam', true ) ) {
225  $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
226  }
227 
228  if ( $sParam = $oConfig->getRequestParameter( 'searchcnid' ) ) {
229  $sAddParams .= "&amp;searchcnid=$sParam";
230  }
231 
232  if ( $sParam = rawurldecode( $oConfig->getRequestParameter( 'searchvendor' ) ) ) {
233  $sAddParams .= "&amp;searchvendor=$sParam";
234  }
235 
236  if ( $sParam = rawurldecode( $oConfig->getRequestParameter( 'searchmanufacturer' ) ) ) {
237  $sAddParams .= "&amp;searchmanufacturer=$sParam";
238  }
239  return $sAddParams;
240  }
241 
253  public function setItemSorting( $sCnid, $sSortBy, $sSortOrder = null )
254  {
255  parent::setItemSorting( $sCnid, $sSortBy, $sSortOrder );
256  }
257 
267  public function getSorting( $sCnid )
268  {
269  return parent::getSorting( $sCnid );
270  }
271 
277  protected function _isSearchClass()
278  {
279  if ( $this->_blSearchClass === null ) {
280  $this->_blSearchClass = false;
281  if ( strtolower($this->getConfig()->getRequestParameter( 'cl' )) == 'search' ) {
282  $this->_blSearchClass = true;
283  }
284  }
285  return $this->_blSearchClass;
286  }
292  public function isEmptySearch()
293  {
294  return $this->_blEmptySearch;
295  }
296 
302  public function getArticleList()
303  {
304  return $this->_aArticleList;
305  }
306 
312  public function getSimilarRecommListIds()
313  {
314  if ( $this->_aSimilarRecommListIds === null ) {
315  $this->_aSimilarRecommListIds = false;
316 
317  $aList = $this->getArticleList();
318  if ( $aList && $aList->count() > 0 ) {
319  $this->_aSimilarRecommListIds = $aList->arrayKeys();
320  }
321  }
322 
324  }
325 
331  public function getSearchParamForHtml()
332  {
333  if ( $this->_sSearchParamForHtml === null ) {
334  $this->_sSearchParamForHtml = false;
335  if ( $this->_isSearchClass() ) {
336  $this->_sSearchParamForHtml = $this->getConfig()->getRequestParameter( 'searchparam' );
337  }
338  }
340  }
341 
347  public function getSearchParam()
348  {
349  if ( $this->_sSearchParam === null ) {
350  $this->_sSearchParam = false;
351  if ( $this->_isSearchClass() ) {
352  $this->_sSearchParam = rawurlencode( $this->getConfig()->getRequestParameter( 'searchparam', true ) );
353  }
354  }
355  return $this->_sSearchParam;
356  }
357 
363  public function getSearchCatId()
364  {
365  if ( $this->_sSearchCatId === null ) {
366  $this->_sSearchCatId = false;
367  if ( $this->_isSearchClass() ) {
368  $this->_sSearchCatId = rawurldecode( $this->getConfig()->getRequestParameter( 'searchcnid' ) );
369  }
370  }
371  return $this->_sSearchCatId;
372  }
373 
379  public function getSearchVendor()
380  {
381  if ( $this->_sSearchVendor === null ) {
382  $this->_sSearchVendor = false;
383  if ( $this->_isSearchClass() ) {
384  // searching in vendor #671
385  $this->_sSearchVendor = rawurldecode( $this->getConfig()->getRequestParameter( 'searchvendor' ) );
386  }
387  }
388  return $this->_sSearchVendor;
389  }
390 
396  public function getSearchManufacturer()
397  {
398  if ( $this->_sSearchManufacturer === null ) {
399  $this->_sSearchManufacturer = false;
400  if ( $this->_isSearchClass() ) {
401  // searching in Manufacturer #671
402  $this->_sSearchManufacturer = rawurldecode( $this->getConfig()->getRequestParameter( 'searchmanufacturer' ) );
403  }
404  }
406  }
407 
413  public function getPageNavigation()
414  {
415  if ( $this->_oPageNavigation === null ) {
416  $this->_oPageNavigation = false;
417  $this->_oPageNavigation = $this->generatePageNavigation();
418  }
420  }
421 
422 
428  public function getActiveCategory()
429  {
430  return $this->getActSearch();
431  }
432 
438  public function getBreadCrumb()
439  {
440  $aPaths = array();
441  $aPath = array();
442 
443  $aPath['title'] = oxRegistry::getLang()->translateString( 'SEARCH', oxRegistry::getLang()->getBaseLanguage(), false );
444  $aPath['link'] = $this->getLink();
445  $aPaths[] = $aPath;
446 
447  return $aPaths;
448  }
449 
455  public function canSelectDisplayType()
456  {
457  return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
458  }
459 
465  protected function _canRedirect()
466  {
467  return false;
468  }
469 
475  public function getArticleCount()
476  {
477  return $this->_iAllArtCnt;
478  }
479 }