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 $oLocatorTarget->prepareSortColumns();
00081 $sOrderBy = $oLocatorTarget->getSortingSql( $sCatId );
00082 }
00083 $oIdList = $this->_loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy );
00084
00085
00086 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00087
00088
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
00102 $oLocatorTarget->setActiveCategory( $oCategory );
00103
00104 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00105
00106
00107 if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00108 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00109
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
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
00143 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00144
00145 $sAdd = null;
00146 if ( !$blSeo ) {
00147 $sAdd = 'listtype=vendor&cnid=v_'.$sVendorId;
00148 }
00149
00150
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
00164 $oLocatorTarget->setActiveCategory( $oVendor );
00165
00166 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00167
00168
00169 if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00170 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00171
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
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
00205 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00206
00207 $sAdd = null;
00208 if ( !$blSeo ) {
00209 $sAdd = 'listtype=manufacturer&mnid='.$sManufacturerId;
00210 }
00211
00212
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
00226 $oLocatorTarget->setActiveCategory( $oManufacturer );
00227
00228 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00229
00230
00231 if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00232 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00233
00234 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00235 }
00236 }
00237 }
00238
00251 protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00252 {
00253 if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00254
00255
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
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
00278 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00279
00280 $sAddSearch = "searchparam={$sSearchLinkParam}";
00281 if ( $sSearchCat !== null ) {
00282 $sAddSearch .= "&searchcnid={$sSearchCat}";
00283 }
00284
00285 if ( $sSearchVendor !== null ) {
00286 $sAddSearch .= "&searchvendor={$sSearchVendor}";
00287 }
00288
00289 if ( $sSearchManufacturer !== null ) {
00290 $sAddSearch .= "&searchmanufacturer={$sSearchManufacturer}";
00291 }
00292
00293
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?'&':'').$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
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
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
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
00348 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00349
00350
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
00359 if ( !$myUtils->seoIsActive() ) {
00360 $sAddSearch = 'searchtag='.rawurlencode( oxConfig::getParameter( 'searchtag', 1 ) );
00361 $sAddSearch .= '&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
00369 $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00370 $oLocatorTarget->addTplParam( 'searchtagforhtml', null );
00371 $oLocatorTarget->setActiveCategory( $oTag );
00372
00373 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00374 }
00375 }
00376
00388 protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00389 {
00390 if ( ( $oRecommList = $oLocatorTarget->getActiveRecommList() ) ) {
00391
00392
00393 $oIdList = oxNew( 'oxarticlelist' );
00394 $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00395
00396
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
00408 $oRecommList->iCntOfProd = $oIdList->count();
00409 $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00410 $blSeo = oxUtils::getInstance()->seoIsActive();
00411
00412 if ( $blSeo && $iPage ) {
00413 $oRecommList->toListLink = oxSeoEncoderRecomm::getInstance()->getRecommPageUrl( $oRecommList, $iPage );
00414 } else {
00415 $oRecommList->toListLink = $this->_makeLink( $oRecommList->getLink(), $this->_getPageNumber( $iPage ) );
00416 }
00417 $oRecommList->toListLink = $this->_makeLink( $oRecommList->toListLink, $sAddSearch );
00418
00419 $sAdd = '';
00420 if ( !$blSeo ) {
00421 $sAdd = 'recommid='.$oRecommList->getId().'&listtype=recommlist'.($sAddSearch?'&':'');
00422 }
00423 $sAdd .= $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
00436 $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00437 $oLocatorTarget->setActiveCategory( $oRecommList );
00438
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
00458 if ( $oCategory->isPriceCategory() ) {
00459 $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00460 } else {
00461 $sActCat = $oCategory->getId();
00462 $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00463
00464 if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00465 $oIdList->loadCategoryIDs( $sActCat, null );
00466 }
00467 }
00468
00469 return $oIdList;
00470 }
00471
00480 protected function _makeLink( $sLink, $sParams )
00481 {
00482 if ( $sParams ) {
00483 $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&' : '?' ) . $sParams;
00484 }
00485 return $sLink;
00486 }
00487
00498 protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00499 {
00500
00501 $iPageNr = (int) $iPageNr;
00502
00503
00504 if ( !$iPageNr && $oIdList && $oArticle ) {
00505 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00506 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00507
00508 $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00509 $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00510 $iPageNr = floor( $iPos / $iNrofCatArticles );
00511 }
00512
00513 return $iPageNr;
00514 }
00515
00523 protected function _getPageNumber( $iPageNr )
00524 {
00525
00526 $iPageNr = (int) $iPageNr;
00527 return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00528 }
00529
00539 protected function _getProductPos( $oArticle, $oIdList, $oLocatorTarget )
00540 {
00541 $iCnt = 1;
00542 $iPos = 0;
00543
00544
00545 $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00546 if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00547
00548 $aIds = $oIdList->arrayKeys();
00549 $iPos = array_search( $sOxid, $aIds );
00550
00551 if ( array_key_exists( $iPos-1, $aIds ) ) {
00552 $oBackProduct = oxNew( 'oxarticle' );
00553 $oBackProduct->setNoVariantLoading( true );
00554 if ( $oBackProduct->load( $aIds[$iPos-1] ) ) {
00555 $oBackProduct->setLinkType( $oLocatorTarget->getLinkType() );
00556 $this->_oBackProduct = $oBackProduct;
00557 }
00558 }
00559
00560 if ( array_key_exists( $iPos+1, $aIds ) ) {
00561 $oNextProduct = oxNew( 'oxarticle' );
00562 $oNextProduct->setNoVariantLoading( true );
00563 if ( $oNextProduct->load( $aIds[$iPos+1] ) ) {
00564 $oNextProduct->setLinkType( $oLocatorTarget->getLinkType() );
00565 $this->_oNextProduct = $oNextProduct;
00566 }
00567 }
00568 return $iPos+1;
00569 }
00570 return 0;
00571 }
00572
00578 public function getErrorMessage()
00579 {
00580 return $this->_sErrorMessage;
00581 }
00582 }