oxarticlelist.php

Go to the documentation of this file.
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         // sorting for multilanguage fields
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         // removing dublicates
00096         $aHistoryArticles = array_unique( $aHistoryArticles);
00097 
00098         if (count($aHistoryArticles) > 5) {
00099             array_shift($aHistoryArticles);
00100         }
00101 
00102         //add to session
00103         $mySession->setVar('aHistoryArticles', $aHistoryArticles);
00104 
00105         //remove current article and return array
00106         //asignment =, not ==
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         //has module?
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                 // switched off, do nothing
00134                 break;
00135             case 1:
00136                 // manually entered
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         //has module?
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                 // switched off, do nothing
00176                 break;
00177             case 1:
00178                 // manually entered
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         // Performance
00204         if ( !trim( $sActionID) ) {
00205             return;
00206         }
00207 
00208         $sShopID        = $this->getConfig()->getShopId();
00209         $sActionID      = strtolower( $sActionID);
00210 
00211         //echo $sSelect;
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         // Performance
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         // #525 bidirectional crossselling
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         // Performance
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         //sorting articles
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         // calc count - we can not use count($this) here as we might have paging enabled
00323         // #1970C - if any filters are used, we can not use cached category article count
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         // this select is FAST so no need to hazzle here with getNrOfArticles()
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         // longdesc field now is kept on different table
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         // load the articles
00434         $sSelect  =  "select $sArticleTable.oxid from $sArticleTable $sDescTable where $sDescJoin";
00435 
00436         // must be additional conditions in select if searching in category
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         // #671
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         //echo( $sSelect);
00495 
00496         if ( !$oCategory ) {
00497             return $this->count();
00498         }
00499 
00500         // #858A
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 match ( oxartextends.oxtags{$sLangExt} )
00590                against( ".oxDb::getDb()->quote( $sTag )." )";
00591 
00592         // checking stock etc
00593         if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00594             $sQ .= " and {$sActiveSnippet}";
00595         }
00596 
00597         if ( $this->_sCustomSorting ) {
00598             $sQ .= " order by {$sArticleTable}.{$this->_sCustomSorting} ";
00599         }
00600 
00601         $this->selectString( $sQ );
00602 
00603         // calc count - we can not use count($this) here as we might have paging enabled
00604         return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00605     }
00606 
00615     public function getTagArticleIds( $sTag, $iLang )
00616     {
00617         $oListObject = $this->getBaseObject();
00618         $sArticleTable = $oListObject->getViewName();
00619         $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00620 
00621         $oTagHandler = oxNew( 'oxtagcloud' );
00622         $sTag = $oTagHandler->prepareTags( $sTag );
00623 
00624         $sQ = "select oxartextends.oxid from oxartextends inner join {$sArticleTable} on
00625                {$sArticleTable}.oxid = oxartextends.oxid where match ( oxartextends.oxtags{$sLangExt} )
00626                against( ".oxDb::getDb()->quote( $sTag )." )";
00627 
00628         // checking stock etc
00629         if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00630             $sQ .= " and {$sActiveSnippet}";
00631         }
00632 
00633         if ( $this->_sCustomSorting ) {
00634             $sQ .= " order by {$sArticleTable}.{$this->_sCustomSorting} ";
00635         }
00636 
00637         return $this->_createIdListFromSql( $sQ );
00638     }
00639 
00647     public function loadIds($aIds)
00648     {
00649         if (!count($aIds)) {
00650             $this->clear();
00651             return;
00652         }
00653 
00654         foreach ($aIds as $iKey => $sVal) {
00655             $aIds[$iKey] = mysql_real_escape_string($sVal);
00656         }
00657 
00658         $oBaseObject    = $this->getBaseObject();
00659         $sArticleTable  = $oBaseObject->getViewName();
00660         $sArticleFields = $oBaseObject->getSelectFields();
00661 
00662         $sSelect  = "select $sArticleFields from $sArticleTable ";
00663         $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00664         $sSelect .= $oBaseObject->getSqlActiveSnippet();
00665 
00666         $this->selectString($sSelect);
00667     }
00668 
00676     public function loadOrderArticles($aOrders)
00677     {
00678         if (!count($aOrders)) {
00679             $this->clear();
00680             return;
00681         }
00682 
00683         foreach ($aOrders as $iKey => $oOrder) {
00684             $aOrdersIds[] = $oOrder->getId();
00685         }
00686 
00687         $oBaseObject    = $this->getBaseObject();
00688         $sArticleTable  = $oBaseObject->getViewName();
00689         $sArticleFields = $oBaseObject->getSelectFields();
00690 
00691         $sSelect  = "SELECT $sArticleFields FROM oxorderarticles ";
00692         $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00693         $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00694         $sSelect .= "order by $sArticleTable.oxid ";
00695 
00696         $this->selectString( $sSelect );
00697     }
00698 
00706     protected function _createIdListFromSql( $sSql)
00707     {
00708         $rs = oxDb::getDb(true)->execute( $sSql);
00709         if ($rs != false && $rs->recordCount() > 0) {
00710             while (!$rs->EOF) {
00711                 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00712                 $this[$rs->fields['oxid']] =  $rs->fields['oxid']; //only the oxid
00713                 $rs->moveNext();
00714             }
00715         }
00716     }
00717 
00726     protected function _getFilterSql($sCatId, $aFilter)
00727     {
00728         $sO2CView      = getViewName( 'oxobject2category' );
00729         $sArticleTable = getViewName( 'oxarticles' );
00730         $sFilter = '';
00731         $iCnt    = 0;
00732         $sSuffix = oxLang::getInstance()->getLanguageTag();
00733 
00734         foreach ( $aFilter as $sAttrId => $sValue ) {
00735             if ( $sValue ) {
00736                 if ( $sFilter ) {
00737                     $sFilter .= ' or ';
00738                 }
00739                 $sValue = mysql_real_escape_string($sValue);
00740                 $sFilter .= "( oa.oxattrid = '$sAttrId' and oa.oxvalue$sSuffix = '$sValue' )";
00741                 $iCnt++;
00742             }
00743         }
00744         if ( $sFilter ) {
00745             $sFilter = "WHERE $sFilter ";
00746         }
00747 
00748         $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00749         $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00750         $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00751         $sFilterSelect.= $sFilter;
00752         $sFilterSelect.= "GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00753 
00754         $aIds = oxDb::getDb( true )->getAll( $sFilterSelect );
00755         $sIds = '';
00756 
00757         if ( $aIds ) {
00758             foreach ( $aIds as $aArt ) {
00759                 if ( $sIds ) {
00760                     $sIds .= ', ';
00761                 }
00762                 $sIds .= " '{$aArt['oxobjectid']}' ";
00763             }
00764 
00765             if ( $sIds ) {
00766                 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00767             }
00768         }
00769         return $sFilterSql;
00770     }
00771 
00781     protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00782     {
00783         $sArticleTable = getViewName( 'oxarticles' );
00784         $sO2CView      = getViewName( 'oxobject2category' );
00785 
00786         // ----------------------------------
00787         // sorting
00788         $sSorting = '';
00789         if ( $this->_sCustomSorting ) {
00790             $sSorting = " {$this->_sCustomSorting} , ";
00791         }
00792 
00793         // ----------------------------------
00794         // filtering ?
00795         $sFilterSql = '';
00796         if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00797             $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00798         }
00799 
00800         $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00801                     ON $sArticleTable.oxid = oc.oxobjectid
00802                     WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00803                     and oc.oxcatnid = '$sCatId' $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00804 
00805         return $sSelect;
00806     }
00807 
00815     protected function _getSearchSelect( $sSearchString )
00816     {
00817         // check if it has string at all
00818         if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00819             return '';
00820         }
00821 
00822         $oDb = oxDb::getDb();
00823         $myConfig = $this->getConfig();
00824         $myUtils  = oxUtils::getInstance();
00825         $sArticleTable = $this->getBaseObject()->getViewName();
00826 
00827         $aSearch = explode( ' ', $sSearchString);
00828 
00829         $sSearch  = ' and ( ';
00830         $blSep = false;
00831 
00832         // #723
00833         if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00834             $sSearchSep = ' and ';
00835         } else {
00836             $sSearchSep = ' or ';
00837         }
00838 
00839         $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00840         $oBaseObject = $this->getBaseObject();
00841         $myUtilsString = oxUtilsString::getInstance();
00842         foreach ( $aSearch as $sSearchString) {
00843 
00844             if ( !strlen( $sSearchString ) ) {
00845                 continue;
00846             }
00847 
00848             if ( $blSep ) {
00849                 $sSearch .= $sSearchSep;
00850             }
00851             $blSep2   = false;
00852             $sSearch .= '( ';
00853 
00854             $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00855             foreach ( $aSearchCols as $sField ) {
00856 
00857                 if ( $blSep2) {
00858                     $sSearch  .= ' or ';
00859                 }
00860 
00861                 // as long description now is on different table table must differ
00862                 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00863                     $sSearchTable = getViewName( 'oxartextends' );
00864                 } else {
00865                     $sSearchTable = $sArticleTable;
00866                 }
00867 
00868                 $sField = $oBaseObject->getSqlFieldName( $sField );
00869 
00870                 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00871                 if ( $sUml ) {
00872                     $sSearch  .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00873                 }
00874                 $blSep2 = true;
00875             }
00876             $sSearch  .= ' ) ';
00877             $blSep = true;
00878         }
00879         $sSearch .= ' ) ';
00880 
00881         return $sSearch;
00882     }
00883 
00892     protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00893     {
00894         $oBaseObject   = $this->getBaseObject();
00895         $sArticleTable = $oBaseObject->getViewName();
00896         $sSelectFields = $oBaseObject->getSelectFields();
00897 
00898         $sSubSelect  = "select if(oxparentid='',oxid,oxparentid) as id from $sArticleTable where oxprice > 0 ";
00899         if ( $dPriceTo) {
00900             $sSubSelect .= $dPriceTo?"and oxprice <= $dPriceTo ":" ";
00901         }
00902         $sSubSelect .= "group by id having ";
00903         if ( $dPriceFrom) {
00904             $sSubSelect .= $dPriceFrom?"min(oxprice) >= $dPriceFrom ":" ";
00905         }
00906         $sSelect =  "select $sSelectFields from $sArticleTable where ";
00907         $sSelect .= "$sArticleTable.oxid in ($sSubSelect) ";
00908         $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1";
00909 
00910         if ( !$this->_sCustomSorting ) {
00911             $sSelect .= " order by $sArticleTable.oxprice asc , $sArticleTable.oxid";
00912         } else {
00913             $sSelect .= " order by {$this->_sCustomSorting}, $sArticleTable.oxid ";
00914         }
00915 
00916         return $sSelect;
00917 
00918     }
00919 
00927     protected function _getVendorSelect( $sVendorId )
00928     {
00929         $sArticleTable = getViewName('oxarticles');
00930         $oBaseObject = $this->getBaseObject();
00931         $sFieldNames = $oBaseObject->getSelectFields();
00932         $sSelect  = "select $sFieldNames from $sArticleTable ";
00933         $sSelect .= "where $sArticleTable.oxvendorid = '$sVendorId' ";
00934         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00935 
00936         if ( $this->_sCustomSorting ) {
00937             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00938         }
00939 
00940         return $sSelect;
00941     }
00942 
00950     protected function _getManufacturerSelect( $sManufacturerId )
00951     {
00952         $sArticleTable = getViewName('oxarticles');
00953         $oBaseObject = $this->getBaseObject();
00954         $sFieldNames = $oBaseObject->getSelectFields();
00955         $sSelect  = "select $sFieldNames from $sArticleTable ";
00956         $sSelect .= "where $sArticleTable.oxmanufacturerid = '$sManufacturerId' ";
00957         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00958 
00959         if ( $this->_sCustomSorting ) {
00960             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00961         }
00962 
00963         return $sSelect;
00964     }
00965 }

Generated on Wed Apr 22 12:26:30 2009 for OXID eShop CE by  doxygen 1.5.5