35 if ( !isset( $iLanguage ) ) {
38 $this->_iLanguage = $iLanguage;
53 public function getSearchArticles( $sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false, $sSortBy =
false )
57 $this->iActPage = ($this->iActPage < 0)?0:$this->iActPage;
61 $iNrofCatArticles = $this->
getConfig()->getConfigParam(
'iNrofCatArticles' );
62 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:10;
64 $oArtList =
oxNew(
'oxarticlelist' );
65 $oArtList->setSqlLimit( $iNrofCatArticles * $this->iActPage, $iNrofCatArticles );
67 $sSelect = $this->
_getSearchSelect( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $sSortBy );
69 $oArtList->selectString( $sSelect );
85 public function getSearchArticleCount( $sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false )
88 $sSelect = $this->
_getSearchSelect( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer,
false );
91 $sPartial = substr( $sSelect, strpos( $sSelect,
' from ' ) );
92 $sSelect =
"select count( ".getViewName(
'oxarticles', $this->_iLanguage ).
".oxid ) $sPartial ";
110 protected function _getSearchSelect( $sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false, $sSortBy =
false)
115 if ( $sInitialSearchCat ) {
117 $oCategory =
oxNew(
'oxcategory' );
118 $sCatTable = $oCategory->getViewName();
120 $sQ =
"select 1 from $sCatTable where $sCatTable.oxid = ".$oDb->quote( $sInitialSearchCat ).
" ";
121 $sQ .=
"and ".$oCategory->getSqlActiveSnippet();
122 if ( !$oDb->getOne( $sQ ) ) {
128 if ( $sInitialSearchVendor ) {
130 $oVendor =
oxNew(
'oxvendor' );
131 $sVndTable = $oVendor->getViewName();
133 $sQ =
"select 1 from $sVndTable where $sVndTable.oxid = ".$oDb->quote( $sInitialSearchVendor ).
" ";
134 $sQ .=
"and ".$oVendor->getSqlActiveSnippet();
135 if ( !$oDb->getOne( $sQ ) ) {
141 if ( $sInitialSearchManufacturer ) {
143 $oManufacturer =
oxNew(
'oxmanufacturer' );
144 $sManTable = $oManufacturer->getViewName();
146 $sQ =
"select 1 from $sManTable where $sManTable.oxid = ".$oDb->quote( $sInitialSearchManufacturer ).
" ";
147 $sQ .=
"and ".$oManufacturer->getSqlActiveSnippet();
148 if ( !$oDb->getOne( $sQ ) ) {
155 if ( $sSearchParamForQuery ) {
156 $sWhere = $this->
_getWhere( $sSearchParamForQuery );
157 } elseif ( !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
162 $oArticle =
oxNew(
'oxarticle' );
163 $sArticleTable = $oArticle->getViewName();
164 $sO2CView = getViewName(
'oxobject2category' );
166 $sSelectFields = $oArticle->getSelectFields();
170 if ( is_array( $aSearchCols = $this->
getConfig()->getConfigParam(
'aSearchCols' ) ) ) {
171 if ( in_array(
'oxlongdesc', $aSearchCols ) || in_array(
'oxtags', $aSearchCols ) ) {
172 $sDescView = getViewName(
'oxartextends', $this->_iLanguage );
173 $sDescJoin =
" LEFT JOIN {$sDescView} ON {$sArticleTable}.oxid={$sDescView}.oxid ";
178 $sSelect =
"select {$sSelectFields}, {$sArticleTable}.oxtimestamp from {$sArticleTable} {$sDescJoin} where ";
181 if ( $sInitialSearchCat ) {
182 $sCatView = getViewName(
'oxcategories', $this->_iLanguage );
183 $sInitialSearchCatQuoted = $oDb->quote( $sInitialSearchCat );
184 $sSelectCat =
"select oxid from {$sCatView} where oxid = $sInitialSearchCatQuoted and (oxpricefrom != '0' or oxpriceto != 0)";
185 if ( $oDb->getOne($sSelectCat) ) {
186 $sSelect =
"select {$sSelectFields}, {$sArticleTable}.oxtimestamp from {$sArticleTable} $sDescJoin " .
187 "where {$sArticleTable}.oxid in ( select {$sArticleTable}.oxid as id from {$sArticleTable}, {$sO2CView} as oxobject2category, {$sCatView} as oxcategories " .
188 "where (oxobject2category.oxcatnid=$sInitialSearchCatQuoted and oxobject2category.oxobjectid={$sArticleTable}.oxid) or (oxcategories.oxid=$sInitialSearchCatQuoted and {$sArticleTable}.oxprice >= oxcategories.oxpricefrom and
189 {$sArticleTable}.oxprice <= oxcategories.oxpriceto )) and ";
191 $sSelect =
"select {$sSelectFields} from {$sO2CView} as
192 oxobject2category, {$sArticleTable} {$sDescJoin} where oxobject2category.oxcatnid=$sInitialSearchCatQuoted and
193 oxobject2category.oxobjectid={$sArticleTable}.oxid and ";
197 $sSelect .= $oArticle->getSqlActiveSnippet();
198 $sSelect .=
" and {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 ";
200 if ( $sInitialSearchVendor ) {
201 $sSelect .=
" and {$sArticleTable}.oxvendorid = " . $oDb->quote( $sInitialSearchVendor ) .
" ";
204 if ( $sInitialSearchManufacturer ) {
205 $sSelect .=
" and {$sArticleTable}.oxmanufacturerid = " . $oDb->quote( $sInitialSearchManufacturer ) .
" ";
211 $sSelect .=
" order by {$sSortBy} ";
229 $sArticleTable = getViewName(
'oxarticles', $this->_iLanguage );
231 $aSearchCols =
$myConfig->getConfigParam(
'aSearchCols' );
232 if ( !(is_array( $aSearchCols ) && count( $aSearchCols ) ) ) {
236 $oTempArticle =
oxNew(
'oxarticle' );
237 $sSearchSep =
$myConfig->getConfigParam(
'blSearchUseAND' )?
'and ':
'or ';
238 $aSearch = explode(
' ', $sSearchString );
239 $sSearch =
' and ( ';
243 foreach ( $aSearch as $sSearchString ) {
245 if ( !strlen( $sSearchString ) ) {
250 $sSearch .= $sSearchSep;
256 foreach ( $aSearchCols as $sField ) {
263 if ( $sField ==
'oxlongdesc' || $sField ==
'oxtags' ) {
264 $sSearchField = getViewName(
'oxartextends', $this->_iLanguage ).
".{$sField}";
266 $sSearchField =
"{$sArticleTable}.{$sField}";
269 $sSearch .=
" {$sSearchField} like ".$oDb->quote(
"%$sSearchString%" );
272 if ( ( $sUml = $myUtilsString->prepareStrForSearch( $sSearchString ) ) ) {
273 $sSearch .=
" or {$sSearchField} like ".$oDb->quote(
"%$sUml%" );