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 
00055     public function setLocatorData( $oCurrArticle, $oLocatorTarget )
00056     {
00057         $sLocfnc = "_set{$this->_sType}LocatorData";
00058         $this->$sLocfnc( $oLocatorTarget, $oCurrArticle );
00059 
00060         // passing list type to view
00061         $oLocatorTarget->setListType( $this->_sType );
00062     }
00063 
00072     protected function _setListLocatorData( $oLocatorTarget, $oCurrArticle )
00073     {
00074         // if no active category is loaded - lets check for category passed by post/get
00075         if ( ( $oCategory = $oLocatorTarget->getActCategory() ) ) {
00076             $sCatId = $oCategory->getId();
00077 
00078             $sOrderBy = null;
00079             if ( $oLocatorTarget->showSorting() ) {
00080                 $oLocatorTarget->prepareSortColumns();
00081                 $sOrderBy = $oLocatorTarget->getSortingSql( $sCatId );
00082             }
00083             $oIdList = $this->_loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy );
00084 
00085             //page number
00086             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00087 
00088             // setting product position in list, amount of articles etc
00089             $oCategory->iCntOfProd  = $oIdList->count();
00090             $oCategory->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00091 
00092             if ( oxUtils::getInstance()->seoIsActive() && $iPage ) {
00093                 $oCategory->toListLink = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage );
00094             } else {
00095                 $oCategory->toListLink  = $this->_makeLink( $oCategory->getLink(), $this->_getPageNumber( $iPage ) );
00096             }
00097 
00098             $oCategory->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), '' ):null;
00099             $oCategory->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), '' ):null;
00100 
00101             // active category
00102             $oLocatorTarget->setActiveCategory( $oCategory );
00103             // for compatibility reasons for a while. will be removed in future
00104             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00105 
00106             // category path
00107             if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00108                 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00109                 // for compatibility reasons for a while. will be removed in future
00110                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00111             }
00112         }
00113     }
00114 
00126     protected function _setVendorLocatorData( $oLocatorTarget, $oCurrArticle )
00127     {
00128         if ( ( $oVendor = $oLocatorTarget->getActVendor() ) ) {
00129             $sVendorId = $oVendor->getId();
00130             $myUtils   = oxUtils::getInstance();
00131 
00132             $blSeo = $myUtils->seoIsActive();
00133 
00134             // loading data for article navigation
00135             $oIdList = oxNew( "oxarticlelist" );
00136             if ( $oLocatorTarget->showSorting() ) {
00137                 $oLocatorTarget->prepareSortColumns();
00138                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sVendorId:vendor" ) );
00139             }
00140             $oIdList->loadVendorIds( $sVendorId );
00141 
00142             //page number
00143             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00144 
00145             $sAdd = null;
00146             if ( !$blSeo ) {
00147                 $sAdd = 'listtype=vendor&amp;cnid=v_'.$sVendorId;
00148             }
00149 
00150             // setting product position in list, amount of articles etc
00151             $oVendor->iCntOfProd  = $oIdList->count();
00152             $oVendor->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00153 
00154             if ( $blSeo && $iPage ) {
00155                 $oVendor->toListLink = oxSeoEncoderVendor::getInstance()->getVendorPageUrl( $oVendor, $iPage );
00156             } else {
00157                 $oVendor->toListLink  = $this->_makeLink( $oVendor->getLink(), $this->_getPageNumber( $iPage ) );
00158             }
00159 
00160             $oVendor->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00161             $oVendor->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00162 
00163             // active vendor
00164             $oLocatorTarget->setActiveCategory( $oVendor );
00165             // for compatibility reasons for a while. will be removed in future
00166             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00167 
00168             // vendor path
00169             if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00170                 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00171                 // for compatibility reasons for a while. will be removed in future
00172                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00173             }
00174         }
00175     }
00176 
00188     protected function _setManufacturerLocatorData( $oLocatorTarget, $oCurrArticle )
00189     {
00190         if ( ( $oManufacturer = $oLocatorTarget->getActManufacturer() ) ) {
00191             $sManufacturerId = $oManufacturer->getId();
00192             $myUtils = oxUtils::getInstance();
00193 
00194             $blSeo = $myUtils->seoIsActive();
00195 
00196             // loading data for article navigation
00197             $oIdList = oxNew( "oxarticlelist" );
00198             if ( $oLocatorTarget->showSorting() ) {
00199                 $oLocatorTarget->prepareSortColumns();
00200                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sManufacturerId:manufacturer" ) );
00201             }
00202             $oIdList->loadManufacturerIds( $sManufacturerId );
00203 
00204             //page number
00205             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00206 
00207             $sAdd = null;
00208             if ( !$blSeo ) {
00209                 $sAdd = 'listtype=manufacturer&amp;mnid='.$sManufacturerId;
00210             }
00211 
00212             // setting product position in list, amount of articles etc
00213             $oManufacturer->iCntOfProd  = $oIdList->count();
00214             $oManufacturer->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00215 
00216             if ( $blSeo && $iPage ) {
00217                 $oManufacturer->toListLink = oxSeoEncoderManufacturer::getInstance()->getManufacturerPageUrl( $oManufacturer, $iPage );
00218             } else {
00219                 $oManufacturer->toListLink  = $this->_makeLink( $oManufacturer->getLink(), $this->_getPageNumber( $iPage ) );
00220             }
00221 
00222             $oManufacturer->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00223             $oManufacturer->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00224 
00225             // active Manufacturer
00226             $oLocatorTarget->setActiveCategory( $oManufacturer );
00227             // for compatibility reasons for a while. will be removed in future
00228             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00229 
00230             // Manufacturer path
00231             if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00232                 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00233                 // for compatibility reasons for a while. will be removed in future
00234                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00235             }
00236         }
00237     }
00238 
00251     protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00252     {
00253         if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00254 
00255             // #1834/1184M - specialchar search
00256             $sSearchParam = oxConfig::getParameter( 'searchparam', true );
00257             $sSearchFormParam = oxConfig::getParameter( 'searchparam' );
00258             $sSearchLinkParam = rawurlencode( $sSearchParam );
00259 
00260             $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00261             $sSearchCat = $sSearchCat?rawurldecode( $sSearchCat ):$sSearchCat;
00262 
00263             $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00264             $sSearchVendor = $sSearchVendor?rawurldecode( $sSearchVendor ):$sSearchVendor;
00265 
00266             $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' );
00267             $sSearchManufacturer = $sSearchManufacturer?rawurldecode( $sSearchManufacturer ):$sSearchManufacturer;
00268 
00269             // loading data for article navigation
00270             $oIdList = oxNew( 'oxarticlelist' );
00271             if ( $oLocatorTarget->showSorting() ) {
00272                 $oLocatorTarget->prepareSortColumns();
00273                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxsearch' ) );
00274             }
00275             $oIdList->loadSearchIds( $sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer );
00276 
00277             //page number
00278             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00279 
00280             $sAddSearch = "searchparam={$sSearchLinkParam}";
00281             if ( $sSearchCat !== null ) {
00282                 $sAddSearch .= "&amp;searchcnid={$sSearchCat}";
00283             }
00284 
00285             if ( $sSearchVendor !== null ) {
00286                 $sAddSearch .= "&amp;searchvendor={$sSearchVendor}";
00287             }
00288 
00289             if ( $sSearchManufacturer !== null ) {
00290                 $sAddSearch .= "&amp;searchmanufacturer={$sSearchManufacturer}";
00291             }
00292 
00293             // setting product position in list, amount of articles etc
00294             $oSearchCat->iCntOfProd  = $oIdList->count();
00295             $oSearchCat->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00296 
00297             $sPageNr = $this->_getPageNumber( $iPage );
00298             $oSearchCat->toListLink  = $this->_makeLink( $oSearchCat->link, $sPageNr.($sPageNr?'&amp;':'').$sAddSearch );
00299             $oSearchCat->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00300             $oSearchCat->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00301 
00302             $sFormat = oxLang::getInstance()->translateString( 'searchResult' );
00303             $oLocatorTarget->setSearchTitle( sprintf( $sFormat, $sSearchFormParam ) );
00304             // for compatibility reasons for a while. will be removed in future
00305             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00306 
00307             $oLocatorTarget->addTplParam( 'searchparam', $sSearchLinkParam );
00308             $oLocatorTarget->addTplParam( 'searchcnid', $sSearchCat );
00309             $oLocatorTarget->addTplParam( 'searchvendor', $sSearchVendor );
00310             $oLocatorTarget->addTplParam( 'searchmanufacturer', $sSearchManufacturer );
00311             $oLocatorTarget->addTplParam( 'searchparamforhtml', $sSearchFormParam );
00312 
00313             $oLocatorTarget->setActiveCategory( $oSearchCat );
00314             // for compatibility reasons for a while. will be removed in future
00315             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00316         }
00317     }
00318 
00330     protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00331     {
00332         if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00333 
00334             $myUtils = oxUtils::getInstance();
00335 
00336             // loading data for article navigation
00337             $oIdList = oxNew( 'oxarticlelist' );
00338             $oLang = oxLang::getInstance();
00339 
00340             if ( $oLocatorTarget->showSorting() ) {
00341                 $oLocatorTarget->prepareSortColumns();
00342                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxtags' ) );
00343             }
00344 
00345             $oIdList->getTagArticleIds( $oTag->sTag, $oLang->getBaseLanguage() );
00346 
00347             //page number
00348             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00349 
00350             // setting product position in list, amount of articles etc
00351             $oTag->iCntOfProd  = $oIdList->count();
00352             $oTag->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00353 
00354             $sPageNr = $this->_getPageNumber( $iPage );
00355             $oTag->toListLink  = $this->_makeLink( $oTag->link, $sPageNr );
00356 
00357             $sAddSearch = '';
00358             // setting parameters when seo is Off
00359             if ( !$myUtils->seoIsActive() ) {
00360                 $sAddSearch  = 'searchtag='.rawurlencode( oxConfig::getParameter( 'searchtag', 1 ) );
00361                 $sAddSearch .= '&amp;listtype=tag';
00362             }
00363 
00364             $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00365             $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00366             $oStr = getStr();
00367             $oLocatorTarget->setSearchTitle( $oLang->translateString('TAGS').' / '.$oStr->htmlspecialchars( $oStr->ucfirst( $oTag->sTag ) ) );
00368             // for compatibility reasons for a while. will be removed in future
00369             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00370             $oLocatorTarget->addTplParam( 'searchtagforhtml', null );
00371             $oLocatorTarget->setActiveCategory( $oTag );
00372             // for compatibility reasons for a while. will be removed in future
00373             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00374         }
00375     }
00376 
00388     protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00389     {
00390         if ( ( $oRecommList = $oLocatorTarget->getActRecommList() ) ) {
00391 
00392             // loading data for article navigation
00393             $oIdList = oxNew( 'oxarticlelist' );
00394             $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00395 
00396             //page number
00397             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00398 
00399             $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00400 
00401             if ( $sSearchRecomm !== null ) {
00402                 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00403                 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00404                 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00405             }
00406 
00407             // setting product position in list, amount of articles etc
00408             $oRecommList->iCntOfProd  = $oIdList->count();
00409             $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00410 
00411             $sPageNr = $this->_getPageNumber( $iPage );
00412             $oRecommList->toListLink  = $this->_makeLink( $oRecommList->getLink(), $sPageNr.(($sPageNr && $sAddSearch)?'&amp;':'').$sAddSearch );
00413 
00414             $sAdd = 'recommid='.$oRecommList->getId().'&amp;listtype=recommlist'.($sAddSearch?'&amp;':'').$sAddSearch;
00415             $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00416             $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00417 
00418             $oLang  = oxLang::getInstance();
00419             $sTitle = $oLang->translateString('RECOMMLIST');
00420             if ( $sSearchRecomm !== null ) {
00421                 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00422                 $oLocatorTarget->addTplParam( 'searchrecomm', $sSearchLinkRecomm );
00423                 $oLocatorTarget->addTplParam( 'searchrecommforhtml', $sSearchFormRecomm );
00424             }
00425             $oLocatorTarget->setSearchTitle( $sTitle );
00426             // for compatibility reasons for a while. will be removed in future
00427             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00428             $oLocatorTarget->setActiveCategory( $oRecommList );
00429             // for compatibility reasons for a while. will be removed in future
00430             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00431         }
00432     }
00433 
00443     protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00444     {
00445         $oIdList = oxNew( 'oxarticlelist' );
00446         $oIdList->setCustomSorting( $sOrderBy ) ;
00447 
00448         // additionally check if this category is loaded and is price category ?
00449         if ( $oCategory->isPriceCategory() ) {
00450             $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00451         } else {
00452             $sActCat = $oCategory->getId();
00453             $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00454             // if not found - reloading with empty filter
00455             if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00456                 $oIdList->loadCategoryIDs( $sActCat, null );
00457             }
00458         }
00459 
00460         return $oIdList;
00461     }
00462 
00471     protected function _makeLink( $sLink, $sParams )
00472     {
00473         if ( $sParams ) {
00474             $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&amp;' : '?' ) . $sParams;
00475         }
00476         return $sLink;
00477     }
00478 
00489     protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00490     {
00491         //page number
00492         $iPageNr = (int) $iPageNr;
00493 
00494         // maybe there is no page number passed, but we still can find the position in id's list
00495         if ( !$iPageNr && $oIdList && $oArticle ) {
00496             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00497             $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00498 
00499             $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00500             $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00501             $iPageNr = floor( $iPos / $iNrofCatArticles );
00502         }
00503 
00504         return $iPageNr;
00505     }
00506 
00514     protected function _getPageNumber( $iPageNr )
00515     {
00516         //page number
00517         $iPageNr = (int) $iPageNr;
00518         return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00519     }
00520 
00530     protected function _getProductPos( $oArticle, $oIdList, $oLocatorTarget )
00531     {
00532         $iCnt = 1;
00533         $iPos = 0;
00534 
00535         // variant handling
00536         $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00537         if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00538 
00539             $aIds = $oIdList->arrayKeys();
00540             $iPos = array_search( $sOxid, $aIds );
00541 
00542             if ( array_key_exists( $iPos-1, $aIds ) ) {
00543                 $oBackProduct = oxNew( 'oxarticle' );
00544                 $oBackProduct->setNoVariantLoading( true );
00545                 if ( $oBackProduct->load( $aIds[$iPos-1] ) ) {
00546                     $oBackProduct->setLinkType( $oLocatorTarget->getLinkType() );
00547                     $this->_oBackProduct = $oBackProduct;
00548                 }
00549             }
00550 
00551             if ( array_key_exists( $iPos+1, $aIds ) ) {
00552                 $oNextProduct = oxNew( 'oxarticle' );
00553                 $oNextProduct->setNoVariantLoading( true );
00554                 if ( $oNextProduct->load( $aIds[$iPos+1] ) ) {
00555                     $oNextProduct->setLinkType( $oLocatorTarget->getLinkType() );
00556                     $this->_oNextProduct = $oNextProduct;
00557                 }
00558             }
00559             return $iPos+1;
00560         }
00561         return 0;
00562     }
00563 
00569     public function getErrorMessage()
00570     {
00571         return $this->_sErrorMessage;
00572     }
00573 }

Generated on Tue Sep 29 16:45:15 2009 for OXID eShop CE by  doxygen 1.5.5