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 $_blSearchClass = null;
00080 
00085     protected $_oPageNavigation = null;
00086 
00093     protected $_iViewIndexState = 1;
00094 
00109     public function init()
00110     {
00111         parent::init();
00112 
00113         $myConfig = $this->getConfig();
00114 
00115         // #1184M - specialchar search
00116         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00117 
00118         // searching in category ?
00119         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00120 
00121         // searching in vendor #671
00122         $sInitialSearchVendor = $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00123 
00124         $this->_blEmptySearch = false;
00125         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor ) {
00126             //no search string
00127             $this->_aArticleList = null;
00128             $this->_blEmptySearch = true;
00129             return false;
00130         }
00131 
00132         // config allows to search in vendors ?
00133         if ( !$myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00134             $sInitialSearchVendor = null;
00135         }
00136 
00137         // searching ..
00138         $oSearchHandler = oxNew( 'oxsearch' );
00139         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $this->getSortingSql( 'oxsearch' ) );
00140 
00141         // list of found articles
00142         $this->_aArticleList = $oSearchList;
00143         $this->_iAllArtCnt    = 0;
00144 
00145         // skip count calculation if no articles in list found
00146         if ( $oSearchList->count() ) {
00147             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor );
00148         }
00149 
00150         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00151         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00152         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00153     }
00154 
00167     public function render()
00168     {
00169         $this->_aViewData['emptysearch'] = $this->isEmptySearch();
00170 
00171         $this->_aViewData['articlelist'] = $this->getArticleList();
00172 
00173         $this->_aViewData['similarrecommlist']  = $this->getSimilarRecommLists();
00174 
00175         $this->_aViewData['searchparamforhtml'] = $this->getSearchParamForHtml();
00176         $this->_aViewData['searchparam']        = $this->getSearchParam();
00177         $this->_aViewData['searchcnid']         = $this->getSearchCatId();
00178         $this->_aViewData['searchvendor']       = $this->getSearchVendor();
00179 
00180         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00181         $this->_aViewData['actCategory']    = $this->getActiveCategory();
00182 
00183         parent::render();
00184 
00185         if (is_array(oxConfig::getInstance()->getConfigParam( 'aRssSelected' )) && in_array('oxrss_search', oxConfig::getInstance()->getConfigParam( 'aRssSelected' ))) {
00186             $oRss = oxNew('oxrssfeed');
00187             $sSearch = oxConfig::getParameter( 'searchparam', true );
00188             $sCnid = oxConfig::getParameter( 'searchcnid', true );
00189             $sVendor = oxConfig::getParameter( 'searchvendor', true );
00190             $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor), 'searchArticles');
00191         }
00192 
00193         // processing list articles
00194         $this->_processListArticles();
00195 
00196         return $this->_sThisTemplate;
00197     }
00198 
00204     public function getAddUrlParams()
00205     {
00206         $sAddParams  = parent::getAddUrlParams();
00207         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00208 
00209         if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00210             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00211         }
00212 
00213         if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00214             $sAddParams .= "&amp;searchcnid=$sParam";
00215         }
00216 
00217         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00218            $sAddParams .= "&amp;searchvendor=$sParam";
00219         }
00220         return $sAddParams;
00221     }
00222 
00232     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00233     {
00234         parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00235     }
00236 
00244     public function getSorting( $sCnid )
00245     {
00246         return parent::getSorting( "oxsearch" );
00247     }
00248 
00254     protected function _isSearchClass()
00255     {
00256         if ( $this->_blSearchClass === null ) {
00257             $this->_blSearchClass = false;
00258             if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00259                 $this->_blSearchClass = true;
00260             }
00261         }
00262         return $this->_blSearchClass;
00263     }
00269     public function isEmptySearch()
00270     {
00271         return $this->_blEmptySearch;
00272     }
00273 
00279     public function getArticleList()
00280     {
00281         return $this->_aArticleList;
00282     }
00283 
00289     public function getSimilarRecommLists()
00290     {
00291         if ( $this->_oRecommList === null ) {
00292             $this->_oRecommList = false;
00293             $aList = $this->getArticleList();
00294             if ( $aList && $aList->count() > 0 ) {
00295                 // loading recommlists
00296                 $oRecommList = oxNew('oxrecommlist');
00297                 $this->_oRecommList  = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00298             }
00299         }
00300         return $this->_oRecommList;
00301     }
00302 
00308     public function getSearchParamForHtml()
00309     {
00310         if ( $this->_sSearchParamForHtml === null ) {
00311             $this->_sSearchParamForHtml = false;
00312             if ( $this->_isSearchClass() ) {
00313                 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00314             }
00315         }
00316         return $this->_sSearchParamForHtml;
00317     }
00318 
00324     public function getSearchParam()
00325     {
00326         if ( $this->_sSearchParam === null ) {
00327             $this->_sSearchParam = false;
00328             if ( $this->_isSearchClass() ) {
00329                 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00330             }
00331         }
00332         return $this->_sSearchParam;
00333     }
00334 
00340     public function getSearchCatId()
00341     {
00342         if ( $this->_sSearchCatId === null ) {
00343             $this->_sSearchCatId = false;
00344             if ( $this->_isSearchClass() ) {
00345                 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00346             }
00347         }
00348         return $this->_sSearchCatId;
00349     }
00350 
00356     public function getSearchVendor()
00357     {
00358         if ( $this->_sSearchVendor === null ) {
00359             $this->_sSearchVendor = false;
00360             if ( $this->_isSearchClass() ) {
00361                 // searching in vendor #671
00362                 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00363             }
00364         }
00365         return $this->_sSearchVendor;
00366     }
00367 
00373     public function getPageNavigation()
00374     {
00375         if ( $this->_oPageNavigation === null ) {
00376             $this->_oPageNavigation = false;
00377             $this->_oPageNavigation = $this->generatePageNavigation();
00378         }
00379         return $this->_oPageNavigation;
00380     }
00381 
00387     public function getActiveCategory()
00388     {
00389         return $this->getActSearch();
00390     }
00391 
00392 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5