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
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
00061 $oLocatorTarget->setListType( $this->_sType );
00062 }
00063
00072 protected function _setListLocatorData( $oLocatorTarget, $oCurrArticle )
00073 {
00074
00075 if ( ( $oCategory = $oLocatorTarget->getActCategory() ) ) {
00076 $sCatId = $oCategory->getId();
00077
00078 $sOrderBy = null;
00079 if ( $oLocatorTarget->showSorting() ) {
00080 $aSorting = $oLocatorTarget->getSorting( $sCatId );
00081
00082 if ( !$aSorting && $oCategory->oxcategories__oxdefsort->value ) {
00083
00084
00085 $sSortBy = getViewName( 'oxarticles' ) . ".{$oCategory->oxcategories__oxdefsort->value}";
00086 $sSortDir = ( $oCategory->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00087 $oLocatorTarget->setItemSorting( $sCatId, $sSortBy, $sSortDir );
00088 }
00089 $oLocatorTarget->prepareSortColumns();
00090 $sOrderBy = $oLocatorTarget->getSortingSql( $sCatId );
00091 }
00092
00093 $oIdList = $this->_loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy );
00094
00095
00096 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00097
00098
00099 $oCategory->iCntOfProd = $oIdList->count();
00100 $oCategory->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00101
00102 if ( oxRegistry::getUtils()->seoIsActive() && $iPage ) {
00103 $oCategory->toListLink = oxRegistry::get("oxSeoEncoderCategory")->getCategoryPageUrl( $oCategory, $iPage );
00104 } else {
00105 $oCategory->toListLink = $this->_makeLink( $oCategory->getLink(), $this->_getPageNumber( $iPage ) );
00106 }
00107
00108 $oCategory->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), '' ):null;
00109 $oCategory->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), '' ):null;
00110
00111
00112 $oLocatorTarget->setActiveCategory( $oCategory );
00113
00114
00115 if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00116 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00117 }
00118 }
00119 }
00120
00129 protected function _setVendorLocatorData( $oLocatorTarget, $oCurrArticle )
00130 {
00131 if ( ( $oVendor = $oLocatorTarget->getActVendor() ) ) {
00132 $sVendorId = $oVendor->getId();
00133 $myUtils = oxRegistry::getUtils();
00134
00135 $blSeo = $myUtils->seoIsActive();
00136
00137
00138 $oIdList = oxNew( "oxarticlelist" );
00139 if ( $oLocatorTarget->showSorting() ) {
00140 $oLocatorTarget->prepareSortColumns();
00141 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sVendorId:vendor" ) );
00142 }
00143 $oIdList->loadVendorIds( $sVendorId );
00144
00145
00146 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00147
00148 $sAdd = null;
00149 if ( !$blSeo ) {
00150 $sAdd = 'listtype=vendor&cnid=v_'.$sVendorId;
00151 }
00152
00153
00154 $oVendor->iCntOfProd = $oIdList->count();
00155 $oVendor->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00156
00157 if ( $blSeo && $iPage ) {
00158 $oVendor->toListLink = oxRegistry::get("oxSeoEncoderVendor")->getVendorPageUrl( $oVendor, $iPage );
00159 } else {
00160 $oVendor->toListLink = $this->_makeLink( $oVendor->getLink(), $this->_getPageNumber( $iPage ) );
00161 }
00162
00163 $oVendor->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00164 $oVendor->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00165
00166
00167 $oLocatorTarget->setActiveCategory( $oVendor );
00168
00169
00170 if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00171 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00172 }
00173 }
00174 }
00175
00184 protected function _setManufacturerLocatorData( $oLocatorTarget, $oCurrArticle )
00185 {
00186 if ( ( $oManufacturer = $oLocatorTarget->getActManufacturer() ) ) {
00187 $sManufacturerId = $oManufacturer->getId();
00188 $myUtils = oxRegistry::getUtils();
00189
00190 $blSeo = $myUtils->seoIsActive();
00191
00192
00193 $oIdList = oxNew( "oxarticlelist" );
00194 if ( $oLocatorTarget->showSorting() ) {
00195 $oLocatorTarget->prepareSortColumns();
00196 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( "$sManufacturerId:manufacturer" ) );
00197 }
00198 $oIdList->loadManufacturerIds( $sManufacturerId );
00199
00200
00201 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00202
00203 $sAdd = null;
00204 if ( !$blSeo ) {
00205 $sAdd = 'listtype=manufacturer&mnid='.$sManufacturerId;
00206 }
00207
00208
00209 $oManufacturer->iCntOfProd = $oIdList->count();
00210 $oManufacturer->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00211
00212 if ( $blSeo && $iPage ) {
00213 $oManufacturer->toListLink = oxRegistry::get("oxSeoEncoderManufacturer")->getManufacturerPageUrl( $oManufacturer, $iPage );
00214 } else {
00215 $oManufacturer->toListLink = $this->_makeLink( $oManufacturer->getLink(), $this->_getPageNumber( $iPage ) );
00216 }
00217
00218 $oManufacturer->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00219 $oManufacturer->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00220
00221
00222 $oLocatorTarget->setActiveCategory( $oManufacturer );
00223
00224
00225 if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00226 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00227 }
00228 }
00229 }
00230
00239 protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00240 {
00241 if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00242
00243
00244 $sSearchParam = oxConfig::getParameter( 'searchparam', true );
00245 $sSearchFormParam = oxConfig::getParameter( 'searchparam' );
00246 $sSearchLinkParam = rawurlencode( $sSearchParam );
00247
00248 $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00249 $sSearchCat = $sSearchCat?rawurldecode( $sSearchCat ):$sSearchCat;
00250
00251 $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00252 $sSearchVendor = $sSearchVendor?rawurldecode( $sSearchVendor ):$sSearchVendor;
00253
00254 $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' );
00255 $sSearchManufacturer = $sSearchManufacturer?rawurldecode( $sSearchManufacturer ):$sSearchManufacturer;
00256
00257
00258 $oIdList = oxNew( 'oxarticlelist' );
00259 if ( $oLocatorTarget->showSorting() ) {
00260 $oLocatorTarget->prepareSortColumns();
00261 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxsearch' ) );
00262 }
00263 $oIdList->loadSearchIds( $sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer );
00264
00265
00266 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00267
00268 $sAddSearch = "searchparam={$sSearchLinkParam}";
00269 $sAddSearch .= '&listtype=search';
00270
00271 if ( $sSearchCat !== null ) {
00272 $sAddSearch .= "&searchcnid={$sSearchCat}";
00273 }
00274
00275 if ( $sSearchVendor !== null ) {
00276 $sAddSearch .= "&searchvendor={$sSearchVendor}";
00277 }
00278
00279 if ( $sSearchManufacturer !== null ) {
00280 $sAddSearch .= "&searchmanufacturer={$sSearchManufacturer}";
00281 }
00282
00283
00284 $oSearchCat->iCntOfProd = $oIdList->count();
00285 $oSearchCat->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00286
00287 $sPageNr = $this->_getPageNumber( $iPage );
00288 $oSearchCat->toListLink = $this->_makeLink( $oSearchCat->link, $sPageNr.($sPageNr?'&':'').$sAddSearch );
00289 $oSearchCat->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00290 $oSearchCat->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00291
00292 $sFormat = oxRegistry::getLang()->translateString( 'searchResult' );
00293 $oLocatorTarget->setSearchTitle( sprintf( $sFormat, $sSearchFormParam ) );
00294 $oLocatorTarget->setActiveCategory( $oSearchCat );
00295 }
00296 }
00297
00306 protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00307 {
00308 if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00309
00310 $myUtils = oxRegistry::getUtils();
00311
00312
00313 $oIdList = oxNew( 'oxarticlelist' );
00314 $oLang = oxRegistry::getLang();
00315
00316 if ( $oLocatorTarget->showSorting() ) {
00317 $oLocatorTarget->prepareSortColumns();
00318 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( 'oxtags' ) );
00319 }
00320
00321 $oIdList->getTagArticleIds( $oTag->sTag, $oLang->getBaseLanguage() );
00322
00323
00324 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00325
00326
00327 $oTag->iCntOfProd = $oIdList->count();
00328 $oTag->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00329
00330 if ( oxRegistry::getUtils()->seoIsActive() ) {
00331 $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl( $oTag->sTag, $iPage );
00332 } else {
00333 $sPageNr = $this->_getPageNumber( $iPage );
00334 $oTag->toListLink = $this->_makeLink( $oTag->link, $sPageNr );
00335 }
00336
00337 $sAddSearch = '';
00338
00339 if ( !$myUtils->seoIsActive() ) {
00340 $sAddSearch = 'searchtag='.rawurlencode( oxConfig::getParameter( 'searchtag', 1 ) );
00341 $sAddSearch .= '&listtype=tag';
00342 }
00343
00344 $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00345 $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00346 $oStr = getStr();
00347 $oLocatorTarget->setSearchTitle( $oLang->translateString('TAGS').' / '.$oStr->htmlspecialchars( $oStr->ucfirst( $oTag->sTag ) ) );
00348 $oLocatorTarget->setActiveCategory( $oTag );
00349 }
00350 }
00351
00363 protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00364 {
00365 if ( ( $oRecommList = $oLocatorTarget->getActiveRecommList() ) ) {
00366
00367
00368 $oIdList = oxNew( 'oxarticlelist' );
00369 $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00370
00371
00372 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00373
00374 $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00375
00376 if ( $sSearchRecomm !== null ) {
00377 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00378 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00379 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00380 }
00381
00382
00383 $oRecommList->iCntOfProd = $oIdList->count();
00384 $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00385 $blSeo = oxRegistry::getUtils()->seoIsActive();
00386
00387 if ( $blSeo && $iPage ) {
00388 $oRecommList->toListLink = oxRegistry::get("oxSeoEncoderRecomm")->getRecommPageUrl( $oRecommList, $iPage );
00389 } else {
00390 $oRecommList->toListLink = $this->_makeLink( $oRecommList->getLink(), $this->_getPageNumber( $iPage ) );
00391 }
00392 $oRecommList->toListLink = $this->_makeLink( $oRecommList->toListLink, $sAddSearch );
00393
00394 $sAdd = '';
00395 if ( !$blSeo ) {
00396 $sAdd = 'recommid='.$oRecommList->getId().'&listtype=recommlist'.($sAddSearch?'&':'');
00397 }
00398 $sAdd .= $sAddSearch;
00399 $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00400 $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00401
00402 $oLang = oxRegistry::getLang();
00403 $sTitle = $oLang->translateString('RECOMMLIST');
00404 if ( $sSearchRecomm !== null ) {
00405 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00406 }
00407 $oLocatorTarget->setSearchTitle( $sTitle );
00408 $oLocatorTarget->setActiveCategory( $oRecommList );
00409 }
00410 }
00411
00421 protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00422 {
00423 $oIdList = oxNew( 'oxarticlelist' );
00424 $oIdList->setCustomSorting( $sOrderBy ) ;
00425
00426
00427 if ( $oCategory->isPriceCategory() ) {
00428 $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00429 } else {
00430 $sActCat = $oCategory->getId();
00431 $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00432
00433 if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00434 $oIdList->loadCategoryIDs( $sActCat, null );
00435 }
00436 }
00437
00438 return $oIdList;
00439 }
00440
00449 protected function _makeLink( $sLink, $sParams )
00450 {
00451 if ( $sParams ) {
00452 $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&' : '?' ) . $sParams;
00453 }
00454 return $sLink;
00455 }
00456
00467 protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00468 {
00469
00470 $iPageNr = (int) $iPageNr;
00471
00472
00473 if ( !$iPageNr && $oIdList && $oArticle ) {
00474 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00475 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00476
00477 $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00478 $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00479 $iPageNr = floor( $iPos / $iNrofCatArticles );
00480 }
00481
00482 return $iPageNr;
00483 }
00484
00492 protected function _getPageNumber( $iPageNr )
00493 {
00494
00495 $iPageNr = (int) $iPageNr;
00496 return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00497 }
00498
00508 protected function _getProductPos( $oArticle, $oIdList, $oLocatorTarget )
00509 {
00510 $iCnt = 1;
00511 $iPos = 0;
00512
00513
00514 $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00515 if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00516
00517 $aIds = $oIdList->arrayKeys();
00518 $iPos = array_search( $sOxid, $aIds );
00519
00520 if ( array_key_exists( $iPos-1, $aIds ) ) {
00521 $oBackProduct = oxNew( 'oxarticle' );
00522 $oBackProduct->modifyCacheKey('_locator');
00523 $oBackProduct->setNoVariantLoading( true );
00524 if ( $oBackProduct->load( $aIds[$iPos-1] ) ) {
00525 $oBackProduct->setLinkType( $oLocatorTarget->getLinkType() );
00526 $this->_oBackProduct = $oBackProduct;
00527 }
00528 }
00529
00530 if ( array_key_exists( $iPos+1, $aIds ) ) {
00531 $oNextProduct = oxNew( 'oxarticle' );
00532 $oNextProduct->modifyCacheKey('_locator');
00533 $oNextProduct->setNoVariantLoading( true );
00534 if ( $oNextProduct->load( $aIds[$iPos+1] ) ) {
00535 $oNextProduct->setLinkType( $oLocatorTarget->getLinkType() );
00536 $this->_oNextProduct = $oNextProduct;
00537 }
00538 }
00539 return $iPos+1;
00540 }
00541 return 0;
00542 }
00543
00549 public function getErrorMessage()
00550 {
00551 return $this->_sErrorMessage;
00552 }
00553 }