Skip to content

Commit

Permalink
#4148 Build-in API support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Trofimov committed Dec 12, 2022
1 parent 0a1c326 commit 839ccdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
17 changes: 17 additions & 0 deletions inc/classes/BxDolSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ function processingRaw ()
*/
function processing ()
{
if (defined('BX_API')) {
return $this->processingAPI ();
}

$sCode = $this->displayResultBlock();
if ($this->aCurrent['paginate']['num'] > 0) {
$sPaginate = $this->showPagination();
Expand All @@ -489,6 +493,19 @@ function processing ()
return $sCode;
}

function processingAPI ()
{
return [
'unit' => 'general',
'data' => $this->getSearchData(),
'paginate' => [
'num' => $this->aCurrent['paginate']['num'],
'per_page' => $this->aCurrent['paginate']['perPage'],
'start' => $this->aCurrent['paginate']['start'],
]
];
}

/**
* Get html output of search result
* @return html code
Expand Down
8 changes: 1 addition & 7 deletions inc/classes/BxDolTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -1630,11 +1630,6 @@ function getHtml($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
function parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
{
if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginTemplate($sName, $sRand = time().rand());

if (defined('BX_API') && constant('BX_API')) {
if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sContent, false);
return $aVariables;
}

if (($sContent = $this->getCached($sName, $aVariables, $mixedKeyWrapperHtml, $sCheckIn)) !== false) {
if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sContent, true);
Expand Down Expand Up @@ -2939,8 +2934,7 @@ function _parseContent($sContent, $aVariables, $mixedKeyWrapperHtml = null)
));

//--- Parse Predefined Keys ---//
if (!defined('BX_API') || !constant('BX_API'))
$sContent = preg_replace($aKeys, $aValues, $sContent);
$sContent = preg_replace($aKeys, $aValues, $sContent);

//--- Parse System Keys ---//
try {
Expand Down
4 changes: 2 additions & 2 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2729,7 +2729,7 @@ protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAc
public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
{
if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
return MsgBox($sMsg);
return defined('BX_API') ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : MsgBox($sMsg);

bx_import($sClassSearchResult, $this->_aModule);
$sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
Expand All @@ -2746,7 +2746,7 @@ public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PA
return '';

if ($s = $o->processing())
return $s;
return defined('BX_API') ? [['id' => 1, 'type' => 'browse', 'data' => $s]] : $s;
else
return '';
}
Expand Down

0 comments on commit 839ccdb

Please sign in to comment.