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