| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Courses Courses
- * @ingroup UnaModules
- *
- * @{
- */
- /*
- * Courses module representation.
- */
- class BxCoursesTemplate extends BxBaseModGroupsTemplate
- {
- protected $_iProfileId;
- public function __construct(&$oConfig, &$oDb)
- {
- $this->MODULE = 'bx_courses';
- parent::__construct($oConfig, $oDb);
- $this->_iProfileId = bx_get_logged_profile_id();
- }
- public function unit ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = [])
- {
- if(!empty($aParams['context']) && in_array($aParams['context'], ['favorite', 'joined_entries']))
- $aParams['template_name'] = 'unit_personal.html';
- return parent::unit($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
- }
- public function unitVars($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- $aVars = parent::unitVars($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
- $bVarsShowProgress = $bVarsShoStats = false;
- $aVarsShowProgress = $aVarsShowStats = [true];
- if(!empty($aParams['context']) && in_array($aParams['context'], ['favorite', 'joined_entries'])) {
- $aLevelToNode = $this->_oConfig->getContentLevel2Node(false);
- $sTxtProgress = _t('_bx_courses_txt_n_m_progress');
- list($iPassPercent, $aPassDetails, $sPassStatus, $sPassTitle) = $this->_oModule->getEntryPass($this->_iProfileId, $aData[$CNF['FIELD_ID']]);
- $bVarsShowProgress = true;
- $aVarsShowProgress = [
- 'progress' => $iPassPercent
- ];
- $aTmplVarsCounters = [];
- foreach($aPassDetails as $iLevel => $aDetails) {
- $aTmplVarsCounters[] = [
- 'cn_title' => $aLevelToNode[$iLevel],
- 'cn_passed' => $aDetails['passed'],
- 'cn_total' => $aDetails['total'],
- 'cn_progress' => bx_replace_markers($sTxtProgress, $aDetails)
- ];
- }
- $bVarsShoStats = true;
- $aVarsShowStats = [
- 'status' => $sPassStatus,
- 'bx_repeat:counters' => $aTmplVarsCounters,
- 'bx_if:show_pass' => [
- 'condition' => $iPassPercent > 0 && $iPassPercent < 100,
- 'content' => [
- 'pass_link' => $aVars['content_url'],
- 'pass_title' => $sPassTitle
- ]
- ]
- ];
- }
- return array_merge($aVars, [
- 'bx_if:show_pass_progress' => [
- 'condition' => $bVarsShowProgress,
- 'content' => $aVarsShowProgress
- ],
- 'bx_if:show_pass_stats' => [
- 'condition' => $bVarsShoStats,
- 'content' => $aVarsShowStats
- ]
- ]);
- }
- public function getCounters($aCounters)
- {
- $aTmplVars = [];
- foreach([BX_COURSES_CND_USAGE_ST, BX_COURSES_CND_USAGE_AT] as $iUsage) {
- $sUsage = $this->_oConfig->getUsageI2S($iUsage);
- $aTmplVarsCounters = [true];
- $bTmplVarsCounters = !empty($aCounters[$sUsage]) && is_array($aCounters[$sUsage]);
- if($bTmplVarsCounters) {
- $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->_bIsApi ? $aTmplVars : $this->parseHtmlByName('counters.html', $aTmplVars);
- }
- public function getJoinedEntriesSummary($iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
- if(!$oConnection)
- return false;
- $aEntries = $oConnection->getConnectedContent($iProfileId);
- $iJoined = count($aEntries);
- $iStarted = 0;
- $iPassed = 0;
- foreach($aEntries as $iEntryId) {
- $aEntryInfo = $this->_oDb->getContentInfoByProfileId($iEntryId);
- list($iPassPercent) = $this->_oModule->getEntryPass($iProfileId, $aEntryInfo[$CNF['FIELD_ID']]);
- if($iPassPercent > 0 && $iPassPercent < 100)
- $iStarted += 1;
- else if($iPassPercent == 100)
- $iPassed +=1;
- }
- $aTmplVars = [
- 'joined' => $iJoined,
- 'passed' => $iPassed,
- 'not_passed' => $iJoined - $iPassed,
- 'passed_percent' => $iJoined != 0 ? (int)round(100 * $iPassed/$iJoined) : 0
- ];
- return $this->_bIsApi ? $aTmplVars : $this->parseHtmlByName('entries_summary.html', $aTmplVars);
- }
- public function entryStructureByLevel($aContentInfo, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- if(!isset($aParams['level']))
- return '';
- $iProfileId = bx_get_logged_profile_id();
- $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
- $bEditable = $this->_oModule->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED;
- $oPermalink = BxDolPermalinks::getInstance();
- $iLevel = (int)$aParams['level'];
- $iSelected = (int)$aParams['selected'];
- $iStart = isset($aParams['start']) ? (int)$aParams['start'] : 0;
- $iPerPage = isset($aParams['per_page']) ? (int)$aParams['per_page'] : 2;
- $aNodes = $this->_oDb->getContentStructure([
- 'sample' => 'entry_id_full',
- 'entry_id' => $iContentId,
- 'level' => $iLevel,
- 'status' => 'active',
- 'start' => $iStart,
- 'per_page' => $iPerPage ? $iPerPage + 1 : 0
- ]);
- if(empty($aNodes) || !is_array($aNodes))
- return $this->_bIsApi ? [
- 'items' => [],
- 'isEditable' => $bEditable,
- 'entry_id' => $iContentId
- ] : '';
- $iLevelMax = $this->_oConfig->getContentLevelMax();
- $aLevelToNode = $this->_oConfig->getContentLevel2Node(false);
- $sTxtProgress = _t('_bx_courses_txt_n_m_progress');
- $sTmplKeysSelected = $this->_bIsApi ? 'selected' : 'bx_if:selected';
- $sTmplKeysCounters = $this->_bIsApi ? 'counters' : 'bx_repeat:counters';
-
- $aTmplVarsNodes = [];
- foreach($aNodes as $iKey => $aNode) {
- $aNodeStats = [];
- $this->_oModule->getNodePassByChildren($iProfileId, $iContentId, $aNode, $aNodeStats);
- $aTmplVarsCounters = [];
- for($i = $iLevel + 1; $i <= $iLevelMax; $i++) {
- if(!isset($aNodeStats[$i]))
- continue;
- $aTmplVarsCounters[] = [
- 'cn_title' => $aLevelToNode[$i],
- 'cn_passed' => $aNodeStats[$i]['passed'],
- 'cn_total' => $aNodeStats[$i]['total'],
- 'cn_progress' => bx_replace_markers($sTxtProgress, $aNodeStats[$i])
- ];
- }
- $bSelected = $aNode['node_id'] == $iSelected;
- $sLink = BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&' . $CNF['FIELD_ID'] . '=' . $iContentId, [
- 'parent_id' => $aNode['node_id']
- ]);
- $aNode = array_merge($aNode, [
- $sTmplKeysSelected => $this->_bIsApi ? $bSelected : [
- 'condition' => $bSelected,
- 'content' => [true]
- ],
- 'index' => $iKey + 1,
- 'link' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink,
- 'percent' => isset($aNodeStats[$iLevelMax]) && ($aStats = $aNodeStats[$iLevelMax]) && $aStats['total'] ? round(100 * $aStats['passed']/$aStats['total']) : 0,
- 'status' => $this->_getNodeStatus($iProfileId, $iContentId, $aNode['node_id']),
- $sTmplKeysCounters => $aTmplVarsCounters
- ]);
- $aTmplVarsNodes[] = $this->_bIsApi ? $aNode : [
- 'node' => $this->parseHtmlByName('node_l' . $iLevel . '.html', $aNode)
- ];
- }
- if($this->_bIsApi)
- return [
- 'items' => $aTmplVarsNodes,
- 'isEditable' => $bEditable,
- 'entry_id' => $iContentId
- ];
- $oPaginate = new BxTemplPaginate([
- 'start' => $iStart,
- 'per_page' => $iPerPage,
- 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}')"
- ]);
- $oPaginate->setNumFromDataArray($aTmplVarsNodes);
- return $this->parseHtmlByName('nodes_l' . $iLevel . '.html', [
- 'level' => $iLevel,
- 'bx_repeat:nodes' => $aTmplVarsNodes,
- 'paginate' => $oPaginate->getSimplePaginate()
- ]);
- }
- /**
- * For 1 level bases structure ( Max Level = 1)
- */
- public function entryStructureByParentMl1($aContentInfo, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
- $iParentId = isset($aParams['parent_id']) ? (int)$aParams['parent_id'] : 0;
- $iProfileId = bx_get_logged_profile_id();
- $aNodes = $this->_oDb->getContentStructure([
- 'sample' => 'entry_id_full',
- 'entry_id' => $iContentId,
- 'parent_id' => $iParentId,
- 'status' => 'active'
- ]);
- if((empty($aNodes) || !is_array($aNodes)) && !$this->_bIsApi)
- return '';
- $sJsObject = $this->_oConfig->getJsObject('entry');
- $oPermalink = BxDolPermalinks::getInstance();
-
- $iLevelMax = $this->_oConfig->getContentLevelMax();
- $sTmplKeysShowPass = $this->_bIsApi ? 'show_pass' : 'bx_if:show_pass';
- $aTmplVarsNodes = [];
- foreach($aNodes as $iKey => $aNode) {
- list($iPassPercent, $sPassProgress, $sPassStatus, $sPassTitle) = $this->_oModule->getNodePassByData($iProfileId, $iContentId, $aNode);
- $sLink = BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iContentId, [
- 'node_id' => $aNode['node_id']
- ]);
- $bShowPass = !empty($sPassTitle);
- $aNode = array_merge($aNode, [
- 'level_max' => $iLevelMax,
- 'index' => $iKey + 1,
- 'link' => $sLink,
- 'pass_percent' => $iPassPercent,
- 'pass_progress' => $sPassProgress,
- 'pass_status' => $sPassStatus,
- $sTmplKeysShowPass => $this->_bIsApi ? $bShowPass : [
- 'condition' => $bShowPass,
- 'content' => [
- 'js_object' => $sJsObject,
- 'id' => $aNode['node_id'],
- 'pass_href' => $sLink,
- 'pass_title' => $sPassTitle,
- ]
- ]
- ]);
- 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¶ms[]=' . $aNode['node_id'],
- ]);
- }
- $aTmplVarsNodes[] = $this->_bIsApi ? $aNode : [
- 'node' => $this->parseHtmlByName('ml' . $iLevelMax . '_node_l' . $aNode['level'] . '.html', $aNode)
- ];
- }
- if($this->_bIsApi)
- return [
- 'items' => $aTmplVarsNodes,
- 'isEditable' => $this->_oModule->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED,
- 'entry_id' => $iContentId,
- 'parent_id' => $iParentId
- ];
- return $this->parseHtmlByName('ml' . $iLevelMax . '_nodes_l' . $aNode['level'] . '.html', [
- 'level_max' => $iLevelMax,
- 'level' => $aNode['level'],
- 'bx_repeat:nodes' => $aTmplVarsNodes
- ]);
- }
- /**
- * For 2 levels bases structure ( Max Level = 2)
- */
- public function entryStructureByParentMl2($aContentInfo, $aParams = [])
- {
- if(empty($aParams['parent_id']))
- return $this->_bIsApi ? [] : '';
- return $this->entryStructureByParentMl1($aContentInfo, $aParams);
- }
- /**
- * For 3 levels bases structure ( Max Level = 3)
- */
- public function entryStructureByParentMl3($aContentInfo, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($aParams['parent_id']))
- return $this->_bIsApi ? [] : '';
- $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
- $iParentId = (int)$aParams['parent_id'];
- $iProfileId = bx_get_logged_profile_id();
- $aNodes = $this->_oDb->getContentStructure([
- 'sample' => 'entry_id_full',
- 'entry_id' => $iContentId,
- 'parent_id' => $iParentId,
- 'status' => 'active'
- ]);
- if(empty($aNodes) || !is_array($aNodes))
- return $this->_bIsApi ? [] : '';
- $sJsObject = $this->_oConfig->getJsObject('entry');
- $oPermalink = BxDolPermalinks::getInstance();
- $iLevelMax = $this->_oConfig->getContentLevelMax();
- $aInputs = [];
- foreach($aNodes as $aNode) {
- $aInputs['node_' . $aNode['node_id']] = [
- 'type' => 'block_header',
- 'caption' => bx_process_output($aNode['title']),
- 'collapsed' => false,
- 'attrs' => ['id' => 'node_' . $aNode['node_id'], 'class' => ''],
- ];
- $aSubNodes = $this->_oDb->getContentStructure([
- 'sample' => 'entry_id_full',
- 'entry_id' => $iContentId,
- 'parent_id' => (int)$aNode['node_id'],
- 'status' => 'active'
- ]);
- if(!empty($aSubNodes) && is_array($aSubNodes)) {
- $sTmplKeysShowPass = $this->_bIsApi ? 'show_pass' : 'bx_if:show_pass';
- $aTmplVarsNodes = [];
- foreach($aSubNodes as $iKey => $aSubNode) {
- list($iPassPercent, $sPassProgress, $sPassStatus, $sPassTitle) = $this->_oModule->getNodePassByData($iProfileId, $iContentId, $aSubNode);
- $sLink = BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iContentId, [
- 'node_id' => $aSubNode['node_id']
- ]);
- $bShowPass = !empty($sPassTitle);
-
- $aSubNode = array_merge($aSubNode, [
- 'level_max' => $iLevelMax,
- 'index' => $iKey + 1,
- 'link' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink,
- 'pass_percent' => $iPassPercent,
- 'pass_progress' => $sPassProgress,
- 'pass_status' => $sPassStatus,
- $sTmplKeysShowPass => $this->_bIsApi ? $bShowPass : [
- 'condition' => $sPassTitle,
- 'content' => [
- 'js_object' => $sJsObject,
- 'id' => $aSubNode['node_id'],
- 'pass_href' => $sLink,
- 'pass_title' => $sPassTitle,
- ]
- ]
- ]);
- $aTmplVarsNodes[] = $this->_bIsApi ? $aSubNode : [
- 'node' => $this->parseHtmlByName('ml3_node_l' . $aSubNode['level'] . '.html', $aSubNode)
- ];
- }
- $sInput = 'node_' . $aNode['node_id'] . '_subnodes';
- $aInputs[$sInput] = [
- 'type' => 'custom',
- 'name' => $sInput,
- 'caption' => '',
- 'content' => $this->_bIsApi ? $aTmplVarsNodes : $this->parseHtmlByName('ml3_nodes_l' . $aSubNode['level'] . '.html', [
- 'level_max' => $iLevelMax,
- 'level' => $aSubNode['level'],
- 'bx_repeat:nodes' => $aTmplVarsNodes
- ]),
- ];
- }
- else
- $aInputs['node_' . $aNode['node_id']]['collapsed'] = true;
- }
- $oForm = new BxTemplFormView([
- 'form_attrs' => [
- 'id' => 'bx-courses-structure-by-parent-' . $iParentId,
- ],
- 'inputs' => $aInputs,
- ]);
- $oForm->setShowEmptySections(true);
- return $this->_bIsApi ? $oForm->getCodeAPI() : $oForm->getCode();
- }
- public function entryNode($aContentInfo, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- if(!isset($aParams['node_id']))
- return '';
- $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
- $iNodeId = (int)$aParams['node_id'];
- $iUsage = isset($aParams['usage']) && $aParams['usage'] !== false ? (int)$aParams['usage'] : BX_COURSES_CND_USAGE_ST;
- $iProfileId = bx_get_logged_profile_id();
- $aNode = $this->_oDb->getContentNodes([
- 'sample' => 'id_full',
- 'id' => $iNodeId,
- ]);
- $aTmplVars = [
- 'index' => $aNode['order'],
- 'sample' => $this->_oConfig->getContentNodeTitle($aNode['level']),
- 'title' => $aNode['title'],
- 'text' => $aNode['text'],
- 'passing' => $aNode['passing']
- ];
- if($this->_bIsApi)
- return array_merge($aTmplVars, [
- 'steps' => $this->_entryNodeItems($iProfileId, $iContentId, $aNode, BX_COURSES_CND_USAGE_ST),
- 'attachments' => $this->_entryNodeItems($iProfileId, $iContentId, $aNode, BX_COURSES_CND_USAGE_AT)
- ]);
- else
- $aTmplVars['bx_repeat:items'] = $this->_entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage);
-
- $sMiName = 'node-data-';
- $sMiLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iContentId, [
- 'node_id' => $iNodeId,
- 'usage' => ''
- ]);
- $oMenu = new BxTemplMenu([
- 'template' => 'menu_block_submenu_ver.html',
- 'menu_id'=> 'node-data',
- 'menu_items' => [
- ['id' => $sMiName . 'st', 'name' => $sMiName . 'st', 'class' => '', 'link' => $sMiLink . '0', 'target' => '_self', 'title' => _t('_bx_courses_menu_item_title_node_data_steps')],
- ['id' => $sMiName . 'at', 'name' => $sMiName . 'at', 'class' => '', 'link' => $sMiLink . '1', 'target' => '_self', 'title' => _t('_bx_courses_menu_item_title_node_data_attachments')]
- ]
- ]);
- $oMenu->setSelected('', $sMiName . $this->_oConfig->getUsageI2S($iUsage));
- return [
- 'content' => $this->parseHtmlByName('node_view.html', $aTmplVars),
- 'menu' => $oMenu
- ];
- }
- public function entryData($aData, $sView)
- {
- $sJsObject = $this->_oConfig->getJsObject('entry');
- $aNode = $this->_oDb->getContentNodes([
- 'sample' => 'id',
- 'id' => $aData['node_id']
- ]);
- $iOrder = (int)$aData['order'];
- $aSiblings = $this->_oDb->getContentData([
- 'sample' => 'siblings',
- 'entry_id' => $aData['entry_id'],
- 'node_id' => $aData['node_id'],
- 'usage' => BX_COURSES_CND_USAGE_ST,
- 'order' => $iOrder
- ]);
- $bTmplVarsBack = false;
- $aTmplVarsBack = ($iOrderB = $iOrder - 1) && ($bTmplVarsBack = !empty($aSiblings[$iOrderB]) && is_array($aSiblings[$iOrderB])) ? [
- 'js_object' => $sJsObject,
- 'id_back' => $aSiblings[$iOrderB]['id']
- ] : [true];
- $bTmplVarsNext = false;
- $aTmplVarsNext = ($iOrderN = $iOrder + 1) && ($bTmplVarsNext = !empty($aSiblings[$iOrderN]) && is_array($aSiblings[$iOrderN])) ? [
- 'js_object' => $sJsObject,
- 'id_next' => $aSiblings[$iOrderN]['id']
- ] : [true];
- return ['popup' => [
- 'html' => BxTemplFunctions::getInstance()->popupBox($this->_oConfig->getHtmlIds('popup_content_data'), $aNode['title'], $this->parseHtmlByName('node_data_view.html', [
- 'js_object' => $sJsObject,
- 'view' => $sView,
- 'bx_if:show_back' => [
- 'condition' => $bTmplVarsBack,
- 'content' => $aTmplVarsBack
- ],
- 'bx_if:show_next' => [
- 'condition' => $bTmplVarsNext,
- 'content' => $aTmplVarsNext
- ]
- ]), true),
- 'options' => [
- 'onHide' => 'document.location = document.location'
- ]
- ]];
- }
- protected function _entryNodeItems($iProfileId, $iContentId, $aNode, $iUsage)
- {
- $sJsObject = $this->_oConfig->getJsObject('entry');
- $aDataItems = $this->_oDb->getContentData([
- 'sample' => 'entry_node_ids',
- 'entry_id' => $iContentId,
- 'node_id' => $aNode['id'],
- 'usage' => $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) {
- $sImageUrl = '';
- if(($sMethod = 'get_thumb') && bx_is_srv($aDataItem['content_type'], $sMethod))
- $sImageUrl = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
- $sVideoUrl = '';
- if(($sMethod = 'get_video') && bx_is_srv($aDataItem['content_type'], $sMethod))
- $sVideoUrl = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
- $sLink = '';
- 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 = $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,
- 'id' => $aDataItem['id'],
- 'link' => $sLink,
- 'title' => $sTxtPass
- ];
- }
- $sType = _t('_bx_courses_txt_data_type_' . $aDataItem['content_type']);
- $sTitle = '';
- if(($sMethod = 'get_title') && bx_is_srv($aDataItem['content_type'], $sMethod))
- $sTitle = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
- if(!$sTitle && ($sMethod = 'get_text') && bx_is_srv($aDataItem['content_type'], $sMethod))
- $sTitle = bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
- if(!$sTitle)
- $sTitle = $sTxtUndefined;
- $bTmplVarsShowLink = $bUsageAt && $sLink;
- $aTmplVarsShowLink = $bTmplVarsShowLink ? [
- 'link' => $sLink,
- 'title' => $sTitle
- ] : false;
- $bTmplVarsShowSize = $aTmplVarsShowSize = false;
- $bTmplVarsShowDownload = $aTmplVarsShowDownload = false;
- 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'])
- ];
- if(($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[] = array_merge([
- 'id' => $aDataItem['id'],
- 'type' => $sType,
- 'title' => $sTitle,
- 'text' => $sText,
- 'image' => $sImageUrl,
- 'video' => $sVideoUrl
- ], ($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 ? $aTmplVarsShowDownload['link'] : '',
- ]));
- }
- else
- $aResults[] = [
- 'bx_if:show_image' => [
- 'condition' => $sImageUrl,
- 'content' => [
- 'image' => $sImageUrl
- ]
- ],
- 'bx_if:show_image_empty' => [
- 'condition' => !$sImageUrl,
- 'content' => [
- 'type' => $sType
- ]
- ],
- 'bx_if:show_video' => [
- 'condition' => $sVideoUrl,
- 'content' => [
- 'video' => $sVideoUrl
- ]
- ],
- 'type' => $sType,
- 'bx_if:show_link' => [
- 'condition' => $bTmplVarsShowLink,
- 'content' => $aTmplVarsShowLink
- ],
- 'bx_if:show_text' => [
- 'condition' => !$bTmplVarsShowLink,
- 'content' => [
- '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
- ],
- ];
- }
- return $aResults;
- }
- protected function _getNodeStatus($iProfileId, $iContentId, $iNodeId)
- {
- if($this->_oModule->isNodePassed($iProfileId, $iNodeId))
- return _t('_bx_courses_txt_status_completed');
- if($this->_oModule->isNodeStarted($iProfileId, $iNodeId))
- return _t('_bx_courses_txt_status_in_process');
-
- return _t('_bx_courses_txt_status_not_started');
- }
- }
- /** @} */
|