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 = 'page/search/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 
00105     protected $_aSimilarRecommListIds = null;
00106 
00107 
00116     public function init()
00117     {
00118         parent::init();
00119 
00120         $myConfig = $this->getConfig();
00121 
00122         // #1184M - specialchar search
00123         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00124 
00125         // searching in category ?
00126         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00127 
00128         // searching in vendor #671
00129         $sInitialSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00130 
00131         // searching in Manufacturer #671
00132         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00133 
00134         $this->_blEmptySearch = false;
00135         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00136             //no search string
00137             $this->_aArticleList = null;
00138             $this->_blEmptySearch = true;
00139             return false;
00140         }
00141 
00142         // config allows to search in Manufacturers ?
00143         if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00144             $sInitialSearchManufacturer = null;
00145         }
00146 
00147         // searching ..
00148         $oSearchHandler = oxNew( 'oxsearch' );
00149         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( $this->getSortIdent() ) );
00150 
00151         // list of found articles
00152         $this->_aArticleList = $oSearchList;
00153         $this->_iAllArtCnt    = 0;
00154 
00155         // skip count calculation if no articles in list found
00156         if ( $oSearchList->count() ) {
00157             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
00158         }
00159 
00160         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00161         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00162         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00163     }
00164 
00171     public function render()
00172     {
00173         parent::render();
00174 
00175         $oConfig = $this->getConfig();
00176         if ( $oConfig->getConfigParam( 'bl_rssSearch' ) ) {
00177             $oRss = oxNew('oxrssfeed');
00178             $sSearch = $oConfig->getRequestParameter( 'searchparam', true );
00179             $sCnid = $oConfig->getRequestParameter( 'searchcnid', true );
00180             $sVendor = $oConfig->getRequestParameter( 'searchvendor', true );
00181             $sManufacturer = $oConfig->getRequestParameter( 'searchmanufacturer', true );
00182             $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
00183         }
00184 
00185         // processing list articles
00186         $this->_processListArticles();
00187 
00188         return $this->_sThisTemplate;
00189     }
00190 
00197     protected function _processListArticles()
00198     {
00199         $sAddDynParams = $this->getAddUrlParams();
00200         if ( $sAddDynParams && ( $aArtList = $this->getArticleList() ) ) {
00201             $blSeo = oxRegistry::getUtils()->seoIsActive();
00202             foreach ( $aArtList as $oArticle ) {
00203                 // appending std and dynamic urls
00204                 if ( !$blSeo ) {
00205                     // only if seo is off..
00206                     $oArticle->appendStdLink( $sAddDynParams );
00207                 }
00208                 $oArticle->appendLink( $sAddDynParams );
00209             }
00210         }
00211     }
00212 
00218     public function getAddUrlParams()
00219     {
00220         $sAddParams  = parent::getAddUrlParams();
00221         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00222         $oConfig = $this->getConfig();
00223 
00224         if ( $sParam = $oConfig->getRequestParameter( 'searchparam', true ) ) {
00225             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00226         }
00227 
00228         if ( $sParam = $oConfig->getRequestParameter( 'searchcnid' ) ) {
00229             $sAddParams .= "&amp;searchcnid=$sParam";
00230         }
00231 
00232         if ( $sParam = rawurldecode( $oConfig->getRequestParameter( 'searchvendor' ) ) ) {
00233             $sAddParams .= "&amp;searchvendor=$sParam";
00234         }
00235 
00236         if ( $sParam = rawurldecode( $oConfig->getRequestParameter( 'searchmanufacturer' ) ) ) {
00237             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00238         }
00239         return $sAddParams;
00240     }
00241 
00253     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00254     {
00255         parent::setItemSorting( $sCnid, $sSortBy, $sSortOrder );
00256     }
00257 
00267     public function getSorting( $sCnid )
00268     {
00269         return parent::getSorting( $sCnid );
00270     }
00271 
00277     protected function _isSearchClass()
00278     {
00279         if ( $this->_blSearchClass === null ) {
00280             $this->_blSearchClass = false;
00281             if ( strtolower($this->getConfig()->getRequestParameter( 'cl' )) == 'search' ) {
00282                 $this->_blSearchClass = true;
00283             }
00284         }
00285         return $this->_blSearchClass;
00286     }
00292     public function isEmptySearch()
00293     {
00294         return $this->_blEmptySearch;
00295     }
00296 
00302     public function getArticleList()
00303     {
00304         return $this->_aArticleList;
00305     }
00306 
00312     public function getSimilarRecommListIds()
00313     {
00314         if ( $this->_aSimilarRecommListIds === null ) {
00315             $this->_aSimilarRecommListIds = false;
00316 
00317             $aList = $this->getArticleList();
00318             if ( $aList && $aList->count() > 0 ) {
00319                 $this->_aSimilarRecommListIds = $aList->arrayKeys();
00320             }
00321         }
00322 
00323         return $this->_aSimilarRecommListIds;
00324     }
00325 
00331     public function getSearchParamForHtml()
00332     {
00333         if ( $this->_sSearchParamForHtml === null ) {
00334             $this->_sSearchParamForHtml = false;
00335             if ( $this->_isSearchClass() ) {
00336                 $this->_sSearchParamForHtml = $this->getConfig()->getRequestParameter( 'searchparam' );
00337             }
00338         }
00339         return $this->_sSearchParamForHtml;
00340     }
00341 
00347     public function getSearchParam()
00348     {
00349         if ( $this->_sSearchParam === null ) {
00350             $this->_sSearchParam = false;
00351             if ( $this->_isSearchClass() ) {
00352                 $this->_sSearchParam = rawurlencode( $this->getConfig()->getRequestParameter( 'searchparam', true ) );
00353             }
00354         }
00355         return $this->_sSearchParam;
00356     }
00357 
00363     public function getSearchCatId()
00364     {
00365         if ( $this->_sSearchCatId === null ) {
00366             $this->_sSearchCatId = false;
00367             if ( $this->_isSearchClass() ) {
00368                 $this->_sSearchCatId = rawurldecode( $this->getConfig()->getRequestParameter( 'searchcnid' ) );
00369             }
00370         }
00371         return $this->_sSearchCatId;
00372     }
00373 
00379     public function getSearchVendor()
00380     {
00381         if ( $this->_sSearchVendor === null ) {
00382             $this->_sSearchVendor = false;
00383             if ( $this->_isSearchClass() ) {
00384                 // searching in vendor #671
00385                 $this->_sSearchVendor = rawurldecode( $this->getConfig()->getRequestParameter( 'searchvendor' ) );
00386             }
00387         }
00388         return $this->_sSearchVendor;
00389     }
00390 
00396     public function getSearchManufacturer()
00397     {
00398         if ( $this->_sSearchManufacturer === null ) {
00399             $this->_sSearchManufacturer = false;
00400             if ( $this->_isSearchClass() ) {
00401                 // searching in Manufacturer #671
00402                 $this->_sSearchManufacturer = rawurldecode( $this->getConfig()->getRequestParameter( 'searchmanufacturer' ) );
00403             }
00404         }
00405         return $this->_sSearchManufacturer;
00406     }
00407 
00413     public function getPageNavigation()
00414     {
00415         if ( $this->_oPageNavigation === null ) {
00416             $this->_oPageNavigation = false;
00417             $this->_oPageNavigation = $this->generatePageNavigation();
00418         }
00419         return $this->_oPageNavigation;
00420     }
00421 
00422 
00428     public function getActiveCategory()
00429     {
00430         return $this->getActSearch();
00431     }
00432 
00438     public function getBreadCrumb()
00439     {
00440         $aPaths = array();
00441         $aPath = array();
00442 
00443         $aPath['title'] = oxRegistry::getLang()->translateString( 'SEARCH', oxRegistry::getLang()->getBaseLanguage(), false );
00444         $aPath['link']  = $this->getLink();
00445         $aPaths[] = $aPath;
00446 
00447         return $aPaths;
00448     }
00449 
00455     public function canSelectDisplayType()
00456     {
00457         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00458     }
00459 
00465     protected function _canRedirect()
00466     {
00467         return false;
00468     }
00469 
00475     public function getArticleCount()
00476     {
00477         return $this->_iAllArtCnt;
00478     }
00479 }