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
00056 public function setLocatorData( $oCurrArticle, $oLocatorTarget )
00057 {
00058 $sLocfnc = "_set{$this->_sType}LocatorData";
00059 $this->$sLocfnc( $oLocatorTarget, $oCurrArticle );
00060
00061
00062 $oLocatorTarget->setListType( $this->_sType );
00063 }
00064
00073 protected function _setListLocatorData( $oLocatorTarget, $oCurrArticle )
00074 {
00075
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
00087 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00088
00089
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
00103 $oLocatorTarget->setActiveCategory( $oCategory );
00104
00105 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00106
00107
00108 if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00109 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00110
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
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
00142 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00143
00144 $sAdd = null;
00145 if ( !$myUtils->seoIsActive() ) {
00146 $sAdd = 'listtype=vendor&cnid=v_'.$sVendorId;
00147 }
00148
00149
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
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
00172 $oLocatorTarget->setActiveCategory( $oVendor );
00173
00174 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00175
00176
00177 if ( ( $oVendorTree = $oLocatorTarget->getVendorTree() ) ) {
00178 $oLocatorTarget->setCatTreePath( $oVendorTree->getPath() );
00179
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
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
00211 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00212
00213 $sAdd = null;
00214 if ( !$myUtils->seoIsActive() ) {
00215 $sAdd = 'listtype=manufacturer&mnid='.$sManufacturerId;
00216 }
00217
00218
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
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
00241 $oLocatorTarget->setActiveCategory( $oManufacturer );
00242
00243 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00244
00245
00246 if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00247 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00248
00249 $oLocatorTarget->addTplParam( 'actCatpath', $oLocatorTarget->getCatTreePath() );
00250 }
00251 }
00252 }
00253
00266 protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00267 {
00268 if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00269
00270
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
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
00293 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00294
00295 $sAddSearch = "searchparam={$sSearchLinkParam}";
00296 if ( $sSearchCat !== null ) {
00297 $sAddSearch .= "&searchcnid={$sSearchCat}";
00298 }
00299
00300 if ( $sSearchVendor !== null ) {
00301 $sAddSearch .= "&searchvendor={$sSearchVendor}";
00302 }
00303
00304 if ( $sSearchManufacturer !== null ) {
00305 $sAddSearch .= "&searchmanufacturer={$sSearchManufacturer}";
00306 }
00307
00308
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?'&':'').$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
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
00330 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00331 }
00332 }
00333
00345 protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00346 {
00347 if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00348
00349
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
00361 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00362
00363 $sAddSearch = 'searchtag='.rawurlencode(oxConfig::getParameter( 'searchtag', 1));
00364
00365
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?'&':'').$sAddSearch );
00371
00372 $sAddSearch .= '&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
00378 $oLocatorTarget->addTplParam( 'sSearchTitle', $oLocatorTarget->getSearchTitle() );
00379 $oLocatorTarget->addTplParam( 'searchtagforhtml', null );
00380 $oLocatorTarget->setActiveCategory( $oTag );
00381
00382 $oLocatorTarget->addTplParam( 'actCategory', $oLocatorTarget->getActiveCategory() );
00383 }
00384 }
00385
00397 protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00398 {
00399 if ( ( $oRecommList = $oLocatorTarget->getActRecommList() ) ) {
00400
00401
00402 $oIdList = oxNew( 'oxarticlelist' );
00403 $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00404
00405
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
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)?'&':'').$sAddSearch );
00422
00423 $sAdd = 'recommid='.$oRecommList->getId().'&listtype=recommlist'.($sAddSearch?'&':'').$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->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
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 ) ? '&' : '?' ) . $sParams;
00486 }
00487 return $sLink;
00488 }
00489
00500 protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00501 {
00502
00503 $iPageNr = (int) $iPageNr;
00504
00505
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
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
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 }