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 8a6abdf commit d5d3049
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
13 changes: 9 additions & 4 deletions modules/boonex/courses/classes/BxCoursesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ public function servicePassNode($iNodeId)
$this->_oDb->deleteContentNodes2Users(['node_id' => $iNodeId, 'profile_id' => $iProfileId]);
}

$sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iEntryId, [
'node_id' => $iNodeId
]);

return [
'code' => 0,
'redirect' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iEntryId, [
'node_id' => $iNodeId
])
'redirect' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink
];
}

Expand Down Expand Up @@ -138,6 +140,9 @@ public function servicePassData($iDataId)
if(($sMethod = 'get_link') && bx_is_srv($aData['content_type'], $sMethod))
$aResult['redirect'] = bx_srv($aData['content_type'], $sMethod, [$aData['content_id']]);

if($this->_bIsApi)
$aResult['redirect'] = bx_api_get_relative_url($aResult['redirect']);

return $aResult;
}

Expand Down Expand Up @@ -361,7 +366,7 @@ public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage =
'usage' => $iUsage
]);

return $this->_bIsApi ? [bx_api_get_block('entity_node', $mixedResult)] : $mixedResult;
return $this->_bIsApi ? [bx_api_get_block('lesson_structure', $mixedResult)] : $mixedResult;
}

public function getNodeLevelByParent($aParentInfo)
Expand Down
28 changes: 24 additions & 4 deletions modules/boonex/courses/classes/BxCoursesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,29 @@ public function getCounters($aCounters)
$bTmplVarsCounters = !empty($aCounters[$sUsage]) && is_array($aCounters[$sUsage]);
if($bTmplVarsCounters) {
$aTmplVarsCounters['bx_repeat:counters_' . $sUsage] = [];
foreach($aCounters[$sUsage] as $sModule => $iCount)
$aTmplVarsCounters['bx_repeat:counters_' . $sUsage][] = [
foreach($aCounters[$sUsage] as $sModule => $iCount) {
$aCounter = [
'title' => _t('_' . $sModule),
'value' => $iCount
];

if($this->_bIsApi)
$aTmplVars[$sUsage] = $aCounter;
else
$aTmplVarsCounters['bx_repeat:counters_' . $sUsage][] = $aCounter;
}
}

if($this->_bIsApi)
continue;

$aTmplVars['bx_if:show_' . $sUsage] = [
'condition' => $bTmplVarsCounters,
'content' => $aTmplVarsCounters
];
}

return $this->parseHtmlByName('counters.html', $aTmplVars);
return $this->_bIsApi ? $aTmplVars : $this->parseHtmlByName('counters.html', $aTmplVars);
}

public function entryStructureByLevel($aContentInfo, $aParams = [])
Expand Down Expand Up @@ -168,7 +177,7 @@ public function entryStructureByParentMl1($aContentInfo, $aParams = [])
$aNode = array_merge($aNode, [
'level_max' => $iLevelMax,
'index' => $iKey,
'link' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink,
'link' => $sLink,
'pass_percent' => $iPassPercent,
'pass_progress' => $sPassProgress,
'pass_status' => $sPassStatus,
Expand All @@ -183,6 +192,17 @@ public function entryStructureByParentMl1($aContentInfo, $aParams = [])
]
]);

if($this->_bIsApi) {
if(!empty($aNode['counters']) && ($aCounters = json_decode($aNode['counters'], true)))
$aNode['counters'] = $this->getCounters($aCounters);

$aNode = array_merge($aNode, [
'link' => bx_api_get_relative_url($aNode['link']),
'pass_title' => $sPassTitle,
'pass_callback' => $this->MODULE . '/pass_node&params[]=' . $aNode['node_id'],
]);
}

$aTmplVarsNodes[] = $this->_bIsApi ? $aNode : [
'node' => $this->parseHtmlByName('ml' . $iLevelMax . '_node_l' . $aNode['level'] . '.html', $aNode)
];
Expand Down

0 comments on commit d5d3049

Please sign in to comment.