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         // #1184M - specialchar search
00121         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00122 
00123         // searching in category ?
00124         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00125 
00126         // searching in vendor #671
00127         $sInitialSearchVendor = $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00128 
00129         // searching in Manufacturer #671
00130         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00131 
00132         $this->_blEmptySearch = false;
00133         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00134             //no search string
00135             $this->_aArticleList = null;
00136             $this->_blEmptySearch = true;
00137             return false;
00138         }
00139 
00140         // config allows to search in vendors ?
00141         if ( !$myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00142             $sInitialSearchVendor = null;
00143         }
00144 
00145         // config allows to search in Manufacturers ?
00146         if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00147             $sInitialSearchManufacturer = null;
00148         }
00149 
00150         // searching ..
00151         $oSearchHandler = oxNew( 'oxsearch' );
00152         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( 'oxsearch' ) );
00153 
00154         // list of found articles
00155         $this->_aArticleList = $oSearchList;
00156         $this->_iAllArtCnt    = 0;
00157 
00158         // skip count calculation if no articles in list found
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 ( is_array( $myConfig->getConfigParam( 'aRssSelected' ) ) && in_array( 'oxrss_search', $myConfig->getConfigParam( 'aRssSelected' ) ) ) {
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         // processing list articles
00211         $this->_processListArticles();
00212 
00213         return $this->_sThisTemplate;
00214     }
00215 
00221     public function getAddUrlParams()
00222     {
00223         $sAddParams  = parent::getAddUrlParams();
00224         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00225 
00226         if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00227             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00228         }
00229 
00230         if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00231             $sAddParams .= "&amp;searchcnid=$sParam";
00232         }
00233 
00234         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00235             $sAddParams .= "&amp;searchvendor=$sParam";
00236         }
00237 
00238         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00239             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00240         }
00241         return $sAddParams;
00242     }
00243 
00253     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00254     {
00255         parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00256     }
00257 
00265     public function getSorting( $sCnid )
00266     {
00267         return parent::getSorting( "oxsearch" );
00268     }
00269 
00275     protected function _isSearchClass()
00276     {
00277         if ( $this->_blSearchClass === null ) {
00278             $this->_blSearchClass = false;
00279             if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00280                 $this->_blSearchClass = true;
00281             }
00282         }
00283         return $this->_blSearchClass;
00284     }
00290     public function isEmptySearch()
00291     {
00292         return $this->_blEmptySearch;
00293     }
00294 
00300     public function getArticleList()
00301     {
00302         return $this->_aArticleList;
00303     }
00304 
00310     public function getSimilarRecommLists()
00311     {
00312         if ( $this->_oRecommList === null ) {
00313             $this->_oRecommList = false;
00314             $aList = $this->getArticleList();
00315             if ( $aList && $aList->count() > 0 ) {
00316                 // loading recommlists
00317                 $oRecommList = oxNew('oxrecommlist');
00318                 $this->_oRecommList  = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00319             }
00320         }
00321         return $this->_oRecommList;
00322     }
00323 
00329     public function getSearchParamForHtml()
00330     {
00331         if ( $this->_sSearchParamForHtml === null ) {
00332             $this->_sSearchParamForHtml = false;
00333             if ( $this->_isSearchClass() ) {
00334                 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00335             }
00336         }
00337         return $this->_sSearchParamForHtml;
00338     }
00339 
00345     public function getSearchParam()
00346     {
00347         if ( $this->_sSearchParam === null ) {
00348             $this->_sSearchParam = false;
00349             if ( $this->_isSearchClass() ) {
00350                 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00351             }
00352         }
00353         return $this->_sSearchParam;
00354     }
00355 
00361     public function getSearchCatId()
00362     {
00363         if ( $this->_sSearchCatId === null ) {
00364             $this->_sSearchCatId = false;
00365             if ( $this->_isSearchClass() ) {
00366                 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00367             }
00368         }
00369         return $this->_sSearchCatId;
00370     }
00371 
00377     public function getSearchVendor()
00378     {
00379         if ( $this->_sSearchVendor === null ) {
00380             $this->_sSearchVendor = false;
00381             if ( $this->_isSearchClass() ) {
00382                 // searching in vendor #671
00383                 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00384             }
00385         }
00386         return $this->_sSearchVendor;
00387     }
00388 
00394     public function getSearchManufacturer()
00395     {
00396         if ( $this->_sSearchManufacturer === null ) {
00397             $this->_sSearchManufacturer = false;
00398             if ( $this->_isSearchClass() ) {
00399                 // searching in Manufacturer #671
00400                 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00401             }
00402         }
00403         return $this->_sSearchManufacturer;
00404     }
00405 
00411     public function getPageNavigation()
00412     {
00413         if ( $this->_oPageNavigation === null ) {
00414             $this->_oPageNavigation = false;
00415             $this->_oPageNavigation = $this->generatePageNavigation();
00416         }
00417         return $this->_oPageNavigation;
00418     }
00419 
00425     public function getActiveCategory()
00426     {
00427         return $this->getActSearch();
00428     }
00429 
00430 }

Generated on Wed May 13 13:25:55 2009 for OXID eShop CE by  doxygen 1.5.5