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         if ( oxUtils::getInstance()->seoIsActive() ) {
00117             // cleaning category id tracked by SEO
00118             $this->setSessionCategoryId( null );
00119         }
00120 
00121         parent::init();
00122 
00123         $myConfig = $this->getConfig();
00124 
00125         // #1184M - specialchar search
00126         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00127 
00128         // searching in category ?
00129         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00130 
00131         // searching in vendor #671
00132         $sInitialSearchVendor = $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00133 
00134         // searching in Manufacturer #671
00135         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00136 
00137         $this->_blEmptySearch = false;
00138         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00139             //no search string
00140             $this->_aArticleList = null;
00141             $this->_blEmptySearch = true;
00142             return false;
00143         }
00144 
00145         // config allows to search in vendors ?
00146         if ( !$myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00147             $sInitialSearchVendor = null;
00148         }
00149 
00150         // config allows to search in Manufacturers ?
00151         if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00152             $sInitialSearchManufacturer = null;
00153         }
00154 
00155         // searching ..
00156         $oSearchHandler = oxNew( 'oxsearch' );
00157         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( 'oxsearch' ) );
00158 
00159         // list of found articles
00160         $this->_aArticleList = $oSearchList;
00161         $this->_iAllArtCnt    = 0;
00162 
00163         // skip count calculation if no articles in list found
00164         if ( $oSearchList->count() ) {
00165             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
00166         }
00167 
00168         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00169         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00170         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00171     }
00172 
00186     public function render()
00187     {
00188         $this->_aViewData['emptysearch'] = $this->isEmptySearch();
00189 
00190         $this->_aViewData['articlelist'] = $this->getArticleList();
00191 
00192         $this->_aViewData['similarrecommlist']  = $this->getSimilarRecommLists();
00193 
00194         $this->_aViewData['searchparamforhtml'] = $this->getSearchParamForHtml();
00195         $this->_aViewData['searchparam']        = $this->getSearchParam();
00196         $this->_aViewData['searchcnid']         = $this->getSearchCatId();
00197         $this->_aViewData['searchvendor']       = $this->getSearchVendor();
00198         $this->_aViewData['searchmanufacturer']       = $this->getSearchManufacturer();
00199 
00200         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00201         $this->_aViewData['actCategory']    = $this->getActiveCategory();
00202 
00203         parent::render();
00204 
00205         $myConfig = $this->getConfig();
00206         if ( is_array( $myConfig->getConfigParam( 'aRssSelected' ) ) && in_array( 'oxrss_search', $myConfig->getConfigParam( 'aRssSelected' ) ) ) {
00207             $oRss = oxNew('oxrssfeed');
00208             $sSearch = oxConfig::getParameter( 'searchparam', true );
00209             $sCnid = oxConfig::getParameter( 'searchcnid', true );
00210             $sVendor = oxConfig::getParameter( 'searchvendor', true );
00211             $sManufacturer = oxConfig::getParameter( 'searchmanufacturer', true );
00212             $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
00213         }
00214 
00215         // processing list articles
00216         $this->_processListArticles();
00217 
00218         return $this->_sThisTemplate;
00219     }
00220 
00226     public function getAddUrlParams()
00227     {
00228         $sAddParams  = parent::getAddUrlParams();
00229         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00230 
00231         if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00232             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00233         }
00234 
00235         if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00236             $sAddParams .= "&amp;searchcnid=$sParam";
00237         }
00238 
00239         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00240             $sAddParams .= "&amp;searchvendor=$sParam";
00241         }
00242 
00243         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00244             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00245         }
00246         return $sAddParams;
00247     }
00248 
00258     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00259     {
00260         parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00261     }
00262 
00270     public function getSorting( $sCnid )
00271     {
00272         return parent::getSorting( "oxsearch" );
00273     }
00274 
00280     protected function _isSearchClass()
00281     {
00282         if ( $this->_blSearchClass === null ) {
00283             $this->_blSearchClass = false;
00284             if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00285                 $this->_blSearchClass = true;
00286             }
00287         }
00288         return $this->_blSearchClass;
00289     }
00295     public function isEmptySearch()
00296     {
00297         return $this->_blEmptySearch;
00298     }
00299 
00305     public function getArticleList()
00306     {
00307         return $this->_aArticleList;
00308     }
00309 
00315     public function getSimilarRecommLists()
00316     {
00317         if ( $this->_oRecommList === null ) {
00318             $this->_oRecommList = false;
00319             $aList = $this->getArticleList();
00320             if ( $aList && $aList->count() > 0 ) {
00321                 // loading recommlists
00322                 $oRecommList = oxNew('oxrecommlist');
00323                 $this->_oRecommList  = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00324             }
00325         }
00326         return $this->_oRecommList;
00327     }
00328 
00334     public function getSearchParamForHtml()
00335     {
00336         if ( $this->_sSearchParamForHtml === null ) {
00337             $this->_sSearchParamForHtml = false;
00338             if ( $this->_isSearchClass() ) {
00339                 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00340             }
00341         }
00342         return $this->_sSearchParamForHtml;
00343     }
00344 
00350     public function getSearchParam()
00351     {
00352         if ( $this->_sSearchParam === null ) {
00353             $this->_sSearchParam = false;
00354             if ( $this->_isSearchClass() ) {
00355                 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00356             }
00357         }
00358         return $this->_sSearchParam;
00359     }
00360 
00366     public function getSearchCatId()
00367     {
00368         if ( $this->_sSearchCatId === null ) {
00369             $this->_sSearchCatId = false;
00370             if ( $this->_isSearchClass() ) {
00371                 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00372             }
00373         }
00374         return $this->_sSearchCatId;
00375     }
00376 
00382     public function getSearchVendor()
00383     {
00384         if ( $this->_sSearchVendor === null ) {
00385             $this->_sSearchVendor = false;
00386             if ( $this->_isSearchClass() ) {
00387                 // searching in vendor #671
00388                 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00389             }
00390         }
00391         return $this->_sSearchVendor;
00392     }
00393 
00399     public function getSearchManufacturer()
00400     {
00401         if ( $this->_sSearchManufacturer === null ) {
00402             $this->_sSearchManufacturer = false;
00403             if ( $this->_isSearchClass() ) {
00404                 // searching in Manufacturer #671
00405                 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00406             }
00407         }
00408         return $this->_sSearchManufacturer;
00409     }
00410 
00416     public function getPageNavigation()
00417     {
00418         if ( $this->_oPageNavigation === null ) {
00419             $this->_oPageNavigation = false;
00420             $this->_oPageNavigation = $this->generatePageNavigation();
00421         }
00422         return $this->_oPageNavigation;
00423     }
00424 
00430     public function getActiveCategory()
00431     {
00432         return $this->getActSearch();
00433     }
00434 
00435 }

Generated on Tue Aug 18 09:21:09 2009 for OXID eShop CE by  doxygen 1.5.5