Skip to content

Commit

Permalink
Ticket #4817 - Courses improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Oct 18, 2024
1 parent dc4aa32 commit 083bd82
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
4 changes: 2 additions & 2 deletions modules/boonex/courses/classes/BxCoursesFormContentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct($aInfo, $oTemplate = false)

if(isset($this->aInputs['passing']))
$this->aInputs['passing']['values'] = [
['key' => 0, 'value' => _t('_bx_courses_form_content_node_input_passing_all')],
['key' => 1, 'value' => _t('_bx_courses_form_content_node_input_passing_alternate')]
['key' => BX_COURSES_CND_PASSING_ALL, 'value' => _t('_bx_courses_form_content_node_input_passing_all')],
['key' => BX_COURSES_CND_PASSING_ALTERNATE, 'value' => _t('_bx_courses_form_content_node_input_passing_alternate')]
];
}

Expand Down
7 changes: 5 additions & 2 deletions modules/boonex/courses/classes/BxCoursesGridCntDataManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ protected function _getActionBack($sType, $sKey, $a, $isSmall = false, $isDisabl
$sUrl = $this->_sPageUrl;
if(!empty($this->_aNodeInfo['parent_id']))
$sUrl = bx_append_url_params($sUrl, ['parent_id' => $this->_aNodeInfo['parent_id']]);

if($this->_bIsApi)
return array_merge($a, ['name' => $sKey, 'type' => 'link', 'link' => bx_api_get_relative_url($sUrl)]);

$a['attr'] = array_merge($a['attr'], [
"onclick" => "window.open('" . $sUrl . "', '_self');"
Expand All @@ -140,7 +143,7 @@ protected function _getActionBack($sType, $sKey, $a, $isSmall = false, $isDisabl
protected function _getActionAddSt($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
{
if($this->_bIsApi)
return array_merge($a, ['name' => $sKey, 'type' => 'modal', 'action' => $sKey, 'values' => $this->_getValues(BX_COURSES_CND_USAGE_ST)]);
return array_merge($a, ['name' => $sKey, 'type' => 'menu', 'action' => $sKey, 'values' => $this->_getValues(BX_COURSES_CND_USAGE_ST)]);

$CNF = &$this->_oModule->_oConfig->CNF;

Expand All @@ -153,7 +156,7 @@ protected function _getActionAddSt($sType, $sKey, $a, $isSmall = false, $isDisab
protected function _getActionAddAt($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
{
if($this->_bIsApi)
return array_merge($a, ['name' => $sKey, 'type' => 'modal', 'action' => $sKey, 'values' => $this->_getValues(BX_COURSES_CND_USAGE_AT)]);
return array_merge($a, ['name' => $sKey, 'type' => 'menu', 'action' => $sKey, 'values' => $this->_getValues(BX_COURSES_CND_USAGE_AT)]);

$CNF = &$this->_oModule->_oConfig->CNF;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,15 @@ protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
protected function _getActionBack($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
{
if(empty($this->_aParentInfo))
return '';
return $this->_bIsApi ? [] : '';

$sUrl = $this->_sPageUrl;
if(!empty($this->_aParentInfo['parent_id']))
$sUrl = bx_append_url_params($sUrl, ['parent_id' => $this->_aParentInfo['parent_id']]);

if($this->_bIsApi)
return array_merge($a, ['name' => $sKey, 'type' => 'link', 'link' => bx_api_get_relative_url($sUrl)]);

$a['attr'] = array_merge($a['attr'], [
"onclick" => "window.open('" . $sUrl . "','_self');"
]);
Expand Down
8 changes: 8 additions & 0 deletions modules/boonex/courses/classes/BxCoursesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
* @{
*/

/**
* How to pass a lesson's steps:
* 0 - all at once, the order is not important
* 1 - alternate, the order is important
*/
define('BX_COURSES_CND_PASSING_ALL', 0);
define('BX_COURSES_CND_PASSING_ALTERNATE', 1);

/**
* Content data usage:
* st - step,
Expand Down
54 changes: 44 additions & 10 deletions modules/boonex/courses/classes/BxCoursesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ public function entryNode($aContentInfo, $aParams = [])
'index' => $aNode['order'],
'sample' => $this->_oConfig->getContentNodeTitle($aNode['level']),
'title' => $aNode['title'],
'text' => $aNode['text']
'text' => $aNode['text'],
'passing' => $aNode['passing']
];

if($this->_bIsApi)
Expand Down Expand Up @@ -478,6 +479,9 @@ protected function _entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage)
$sTxtUndefined = _t('_undefined');
$sTxtPass = _t('_bx_courses_txt_pass');

$bUsageSt = $iUsage == BX_COURSES_CND_USAGE_ST;
$bUsageAt = $iUsage == BX_COURSES_CND_USAGE_AT;

$aResults = [];
if(!empty($aDataItems) && is_array($aDataItems))
foreach($aDataItems as $iIndex => $aDataItem) {
Expand All @@ -489,8 +493,10 @@ protected function _entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage)
if(($sMethod = 'get_link') && bx_is_srv($aDataItem['content_type'], $sMethod))
$sLink = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);

$bPassed = $bUsageSt && $this->_oModule->isDataPassed($iProfileId, $aDataItem);

$aTmplVarsPass = [true];
$bTmplVarsPass = $iUsage == BX_COURSES_CND_USAGE_ST && $sLink && !$this->_oModule->isDataPassed($iProfileId, $aDataItem) && ((int)$aNode['passing'] == 0 || $iIndex == 0 || $this->_oModule->isDataPassed($iProfileId, $aDataItems[$iIndex - 1]));
$bTmplVarsPass = $bUsageSt && !$bPassed && $sLink && ((int)$aNode['passing'] == BX_COURSES_CND_PASSING_ALL || $iIndex == 0 || $this->_oModule->isDataPassed($iProfileId, $aDataItems[$iIndex - 1]));
if($bTmplVarsPass) {
$aTmplVarsPass = [
'js_object' => $sJsObject,
Expand All @@ -510,28 +516,48 @@ protected function _entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage)
if(!$sTitle)
$sTitle = $sTxtUndefined;

$bTmplVarsShowLink = $iUsage == BX_COURSES_CND_USAGE_AT && $sLink;
$bTmplVarsShowLink = $bUsageAt && $sLink;
$aTmplVarsShowLink = $bTmplVarsShowLink ? [
'link' => $sLink,
'title' => $sTitle
] : [true];

$bTmplVarsShowSize = false;
$aTmplVarsShowSize = [true];
$bTmplVarsShowDownload = false;
$aTmplVarsShowDownload = [true];
if($bUsageAt && ($bTmplVarsShowSize = ($sMethod = 'get_file') && bx_is_srv($aDataItem['content_type'], $sMethod))) {
$aFileInfo = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
if(!empty($aFileInfo) && is_array($aFileInfo)) {
$aTmplVarsShowSize['size'] = _t_format_size($aFileInfo['size']);

$bTmplVarsShowDownload = !empty($aFileInfo['url_download']);
$aTmplVarsShowDownload = [
'link' => $aFileInfo['url_download']
];
}
}

if($this->_bIsApi) {
$sText = '';
if(($sMethod = 'get_text') && bx_is_srv($aDataItem['content_type'], $sMethod))
$sText = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);

$aResults[] = [
$aResults[] = array_merge([
'id' => $aDataItem['id'],
'type' => $sType,
'title' => $sTitle,
'text' => $sText,
'image' => $sImageUrl,
'link_view' => $bTmplVarsShowLink ? bx_api_get_relative_url($sLink) : '',
'link_pass' => $bTmplVarsPass ? bx_api_get_relative_url($sLink) : '',
'link_title' => $sTxtPass,
'status' => '???' //TODO: Some status is needed. Ask Roman.
];
], ($bUsageSt ? [
'pass_link' => $bTmplVarsPass ? bx_api_get_relative_url($sLink) : '',
'pass_title' => $sTxtPass,
'passed' => $bPassed
] : [
'size' => $bTmplVarsShowSize ? $aTmplVarsShowSize['size'] : '',
'view_link' => $bTmplVarsShowLink ? bx_api_get_relative_url($sLink) : '',
'download_link' => $bTmplVarsShowDownload ? bx_api_get_relative_url($aTmplVarsShowDownload['link']) : '',
]));
}
else
$aResults[] = [
Expand All @@ -558,10 +584,18 @@ protected function _entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage)
'title' => $sTitle,
]
],
'bx_if:show_size' => [
'condition' => $bTmplVarsShowSize,
'content' => $aTmplVarsShowSize
],
'bx_if:show_pass' => [
'condition' => $bTmplVarsPass,
'content' => $aTmplVarsPass
]
],
'bx_if:show_download' => [
'condition' => $bTmplVarsShowDownload,
'content' => $aTmplVarsShowDownload
],
];
}

Expand Down
2 changes: 1 addition & 1 deletion modules/boonex/courses/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
<string name="_bx_courses_txt_data_type_bx_videos"><![CDATA[video]]></string>
<string name="_bx_courses_txt_data_usage_0"><![CDATA[step]]></string>
<string name="_bx_courses_txt_data_usage_1"><![CDATA[attachment]]></string>

<string name="_bx_courses_txt_download"><![CDATA[Download]]></string>

<string name="_bx_courses_msg_performed"><![CDATA[The action was successfully performed.]]></string>
<string name="_bx_courses_err_price_duplicate"><![CDATA[Similar pricing plan is already exists.]]></string>
Expand Down
6 changes: 6 additions & 0 deletions modules/boonex/courses/template/node_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
<bx_if:show_link><a href="__link__" target="_blank">__title__</a></bx_if:show_link>
<bx_if:show_text>__title__</bx_if:show_text>
</div>
<bx_if:show_size>
<div class="bx-courses-nid-size">__size__</div>
</bx_if:show_size>
</div>
<div class="bx-courses-ni-action flex items-center">
<bx_if:show_pass>
<a class="bx-btn bx-btn-small" href="__link__" onclick="javascript:return __js_object__.passData(this, __id__);">__title__</a>
</bx_if:show_pass>
<bx_if:show_download>
<a class="bx-btn bx-btn-small" href="__link__"><bx_text:_bx_courses_txt_download /></a>
</bx_if:show_download>
</div>
</div>
</bx_repeat:items>
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/russian/data/langs/bx_courses/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
<string name="_bx_courses_txt_data_type_bx_videos"><![CDATA[видео]]></string>
<string name="_bx_courses_txt_data_usage_0"><![CDATA[шаг]]></string>
<string name="_bx_courses_txt_data_usage_1"><![CDATA[вложение]]></string>
<string name="_bx_courses_txt_download"><![CDATA[Скачать]]></string>

<string name="_bx_courses_msg_performed"><![CDATA[Действие было успешно выполнено.]]></string>
<string name="_bx_courses_err_price_duplicate"><![CDATA[Аналогичный ценовой план уже существует.]]></string>
Expand Down

0 comments on commit 083bd82

Please sign in to comment.