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 $blSeo = oxUtils::getInstance()->seoIsActive();
00227 foreach ( $aArtList as $oArticle ) {
00228
00229 if ( !$blSeo ) {
00230
00231 $oArticle->appendStdLink( $sAddDynParams );
00232 }
00233 $oArticle->appendLink( $sAddDynParams );
00234 }
00235 }
00236 }
00237
00243 public function getAddUrlParams()
00244 {
00245 $sAddParams = parent::getAddUrlParams();
00246 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00247
00248 if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00249 $sAddParams .= "&searchparam=".rawurlencode($sParam);
00250 }
00251
00252 if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00253 $sAddParams .= "&searchcnid=$sParam";
00254 }
00255
00256 if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00257 $sAddParams .= "&searchvendor=$sParam";
00258 }
00259
00260 if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00261 $sAddParams .= "&searchmanufacturer=$sParam";
00262 }
00263 return $sAddParams;
00264 }
00265
00275 public function setItemSorting( $sCnid, $sSortBy, $sSortOrder = null )
00276 {
00277 parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00278 }
00279
00287 public function getSorting( $sCnid )
00288 {
00289 return parent::getSorting( "oxsearch" );
00290 }
00291
00297 protected function _isSearchClass()
00298 {
00299 if ( $this->_blSearchClass === null ) {
00300 $this->_blSearchClass = false;
00301 if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00302 $this->_blSearchClass = true;
00303 }
00304 }
00305 return $this->_blSearchClass;
00306 }
00312 public function isEmptySearch()
00313 {
00314 return $this->_blEmptySearch;
00315 }
00316
00322 public function getArticleList()
00323 {
00324 return $this->_aArticleList;
00325 }
00326
00332 public function getSimilarRecommLists()
00333 {
00334 if (!$this->getViewConfig()->getShowListmania()) {
00335 return false;
00336 }
00337
00338 if ( $this->_oRecommList === null ) {
00339 $this->_oRecommList = false;
00340 $aList = $this->getArticleList();
00341 if ( $aList && $aList->count() > 0 ) {
00342
00343 $oRecommList = oxNew('oxrecommlist');
00344 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00345 }
00346 }
00347 return $this->_oRecommList;
00348 }
00349
00355 public function getSearchParamForHtml()
00356 {
00357 if ( $this->_sSearchParamForHtml === null ) {
00358 $this->_sSearchParamForHtml = false;
00359 if ( $this->_isSearchClass() ) {
00360 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00361 }
00362 }
00363 return $this->_sSearchParamForHtml;
00364 }
00365
00371 public function getSearchParam()
00372 {
00373 if ( $this->_sSearchParam === null ) {
00374 $this->_sSearchParam = false;
00375 if ( $this->_isSearchClass() ) {
00376 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00377 }
00378 }
00379 return $this->_sSearchParam;
00380 }
00381
00387 public function getSearchCatId()
00388 {
00389 if ( $this->_sSearchCatId === null ) {
00390 $this->_sSearchCatId = false;
00391 if ( $this->_isSearchClass() ) {
00392 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00393 }
00394 }
00395 return $this->_sSearchCatId;
00396 }
00397
00403 public function getSearchVendor()
00404 {
00405 if ( $this->_sSearchVendor === null ) {
00406 $this->_sSearchVendor = false;
00407 if ( $this->_isSearchClass() ) {
00408
00409 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00410 }
00411 }
00412 return $this->_sSearchVendor;
00413 }
00414
00420 public function getSearchManufacturer()
00421 {
00422 if ( $this->_sSearchManufacturer === null ) {
00423 $this->_sSearchManufacturer = false;
00424 if ( $this->_isSearchClass() ) {
00425
00426 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00427 }
00428 }
00429 return $this->_sSearchManufacturer;
00430 }
00431
00437 public function getPageNavigation()
00438 {
00439 if ( $this->_oPageNavigation === null ) {
00440 $this->_oPageNavigation = false;
00441 $this->_oPageNavigation = $this->generatePageNavigation();
00442 }
00443 return $this->_oPageNavigation;
00444 }
00445
00451 public function getActiveCategory()
00452 {
00453 return $this->getActSearch();
00454 }
00455
00456 }