Skip to content

Commit

Permalink
Ticket #4148 - Build-in API support: Improve DecodeData process.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Nov 13, 2023
1 parent 5232bdb commit c58ccf5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
68 changes: 47 additions & 21 deletions inc/classes/BxDolSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,21 @@ public function response ()
$sCode = $this->_bDataProcessing ? array() : '';

$bSingle = count($this->aChoice) == 1;
foreach ($this->aChoice as $sKey => $aValue) {
if (!$this->_sMetaType && !$aValue['GlobalSearch'])
foreach($this->aChoice as $sKey => $aValue) {
if(!$this->_sMetaType && !$aValue['GlobalSearch'])
continue;

$sClassName = 'BxTemplSearchResult';
if(!empty($aValue['class'])) {
$sClassName = $aValue['class'];
if(!empty($aValue['file']))
require_once(BX_DIRECTORY_PATH_ROOT . $aValue['file']);
}
$sClassName = 'BxTemplSearchResult';
if(!empty($aValue['class'])) {
$sClassName = $aValue['class'];
if(!empty($aValue['file']))
require_once(BX_DIRECTORY_PATH_ROOT . $aValue['file']);
}

$oEx = new $sClassName();
if ($this->_sMetaType && !$oEx->isMetaEnabled($this->_sMetaType))
if($this->_sMetaType && !$oEx->isMetaEnabled($this->_sMetaType))
continue;

$oEx->setId($aValue['id']);
$oEx->setLiveSearch($this->_bLiveSearch);
$oEx->setMetaType($this->_sMetaType);
Expand All @@ -113,15 +114,15 @@ public function response ()
$oEx->setCustomSearchCondition($this->_aCustomSearchCondition);

$oEx->aCurrent = array_merge_recursive($oEx->aCurrent, $this->_aCustomCurrentCondition);
if ($this->_sUnitTemplate)
if($this->_sUnitTemplate)
$oEx->setUnitTemplate($this->_sUnitTemplate);

if ($this->_bDataProcessing) {
if($this->_bDataProcessing) {
if($this->_bIsApi) {
if($bSingle)
$sCode = $oEx->decodeDataAPI($oEx->getSearchData());
else
$sCode[$sKey] = $oEx->getSearchQuery(['for_union' => true]);
$sCode[$sKey] = $oEx->getSearchQuery();
}
else
$sCode[$sKey] = $oEx->getSearchData();
Expand All @@ -140,10 +141,9 @@ public function response ()
$aItems = BxDolDb::getInstance()->getAll('(' . implode(') UNION (', $aQueries) . ') ORDER BY `added` DESC ' . current($sCode)['limit']);

$sCode = [];
foreach($aItems as $aItem) {
foreach($aItems as $aItem)
if(($oContentInfo = BxDolContentInfo::getObjectInstance($aItem['content_info'])) !== false)
$sCode[] = $oContentInfo->getContentInfoAPI($aItem['id'], $bExtendedUnits);
}
}

return $sCode;
Expand Down Expand Up @@ -722,24 +722,50 @@ function showPagination ($bAdmin = false, $bChangePage = true, $bPageReload = tr
*/
function getSearchData ()
{
bx_alert('simple_search', 'before_get_data', 0, false, [
'object' => &$this->aCurrent,
'mode' => $this->_sMode
]);

$this->aPseud = $this->_getPseud();
$this->setConditionParams();
if ($this->aCurrent['paginate']['num'] > 0) {
$aData = $this->getSearchDataByParams();
return $aData;
}
return array();
$aData = $this->aCurrent['paginate']['num'] > 0 ? $this->getSearchDataByParams() : [];

bx_alert('simple_search', 'get_data', 0, false, [
'object' => &$this->aCurrent,
'mode' => $this->_sMode,
'search_results' => &$aData
]);

return $aData;
}


/**
* Get query [query, limit] for search results. Is used for combined search from different sections.
* @param type $aParams array with params
* @return type array with query and limit
*/
function getSearchQuery($aParams = [])
{
if(!is_array($aParams))
$aParams = [];
$aParams = array_merge($aParams, ['for_union' => true]);

$this->aPseud = [
'id' => !empty($this->aCurrent['ident']) ? $this->aCurrent['ident'] : 'id',
'added' => !empty($this->aCurrent['added']) ? $this->aCurrent['added'] : 'added'
];

$this->setConditionParams();
return $this->getSearchDataByParams($aParams);
$aQuery = $this->getSearchDataByParams($aParams);

bx_alert('simple_search', 'get_query', 0, false, [
'object' => &$this->aCurrent,
'mode' => $this->_sMode,
'search_query' => &$aQuery
]);

return $aQuery;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions template/scripts/BxBaseSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ function getMain()
function displayResultBlock ()
{
$sCode = '';
bx_alert('simple_search', 'before_get_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode));

$aData = $this->getSearchData();
bx_alert('simple_search', 'get_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode, 'search_results' => &$aData));

if ($this->aCurrent['paginate']['num'] > 0) {
if($this->aCurrent['paginate']['num'] > 0) {
$sCode .= $this->addCustomParts();

foreach ($aData as $aValue)
Expand Down Expand Up @@ -85,7 +82,11 @@ function displayResultBlock ()
]);
}

bx_alert('simple_search', 'show_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode, 'search_results' => &$sCode));
bx_alert('simple_search', 'show_data', 0, false, [
'object' => &$this->aCurrent,
'mode' => $this->_sMode,
'search_results' => &$sCode
]);

return $sCode;
}
Expand Down

0 comments on commit c58ccf5

Please sign in to comment.