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->getActiveCategory() ) ) {
00076 $sCatId = $oCategory->getId();
00077
00078 $sOrderBy = null;
00079 if ( $oLocatorTarget->showSorting() ) {
00080 $sOrderBy = $oLocatorTarget->getSortingSql( $oLocatorTarget->getSortIdent() );
00081 }
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 ( oxRegistry::getUtils()->seoIsActive() && $iPage ) {
00093 $oCategory->toListLink = oxRegistry::get("oxSeoEncoderCategory")->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
00105 if ( ( $oCatTree = $oLocatorTarget->getCategoryTree() ) ) {
00106 $oLocatorTarget->setCatTreePath( $oCatTree->getPath() );
00107 }
00108 }
00109 }
00110
00119 protected function _setVendorLocatorData( $oLocatorTarget, $oCurrArticle )
00120 {
00121 if ( ( $oVendor = $oLocatorTarget->getActVendor() ) ) {
00122 $sVendorId = $oVendor->getId();
00123 $myUtils = oxRegistry::getUtils();
00124
00125 $blSeo = $myUtils->seoIsActive();
00126
00127
00128 $oIdList = oxNew( "oxArticleList" );
00129 if ( $oLocatorTarget->showSorting() ) {
00130 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( $oLocatorTarget->getSortIdent() ) );
00131 }
00132 $oIdList->loadVendorIds( $sVendorId );
00133
00134
00135 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00136
00137 $sAdd = null;
00138 if ( !$blSeo ) {
00139 $sAdd = 'listtype=vendor&cnid=v_'.$sVendorId;
00140 }
00141
00142
00143 $oVendor->iCntOfProd = $oIdList->count();
00144 $oVendor->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00145
00146 if ( $blSeo && $iPage ) {
00147 $oVendor->toListLink = oxRegistry::get("oxSeoEncoderVendor")->getVendorPageUrl( $oVendor, $iPage );
00148 } else {
00149 $oVendor->toListLink = $this->_makeLink( $oVendor->getLink(), $this->_getPageNumber( $iPage ) );
00150 }
00151
00152 $oVendor->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00153 $oVendor->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00154 }
00155 }
00156
00165 protected function _setManufacturerLocatorData( $oLocatorTarget, $oCurrArticle )
00166 {
00167 if ( ( $oManufacturer = $oLocatorTarget->getActManufacturer() ) ) {
00168 $sManufacturerId = $oManufacturer->getId();
00169 $myUtils = oxRegistry::getUtils();
00170
00171 $blSeo = $myUtils->seoIsActive();
00172
00173
00174 $oIdList = oxNew( "oxarticlelist" );
00175 if ( $oLocatorTarget->showSorting() ) {
00176 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( $oLocatorTarget->getSortIdent() ) );
00177 }
00178 $oIdList->loadManufacturerIds( $sManufacturerId );
00179
00180
00181 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00182
00183 $sAdd = null;
00184 if ( !$blSeo ) {
00185 $sAdd = 'listtype=manufacturer&mnid='.$sManufacturerId;
00186 }
00187
00188
00189 $oManufacturer->iCntOfProd = $oIdList->count();
00190 $oManufacturer->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00191
00192 if ( $blSeo && $iPage ) {
00193 $oManufacturer->toListLink = oxRegistry::get("oxSeoEncoderManufacturer")->getManufacturerPageUrl( $oManufacturer, $iPage );
00194 } else {
00195 $oManufacturer->toListLink = $this->_makeLink( $oManufacturer->getLink(), $this->_getPageNumber( $iPage ) );
00196 }
00197
00198 $oManufacturer->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00199 $oManufacturer->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00200
00201
00202 $oLocatorTarget->setActiveCategory( $oManufacturer );
00203
00204
00205 if ( ( $oManufacturerTree = $oLocatorTarget->getManufacturerTree() ) ) {
00206 $oLocatorTarget->setCatTreePath( $oManufacturerTree->getPath() );
00207 }
00208 }
00209 }
00210
00219 protected function _setSearchLocatorData( $oLocatorTarget, $oCurrArticle )
00220 {
00221 if ( ( $oSearchCat = $oLocatorTarget->getActSearch() ) ) {
00222
00223
00224 $sSearchParam = oxConfig::getParameter( 'searchparam', true );
00225 $sSearchFormParam = oxConfig::getParameter( 'searchparam' );
00226 $sSearchLinkParam = rawurlencode( $sSearchParam );
00227
00228 $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00229 $sSearchCat = $sSearchCat?rawurldecode( $sSearchCat ):$sSearchCat;
00230
00231 $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00232 $sSearchVendor = $sSearchVendor?rawurldecode( $sSearchVendor ):$sSearchVendor;
00233
00234 $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' );
00235 $sSearchManufacturer = $sSearchManufacturer?rawurldecode( $sSearchManufacturer ):$sSearchManufacturer;
00236
00237
00238 $oIdList = oxNew( 'oxarticlelist' );
00239 if ( $oLocatorTarget->showSorting() ) {
00240 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( $oLocatorTarget->getSortIdent() ) );
00241 }
00242 $oIdList->loadSearchIds( $sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer );
00243
00244
00245 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00246
00247 $sAddSearch = "searchparam={$sSearchLinkParam}";
00248 $sAddSearch .= '&listtype=search';
00249
00250 if ( $sSearchCat !== null ) {
00251 $sAddSearch .= "&searchcnid={$sSearchCat}";
00252 }
00253
00254 if ( $sSearchVendor !== null ) {
00255 $sAddSearch .= "&searchvendor={$sSearchVendor}";
00256 }
00257
00258 if ( $sSearchManufacturer !== null ) {
00259 $sAddSearch .= "&searchmanufacturer={$sSearchManufacturer}";
00260 }
00261
00262
00263 $oSearchCat->iCntOfProd = $oIdList->count();
00264 $oSearchCat->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00265
00266 $sPageNr = $this->_getPageNumber( $iPage );
00267 $oSearchCat->toListLink = $this->_makeLink( $oSearchCat->link, $sPageNr.($sPageNr?'&':'').$sAddSearch );
00268 $oSearchCat->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00269 $oSearchCat->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00270
00271 $sFormat = oxRegistry::getLang()->translateString( 'searchResult' );
00272 $oLocatorTarget->setSearchTitle( sprintf( $sFormat, $sSearchFormParam ) );
00273 $oLocatorTarget->setActiveCategory( $oSearchCat );
00274 }
00275 }
00276
00285 protected function _setTagLocatorData( $oLocatorTarget, $oCurrArticle )
00286 {
00287 if ( ( $oTag = $oLocatorTarget->getActTag() ) ) {
00288
00289 $myUtils = oxRegistry::getUtils();
00290
00291
00292 $oIdList = oxNew( 'oxarticlelist' );
00293 $oLang = oxRegistry::getLang();
00294
00295 if ( $oLocatorTarget->showSorting() ) {
00296 $oIdList->setCustomSorting( $oLocatorTarget->getSortingSql( $oLocatorTarget->getSortIdent() ) );
00297 }
00298
00299 $oIdList->getTagArticleIds( $oTag->sTag, $oLang->getBaseLanguage() );
00300
00301
00302 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00303
00304
00305 $oTag->iCntOfProd = $oIdList->count();
00306 $oTag->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00307
00308 if ( oxRegistry::getUtils()->seoIsActive() ) {
00309 $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl( $oTag->sTag, $iPage );
00310 } else {
00311 $sPageNr = $this->_getPageNumber( $iPage );
00312 $oTag->toListLink = $this->_makeLink( $oTag->link, $sPageNr );
00313 }
00314
00315 $sAddSearch = '';
00316
00317 if ( !$myUtils->seoIsActive() ) {
00318 $sAddSearch = 'searchtag='.rawurlencode( oxConfig::getParameter( 'searchtag', 1 ) );
00319 $sAddSearch .= '&listtype=tag';
00320 }
00321
00322 $oTag->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAddSearch ):null;
00323 $oTag->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAddSearch ):null;
00324 $oStr = getStr();
00325 $oLocatorTarget->setSearchTitle( $oLang->translateString('TAGS').' / '.$oStr->htmlspecialchars( $oStr->ucfirst( $oTag->sTag ) ) );
00326 $oLocatorTarget->setActiveCategory( $oTag );
00327 }
00328 }
00329
00341 protected function _setRecommlistLocatorData( $oLocatorTarget, $oCurrArticle )
00342 {
00343 if ( ( $oRecommList = $oLocatorTarget->getActiveRecommList() ) ) {
00344
00345
00346 $oIdList = oxNew( 'oxarticlelist' );
00347 $oIdList->loadRecommArticleIds( $oRecommList->getId(), null );
00348
00349
00350 $iPage = $this->_findActPageNumber( $oLocatorTarget->getActPage(), $oIdList, $oCurrArticle );
00351
00352 $sSearchRecomm = oxConfig::getParameter( 'searchrecomm', true );
00353
00354 if ( $sSearchRecomm !== null ) {
00355 $sSearchFormRecomm = oxConfig::getParameter( 'searchrecomm' );
00356 $sSearchLinkRecomm = rawurlencode( $sSearchRecomm );
00357 $sAddSearch = 'searchrecomm='.$sSearchLinkRecomm;
00358 }
00359
00360
00361 $oRecommList->iCntOfProd = $oIdList->count();
00362 $oRecommList->iProductPos = $this->_getProductPos( $oCurrArticle, $oIdList, $oLocatorTarget );
00363 $blSeo = oxRegistry::getUtils()->seoIsActive();
00364
00365 if ( $blSeo && $iPage ) {
00366 $oRecommList->toListLink = oxRegistry::get("oxSeoEncoderRecomm")->getRecommPageUrl( $oRecommList, $iPage );
00367 } else {
00368 $oRecommList->toListLink = $this->_makeLink( $oRecommList->getLink(), $this->_getPageNumber( $iPage ) );
00369 }
00370 $oRecommList->toListLink = $this->_makeLink( $oRecommList->toListLink, $sAddSearch );
00371
00372 $sAdd = '';
00373 if ( !$blSeo ) {
00374 $sAdd = 'recommid='.$oRecommList->getId().'&listtype=recommlist'.($sAddSearch?'&':'');
00375 }
00376 $sAdd .= $sAddSearch;
00377 $oRecommList->nextProductLink = $this->_oNextProduct?$this->_makeLink( $this->_oNextProduct->getLink(), $sAdd ):null;
00378 $oRecommList->prevProductLink = $this->_oBackProduct?$this->_makeLink( $this->_oBackProduct->getLink(), $sAdd ):null;
00379
00380 $oLang = oxRegistry::getLang();
00381 $sTitle = $oLang->translateString('RECOMMLIST');
00382 if ( $sSearchRecomm !== null ) {
00383 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchFormRecomm.'"';
00384 }
00385 $oLocatorTarget->setSearchTitle( $sTitle );
00386 $oLocatorTarget->setActiveCategory( $oRecommList );
00387 }
00388 }
00389
00399 protected function _loadIdsInList( $oCategory, $oCurrArticle, $sOrderBy = null )
00400 {
00401 $oIdList = oxNew( 'oxarticlelist' );
00402 $oIdList->setCustomSorting( $sOrderBy ) ;
00403
00404
00405 if ( $oCategory->isPriceCategory() ) {
00406 $oIdList->loadPriceIds( $oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value );
00407 } else {
00408 $sActCat = $oCategory->getId();
00409 $oIdList->loadCategoryIDs( $sActCat, oxSession::getVar( 'session_attrfilter' ) );
00410
00411 if ( !isset( $oIdList[$oCurrArticle->getId()] ) ) {
00412 $oIdList->loadCategoryIDs( $sActCat, null );
00413 }
00414 }
00415
00416 return $oIdList;
00417 }
00418
00427 protected function _makeLink( $sLink, $sParams )
00428 {
00429 if ( $sParams ) {
00430 $sLink .= ( ( strpos( $sLink, '?' ) !== false ) ? '&' : '?' ) . $sParams;
00431 }
00432 return $sLink;
00433 }
00434
00445 protected function _findActPageNumber( $iPageNr, $oIdList = null, $oArticle = null )
00446 {
00447
00448 $iPageNr = (int) $iPageNr;
00449
00450
00451 if ( !$iPageNr && $oIdList && $oArticle ) {
00452 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00453 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00454
00455 $sArticleId = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00456 $iPos = array_search( $sArticleId, $oIdList->arrayKeys() );
00457 $iPageNr = floor( $iPos / $iNrofCatArticles );
00458 }
00459
00460 return $iPageNr;
00461 }
00462
00470 protected function _getPageNumber( $iPageNr )
00471 {
00472
00473 $iPageNr = (int) $iPageNr;
00474 return ( ($iPageNr > 0 )?"pgNr=$iPageNr":'' );
00475 }
00476
00486 protected function _getProductPos( $oArticle, $oIdList, $oLocatorTarget )
00487 {
00488 $iCnt = 1;
00489 $iPos = 0;
00490
00491
00492 $sOxid = $oArticle->oxarticles__oxparentid->value?$oArticle->oxarticles__oxparentid->value:$oArticle->getId();
00493 if ( $oIdList->count() && isset( $oIdList[$sOxid] ) ) {
00494
00495 $aIds = $oIdList->arrayKeys();
00496 $iPos = array_search( $sOxid, $aIds );
00497
00498 if ( array_key_exists( $iPos-1, $aIds ) ) {
00499 $oBackProduct = oxNew( 'oxarticle' );
00500 $oBackProduct->modifyCacheKey('_locator');
00501 $oBackProduct->setNoVariantLoading( true );
00502 if ( $oBackProduct->load( $aIds[$iPos-1] ) ) {
00503 $oBackProduct->setLinkType( $oLocatorTarget->getLinkType() );
00504 $this->_oBackProduct = $oBackProduct;
00505 }
00506 }
00507
00508 if ( array_key_exists( $iPos+1, $aIds ) ) {
00509 $oNextProduct = oxNew( 'oxarticle' );
00510 $oNextProduct->modifyCacheKey('_locator');
00511 $oNextProduct->setNoVariantLoading( true );
00512 if ( $oNextProduct->load( $aIds[$iPos+1] ) ) {
00513 $oNextProduct->setLinkType( $oLocatorTarget->getLinkType() );
00514 $this->_oNextProduct = $oNextProduct;
00515 }
00516 }
00517 return $iPos+1;
00518 }
00519 return 0;
00520 }
00521
00527 public function getErrorMessage()
00528 {
00529 return $this->_sErrorMessage;
00530 }
00531 }