oxlocator.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxLocator extends oxSuperCfg
00007 {
00011     protected $_sType = "list";
00012 
00016     protected $_oNextProduct = null;
00017 
00021     protected $_oBackProduct = null;
00022 
00026     protected $_sSearchHandle = null;
00027 
00031     protected $_sErrorMessage = null;
00032 
00039     public function __construct( $sType = null )
00040     {
00041         // setting locator type
00042         if ( $sType ) {
00043             $this->_sType = trim( $sType );
00044         }
00045     }
00046 
00056     public function setLocatorData( $oCurrArticle, $oLocatorTarget )
00057     {
00058         $sLocfnc = "_set{$this->_sType}LocatorData";
00059         $this->$sLocfnc( $oLocatorTarget, $oCurrArticle );
00060 
00061         // passing list type to view
00062         $oLocatorTarget->setListType( 'sListType', $this->_sType );
00063     }
00064 
00073     protected function _setListLocatorData( $oLocatorTarget, $oCurrArticle )
00074     {
00075         // if no active category is loaded - lets check for category passed by post/get
00076         if ( ( $oCategory = $oLocatorTarget->getActCategory() ) ) {
00077             $sCatId = $oCategory->getId();
00078 
00079             $sOrderBy = null;
00080             if ( $oLocatorTarget->showSorting() ) {
00081                 $oLocatorTarget->prepareSortColumns();
00082                 $sOrderBy = $oLocatorTarget->getSortingSql( $sCatId );
00083             }
00084             $oIdList = $this->_loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy );
00085 
00086             //page number
00087             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00088 
00089             // setting product position in list, amount of articles etc
00090             $oCategory->iCntOfProd  = $oIdList->count();
00091             $oCategory->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00092 
00093             if ( oxUtils::getInstance()->seoIsActive() && $iPage ) {
00094                 $oCategory->toListLink = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage );
00095             } else {
00096                 $oCategory->toListLink  = $this->_makeLink( $oCategory->getLink(), $this->_getPageNumber( $iPage ) );
00097             }
00098 
00099             $oCategory->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), '' ):null;
00100             $oCategory->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), '' ):null;
00101 
00102             // active category
00103             $oLocatorTarget->setActiveCategory( $oCategory );
00104             // for compatibility reasons for a while. will be removed in future
00105             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00106 
00107             // category path
00108             if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00109                 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00110                 // for compatibility reasons for a while. will be removed in future
00111                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00112             }
00113         }
00114     }
00115 
00127     protected function _setVendorLocatorData( $oLocatorTarget, $oCurrArticle )
00128     {
00129         if ( ( $oVendor = $oLocatorTarget->getActVendor() ) ) {
00130             $sVendorId = $oVendor->getId();
00131 
00132             // loading data for article navigation
00133             $oIdList = oxNew( "oxarticlelist" );
00134             if ( $oLocatorTarget->showSorting() ) {
00135                 $oLocatorTarget->prepareSortColumns();
00136                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sVendorId:vendor" ) );
00137             }
00138             $oIdList->loadVendorIds( $sVendorId );
00139 
00140             //page number
00141             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00142 
00143             $sAdd = null;
00144             if ( !oxUtils::getInstance()->seoIsActive() ) {
00145                 $sAdd = 'listtype=vendor&amp;cnid=v_'.$sVendorId;
00146             }
00147 
00148             // setting product position in list, amount of articles etc
00149             $oVendor->iCntOfProd  = $oIdList->count();
00150             $oVendor->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00151 
00152             if ( oxUtils::getInstance()->seoIsActive() && $iPage ) {
00153                 $oVendor->toListLink = oxSeoEncoderVendor::getInstance()->getVendorPageUrl( $oVendor, $iPage );
00154             } else {
00155                 $oVendor->toListLink  = $this->_makeLink( $oVendor->getLink(), $this->_getPageNumber( $iPage ) );
00156             }
00157 
00158             // forcing vendor links
00159             if ( $this->_oNextProduct ) {
00160                 $this->_oNextProduct->setLinkType( 1 );
00161             }
00162 
00163             if ( $this->_oBackProduct ) {
00164                 $this->_oBackProduct->setLinkType( 1 );
00165             }
00166 
00167             $oVendor->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00168             $oVendor->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00169 
00170             // active vendor
00171             $oLocatorTarget->setActiveCategory( $oVendor );
00172             // for compatibility reasons for a while. will be removed in future
00173             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00174 
00175             // vendor path
00176             if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00177                 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00178                 // for compatibility reasons for a while. will be removed in future
00179                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00180             }
00181         }
00182     }
00183 
00196     protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00197     {
00198         if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00199 
00200             // #1834/1184M - specialchar search
00201             $sSearchParam = oxConfig::getParameter( 'searchparam', true );
00202             $sSearchFormParam = oxConfig::getParameter( 'searchparam' );
00203             $sSearchLinkParam = rawurlencode( $sSearchParam );
00204 
00205             $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00206             $sSearchCat = $sSearchCat?rawurldecode( $sSearchCat ):$sSearchCat;
00207 
00208             $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00209             $sSearchVendor = $sSearchVendor?rawurldecode( $sSearchVendor ):$sSearchVendor;
00210 
00211             // loading data for article navigation
00212             $oIdList = oxNew( 'oxarticlelist' );
00213             if ( $oLocatorTarget->showSorting() ) {
00214                 $oLocatorTarget->prepareSortColumns();
00215                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxsearch' ) );
00216             }
00217             $oIdList->loadSearchIds( $sSearchParam, $sSearchCat, $sSearchVendor );
00218 
00219             //page number
00220             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00221 
00222             $sAddSearch = "searchparam={$sSearchLinkParam}";
00223             if ( $sSearchCat !== null ) {
00224                 $sAddSearch .= "&amp;searchcnid={$sSearchCat}";
00225             }
00226 
00227             if ( $sSearchVendor !== null ) {
00228                 $sAddSearch .= "&amp;searchvendor={$sSearchVendor}";
00229             }
00230 
00231             // setting product position in list, amount of articles etc
00232             $oSearchCat->iCntOfProd  = $oIdList->count();
00233             $oSearchCat->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00234 
00235             $sPageNr = $this->_getPageNumber( $iPage );
00236             $oSearchCat->toListLink  = $this->_makeLink( $oSearchCat->link, $sPageNr.($sPageNr?'&amp;':'').$sAddSearch );
00237             $oSearchCat->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00238             $oSearchCat->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00239 
00240             $sFormat = oxLang::getInstance()->translateString( 'searchResult' );
00241             $oLocatorTarget->setSearchTitle( sprintf( $sFormat, $sSearchFormParam ) );
00242             // for compatibility reasons for a while. will be removed in future
00243             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00244 
00245             $oLocatorTarget->addTplParam( 'searchparam', $sSearchLinkParam );
00246             $oLocatorTarget->addTplParam( 'searchcnid', $sSearchCat );
00247             $oLocatorTarget->addTplParam( 'searchvendor', $sSearchVendor );
00248             $oLocatorTarget->addTplParam( 'searchparamforhtml', $sSearchFormParam );
00249 
00250             $oLocatorTarget->setActiveCategory( $oSearchCat );
00251             // for compatibility reasons for a while. will be removed in future
00252             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00253         }
00254     }
00255 
00267     protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00268     {
00269         if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00270 
00271             // loading data for article navigation
00272             $oIdList = oxNew( 'oxarticlelist' );
00273 
00274             if ( $oLocatorTarget->showSorting() ) {
00275                 $oLocatorTarget->prepareSortColumns();
00276                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxtags' ) );
00277             }
00278 
00279             $oIdList->getTagArticleIds( $oTag->sTag, oxLang::getInstance()->getBaseLanguage() );
00280 
00281             //page number
00282             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00283 
00284             $sAddSearch = 'searchtag='.rawurlencode(oxConfig::getParameter( 'searchtag', 1));
00285 
00286             // setting product position in list, amount of articles etc
00287             $oTag->iCntOfProd  = $oIdList->count();
00288             $oTag->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00289 
00290             $sPageNr = $this->_getPageNumber( $iPage );
00291             $oTag->toListLink  = $this->_makeLink( $oTag->link, $sPageNr.($sPageNr?'&amp;':'').$sAddSearch );
00292 
00293             $sAddSearch .= '&amp;listtype=tag';
00294             $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00295             $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00296 
00297             $oLocatorTarget->setSearchTitle( oxLang::getInstance()->translateString('TAGS').' / '.htmlspecialchars( ucfirst( $oTag->sTag ) ) );
00298             // for compatibility reasons for a while. will be removed in future
00299             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00300             $oLocatorTarget->addTplParam( 'searchtagforhtml', null );
00301             $oLocatorTarget->setActiveCategory( $oTag );
00302             // for compatibility reasons for a while. will be removed in future
00303             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00304         }
00305     }
00306 
00318     protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00319     {
00320         if ( ( $oRecommList = $oLocatorTarget->getActRecommList() ) ) {
00321 
00322             // loading data for article navigation
00323             $oIdList = oxNew( 'oxarticlelist' );
00324             $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00325 
00326             //page number
00327             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00328 
00329             $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00330 
00331             if ( $sSearchRecomm !== null ) {
00332                 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00333                 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00334                 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00335             }
00336 
00337             // setting product position in list, amount of articles etc
00338             $oRecommList->iCntOfProd  = $oIdList->count();
00339             $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00340 
00341             $sPageNr = $this->_getPageNumber( $iPage );
00342             $oRecommList->toListLink  = $this->_makeLink( $oRecommList->getLink(), $sPageNr.(($sPageNr && $sAddSearch)?'&amp;':'').$sAddSearch );
00343 
00344             $sAdd = 'recommid='.$oRecommList->getId().'&amp;listtype=recommlist'.($sAddSearch?'&amp;':'').$sAddSearch;
00345             $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00346             $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00347 
00348             $sTitle = oxLang::getInstance()->translateString('RECOMMLIST');
00349             if ( $sSearchRecomm !== null ) {
00350                 $sTitle .= " / ".oxLang::getInstance()->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00351                 $oLocatorTarget->addTplParam( 'searchrecomm', $sSearchLinkRecomm );
00352                 $oLocatorTarget->addTplParam( 'searchrecommforhtml', $sSearchFormRecomm );
00353             }
00354             $oLocatorTarget->setSearchTitle( $sTitle );
00355             // for compatibility reasons for a while. will be removed in future
00356             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00357             $oLocatorTarget->setActiveCategory( $oRecommList );
00358             // for compatibility reasons for a while. will be removed in future
00359             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00360         }
00361     }
00362 
00372     protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00373     {
00374         $oIdList = oxNew( 'oxarticlelist' );
00375         $oIdList->setCustomSorting( $sOrderBy ) ;
00376 
00377         // additionally check if this category is loaded and is price category ?
00378         if ( $oCategory->oxcategories__oxpricefrom->value || $oCategory->oxcategories__oxpriceto->value ) {
00379 
00380             $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00381         } else {
00382 
00383             $sActCat = $oCategory->getId();
00384             $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00385 
00386             // if not found - reloading with empty filter
00387             if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00388                 $oIdList->loadCategoryIDs( $sActCat, null );
00389             }
00390         }
00391 
00392         return $oIdList;
00393     }
00394 
00403     protected function _makeLink( $sLink, $sParams )
00404     {
00405         if ( $sParams ) {
00406             $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&amp;' : '?' ) . $sParams;
00407         }
00408         return $sLink;
00409     }
00410 
00421     protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00422     {
00423         //page number
00424         $iPageNr = (int) $iPageNr;
00425 
00426         // maybe there is no page number passed, but we still can find the position in id's list
00427         if ( !$iPageNr && $oIdList && $oArticle ) {
00428             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00429             $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00430 
00431             $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00432             $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00433             $iPageNr = floor( $iPos / $iNrofCatArticles );
00434         }
00435 
00436         return $iPageNr;
00437     }
00438 
00446     protected function _getPageNumber( $iPageNr )
00447     {
00448         //page number
00449         $iPageNr = (int) $iPageNr;
00450         return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00451     }
00452 
00461     protected function _getProductPos( $oArticle, $oIdList )
00462     {
00463         $iCnt = 1;
00464         $iPos = 0;
00465 
00466         // variant handling
00467         $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00468 
00469         if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00470 
00471             $aIds = $oIdList->arrayKeys();
00472 
00473             $iPos = array_search($sOxid, $aIds);
00474 
00475             if (array_key_exists($iPos-1, $aIds)) {
00476                 $this->_oBackProduct = oxNew( 'oxarticle' );
00477                 if (!$this->_oBackProduct->load( $aIds[$iPos-1] )) {
00478                     $this->_oBackProduct = null;
00479                 }
00480             }
00481 
00482             if (array_key_exists($iPos+1, $aIds)) {
00483                 $this->_oNextProduct = oxNew( 'oxarticle' );
00484                 if (!$this->_oNextProduct->load( $aIds[$iPos+1] )) {
00485                     $this->_oNextProduct = null;
00486                 }
00487             }
00488             return $iPos+1;
00489         }
00490         return 0;
00491     }
00492 
00498     public function getErrorMessage()
00499     {
00500         return $this->_sErrorMessage;
00501     }
00502 
00503 }

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