00001 <?php
00002
00006 class oxLocator extends oxSuperCfg
00007 {
00008
00012 protected $_sType = "list";
00013
00017 protected $_oNextProduct = null;
00018
00022 protected $_oBackProduct = null;
00023
00027 protected $_sSearchHandle = null;
00028
00032 protected $_sErrorMessage = null;
00033
00040 public function __construct($sType = null)
00041 {
00042
00043 if ($sType) {
00044 $this->_sType = trim($sType);
00045 }
00046 }
00047
00054 public function setLocatorData($oCurrArticle, $oLocatorTarget)
00055 {
00056 $sLocfnc = "_set{$this->_sType}LocatorData";
00057 $this->$sLocfnc($oLocatorTarget, $oCurrArticle);
00058
00059
00060 $oLocatorTarget->setListType($this->_sType);
00061 }
00062
00069 protected function _setListLocatorData($oLocatorTarget, $oCurrArticle)
00070 {
00071
00072 if (($oCategory = $oLocatorTarget->getActiveCategory())) {
00073
00074 $sOrderBy = null;
00075 if ($oLocatorTarget->showSorting()) {
00076 $sOrderBy = $oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent());
00077 }
00078
00079 $oIdList = $this->_loadIdsInList($oCategory, $oCurrArticle, $sOrderBy);
00080
00081
00082 $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
00083
00084
00085 $oCategory->iCntOfProd = $oIdList->count();
00086 $oCategory->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
00087
00088 if (oxRegistry::getUtils()->seoIsActive() && $iPage) {
00090 $oSeoEncoderCategory = oxRegistry::get("oxSeoEncoderCategory");
00091 $oCategory->toListLink = $oSeoEncoderCategory->getCategoryPageUrl($oCategory, $iPage);
00092 } else {
00093 $oCategory->toListLink = $this->_makeLink($oCategory->getLink(), $this->_getPageNumber($iPage));
00094 }
00095
00096 $oNextProduct = $this->_oNextProduct;
00097 $oBackProduct = $this->_oBackProduct;
00098 $oCategory->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), '') : null;
00099 $oCategory->prevProductLink = $oBackProduct ? $this->_makeLink($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
00117 protected function _setVendorLocatorData($oLocatorTarget, $oCurrArticle)
00118 {
00119 if (($oVendor = $oLocatorTarget->getActVendor())) {
00120 $sVendorId = $oVendor->getId();
00121 $myUtils = oxRegistry::getUtils();
00122
00123 $blSeo = $myUtils->seoIsActive();
00124
00125
00126 $oIdList = oxNew("oxArticleList");
00127 if ($oLocatorTarget->showSorting()) {
00128 $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
00129 }
00130 $oIdList->loadVendorIds($sVendorId);
00131
00132
00133 $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
00134
00135 $sAdd = null;
00136 if (!$blSeo) {
00137 $sAdd = 'listtype=vendor&cnid=v_' . $sVendorId;
00138 }
00139
00140
00141 $oVendor->iCntOfProd = $oIdList->count();
00142 $oVendor->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
00143
00144 if ($blSeo && $iPage) {
00145 $oVendor->toListLink = oxRegistry::get("oxSeoEncoderVendor")->getVendorPageUrl($oVendor, $iPage);
00146 } else {
00147 $oVendor->toListLink = $this->_makeLink($oVendor->getLink(), $this->_getPageNumber($iPage));
00148 }
00149
00150 $oNextProduct = $this->_oNextProduct;
00151 $oBackProduct = $this->_oBackProduct;
00152 $oVendor->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
00153 $oVendor->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
00154 }
00155 }
00156
00163 protected function _setManufacturerLocatorData($oLocatorTarget, $oCurrArticle)
00164 {
00165 if (($oManufacturer = $oLocatorTarget->getActManufacturer())) {
00166 $sManufacturerId = $oManufacturer->getId();
00167 $myUtils = oxRegistry::getUtils();
00168
00169 $blSeo = $myUtils->seoIsActive();
00170
00171
00172 $oIdList = oxNew("oxarticlelist");
00173 if ($oLocatorTarget->showSorting()) {
00174 $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
00175 }
00176 $oIdList->loadManufacturerIds($sManufacturerId);
00177
00178
00179 $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
00180
00181 $sAdd = null;
00182 if (!$blSeo) {
00183 $sAdd = 'listtype=manufacturer&mnid=' . $sManufacturerId;
00184 }
00185
00186
00187 $oManufacturer->iCntOfProd = $oIdList->count();
00188 $oManufacturer->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
00189
00190 if ($blSeo && $iPage) {
00192 $oSeoEncoderManufacturer = oxRegistry::get("oxSeoEncoderManufacturer");
00193 $oManufacturer->toListLink = $oSeoEncoderManufacturer->getManufacturerPageUrl($oManufacturer, $iPage);
00194 } else {
00195 $oManufacturer->toListLink = $this->_makeLink($oManufacturer->getLink(), $this->_getPageNumber($iPage));
00196 }
00197
00198 $oNextProduct = $this->_oNextProduct;
00199 $oBackProduct = $this->_oBackProduct;
00200 $oManufacturer->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
00201 $oManufacturer->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
00202
00203
00204 $oLocatorTarget->setActiveCategory($oManufacturer);
00205
00206
00207 if (($oManufacturerTree = $oLocatorTarget->getManufacturerTree())) {
00208 $oLocatorTarget->setCatTreePath($oManufacturerTree->getPath());
00209 }
00210 }
00211 }
00212
00219 protected function _setSearchLocatorData($oLocatorTarget, $oCurrArticle)
00220 {
00221 if (($oSearchCat = $oLocatorTarget->getActSearch())) {
00222
00223
00224 $sSearchParam = oxRegistry::getConfig()->getRequestParameter('searchparam', true);
00225 $sSearchFormParam = oxRegistry::getConfig()->getRequestParameter('searchparam');
00226 $sSearchLinkParam = rawurlencode($sSearchParam);
00227
00228 $sSearchCat = oxRegistry::getConfig()->getRequestParameter('searchcnid');
00229 $sSearchCat = $sSearchCat ? rawurldecode($sSearchCat) : $sSearchCat;
00230
00231 $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
00232 $sSearchVendor = $sSearchVendor ? rawurldecode($sSearchVendor) : $sSearchVendor;
00233
00234 $sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('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 $sParams = $sPageNr . ($sPageNr ? '&' : '') . $sAddSearch;
00268 $oSearchCat->toListLink = $this->_makeLink($oSearchCat->link, $sParams);
00269 $oNextProd = $this->_oNextProduct;
00270 $oBackProd = $this->_oBackProduct;
00271 $oSearchCat->nextProductLink = $oNextProd ? $this->_makeLink($oNextProd->getLink(), $sAddSearch) : null;
00272 $oSearchCat->prevProductLink = $oBackProd ? $this->_makeLink($oBackProd->getLink(), $sAddSearch) : null;
00273
00274 $sFormat = oxRegistry::getLang()->translateString('SEARCH_RESULT');
00275 $oLocatorTarget->setSearchTitle(sprintf($sFormat, $sSearchFormParam));
00276 $oLocatorTarget->setActiveCategory($oSearchCat);
00277 }
00278 }
00279
00286 protected function _setTagLocatorData($oLocatorTarget, $oCurrArticle)
00287 {
00288 if (($oTag = $oLocatorTarget->getActTag())) {
00289
00290 $myUtils = oxRegistry::getUtils();
00291
00292
00293 $oIdList = oxNew('oxarticlelist');
00294 $oLang = oxRegistry::getLang();
00295
00296 if ($oLocatorTarget->showSorting()) {
00297 $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
00298 }
00299
00300 $oIdList->getTagArticleIds($oTag->sTag, $oLang->getBaseLanguage());
00301
00302
00303 $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
00304
00305
00306 $oTag->iCntOfProd = $oIdList->count();
00307 $oTag->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
00308
00309 if (oxRegistry::getUtils()->seoIsActive()) {
00310 $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($oTag->sTag, $iPage);
00311 } else {
00312 $sPageNr = $this->_getPageNumber($iPage);
00313 $oTag->toListLink = $this->_makeLink($oTag->link, $sPageNr);
00314 }
00315
00316 $sAddSearch = '';
00317
00318 if (!$myUtils->seoIsActive()) {
00319 $sSearchTagParameter = oxRegistry::getConfig()->getRequestParameter('searchtag', true);
00320 $sAddSearch = 'searchtag=' . rawurlencode($sSearchTagParameter);
00321 $sAddSearch .= '&listtype=tag';
00322 }
00323
00324 $oNextProduct = $this->_oNextProduct;
00325 $oBackProduct = $this->_oBackProduct;
00326 $oTag->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAddSearch) : null;
00327 $oTag->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAddSearch) : null;
00328 $oStr = getStr();
00329 $sTitle = $oLang->translateString('TAGS') . ' / ' . $oStr->htmlspecialchars($oStr->ucfirst($oTag->sTag));
00330 $oLocatorTarget->setSearchTitle($sTitle);
00331 $oLocatorTarget->setActiveCategory($oTag);
00332 }
00333 }
00334
00344 protected function _setRecommlistLocatorData($oLocatorTarget, $oCurrArticle)
00345 {
00346 if (($oRecommList = $oLocatorTarget->getActiveRecommList())) {
00347
00348
00349 $oIdList = oxNew('oxarticlelist');
00350 $oIdList->loadRecommArticleIds($oRecommList->getId(), null);
00351
00352
00353 $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
00354
00355 $sSearchRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm', true);
00356
00357 if ($sSearchRecomm !== null) {
00358 $sSearchFormRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
00359 $sSearchLinkRecomm = rawurlencode($sSearchRecomm);
00360 $sAddSearch = 'searchrecomm=' . $sSearchLinkRecomm;
00361 }
00362
00363
00364 $oRecommList->iCntOfProd = $oIdList->count();
00365 $oRecommList->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
00366 $blSeo = oxRegistry::getUtils()->seoIsActive();
00367
00368 if ($blSeo && $iPage) {
00370 $oSeoEncoderRecomm = oxRegistry::get("oxSeoEncoderRecomm");
00371 $oRecommList->toListLink = $oSeoEncoderRecomm->getRecommPageUrl($oRecommList, $iPage);
00372 } else {
00373 $oRecommList->toListLink = $this->_makeLink($oRecommList->getLink(), $this->_getPageNumber($iPage));
00374 }
00375 $oRecommList->toListLink = $this->_makeLink($oRecommList->toListLink, $sAddSearch);
00376
00377 $sAdd = '';
00378 if (!$blSeo) {
00379 $sAdd = 'recommid=' . $oRecommList->getId() . '&listtype=recommlist' . ($sAddSearch ? '&' : '');
00380 }
00381 $sAdd .= $sAddSearch;
00382 $oNextProduct = $this->_oNextProduct;
00383 $oBackProduct = $this->_oBackProduct;
00384 $oRecommList->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
00385 $oRecommList->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
00386
00387 $oLang = oxRegistry::getLang();
00388 $sTitle = $oLang->translateString('RECOMMLIST');
00389 if ($sSearchRecomm !== null) {
00390 $sTitle .= " / " . $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchFormRecomm . '"';
00391 }
00392 $oLocatorTarget->setSearchTitle($sTitle);
00393 $oLocatorTarget->setActiveCategory($oRecommList);
00394 }
00395 }
00396
00406 protected function _loadIdsInList($oCategory, $oCurrArticle, $sOrderBy = null)
00407 {
00408 $oIdList = oxNew('oxarticlelist');
00409 $oIdList->setCustomSorting($sOrderBy);
00410
00411
00412 if ($oCategory->isPriceCategory()) {
00413 $oIdList->loadPriceIds($oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value);
00414 } else {
00415 $sActCat = $oCategory->getId();
00416 $oIdList->loadCategoryIDs($sActCat, oxRegistry::getSession()->getVariable('session_attrfilter'));
00417
00418 if (!isset($oIdList[$oCurrArticle->getId()])) {
00419 $oIdList->loadCategoryIDs($sActCat, null);
00420 }
00421 }
00422
00423 return $oIdList;
00424 }
00425
00434 protected function _makeLink($sLink, $sParams)
00435 {
00436 if ($sParams) {
00437 $sLink .= ((strpos($sLink, '?') !== false) ? '&' : '?') . $sParams;
00438 }
00439
00440 return $sLink;
00441 }
00442
00453 protected function _findActPageNumber($iPageNr, $oIdList = null, $oArticle = null)
00454 {
00455
00456 $iPageNr = (int) $iPageNr;
00457
00458
00459 if (!$iPageNr && $oIdList && $oArticle) {
00460 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
00461 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
00462 $sParentIdField = 'oxarticles__oxparentid';
00463 $sArticleId = $oArticle->$sParentIdField->value ? $oArticle->$sParentIdField->value : $oArticle->getId();
00464 $iPos = array_search($sArticleId, $oIdList->arrayKeys());
00465 $iPageNr = floor($iPos / $iNrofCatArticles);
00466 }
00467
00468 return $iPageNr;
00469 }
00470
00478 protected function _getPageNumber($iPageNr)
00479 {
00480
00481 $iPageNr = (int) $iPageNr;
00482
00483 return (($iPageNr > 0) ? "pgNr=$iPageNr" : '');
00484 }
00485
00495 protected function _getProductPos($oArticle, $oIdList, $oLocatorTarget)
00496 {
00497 $iCnt = 1;
00498 $iPos = 0;
00499
00500
00501 $sOxid = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
00502 if ($oIdList->count() && isset($oIdList[$sOxid])) {
00503
00504 $aIds = $oIdList->arrayKeys();
00505 $iPos = array_search($sOxid, $aIds);
00506
00507 if (array_key_exists($iPos - 1, $aIds)) {
00508 $oBackProduct = oxNew('oxarticle');
00509 $oBackProduct->modifyCacheKey('_locator');
00510 $oBackProduct->setNoVariantLoading(true);
00511 if ($oBackProduct->load($aIds[$iPos - 1])) {
00512 $oBackProduct->setLinkType($oLocatorTarget->getLinkType());
00513 $this->_oBackProduct = $oBackProduct;
00514 }
00515 }
00516
00517 if (array_key_exists($iPos + 1, $aIds)) {
00518 $oNextProduct = oxNew('oxarticle');
00519 $oNextProduct->modifyCacheKey('_locator');
00520 $oNextProduct->setNoVariantLoading(true);
00521 if ($oNextProduct->load($aIds[$iPos + 1])) {
00522 $oNextProduct->setLinkType($oLocatorTarget->getLinkType());
00523 $this->_oNextProduct = $oNextProduct;
00524 }
00525 }
00526
00527 return $iPos + 1;
00528 }
00529
00530 return 0;
00531 }
00532
00538 public function getErrorMessage()
00539 {
00540 return $this->_sErrorMessage;
00541 }
00542 }