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( $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             $myUtils   = oxUtils::getInstance();
00132 
00133             // loading data for article navigation
00134             $oIdList = oxNew( "oxarticlelist" );
00135             if ( $oLocatorTarget->showSorting() ) {
00136                 $oLocatorTarget->prepareSortColumns();
00137                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sVendorId:vendor" ) );
00138             }
00139             $oIdList->loadVendorIds( $sVendorId );
00140 
00141             //page number
00142             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00143 
00144             $sAdd = null;
00145             if ( !$myUtils->seoIsActive() ) {
00146                 $sAdd = 'listtype=vendor&amp;cnid=v_'.$sVendorId;
00147             }
00148 
00149             // setting product position in list, amount of articles etc
00150             $oVendor->iCntOfProd  = $oIdList->count();
00151             $oVendor->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00152 
00153             if ( $myUtils->seoIsActive() && $iPage ) {
00154                 $oVendor->toListLink = oxSeoEncoderVendor::getInstance()->getVendorPageUrl( $oVendor, $iPage );
00155             } else {
00156                 $oVendor->toListLink  = $this->_makeLink( $oVendor->getLink(), $this->_getPageNumber( $iPage ) );
00157             }
00158 
00159             // forcing vendor links
00160             if ( $this->_oNextProduct ) {
00161                 $this->_oNextProduct->setLinkType( OXARTICLE_LINKTYPE_VENDOR );
00162             }
00163 
00164             if ( $this->_oBackProduct ) {
00165                 $this->_oBackProduct->setLinkType( OXARTICLE_LINKTYPE_VENDOR );
00166             }
00167 
00168             $oVendor->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00169             $oVendor->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00170 
00171             // active vendor
00172             $oLocatorTarget->setActiveCategory( $oVendor );
00173             // for compatibility reasons for a while. will be removed in future
00174             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00175 
00176             // vendor path
00177             if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00178                 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00179                 // for compatibility reasons for a while. will be removed in future
00180                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00181             }
00182         }
00183     }
00184 
00196     protected function _setManufacturerLocatorData( $oLocatorTarget, $oCurrArticle )
00197     {
00198         if ( ( $oManufacturer = $oLocatorTarget->getActManufacturer() ) ) {
00199             $sManufacturerId = $oManufacturer->getId();
00200             $myUtils = oxUtils::getInstance();
00201 
00202             // loading data for article navigation
00203             $oIdList = oxNew( "oxarticlelist" );
00204             if ( $oLocatorTarget->showSorting() ) {
00205                 $oLocatorTarget->prepareSortColumns();
00206                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sManufacturerId:manufacturer" ) );
00207             }
00208             $oIdList->loadManufacturerIds( $sManufacturerId );
00209 
00210             //page number
00211             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00212 
00213             $sAdd = null;
00214             if ( !$myUtils->seoIsActive() ) {
00215                 $sAdd = 'listtype=manufacturer&amp;mnid='.$sManufacturerId;
00216             }
00217 
00218             // setting product position in list, amount of articles etc
00219             $oManufacturer->iCntOfProd  = $oIdList->count();
00220             $oManufacturer->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00221 
00222             if ( $myUtils->seoIsActive() && $iPage ) {
00223                 $oManufacturer->toListLink = oxSeoEncoderManufacturer::getInstance()->getManufacturerPageUrl( $oManufacturer, $iPage );
00224             } else {
00225                 $oManufacturer->toListLink  = $this->_makeLink( $oManufacturer->getLink(), $this->_getPageNumber( $iPage ) );
00226             }
00227 
00228             // forcing Manufacturer links
00229             if ( $this->_oNextProduct ) {
00230                 $this->_oNextProduct->setLinkType( OXARTICLE_LINKTYPE_MANUFACTURER );
00231             }
00232 
00233             if ( $this->_oBackProduct ) {
00234                 $this->_oBackProduct->setLinkType( OXARTICLE_LINKTYPE_MANUFACTURER );
00235             }
00236 
00237             $oManufacturer->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00238             $oManufacturer->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00239 
00240             // active Manufacturer
00241             $oLocatorTarget->setActiveCategory( $oManufacturer );
00242             // for compatibility reasons for a while. will be removed in future
00243             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00244 
00245             // Manufacturer path
00246             if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00247                 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00248                 // for compatibility reasons for a while. will be removed in future
00249                 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00250             }
00251         }
00252     }
00253 
00266     protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00267     {
00268         if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00269 
00270             // #1834/1184M - specialchar search
00271             $sSearchParam = oxConfig::getParameter( 'searchparam', true );
00272             $sSearchFormParam = oxConfig::getParameter( 'searchparam' );
00273             $sSearchLinkParam = rawurlencode( $sSearchParam );
00274 
00275             $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00276             $sSearchCat = $sSearchCat?rawurldecode( $sSearchCat ):$sSearchCat;
00277 
00278             $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00279             $sSearchVendor = $sSearchVendor?rawurldecode( $sSearchVendor ):$sSearchVendor;
00280 
00281             $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' );
00282             $sSearchManufacturer = $sSearchManufacturer?rawurldecode( $sSearchManufacturer ):$sSearchManufacturer;
00283 
00284             // loading data for article navigation
00285             $oIdList = oxNew( 'oxarticlelist' );
00286             if ( $oLocatorTarget->showSorting() ) {
00287                 $oLocatorTarget->prepareSortColumns();
00288                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxsearch' ) );
00289             }
00290             $oIdList->loadSearchIds( $sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer );
00291 
00292             //page number
00293             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00294 
00295             $sAddSearch = "searchparam={$sSearchLinkParam}";
00296             if ( $sSearchCat !== null ) {
00297                 $sAddSearch .= "&amp;searchcnid={$sSearchCat}";
00298             }
00299 
00300             if ( $sSearchVendor !== null ) {
00301                 $sAddSearch .= "&amp;searchvendor={$sSearchVendor}";
00302             }
00303 
00304             if ( $sSearchManufacturer !== null ) {
00305                 $sAddSearch .= "&amp;searchmanufacturer={$sSearchManufacturer}";
00306             }
00307 
00308             // setting product position in list, amount of articles etc
00309             $oSearchCat->iCntOfProd  = $oIdList->count();
00310             $oSearchCat->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00311 
00312             $sPageNr = $this->_getPageNumber( $iPage );
00313             $oSearchCat->toListLink  = $this->_makeLink( $oSearchCat->link, $sPageNr.($sPageNr?'&amp;':'').$sAddSearch );
00314             $oSearchCat->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00315             $oSearchCat->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00316 
00317             $sFormat = oxLang::getInstance()->translateString( 'searchResult' );
00318             $oLocatorTarget->setSearchTitle( sprintf( $sFormat, $sSearchFormParam ) );
00319             // for compatibility reasons for a while. will be removed in future
00320             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00321 
00322             $oLocatorTarget->addTplParam( 'searchparam', $sSearchLinkParam );
00323             $oLocatorTarget->addTplParam( 'searchcnid', $sSearchCat );
00324             $oLocatorTarget->addTplParam( 'searchvendor', $sSearchVendor );
00325             $oLocatorTarget->addTplParam( 'searchmanufacturer', $sSearchManufacturer );
00326             $oLocatorTarget->addTplParam( 'searchparamforhtml', $sSearchFormParam );
00327 
00328             $oLocatorTarget->setActiveCategory( $oSearchCat );
00329             // for compatibility reasons for a while. will be removed in future
00330             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00331         }
00332     }
00333 
00345     protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00346     {
00347         if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00348 
00349             // loading data for article navigation
00350             $oIdList = oxNew( 'oxarticlelist' );
00351             $oLang = oxLang::getInstance();
00352 
00353             if ( $oLocatorTarget->showSorting() ) {
00354                 $oLocatorTarget->prepareSortColumns();
00355                 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxtags' ) );
00356             }
00357 
00358             $oIdList->getTagArticleIds( $oTag->sTag, $oLang->getBaseLanguage() );
00359 
00360             //page number
00361             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00362 
00363             $sAddSearch = 'searchtag='.rawurlencode(oxConfig::getParameter( 'searchtag', 1));
00364 
00365             // setting product position in list, amount of articles etc
00366             $oTag->iCntOfProd  = $oIdList->count();
00367             $oTag->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00368 
00369             $sPageNr = $this->_getPageNumber( $iPage );
00370             $oTag->toListLink  = $this->_makeLink( $oTag->link, $sPageNr.($sPageNr?'&amp;':'').$sAddSearch );
00371 
00372             $sAddSearch .= '&amp;listtype=tag';
00373             $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00374             $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00375             $oStr = getStr();
00376             $oLocatorTarget->setSearchTitle( $oLang->translateString('TAGS').' / '.$oStr->htmlspecialchars( $oStr->ucfirst( $oTag->sTag ) ) );
00377             // for compatibility reasons for a while. will be removed in future
00378             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00379             $oLocatorTarget->addTplParam( 'searchtagforhtml', null );
00380             $oLocatorTarget->setActiveCategory( $oTag );
00381             // for compatibility reasons for a while. will be removed in future
00382             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00383         }
00384     }
00385 
00397     protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00398     {
00399         if ( ( $oRecommList = $oLocatorTarget->getActRecommList() ) ) {
00400 
00401             // loading data for article navigation
00402             $oIdList = oxNew( 'oxarticlelist' );
00403             $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00404 
00405             //page number
00406             $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00407 
00408             $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00409 
00410             if ( $sSearchRecomm !== null ) {
00411                 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00412                 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00413                 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00414             }
00415 
00416             // setting product position in list, amount of articles etc
00417             $oRecommList->iCntOfProd  = $oIdList->count();
00418             $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList );
00419 
00420             $sPageNr = $this->_getPageNumber( $iPage );
00421             $oRecommList->toListLink  = $this->_makeLink( $oRecommList->getLink(), $sPageNr.(($sPageNr && $sAddSearch)?'&amp;':'').$sAddSearch );
00422 
00423             $sAdd = 'recommid='.$oRecommList->getId().'&amp;listtype=recommlist'.($sAddSearch?'&amp;':'').$sAddSearch;
00424             $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00425             $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00426 
00427             $oLang  = oxLang::getInstance();
00428             $sTitle = $oLang->translateString('RECOMMLIST');
00429             if ( $sSearchRecomm !== null ) {
00430                 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00431                 $oLocatorTarget->addTplParam( 'searchrecomm', $sSearchLinkRecomm );
00432                 $oLocatorTarget->addTplParam( 'searchrecommforhtml', $sSearchFormRecomm );
00433             }
00434             $oLocatorTarget->setSearchTitle( $sTitle );
00435             // for compatibility reasons for a while. will be removed in future
00436             $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00437             $oLocatorTarget->setActiveCategory( $oRecommList );
00438             // for compatibility reasons for a while. will be removed in future
00439             $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00440         }
00441     }
00442 
00452     protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00453     {
00454         $oIdList = oxNew( 'oxarticlelist' );
00455         $oIdList->setCustomSorting( $sOrderBy ) ;
00456 
00457         // additionally check if this category is loaded and is price category ?
00458         if ( $oCategory->oxcategories__oxpricefrom->value || $oCategory->oxcategories__oxpriceto->value ) {
00459 
00460             $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00461         } else {
00462 
00463             $sActCat = $oCategory->getId();
00464             $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00465             // if not found - reloading with empty filter
00466             if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00467                 $oIdList->loadCategoryIDs( $sActCat, null );
00468             }
00469         }
00470 
00471         return $oIdList;
00472     }
00473 
00482     protected function _makeLink( $sLink, $sParams )
00483     {
00484         if ( $sParams ) {
00485             $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&amp;' : '?' ) . $sParams;
00486         }
00487         return $sLink;
00488     }
00489 
00500     protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00501     {
00502         //page number
00503         $iPageNr = (int) $iPageNr;
00504 
00505         // maybe there is no page number passed, but we still can find the position in id's list
00506         if ( !$iPageNr && $oIdList && $oArticle ) {
00507             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00508             $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00509 
00510             $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00511             $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00512             $iPageNr = floor( $iPos / $iNrofCatArticles );
00513         }
00514 
00515         return $iPageNr;
00516     }
00517 
00525     protected function _getPageNumber( $iPageNr )
00526     {
00527         //page number
00528         $iPageNr = (int) $iPageNr;
00529         return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00530     }
00531 
00540     protected function _getProductPos( $oArticle, $oIdList )
00541     {
00542         $iCnt = 1;
00543         $iPos = 0;
00544 
00545         // variant handling
00546         $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00547 
00548         if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00549 
00550             $aIds = $oIdList->arrayKeys();
00551 
00552             $iPos = array_search($sOxid, $aIds);
00553 
00554             if (array_key_exists($iPos-1, $aIds)) {
00555                 $this->_oBackProduct = oxNew( 'oxarticle' );
00556                 $this->_oBackProduct->setNoVariantLoading(true);
00557                 if (!$this->_oBackProduct->load( $aIds[$iPos-1] )) {
00558                     $this->_oBackProduct = null;
00559                 }
00560             }
00561 
00562             if (array_key_exists($iPos+1, $aIds)) {
00563                 $this->_oNextProduct = oxNew( 'oxarticle' );
00564                 $this->_oNextProduct->setNoVariantLoading(true);
00565                 if (!$this->_oNextProduct->load( $aIds[$iPos+1] )) {
00566                     $this->_oNextProduct = null;
00567                 }
00568             }
00569             return $iPos+1;
00570         }
00571         return 0;
00572     }
00573 
00579     public function getErrorMessage()
00580     {
00581         return $this->_sErrorMessage;
00582     }
00583 
00584 }

Generated on Tue Apr 21 15:45:45 2009 for OXID eShop CE by  doxygen 1.5.5