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 ( oxUtils::getInstance()->seoIsActive() && $iPage ) {
00103 $oCategory->toListLink = oxSeoEncoderCategory::getInstance()->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 = oxUtils::getInstance();
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 = oxSeoEncoderVendor::getInstance()->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 = oxUtils::getInstance();
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 = oxSeoEncoderManufacturer::getInstance()->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 = oxLang::getInstance()->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 = oxUtils::getInstance();
00311
00312
00313 $oIdList = oxNew( 'oxarticlelist' );
00314 $oLang = oxLang::getInstance();
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 $sPageNr = $this->_getPageNumber( $iPage );
00331 $oTag->toListLink = $this->_makeLink( $oTag->link, $sPageNr );
00332
00333 $sAddSearch = '';
00334
00335 if ( !$myUtils->seoIsActive() ) {
00336 $sAddSearch = 'searchtag='.rawurlencode( oxConfig::getParameter( 'searchtag', 1 ) );
00337 $sAddSearch .= '&listtype=tag';
00338 }
00339
00340 $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00341 $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00342 $oStr = getStr();
00343 $oLocatorTarget->setSearchTitle( $oLang->translateString('TAGS').' / '.$oStr->htmlspecialchars( $oStr->ucfirst( $oTag->sTag ) ) );
00344 $oLocatorTarget->setActiveCategory( $oTag );
00345 }
00346 }
00347
00359 protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00360 {
00361 if ( ( $oRecommList = $oLocatorTarget->getActiveRecommList() ) ) {
00362
00363
00364 $oIdList = oxNew( 'oxarticlelist' );
00365 $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00366
00367
00368 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00369
00370 $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00371
00372 if ( $sSearchRecomm !== null ) {
00373 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00374 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00375 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00376 }
00377
00378
00379 $oRecommList->iCntOfProd = $oIdList->count();
00380 $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00381 $blSeo = oxUtils::getInstance()->seoIsActive();
00382
00383 if ( $blSeo && $iPage ) {
00384 $oRecommList->toListLink = oxSeoEncoderRecomm::getInstance()->getRecommPageUrl( $oRecommList, $iPage );
00385 } else {
00386 $oRecommList->toListLink = $this->_makeLink( $oRecommList->getLink(), $this->_getPageNumber( $iPage ) );
00387 }
00388 $oRecommList->toListLink = $this->_makeLink( $oRecommList->toListLink, $sAddSearch );
00389
00390 $sAdd = '';
00391 if ( !$blSeo ) {
00392 $sAdd = 'recommid='.$oRecommList->getId().'&listtype=recommlist'.($sAddSearch?'&':'');
00393 }
00394 $sAdd .= $sAddSearch;
00395 $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00396 $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00397
00398 $oLang = oxLang::getInstance();
00399 $sTitle = $oLang->translateString('RECOMMLIST');
00400 if ( $sSearchRecomm !== null ) {
00401 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00402 }
00403 $oLocatorTarget->setSearchTitle( $sTitle );
00404 $oLocatorTarget->setActiveCategory( $oRecommList );
00405 }
00406 }
00407
00417 protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00418 {
00419 $oIdList = oxNew( 'oxarticlelist' );
00420 $oIdList->setCustomSorting( $sOrderBy ) ;
00421
00422
00423 if ( $oCategory->isPriceCategory() ) {
00424 $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00425 } else {
00426 $sActCat = $oCategory->getId();
00427 $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00428
00429 if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00430 $oIdList->loadCategoryIDs( $sActCat, null );
00431 }
00432 }
00433
00434 return $oIdList;
00435 }
00436
00445 protected function _makeLink( $sLink, $sParams )
00446 {
00447 if ( $sParams ) {
00448 $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&' : '?' ) . $sParams;
00449 }
00450 return $sLink;
00451 }
00452
00463 protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00464 {
00465
00466 $iPageNr = (int) $iPageNr;
00467
00468
00469 if ( !$iPageNr && $oIdList && $oArticle ) {
00470 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00471 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00472
00473 $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00474 $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00475 $iPageNr = floor( $iPos / $iNrofCatArticles );
00476 }
00477
00478 return $iPageNr;
00479 }
00480
00488 protected function _getPageNumber( $iPageNr )
00489 {
00490
00491 $iPageNr = (int) $iPageNr;
00492 return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00493 }
00494
00504 protected function _getProductPos( $oArticle, $oIdList, $oLocatorTarget )
00505 {
00506 $iCnt = 1;
00507 $iPos = 0;
00508
00509
00510 $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00511 if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00512
00513 $aIds = $oIdList->arrayKeys();
00514 $iPos = array_search( $sOxid, $aIds );
00515
00516 if ( array_key_exists( $iPos-1, $aIds ) ) {
00517 $oBackProduct = oxNew( 'oxarticle' );
00518 $oBackProduct->modifyCacheKey('_locator');
00519 $oBackProduct->setNoVariantLoading( true );
00520 if ( $oBackProduct->load( $aIds[$iPos-1] ) ) {
00521 $oBackProduct->setLinkType( $oLocatorTarget->getLinkType() );
00522 $this->_oBackProduct = $oBackProduct;
00523 }
00524 }
00525
00526 if ( array_key_exists( $iPos+1, $aIds ) ) {
00527 $oNextProduct = oxNew( 'oxarticle' );
00528 $oNextProduct->modifyCacheKey('_locator');
00529 $oNextProduct->setNoVariantLoading( true );
00530 if ( $oNextProduct->load( $aIds[$iPos+1] ) ) {
00531 $oNextProduct->setLinkType( $oLocatorTarget->getLinkType() );
00532 $this->_oNextProduct = $oNextProduct;
00533 }
00534 }
00535 return $iPos+1;
00536 }
00537 return 0;
00538 }
00539
00545 public function getErrorMessage()
00546 {
00547 return $this->_sErrorMessage;
00548 }
00549 }