search.php
Go to the documentation of this file.00001 <?php
00002
00007 class Search extends oxUBase
00008 {
00013 protected $_iAllArtCnt = 0;
00014
00019 protected $_iCntPages = null;
00020
00025 protected $_sThisTemplate = 'search.tpl';
00026
00031 protected $_sListType = 'search';
00032
00037 protected $_blShowSorting = true;
00038
00043 protected $_blEmptySearch = null;
00044
00049 protected $_oRecommList = null;
00050
00055 protected $_sSearchParamForHtml = null;
00056
00061 protected $_sSearchParam = null;
00062
00067 protected $_sSearchCatId = null;
00068
00073 protected $_sSearchVendor = null;
00074
00079 protected $_sSearchManufacturer = null;
00080
00085 protected $_blSearchClass = null;
00086
00091 protected $_oPageNavigation = null;
00092
00098 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00099
00114 public function init()
00115 {
00116 parent::init();
00117
00118 $myConfig = $this->getConfig();
00119
00120
00121 $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00122
00123
00124 $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00125
00126
00127 $sInitialSearchVendor = $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00128
00129
00130 $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00131
00132 $this->_blEmptySearch = false;
00133 if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00134
00135 $this->_aArticleList = null;
00136 $this->_blEmptySearch = true;
00137 return false;
00138 }
00139
00140
00141 if ( !$myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00142 $sInitialSearchVendor = null;
00143 }
00144
00145
00146 if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00147 $sInitialSearchManufacturer = null;
00148 }
00149
00150
00151 $oSearchHandler = oxNew( 'oxsearch' );
00152 $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( 'oxsearch' ) );
00153
00154
00155 $this->_aArticleList = $oSearchList;
00156 $this->_iAllArtCnt = 0;
00157
00158
00159 if ( $oSearchList->count() ) {
00160 $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
00161 }
00162
00163 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00164 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00165 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00166 }
00167
00181 public function render()
00182 {
00183 $this->_aViewData['emptysearch'] = $this->isEmptySearch();
00184
00185 $this->_aViewData['articlelist'] = $this->getArticleList();
00186
00187 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00188
00189 $this->_aViewData['searchparamforhtml'] = $this->getSearchParamForHtml();
00190 $this->_aViewData['searchparam'] = $this->getSearchParam();
00191 $this->_aViewData['searchcnid'] = $this->getSearchCatId();
00192 $this->_aViewData['searchvendor'] = $this->getSearchVendor();
00193 $this->_aViewData['searchmanufacturer'] = $this->getSearchManufacturer();
00194
00195 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00196 $this->_aViewData['actCategory'] = $this->getActiveCategory();
00197
00198 parent::render();
00199
00200 $myConfig = $this->getConfig();
00201 if ( $myConfig->getConfigParam( 'bl_rssSearch' ) ) {
00202 $oRss = oxNew('oxrssfeed');
00203 $sSearch = oxConfig::getParameter( 'searchparam', true );
00204 $sCnid = oxConfig::getParameter( 'searchcnid', true );
00205 $sVendor = oxConfig::getParameter( 'searchvendor', true );
00206 $sManufacturer = oxConfig::getParameter( 'searchmanufacturer', true );
00207 $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
00208 }
00209
00210
00211 $this->_processListArticles();
00212
00213 return $this->_sThisTemplate;
00214 }
00215
00222 protected function _processListArticles()
00223 {
00224 $sAddDynParams = $this->getAddUrlParams();
00225 if ( $sAddDynParams && ( $aArtList = $this->getArticleList() ) ) {
00226 foreach ( $aArtList as $oArticle ) {
00227
00228 $oArticle->appendStdLink( $sAddDynParams );
00229 $oArticle->appendLink( $sAddDynParams );
00230 }
00231 }
00232 }
00233
00239 public function getAddUrlParams()
00240 {
00241 $sAddParams = parent::getAddUrlParams();
00242 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00243
00244 if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00245 $sAddParams .= "&searchparam=".rawurlencode($sParam);
00246 }
00247
00248 if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00249 $sAddParams .= "&searchcnid=$sParam";
00250 }
00251
00252 if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00253 $sAddParams .= "&searchvendor=$sParam";
00254 }
00255
00256 if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00257 $sAddParams .= "&searchmanufacturer=$sParam";
00258 }
00259 return $sAddParams;
00260 }
00261
00271 public function setItemSorting( $sCnid, $sSortBy, $sSortOrder = null )
00272 {
00273 parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00274 }
00275
00283 public function getSorting( $sCnid )
00284 {
00285 return parent::getSorting( "oxsearch" );
00286 }
00287
00293 protected function _isSearchClass()
00294 {
00295 if ( $this->_blSearchClass === null ) {
00296 $this->_blSearchClass = false;
00297 if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00298 $this->_blSearchClass = true;
00299 }
00300 }
00301 return $this->_blSearchClass;
00302 }
00308 public function isEmptySearch()
00309 {
00310 return $this->_blEmptySearch;
00311 }
00312
00318 public function getArticleList()
00319 {
00320 return $this->_aArticleList;
00321 }
00322
00328 public function getSimilarRecommLists()
00329 {
00330 if (!$this->getViewConfig()->getShowListmania()) {
00331 return false;
00332 }
00333
00334 if ( $this->_oRecommList === null ) {
00335 $this->_oRecommList = false;
00336 $aList = $this->getArticleList();
00337 if ( $aList && $aList->count() > 0 ) {
00338
00339 $oRecommList = oxNew('oxrecommlist');
00340 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00341 }
00342 }
00343 return $this->_oRecommList;
00344 }
00345
00351 public function getSearchParamForHtml()
00352 {
00353 if ( $this->_sSearchParamForHtml === null ) {
00354 $this->_sSearchParamForHtml = false;
00355 if ( $this->_isSearchClass() ) {
00356 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00357 }
00358 }
00359 return $this->_sSearchParamForHtml;
00360 }
00361
00367 public function getSearchParam()
00368 {
00369 if ( $this->_sSearchParam === null ) {
00370 $this->_sSearchParam = false;
00371 if ( $this->_isSearchClass() ) {
00372 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00373 }
00374 }
00375 return $this->_sSearchParam;
00376 }
00377
00383 public function getSearchCatId()
00384 {
00385 if ( $this->_sSearchCatId === null ) {
00386 $this->_sSearchCatId = false;
00387 if ( $this->_isSearchClass() ) {
00388 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00389 }
00390 }
00391 return $this->_sSearchCatId;
00392 }
00393
00399 public function getSearchVendor()
00400 {
00401 if ( $this->_sSearchVendor === null ) {
00402 $this->_sSearchVendor = false;
00403 if ( $this->_isSearchClass() ) {
00404
00405 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00406 }
00407 }
00408 return $this->_sSearchVendor;
00409 }
00410
00416 public function getSearchManufacturer()
00417 {
00418 if ( $this->_sSearchManufacturer === null ) {
00419 $this->_sSearchManufacturer = false;
00420 if ( $this->_isSearchClass() ) {
00421
00422 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00423 }
00424 }
00425 return $this->_sSearchManufacturer;
00426 }
00427
00433 public function getPageNavigation()
00434 {
00435 if ( $this->_oPageNavigation === null ) {
00436 $this->_oPageNavigation = false;
00437 $this->_oPageNavigation = $this->generatePageNavigation();
00438 }
00439 return $this->_oPageNavigation;
00440 }
00441
00447 public function getActiveCategory()
00448 {
00449 return $this->getActSearch();
00450 }
00451
00452 }