00001 <?php
00002
00007 class oxArticleList extends oxList
00008 {
00012 protected $_sCustomSorting;
00013
00019 protected $_sObjectsInListName = 'oxarticle';
00020
00026 protected $_blLoadSelectLists = false;
00027
00033 protected $_blLoadPrice = true;
00034
00042 public function setCustomSorting( $sSorting)
00043 {
00044
00045 $aSorting = explode(" ", $sSorting);
00046 $aSorting[0] = $this->getBaseObject()->getSqlFieldName($aSorting[0]);
00047 $this->_sCustomSorting = implode( " ", $aSorting );
00048 }
00049
00055 public function enableSelectLists()
00056 {
00057 $this->_blLoadSelectLists = true;
00058 }
00059
00068 public function selectString( $sSelect )
00069 {
00070 if ( !$this->isAdmin() ) {
00071 $this->_aAssignCallbackPrepend = ( !$this->_blLoadPrice )?array( oxNew("oxarticle"), 'disablePriceLoad'):null;
00072 }
00073
00074 startProfile("loadinglists");
00075 $oRes = parent::selectString( $sSelect );
00076 stopProfile("loadinglists");
00077
00078 return $oRes;
00079 }
00080
00089 public function loadHistoryArticles($sArtId)
00090 {
00091 $mySession = $this->getSession();
00092 $aHistoryArticles = $mySession->getVar('aHistoryArticles');
00093 $aHistoryArticles[] = $sArtId;
00094
00095
00096 $aHistoryArticles = array_unique( $aHistoryArticles);
00097
00098 if (count($aHistoryArticles) > 5) {
00099 array_shift($aHistoryArticles);
00100 }
00101
00102
00103 $mySession->setVar('aHistoryArticles', $aHistoryArticles);
00104
00105
00106
00107 if (($iCurrentArt = array_search($sArtId, $aHistoryArticles)) !== false) {
00108 unset ($aHistoryArticles[$iCurrentArt]);
00109 }
00110
00111 $this->loadIds(array_values($aHistoryArticles));
00112 }
00113
00121 public function loadNewestArticles( $iLimit = null )
00122 {
00123
00124 $myConfig = $this->getConfig();
00125
00126 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00127 $this->_blLoadPrice = false;
00128 }
00129
00130 $this->_aArray = array();
00131 switch( $myConfig->getConfigParam( 'iNewestArticlesMode' ) ) {
00132 case 0:
00133
00134 break;
00135 case 1:
00136
00137 $this->loadAktionArticles( 'oxnewest' );
00138 break;
00139 case 2:
00140 $sArticleTable = getViewName('oxarticles');
00141 if ( $myConfig->getConfigParam( 'blNewArtByInsert' ) ) {
00142 $sType = 'oxinsert';
00143 } else {
00144 $sType = 'oxtimestamp';
00145 }
00146 $sSelect = "select * from $sArticleTable ";
00147 $sSelect .= "where oxparentid = '' and ".$this->getBaseObject()->getSqlActiveSnippet()." and oxissearch = 1 order by $sType desc ";
00148 if (!($iLimit = (int) $iLimit)) {
00149 $iLimit = $myConfig->getConfigParam( 'iNrofNewcomerArticles' );
00150 }
00151 $sSelect .= "limit " . $iLimit;
00152
00153 $this->selectString($sSelect);
00154 break;
00155 }
00156
00157 }
00158
00164 public function loadTop5Articles()
00165 {
00166
00167 $myConfig = $this->getConfig();
00168
00169 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00170 $this->_blLoadPrice = false;
00171 }
00172
00173 switch( $myConfig->getConfigParam( 'iTop5Mode' ) ) {
00174 case 0:
00175
00176 break;
00177 case 1:
00178
00179 $this->loadAktionArticles( 'oxtop5');
00180 break;
00181 case 2:
00182 $sArticleTable = getViewName('oxarticles');
00183
00184 $sSelect = "select * from $sArticleTable ";
00185 $sSelect .= "where ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 ";
00186 $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
00187 $sSelect .= "order by $sArticleTable.oxsoldamount desc limit 5";
00188
00189 $this->selectString($sSelect);
00190 break;
00191 }
00192 }
00193
00201 public function loadAktionArticles( $sActionID )
00202 {
00203
00204 if ( !trim( $sActionID) ) {
00205 return;
00206 }
00207
00208 $sShopID = $this->getConfig()->getShopId();
00209 $sActionID = strtolower( $sActionID);
00210
00211
00212 $oBaseObject = $this->getBaseObject();
00213 $sArticleTable = $oBaseObject->getViewName();
00214 $sArticleFields = $oBaseObject->getSelectFields();
00215
00216 $oBase = oxNew("oxactions");
00217 $sActiveSql = $oBase->getSqlActiveSnippet();
00218
00219 $sSelect = "select $sArticleFields from oxactions2article
00220 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
00221 left join oxactions on oxactions.oxid = oxactions2article.oxactionid
00222 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = '$sActionID' and $sActiveSql
00223 and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). "
00224 order by oxactions2article.oxsort";
00225
00226 $this->selectString( $sSelect );
00227 }
00228
00236 public function loadArticleCrossSell( $sArticleId )
00237 {
00238 $myConfig = $this->getConfig();
00239
00240
00241 if ( !$myConfig->getConfigParam( 'bl_perfLoadCrossselling' ) ) {
00242 return null;
00243 }
00244
00245 $oBaseObject = $this->getBaseObject();
00246 $sArticleTable = $oBaseObject->getViewName();
00247
00248 $sSelect = "select $sArticleTable.* from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00249 $sSelect .= "where oxobject2article.oxarticlenid = '$sArticleId' ";
00250 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " order by rand()";
00251
00252
00253 if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00254 $sSelect = "select distinct $sArticleTable.* from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00255 $sSelect .= "where (oxobject2article.oxarticlenid = '$sArticleId' or oxobject2article.oxobjectid = '$sArticleId' )";
00256 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " having $sArticleTable.oxid!='$sArticleId' order by rand()";
00257 }
00258
00259 $this->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00260 $this->selectString( $sSelect );
00261 }
00262
00270 public function loadArticleAccessoires( $sArticleId )
00271 {
00272 $myConfig = $this->getConfig();
00273
00274
00275 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00276 return;
00277 }
00278
00279 $oBaseObject = $this->getBaseObject();
00280 $sArticleTable = $oBaseObject->getViewName();
00281
00282 $sSelect = "select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00283 $sSelect .= "where oxaccessoire2article.oxarticlenid = '$sArticleId' ";
00284 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet();
00285
00286 $sSelect .= " order by oxaccessoire2article.oxsort";
00287
00288 $this->selectString( $sSelect );
00289 }
00290
00299 public function loadCategoryIds( $sCatId, $aSessionFilter )
00300 {
00301 $sArticleTable = $this->getBaseObject()->getViewName();
00302 $sSelect = $this->_getCategorySelect( $sArticleTable.'.oxid as oxid', $sCatId, $aSessionFilter );
00303
00304 $this->_createIdListFromSql( $sSelect );
00305 }
00306
00316 public function loadCategoryArticles( $sCatId, $aSessionFilter, $iLimit = null )
00317 {
00318 $sArticleFields = $this->getBaseObject()->getSelectFields();
00319
00320 $sSelect = $this->_getCategorySelect( $sArticleFields, $sCatId, $aSessionFilter );
00321
00322
00323
00324 $iArticleCount = null;
00325 if ( $aSessionFilter) {
00326 $oRet = oxDb::getDb()->Execute( $sSelect );
00327 $iArticleCount = $oRet->recordCount();
00328 }
00329
00330 if ($iLimit = (int) $iLimit) {
00331 $sSelect .= " LIMIT $iLimit";
00332 }
00333
00334 $this->selectString( $sSelect );
00335
00336 if ( $iArticleCount !== null ) {
00337 return $iArticleCount;
00338 }
00339
00340 $iTotalCount = oxUtilsCount::getInstance()->getCatArticleCount($sCatId);
00341
00342
00343 return $iTotalCount;
00344 }
00345
00354 public function loadRecommArticles( $sRecommId, $sArticlesFilter = null )
00355 {
00356 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter);
00357 $this->selectString( $sSelect );
00358 }
00359
00368 public function loadRecommArticleIds( $sRecommId, $sArticlesFilter )
00369 {
00370 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter );
00371
00372 $sArtView = getViewName( 'oxarticles' );
00373 $sPartial = substr( $sSelect, strpos( $sSelect, ' from ' ) );
00374 $sSelect = "select distinct $sArtView.oxid $sPartial ";
00375
00376 $this->_createIdListFromSql( $sSelect );
00377 }
00378
00387 protected function _getArticleSelect( $sRecommId, $sArticlesFilter = null )
00388 {
00389 $sArtView = getViewName( 'oxarticles' );
00390 $sSelect = "select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
00391 $sSelect .= "left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
00392 $sSelect .= "where (oxobject2list.oxlistid = '".$sRecommId."') ".$sArticlesFilter;
00393
00394 return $sSelect;
00395 }
00396
00407 public function loadSearchIds( $sSearchStr = '', $sSearchCat = '', $sSearchVendor = '', $sSearchManufacturer = '' )
00408 {
00409 $oDb = oxDb::getDb();
00410 $sSearchCat = $sSearchCat?$oDb->quote( $sSearchCat ):null;
00411 $sSearchVendor = $sSearchVendor?$oDb->quote( $sSearchVendor ):null;
00412 $sSearchManufacturer = $sSearchManufacturer?$oDb->quote( $sSearchManufacturer ):null;
00413
00414 $sWhere = null;
00415
00416 if ( $sSearchStr ) {
00417 $sWhere = $this->_getSearchSelect( $sSearchStr );
00418 }
00419
00420 $sArticleTable = getViewName('oxarticles');
00421
00422
00423 $sDescTable = '';
00424 $sDescJoin = '';
00425 if ( is_array( $aSearchCols = $this->getConfig()->getConfigParam( 'aSearchCols' ) ) ) {
00426 if ( in_array( 'oxlongdesc', $aSearchCols ) || in_array( 'oxtags', $aSearchCols ) ) {
00427 $sDescView = getViewName( 'oxartextends' );
00428 $sDescTable = ", {$sDescView} ";
00429 $sDescJoin = " {$sDescView}.oxid={$sArticleTable}.oxid and ";
00430 }
00431 }
00432
00433
00434 $sSelect = "select $sArticleTable.oxid from $sArticleTable $sDescTable where $sDescJoin";
00435
00436
00437 if ( $sSearchCat ) {
00438 $sO2CView = getViewName('oxobject2category');
00439 $sSelect = "select $sArticleTable.oxid from $sArticleTable, $sO2CView as oxobject2category $sDescTable ";
00440 $sSelect .= "where oxobject2category.oxcatnid=$sSearchCat and oxobject2category.oxobjectid=$sArticleTable.oxid and $sDescJoin ";
00441 }
00442 $sSelect .= $this->getBaseObject()->getSqlActiveSnippet();
00443 $sSelect .= " and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
00444
00445
00446 if ( $sSearchVendor ) {
00447 $sSelect .= " and $sArticleTable.oxvendorid = $sSearchVendor ";
00448 }
00449
00450 if ( $sSearchManufacturer ) {
00451 $sSelect .= " and $sArticleTable.oxmanufacturerid = $sSearchManufacturer ";
00452 }
00453 $sSelect .= $sWhere;
00454
00455 if ($this->_sCustomSorting) {
00456 $sSelect .= " order by {$this->_sCustomSorting} ";
00457 }
00458
00459 $this->_createIdListFromSql($sSelect);
00460 }
00461
00470 public function loadPriceIds( $dPriceFrom, $dPriceTo )
00471 {
00472
00473 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00474 $this->_createIdListFromSql($sSelect);
00475 }
00476
00487 public function loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory = null)
00488 {
00489 $sArticleTable = getViewName('oxarticles');
00490
00491 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00492
00493 $this->selectString( $sSelect);
00494
00495
00496 if ( !$oCategory ) {
00497 return $this->count();
00498 }
00499
00500
00501 $iNumOfArticles = $oCategory->getNrOfArticles();
00502 if ( !isset($iNumOfArticles) || $iNumOfArticles == -1) {
00503 return oxUtilsCount::getInstance()->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo );
00504 } else {
00505 return $oCategory->getNrOfArticles();
00506 }
00507 }
00508
00516 public function loadVendorIDs( $sVendorId)
00517 {
00518 $sSelect = $this->_getVendorSelect($sVendorId);
00519 $this->_createIdListFromSql($sSelect);
00520 }
00521
00529 public function loadManufacturerIDs( $sManufacturerId)
00530 {
00531 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00532 $this->_createIdListFromSql($sSelect);
00533 }
00534
00544 public function loadVendorArticles( $sVendorId, $oVendor = null )
00545 {
00546 $sSelect = $this->_getVendorSelect($sVendorId);
00547 $this->selectString( $sSelect);
00548
00549 return oxUtilsCount::getInstance()->getVendorArticleCount( $sVendorId );
00550 }
00551
00561 public function loadManufacturerArticles( $sManufacturerId, $oManufacturer = null )
00562 {
00563 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00564 $this->selectString( $sSelect);
00565
00566 return oxUtilsCount::getInstance()->getManufacturerArticleCount( $sManufacturerId );
00567 }
00568
00577 public function loadTagArticles( $sTag, $iLang )
00578 {
00579 $oListObject = $this->getBaseObject();
00580 $sArticleTable = $oListObject->getViewName();
00581 $sArticleFields = $oListObject->getSelectFields();
00582
00583 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00584
00585 $oTagHandler = oxNew( 'oxtagcloud' );
00586 $sTag = $oTagHandler->prepareTags( $sTag );
00587
00588 $sQ = "select {$sArticleFields} from oxartextends inner join {$sArticleTable} on
00589 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1
00590 and match ( oxartextends.oxtags{$sLangExt} )
00591 against( ".oxDb::getDb()->quote( $sTag )." )";
00592
00593
00594 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00595 $sQ .= " and {$sActiveSnippet}";
00596 }
00597
00598 if ( $this->_sCustomSorting ) {
00599 $sSort = $this->_sCustomSorting;
00600 if (strpos($sSort, '.') === false) {
00601 $sSort = $sArticleTable.'.'.$sSort;
00602 }
00603 $sQ .= " order by $sSort ";
00604 }
00605
00606 $this->selectString( $sQ );
00607
00608
00609 return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00610 }
00611
00620 public function getTagArticleIds( $sTag, $iLang )
00621 {
00622 $oListObject = $this->getBaseObject();
00623 $sArticleTable = $oListObject->getViewName();
00624 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00625
00626 $oTagHandler = oxNew( 'oxtagcloud' );
00627 $sTag = $oTagHandler->prepareTags( $sTag );
00628
00629 $sQ = "select oxartextends.oxid from oxartextends inner join {$sArticleTable} on
00630 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1 and
00631 match ( oxartextends.oxtags{$sLangExt} )
00632 against( ".oxDb::getDb()->quote( $sTag )." )";
00633
00634
00635 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00636 $sQ .= " and {$sActiveSnippet}";
00637 }
00638
00639 if ( $this->_sCustomSorting ) {
00640 $sSort = $this->_sCustomSorting;
00641 if (strpos($sSort, '.') === false) {
00642 $sSort = $sArticleTable.'.'.$sSort;
00643 }
00644 $sQ .= " order by $sSort ";
00645 }
00646
00647 return $this->_createIdListFromSql( $sQ );
00648 }
00649
00657 public function loadIds($aIds)
00658 {
00659 if (!count($aIds)) {
00660 $this->clear();
00661 return;
00662 }
00663
00664 foreach ($aIds as $iKey => $sVal) {
00665 $aIds[$iKey] = mysql_real_escape_string($sVal);
00666 }
00667
00668 $oBaseObject = $this->getBaseObject();
00669 $sArticleTable = $oBaseObject->getViewName();
00670 $sArticleFields = $oBaseObject->getSelectFields();
00671
00672 $sSelect = "select $sArticleFields from $sArticleTable ";
00673 $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00674 $sSelect .= $oBaseObject->getSqlActiveSnippet();
00675
00676 $this->selectString($sSelect);
00677 }
00678
00686 public function loadOrderArticles($aOrders)
00687 {
00688 if (!count($aOrders)) {
00689 $this->clear();
00690 return;
00691 }
00692
00693 foreach ($aOrders as $iKey => $oOrder) {
00694 $aOrdersIds[] = $oOrder->getId();
00695 }
00696
00697 $oBaseObject = $this->getBaseObject();
00698 $sArticleTable = $oBaseObject->getViewName();
00699 $sArticleFields = $oBaseObject->getSelectFields();
00700 $sArticleFields = str_replace( "$sArticleTable.oxid", "oxorderarticles.oxartid as oxid", $sArticleFields );
00701
00702 $sSelect = "SELECT $sArticleFields FROM oxorderarticles ";
00703 $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00704 $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00705 $sSelect .= "order by $sArticleTable.oxid ";
00706
00707 $this->selectString( $sSelect );
00708
00709
00710 foreach ( $this as $oArticle ) {
00711 if ( !$oArticle->oxarticles__oxactive->value ) {
00712 $oArticle->setBuyableState( false );
00713 }
00714 }
00715 }
00716
00724 protected function _createIdListFromSql( $sSql)
00725 {
00726 $rs = oxDb::getDb(true)->execute( $sSql);
00727 if ($rs != false && $rs->recordCount() > 0) {
00728 while (!$rs->EOF) {
00729 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00730 $this[$rs->fields['oxid']] = $rs->fields['oxid'];
00731 $rs->moveNext();
00732 }
00733 }
00734 }
00735
00744 protected function _getFilterSql($sCatId, $aFilter)
00745 {
00746 $sO2CView = getViewName( 'oxobject2category' );
00747 $sArticleTable = getViewName( 'oxarticles' );
00748 $sFilter = '';
00749 $iCnt = 0;
00750 $sSuffix = oxLang::getInstance()->getLanguageTag();
00751
00752 foreach ( $aFilter as $sAttrId => $sValue ) {
00753 if ( $sValue ) {
00754 if ( $sFilter ) {
00755 $sFilter .= ' or ';
00756 }
00757 $sValue = mysql_real_escape_string($sValue);
00758 $sFilter .= "( oa.oxattrid = '$sAttrId' and oa.oxvalue$sSuffix = '$sValue' )";
00759 $iCnt++;
00760 }
00761 }
00762 if ( $sFilter ) {
00763 $sFilter = "WHERE $sFilter ";
00764 }
00765
00766 $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00767 $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00768 $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00769 $sFilterSelect.= $sFilter;
00770 $sFilterSelect.= "GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00771
00772 $aIds = oxDb::getDb( true )->getAll( $sFilterSelect );
00773 $sIds = '';
00774
00775 if ( $aIds ) {
00776 foreach ( $aIds as $aArt ) {
00777 if ( $sIds ) {
00778 $sIds .= ', ';
00779 }
00780 $sIds .= " '{$aArt['oxobjectid']}' ";
00781 }
00782
00783 if ( $sIds ) {
00784 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00785 }
00786 }
00787 return $sFilterSql;
00788 }
00789
00799 protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00800 {
00801 $sArticleTable = getViewName( 'oxarticles' );
00802 $sO2CView = getViewName( 'oxobject2category' );
00803
00804
00805
00806 $sSorting = '';
00807 if ( $this->_sCustomSorting ) {
00808 $sSorting = " {$this->_sCustomSorting} , ";
00809 }
00810
00811
00812
00813 $sFilterSql = '';
00814 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00815 $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00816 }
00817
00818 $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00819 ON $sArticleTable.oxid = oc.oxobjectid
00820 WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00821 and oc.oxcatnid = '$sCatId' $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00822
00823 return $sSelect;
00824 }
00825
00833 protected function _getSearchSelect( $sSearchString )
00834 {
00835
00836 if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00837 return '';
00838 }
00839
00840 $oDb = oxDb::getDb();
00841 $myConfig = $this->getConfig();
00842 $myUtils = oxUtils::getInstance();
00843 $sArticleTable = $this->getBaseObject()->getViewName();
00844
00845 $aSearch = explode( ' ', $sSearchString);
00846
00847 $sSearch = ' and ( ';
00848 $blSep = false;
00849
00850
00851 if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00852 $sSearchSep = ' and ';
00853 } else {
00854 $sSearchSep = ' or ';
00855 }
00856
00857 $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00858 $oBaseObject = $this->getBaseObject();
00859 $myUtilsString = oxUtilsString::getInstance();
00860 foreach ( $aSearch as $sSearchString) {
00861
00862 if ( !strlen( $sSearchString ) ) {
00863 continue;
00864 }
00865
00866 if ( $blSep ) {
00867 $sSearch .= $sSearchSep;
00868 }
00869 $blSep2 = false;
00870 $sSearch .= '( ';
00871
00872 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00873 foreach ( $aSearchCols as $sField ) {
00874
00875 if ( $blSep2) {
00876 $sSearch .= ' or ';
00877 }
00878
00879
00880 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00881 $sSearchTable = getViewName( 'oxartextends' );
00882 } else {
00883 $sSearchTable = $sArticleTable;
00884 }
00885
00886 $sField = $oBaseObject->getSqlFieldName( $sField );
00887
00888 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00889 if ( $sUml ) {
00890 $sSearch .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00891 }
00892 $blSep2 = true;
00893 }
00894 $sSearch .= ' ) ';
00895 $blSep = true;
00896 }
00897 $sSearch .= ' ) ';
00898
00899 return $sSearch;
00900 }
00901
00910 protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00911 {
00912 $oBaseObject = $this->getBaseObject();
00913 $sArticleTable = $oBaseObject->getViewName();
00914 $sSelectFields = $oBaseObject->getSelectFields();
00915
00916 $sSubSelect = "select if(oxparentid='',oxid,oxparentid) as id from $sArticleTable where oxprice > 0 ";
00917 if ( $dPriceTo) {
00918 $sSubSelect .= $dPriceTo?"and oxprice <= $dPriceTo ":" ";
00919 }
00920 $sSubSelect .= "group by id having ";
00921 if ( $dPriceFrom) {
00922 $sSubSelect .= $dPriceFrom?"min(oxprice) >= $dPriceFrom ":" ";
00923 }
00924 $sSelect = "select $sSelectFields from $sArticleTable where ";
00925 $sSelect .= "$sArticleTable.oxid in ($sSubSelect) ";
00926 $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1";
00927
00928 if ( !$this->_sCustomSorting ) {
00929 $sSelect .= " order by $sArticleTable.oxprice asc , $sArticleTable.oxid";
00930 } else {
00931 $sSelect .= " order by {$this->_sCustomSorting}, $sArticleTable.oxid ";
00932 }
00933
00934 return $sSelect;
00935
00936 }
00937
00945 protected function _getVendorSelect( $sVendorId )
00946 {
00947 $sArticleTable = getViewName('oxarticles');
00948 $oBaseObject = $this->getBaseObject();
00949 $sFieldNames = $oBaseObject->getSelectFields();
00950 $sSelect = "select $sFieldNames from $sArticleTable ";
00951 $sSelect .= "where $sArticleTable.oxvendorid = '$sVendorId' ";
00952 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
00953
00954 if ( $this->_sCustomSorting ) {
00955 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00956 }
00957
00958 return $sSelect;
00959 }
00960
00968 protected function _getManufacturerSelect( $sManufacturerId )
00969 {
00970 $sArticleTable = getViewName('oxarticles');
00971 $oBaseObject = $this->getBaseObject();
00972 $sFieldNames = $oBaseObject->getSelectFields();
00973 $sSelect = "select $sFieldNames from $sArticleTable ";
00974 $sSelect .= "where $sArticleTable.oxmanufacturerid = '$sManufacturerId' ";
00975 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
00976
00977 if ( $this->_sCustomSorting ) {
00978 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00979 }
00980
00981 return $sSelect;
00982 }
00983 }