BxCoursesModule.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Courses Courses
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * How to pass a lesson's steps:
  13. * 0 - all at once, the order is not important
  14. * 1 - alternate, the order is important
  15. */
  16. define('BX_COURSES_CND_PASSING_ALL', 0);
  17. define('BX_COURSES_CND_PASSING_ALTERNATE', 1);
  18. /**
  19. * Content data usage:
  20. * st - step,
  21. * at - attachment
  22. */
  23. define('BX_COURSES_CND_USAGE_ST', 0);
  24. define('BX_COURSES_CND_USAGE_AT', 1);
  25. /**
  26. * Courses profiles module.
  27. */
  28. class BxCoursesModule extends BxBaseModGroupsModule
  29. {
  30. function __construct(&$aModule)
  31. {
  32. parent::__construct($aModule);
  33. $this->_aSearchableNamesExcept[] = $this->_oConfig->CNF['FIELD_JOIN_CONFIRMATION'];
  34. }
  35. public function actionPassNode()
  36. {
  37. $iNodeId = bx_get('node_id');
  38. if($iNodeId === false)
  39. return echoJson([]);
  40. return echoJson($this->servicePassNode((int)$iNodeId));
  41. }
  42. public function actionPassData()
  43. {
  44. $iDataId = bx_get('data_id');
  45. if($iDataId === false)
  46. return echoJson([]);
  47. return echoJson($this->servicePassData((int)$iDataId));
  48. }
  49. public function serviceGetSafeServices()
  50. {
  51. return array_merge(parent::serviceGetSafeServices(), [
  52. 'PassNode' => '',
  53. 'PassData' => '',
  54. ]);
  55. }
  56. public function servicePassNode($iNodeId)
  57. {
  58. $CNF = &$this->_oConfig->CNF;
  59. $aNode = $this->_oDb->getContentNodes([
  60. 'sample' => 'id',
  61. 'id' => $iNodeId
  62. ]);
  63. if(empty($aNode) || !is_array($aNode))
  64. return ['code' => 1];
  65. $iEntryId = (int)$aNode['entry_id'];
  66. $iProfileId = bx_get_logged_profile_id();
  67. if($this->isNodePassed($iProfileId, $iNodeId)) {
  68. $aDataItems = $this->_oDb->getContentData([
  69. 'sample' => 'entry_node_ids',
  70. 'entry_id' => $iEntryId,
  71. 'node_id' => $iNodeId,
  72. ]);
  73. if(!empty($aDataItems) && is_array($aDataItems))
  74. foreach($aDataItems as $aDataItem)
  75. $this->_oDb->deleteContentData2Users(['data_id' => $aDataItem['id'], 'profile_id' => $iProfileId]);
  76. $this->_oDb->deleteContentNodes2Users(['node_id' => $iNodeId, 'profile_id' => $iProfileId]);
  77. }
  78. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_NODE'] . '&id=' . $iEntryId, [
  79. 'node_id' => $iNodeId
  80. ]);
  81. return [
  82. 'code' => 0,
  83. 'redirect' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink
  84. ];
  85. }
  86. public function servicePassData($iDataId)
  87. {
  88. $iNow = time();
  89. $iProfileId = bx_get_logged_profile_id();
  90. $aData = $this->_oDb->getContentData([
  91. 'sample' => 'id',
  92. 'id' => $iDataId
  93. ]);
  94. if(empty($aData) || !is_array($aData))
  95. return ['code' => 1];
  96. $this->_oDb->insertContentData2Users([
  97. 'data_id' => $iDataId,
  98. 'profile_id' => $iProfileId,
  99. 'date' => $iNow
  100. ]);
  101. $aNode = $this->_oDb->getContentNodes([
  102. 'sample' => 'id_full',
  103. 'id' => $aData['node_id']
  104. ]);
  105. $iTotal = $this->getDataTotalByNode($aNode, BX_COURSES_CND_USAGE_ST);
  106. $aUserTrack = $this->_oDb->getContentData([
  107. 'sample' => 'user_track',
  108. 'entry_id' => $aNode['entry_id'],
  109. 'node_id' => $aNode['id'],
  110. 'profile_id' => $iProfileId
  111. ]);
  112. if(count($aUserTrack) == $iTotal) {
  113. $this->_oDb->insertContentNodes2Users([
  114. 'node_id' => $aNode['id'],
  115. 'profile_id' => $iProfileId,
  116. 'date' => $iNow
  117. ]);
  118. $this->_autoPassNodes($iProfileId, $aNode['parent_id']);
  119. }
  120. $aResult = ['code' => 0];
  121. if(($sMethod = 'get_link') && bx_is_srv($aData['content_type'], $sMethod))
  122. $aResult['redirect'] = bx_srv($aData['content_type'], $sMethod, [$aData['content_id']]);
  123. if($this->_bIsApi)
  124. $aResult['redirect'] = bx_api_get_relative_url($aResult['redirect']);
  125. return $aResult;
  126. }
  127. protected function _autoPassNodes($iProfileId, $iNodeId)
  128. {
  129. $aNode = $this->_oDb->getContentStructure([
  130. 'sample' => 'node_id',
  131. 'node_id' => $iNodeId,
  132. ]);
  133. if(empty($aNode) || !is_array($aNode))
  134. return;
  135. $iTotal = (int)$aNode['cn_l' . ($aNode['level'] + 1)];
  136. if(!$iTotal)
  137. return;
  138. $aUserTrack = $this->_oDb->getContentStructure([
  139. 'sample' => 'user_track',
  140. 'profile_id' => $iProfileId,
  141. 'entry_id' => $aNode['entry_id'],
  142. 'node_id' => $iNodeId
  143. ]);
  144. if(count($aUserTrack) == $iTotal) {
  145. $this->_oDb->insertContentNodes2Users([
  146. 'node_id' => $iNodeId,
  147. 'profile_id' => $iProfileId,
  148. 'date' => time()
  149. ]);
  150. if((int)$aNode['parent_id'] != 0)
  151. $this->_autoPassNodes($iProfileId, $aNode['parent_id']);
  152. }
  153. }
  154. public function serviceGetOptionsContentModulesSt()
  155. {
  156. return $this->_getOptionsContentModules();
  157. }
  158. public function serviceGetOptionsContentModulesAt()
  159. {
  160. return $this->_getOptionsContentModules();
  161. }
  162. public function serviceIsContentAvaliable($iProfileId)
  163. {
  164. if(!$this->_oConfig->isContent())
  165. return false;
  166. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  167. if($this->checkAllowedEdit($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  168. return false;
  169. return true;
  170. }
  171. public function serviceOnContentAdded($sContentType, $iContentId, $iContextId, $iContextNodeId, $iContextUsage)
  172. {
  173. $this->_oDb->insertContentData([
  174. 'entry_id' => $iContextId,
  175. 'node_id' => $iContextNodeId,
  176. 'content_type' => $sContentType,
  177. 'content_id' => $iContentId,
  178. 'usage' => $iContextUsage,
  179. 'added' => time(),
  180. 'order' => $this->_oDb->getContentDataOrderMax($iContextId, $iContextNodeId)
  181. ]);
  182. $aNode = $this->_oDb->getContentNodes(['sample' => 'id', 'id' => $iContextNodeId]);
  183. $aCounters = [];
  184. if(!empty($aNode['counters']))
  185. $aCounters = json_decode($aNode['counters'], true);
  186. $sUsage = $this->_oConfig->getUsageI2S($iContextUsage);
  187. if(!isset($aCounters[$sUsage]))
  188. $aCounters[$sUsage] = [];
  189. if(!isset($aCounters[$sUsage][$sContentType]))
  190. $aCounters[$sUsage][$sContentType] = 0;
  191. $aCounters[$sUsage][$sContentType] += 1;
  192. $this->_oDb->updateContentNodes(['counters' => json_encode($aCounters)], ['id' => $iContextNodeId]);
  193. }
  194. public function serviceOnContentDeleted($sContentType, $iContentId, $iContextId)
  195. {
  196. $aData = $this->_oDb->getContentData(['sample' => 'content', 'content_type' => $sContentType, 'content_id' => $iContentId]);
  197. if(empty($aData) || !is_array($aData))
  198. return;
  199. $this->_oDb->deleteContentData([
  200. 'entry_id' => $iContextId,
  201. 'content_type' => $sContentType,
  202. 'content_id' => $iContentId,
  203. ]);
  204. $this->_oDb->deleteContentData2Users([
  205. 'data_id' => $aData['id']
  206. ]);
  207. $aNode = $this->_oDb->getContentNodes(['sample' => 'id', 'id' => $aData['node_id']]);
  208. if(!empty($aNode['counters'])) {
  209. $sUsage = $this->_oConfig->getUsageI2S($aData['usage']);
  210. $aCounters = json_decode($aNode['counters'], true);
  211. if(!empty($aCounters[$sUsage][$sContentType])) {
  212. if((int)$aCounters[$sUsage][$sContentType] > 1)
  213. $aCounters[$sUsage][$sContentType] -= 1;
  214. else
  215. unset($aCounters[$sUsage][$sContentType]);
  216. $this->_oDb->updateContentNodes(['counters' => json_encode($aCounters)], ['id' => $aData['node_id']]);
  217. }
  218. }
  219. }
  220. public function serviceEntityContentStructureBlock($iProfileId = 0)
  221. {
  222. $CNF = &$this->_oConfig->CNF;
  223. if(!$this->_oConfig->isContent())
  224. return '';
  225. if(!$iProfileId)
  226. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  227. if(!$iProfileId)
  228. return '';
  229. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  230. $sGridKey = 'OBJECT_GRID_CNT_STRUCTURE_' . ($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED ? 'MANAGE' : 'VIEW');
  231. $oGrid = BxDolGrid::getObjectInstance($CNF[$sGridKey]);
  232. if(!$oGrid)
  233. return '';
  234. $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
  235. if($this->_bIsApi)
  236. return ($aGrid = $oGrid->getCodeAPI()) ? [
  237. bx_api_get_block('grid', $aGrid)
  238. ] : [];
  239. return $oGrid->getCode();
  240. }
  241. public function serviceEntityContentDataBlock($iProfileId = 0)
  242. {
  243. $CNF = &$this->_oConfig->CNF;
  244. if(!$this->_oConfig->isContent())
  245. return '';
  246. if(!$iProfileId)
  247. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  248. if(!$iProfileId)
  249. return '';
  250. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  251. $sGridKey = 'OBJECT_GRID_CNT_DATA_' . ($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED ? 'MANAGE' : 'VIEW');
  252. $oGrid = BxDolGrid::getObjectInstance($CNF[$sGridKey]);
  253. if(!$oGrid)
  254. return '';
  255. $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
  256. if($this->_bIsApi)
  257. return ($aGrid = $oGrid->getCodeAPI()) ? [
  258. bx_api_get_block('grid', $aGrid)
  259. ] : [];
  260. return $oGrid->getCode();
  261. }
  262. public function serviceEntityStructureL1Block($iContentId = 0)
  263. {
  264. if(!$this->_oConfig->isContent() || $this->_oConfig->getContentLevelMax() == 1)
  265. return $this->_bIsApi ? [] : '';
  266. $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByLevel', $iContentId, [
  267. 'level' => 1,
  268. 'selected' => ($iNodeId = bx_get('parent_id')) !== false ? (int)$iNodeId : 0,
  269. 'start' => ($iStart = bx_get('start')) !== false ? (int)$iStart : 0,
  270. 'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : 2,
  271. ]);
  272. return $this->_bIsApi ? [bx_api_get_block('course_structure', $mixedResult)] : $mixedResult;
  273. }
  274. public function serviceEntityStructureL2Block($iContentId = 0, $iParentId = 0)
  275. {
  276. if(!$this->_oConfig->isContent())
  277. return $this->_bIsApi ? [] : '';
  278. if(!$iParentId && ($_iParentId = bx_get('parent_id')) !== false)
  279. $iParentId = (int)$_iParentId;
  280. $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByParentMl' . $this->_oConfig->getContentLevelMax(), $iContentId, [
  281. 'parent_id' => $iParentId
  282. ]);
  283. return $this->_bIsApi ? [bx_api_get_block('module_structure', $mixedResult)] : $mixedResult;
  284. }
  285. public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage = false)
  286. {
  287. if(!$this->_oConfig->isContent())
  288. return $this->_bIsApi ? [] : '';
  289. if(!$iNodeId && ($_iNodeId = bx_get('node_id')) !== false)
  290. $iNodeId = (int)$_iNodeId;
  291. if($iUsage === false && ($_iUsage = bx_get('usage')) !== false)
  292. $iUsage = (int)$_iUsage;
  293. $mixedResult = $this->_serviceTemplateFuncEx('entryNode', $iContentId, [
  294. 'node_id' => $iNodeId,
  295. 'usage' => $iUsage
  296. ]);
  297. return $this->_bIsApi ? [bx_api_get_block('lesson_structure', $mixedResult)] : $mixedResult;
  298. }
  299. public function getNodeLevelByParent($aParentInfo)
  300. {
  301. return (is_array($aParentInfo) && !empty($aParentInfo['level']) ? (int)$aParentInfo['level'] : 0) + 1;
  302. }
  303. public function getDataTotalByNode($mixedNode, $iUsage = 0)
  304. {
  305. if(!is_array($mixedNode))
  306. $mixedNode = $this->_oDb->getContentNodes([
  307. 'sample' => 'id',
  308. 'id' => (int)$mixedNode
  309. ]);
  310. $iTotal = 0;
  311. $sUsage = $this->_oConfig->getUsageI2S($iUsage);
  312. if(!empty($mixedNode['counters']) && ($aCountes = json_decode($mixedNode['counters'], true)) && !empty($aCountes[$sUsage]) && is_array($aCountes[$sUsage]))
  313. $iTotal = array_sum($aCountes[$sUsage]);
  314. return $iTotal;
  315. }
  316. public function isNodeStarted($iProfileId, $mixedNode)
  317. {
  318. $iNodeId = is_array($mixedNode) ? $mixedNode['id'] : (int)$mixedNode;
  319. $aChildNodes = $this->_oDb->getContentStructure([
  320. 'sample' => 'parent_id',
  321. 'parent_id' => $iNodeId
  322. ]);
  323. if(!empty($aChildNodes) && is_array($aChildNodes)) {
  324. foreach($aChildNodes as $aChildNode)
  325. if($this->isNodePassed($iProfileId, $aChildNode['node_id']))
  326. return true;
  327. else
  328. return $this->isNodeStarted($iProfileId, $aChildNode['node_id']);
  329. }
  330. else {
  331. $aChildData = $this->_oDb->getContentData([
  332. 'sample' => 'node_id',
  333. 'node_id' => $iNodeId
  334. ]);
  335. if(!empty($aChildData) && is_array($aChildData))
  336. foreach($aChildData as $aChildData)
  337. if($this->isDataPassed($iProfileId, $aChildData['id']))
  338. return true;
  339. return false;
  340. }
  341. }
  342. public function isNodePassed($iProfileId, $mixedNode)
  343. {
  344. $aUserTrack = $this->_oDb->getContentStructure([
  345. 'sample' => 'user_passed',
  346. 'profile_id' => $iProfileId,
  347. 'node_id' => is_array($mixedNode) ? $mixedNode['id'] : (int)$mixedNode
  348. ]);
  349. return !empty($aUserTrack) && is_array($aUserTrack);
  350. }
  351. public function isDataPassed($iProfileId, $mixedData)
  352. {
  353. $aUserTrack = $this->_oDb->getContentData([
  354. 'sample' => 'user_passed',
  355. 'profile_id' => $iProfileId,
  356. 'data_id' => is_array($mixedData) ? $mixedData['id'] : (int)$mixedData
  357. ]);
  358. return !empty($aUserTrack) && is_array($aUserTrack);
  359. }
  360. public function getEntryPass($iProfileId, $iContentId)
  361. {
  362. $aChildren = $this->_oDb->getContentStructure([
  363. 'sample' => 'entry_id',
  364. 'entry_id' => $iContentId,
  365. 'level' => 1
  366. ]);
  367. $aPassDetails = [];
  368. foreach($aChildren as $aChild)
  369. $this->getNodePass($iProfileId, $iContentId, $aChild, $aPassDetails);
  370. $iPassPercent = 0;
  371. $sPassStatus = $sPassTitle = '';
  372. $iLevelMax = $this->_oConfig->getContentLevelMax();
  373. if(isset($aPassDetails[$iLevelMax]) && ($aPassLevelMax = $aPassDetails[$iLevelMax])) {
  374. $iPassPercent = ($iTotal = (int)$aPassLevelMax['total']) != 0 ? (int)round(100 * $aPassLevelMax['passed']/$iTotal) : 0;
  375. if($aPassLevelMax['passed'] != 0) {
  376. if($aPassLevelMax['passed'] != $aPassLevelMax['total']) {
  377. $sPassStatus = '_bx_courses_txt_status_in_process';
  378. $sPassTitle = '_bx_courses_txt_pass_continue';
  379. }
  380. else {
  381. $sPassStatus = '_bx_courses_txt_status_completed';
  382. $sPassTitle = '_bx_courses_txt_pass_again';
  383. }
  384. }
  385. else {
  386. $sPassStatus = '_bx_courses_txt_status_not_started';
  387. $sPassTitle = '_bx_courses_txt_pass_start';
  388. }
  389. }
  390. return [
  391. $iPassPercent,
  392. $aPassDetails,
  393. _t($sPassStatus),
  394. _t($sPassTitle)
  395. ];
  396. }
  397. public function getNodePass($iProfileId, $iContentId, $aNode, &$aResults)
  398. {
  399. $iLevel = $aNode['level'];
  400. if(!isset($aResults[$iLevel]))
  401. $aResults[$iLevel] = [
  402. 'passed' => 0,
  403. 'total' => 0
  404. ];
  405. $aResults[$iLevel]['passed'] += $this->isNodePassed($iProfileId, $aNode['node_id']);
  406. $aResults[$iLevel]['total'] += 1;
  407. if($iLevel != $this->_oConfig->getContentLevelMax() && !empty($aNode['cn_l' . ($iLevel + 1)])) {
  408. $aChildren = $this->_oDb->getContentStructure([
  409. 'sample' => 'parent_id',
  410. 'parent_id' => $aNode['node_id']
  411. ]);
  412. foreach($aChildren as $aChild)
  413. $this->getNodePass($iProfileId, $iContentId, $aChild, $aResults);
  414. }
  415. }
  416. public function getNodePassByChildren($iProfileId, $iContentId, $aNode, &$aResults)
  417. {
  418. $aUserTrack = $this->_oDb->getContentStructure([
  419. 'sample' => 'user_track',
  420. 'entry_id' => $iContentId,
  421. 'node_id' => $aNode['node_id'],
  422. 'profile_id' => $iProfileId
  423. ]);
  424. $iLevelChildren = $aNode['level'] + 1;
  425. $iCountChildren = $aNode['cn_l' . $iLevelChildren];
  426. if(!isset($aResults[$iLevelChildren]))
  427. $aResults[$iLevelChildren] = [
  428. 'passed' => 0,
  429. 'total' => 0
  430. ];
  431. $aResults[$iLevelChildren]['passed'] += count($aUserTrack);
  432. $aResults[$iLevelChildren]['total'] += $iCountChildren;
  433. if($iCountChildren && $iLevelChildren != $this->_oConfig->getContentLevelMax()) {
  434. $aChildren = $this->_oDb->getContentStructure([
  435. 'sample' => 'parent_id',
  436. 'parent_id' => $aNode['node_id']
  437. ]);
  438. foreach($aChildren as $aChild)
  439. $this->getNodePassByChildren($iProfileId, $iContentId, $aChild, $aResults);
  440. }
  441. }
  442. public function getNodePassByData($iProfileId, $iContentId, $aNode)
  443. {
  444. $iTotal = 0;
  445. $iPassCount = $iPassPercent = 0;
  446. $sPassStatus = $sPassTitle = '';
  447. if(($iTotal = $this->getDataTotalByNode($aNode)) != 0) {
  448. $aUserTrack = $this->_oDb->getContentData([
  449. 'sample' => 'user_track',
  450. 'entry_id' => $iContentId,
  451. 'node_id' => $aNode['node_id'],
  452. 'profile_id' => $iProfileId
  453. ]);
  454. $iPassCount = count($aUserTrack);
  455. $iPassPercent = (int)round(100 * $iPassCount/$iTotal);
  456. if($iPassCount == 0) {
  457. $sPassStatus = '_bx_courses_txt_status_not_started';
  458. $sPassTitle = '_bx_courses_txt_pass_start';
  459. }
  460. else {
  461. if($iPassCount != $iTotal) {
  462. $sPassStatus = '_bx_courses_txt_status_in_process';
  463. $sPassTitle = '_bx_courses_txt_pass_continue';
  464. }
  465. else {
  466. $sPassStatus = '_bx_courses_txt_status_completed';
  467. $sPassTitle = '_bx_courses_txt_pass_again';
  468. }
  469. }
  470. }
  471. return [
  472. $iPassPercent,
  473. _t('_bx_courses_txt_n_m_steps', $iPassCount, $iTotal),
  474. _t($sPassStatus ? $sPassStatus : '_undefined'),
  475. _t($sPassTitle)
  476. ];
  477. }
  478. public function decodeDataAPI($aData, $aParams = [])
  479. {
  480. $CNF = $this->_oConfig->CNF;
  481. $aResult = parent::decodeDataAPI($aData, $aParams);
  482. $aResultAdd = [];
  483. $iEntryId = (int)$aData[$CNF['FIELD_ID']];
  484. $aLevelToNode = $this->_oConfig->getContentLevel2Node(false);
  485. if($this->isFan($iEntryId, $this->_iProfileId)) {
  486. $sTxtProgress = _t('_bx_courses_txt_n_m_progress');
  487. list($iPassPercent, $aPassDetails, $sPassStatus, $sPassTitle) = $this->getEntryPass($this->_iProfileId, $iEntryId);
  488. $aCounters = [];
  489. foreach($aPassDetails as $iLevel => $aDetails) {
  490. $aCounters[] = [
  491. 'level' => $iLevel,
  492. 'title' => $aLevelToNode[$iLevel],
  493. 'passed' => $aDetails['passed'],
  494. 'total' => $aDetails['total'],
  495. 'progress' => bx_replace_markers($sTxtProgress, $aDetails)
  496. ];
  497. }
  498. $aResultAdd = [
  499. 'percent' => $iPassPercent,
  500. 'counters' => $aCounters,
  501. 'status' => $sPassStatus,
  502. 'show_pass' => $iPassPercent > 0 && $iPassPercent < 100,
  503. ];
  504. if($aResultAdd['show_pass'])
  505. $aResultAdd = array_merge($aResultAdd, [
  506. 'pass_link' => $aResult['url'],
  507. 'pass_title' => $sPassTitle,
  508. ]);
  509. }
  510. else {
  511. $iLevelMax = $this->_oConfig->getContentLevelMax();
  512. $aEntryCounters = $this->_oDb->getContentStructure(['sample' => 'entry_id_counters', 'entry_id' => $iEntryId]);
  513. $aCounters = [];
  514. for($i = 1; $i <= $iLevelMax; $i++) {
  515. $aCounters[] = [
  516. 'level' => $i,
  517. 'title' => $aLevelToNode[$i],
  518. 'total' => $aEntryCounters['cn_l' . $i]
  519. ];
  520. }
  521. $aResultAdd = [
  522. 'counters' => $aCounters,
  523. ];
  524. }
  525. return array_merge($aResult, $aResultAdd);
  526. }
  527. protected function _getOptionsContentModules()
  528. {
  529. $aResult = [];
  530. $aModules = bx_srv('system', 'get_modules_by_type', ['content']);
  531. foreach($aModules as $aModule)
  532. $aResult[] = ['key' => $aModule['name'], 'value' => $aModule['title']];
  533. return $aResult;
  534. }
  535. }
  536. /** @} */