Skip to content

Commit

Permalink
Ticket #4558 - Build-in API support: Courses.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Oct 15, 2024
1 parent d5d3049 commit d4e1f41
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getCodeAPI($bForceReturn = false)
return [];

return parent::getCodeAPI($bForceReturn);
}
}

protected function _getCellContentId($mixedValue, $sKey, $aField, $aRow)
{
Expand Down
74 changes: 62 additions & 12 deletions modules/boonex/courses/classes/BxCoursesGridCntStructureManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ public function getCode ($isDisplayHeader = true)
return parent::getCode($isDisplayHeader);
}

public function getFormBlockTitleAPI($sAction, $iId = 0)
{
$CNF = &$this->_oModule->_oConfig->CNF;

$sResult = '';

switch($sAction) {
case 'add':
$sResult = $CNF['T']['popup_title_content_node_add'];
break;

case 'edit':
$sResult = $CNF['T']['popup_title_content_node_edit'];
break;
}

return $this->_parseNodeName(_t($sResult));
}

public function getFormCallBackUrlAPI($sAction, $iId = 0)
{
return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction . '&entry_id=' . $this->_iEntryId . '&parent_id=' . $this->_iParentId . '&id=' . $iId;
}

public function getCodeAPI($bForceReturn = false)
{
if($this->_iLevel > $this->_iLevelMax)
Expand All @@ -86,6 +110,18 @@ public function getCodeAPI($bForceReturn = false)
return parent::getCodeAPI($bForceReturn);
}

protected function _getActionsAPI ($sType)
{
$aResult = parent::_getActionsAPI($sType);

if($aResult && $sType == 'independent') {
if(!empty($aResult['add']))
$aResult['add']['title'] = $this->_parseNodeName($aResult['add']['title']);
}

return $aResult;
}

public function performActionAdd()
{
$CNF = &$this->_oModule->_oConfig->CNF;
Expand All @@ -94,7 +130,7 @@ public function performActionAdd()

$aEntryInfo = $this->_oModule->_oDb->getContentInfoById($this->_iEntryId);
if(($mixedResult = $this->_oModule->checkAllowedEdit($aEntryInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
return echoJson(['msg' => $mixedResult]);
return $this->_getActionResult(['msg' => $mixedResult]);

$sForm = $CNF['OBJECT_FORM_CNT_NODE_DISPLAY_ADD'];
$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_CNT_NODE'], $CNF['OBJECT_FORM_CNT_NODE_DISPLAY_ADD']);
Expand All @@ -119,14 +155,17 @@ public function performActionAdd()
if($this->_iLevel > 1)
$this->_oModule->_oDb->updateContentStructureCounters($this->_iParentId, $this->_iLevel, 1);

$aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
$aResult = $this->_bIsApi ? [] : ['grid' => $this->getCode(false), 'blink' => $iId];
}
else
$aRes = ['msg' => _t($CNF['T']['err_cannot_perform'])];
$aResult = ['msg' => _t($CNF['T']['err_cannot_perform'])];

return echoJson($aRes);
return $this->_getActionResult($aResult);
}

if($this->_bIsApi)
return $this->getFormBlockAPI($oForm, $sAction);

bx_import('BxTemplFunctions');
$sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_content_node'), $this->_parseNodeName(_t($CNF['T']['popup_title_content_node_add'])), $this->_oModule->_oTemplate->parseHtmlByName('popup_content_node.html', [
'form_id' => $oForm->getId(),
Expand All @@ -146,15 +185,15 @@ public function performActionEdit()

$aEntryInfo = $this->_oModule->_oDb->getContentInfoById($this->_iEntryId);
if(($mixedResult = $this->_oModule->checkAllowedEdit($aEntryInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
return echoJson(['msg' => $mixedResult]);
return $this->_getActionResult(['msg' => $mixedResult]);

$aIds = $this->_getIds();
if($aIds === false)
return echoJson([]);
return $this->_getActionResult([]);

$aNode = $this->_oModule->_oDb->getContentNodes(['sample' => 'id', 'id' => array_shift($aIds)]);
if(!is_array($aNode) || empty($aNode))
return echoJson([]);
return $this->_getActionResult([]);

$sForm = $CNF['OBJECT_FORM_CNT_NODE_DISPLAY_EDIT'];
$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_CNT_NODE'], $CNF['OBJECT_FORM_CNT_NODE_DISPLAY_EDIT']);
Expand All @@ -166,13 +205,16 @@ public function performActionEdit()
$oForm->initChecker($aNode);
if($oForm->isSubmittedAndValid()) {
if($oForm->update($aNode['id']) !== false)
$aRes = ['grid' => $this->getCode(false), 'blink' => $aNode['id']];
$aResult = $this->_bIsApi ? [] : ['grid' => $this->getCode(false), 'blink' => $aNode['id']];
else
$aRes = ['msg' => _t($CNF['T']['err_cannot_perform'])];
$aResult = ['msg' => _t($CNF['T']['err_cannot_perform'])];

return echoJson($aRes);
return $this->_getActionResult($aResult);
}

if($this->_bIsApi)
return $this->getFormBlockAPI($oForm, $sAction, $aNode['id']);

bx_import('BxTemplFunctions');
$sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_content_node'), $this->_parseNodeName(_t($CNF['T']['popup_title_content_node_edit'])), $this->_oModule->_oTemplate->parseHtmlByName('popup_content_node.html', [
'form_id' => $oForm->getId(),
Expand Down Expand Up @@ -212,11 +254,16 @@ protected function _getCellHeaderCounters($sKey, $aField)

protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
{
$sLink = bx_append_url_params($this->_sPageUrl, ['parent_id' => $aRow['id']]);

if($this->_bIsApi)
return ['type' => 'text', 'value'=> $mixedValue];
return ['type' => 'link', 'data' => [
'text' => $mixedValue,
'url' => bx_api_get_relative_url($sLink)
]];

$mixedValue = $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', [
'href' => bx_append_url_params($this->_sPageUrl, ['parent_id' => $aRow['id']]),
'href' => $sLink,
'title' => bx_html_attribute($mixedValue),
'content' => $mixedValue
]);
Expand Down Expand Up @@ -249,6 +296,9 @@ protected function _getCellCounters($mixedValue, $sKey, $aField, $aRow)
if(!empty($mixedValue) && ($aCounters = json_decode(html_entity_decode($mixedValue), true)))
$sCounters = $this->_oModule->_oTemplate->getCounters($aCounters);

if($this->_bIsApi)
return ['type' => 'text', 'data' => $sCounters];

return parent::_getCellDefault($sCounters, $sKey, $aField, $aRow);
}

Expand Down

0 comments on commit d4e1f41

Please sign in to comment.