BxCoursesModule.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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_view') && bx_is_srv($aData['content_type'], $sMethod)) {
  122. $sView = bx_srv($aData['content_type'], $sMethod, [$aData['content_id']]);
  123. $aResult = $this->_oTemplate->entryData($aData, $sView);
  124. }
  125. else if(($sMethod = 'get_link') && bx_is_srv($aData['content_type'], $sMethod))
  126. $aResult['redirect'] = bx_srv($aData['content_type'], $sMethod, [$aData['content_id']]);
  127. if($this->_bIsApi)
  128. $aResult['redirect'] = bx_api_get_relative_url($aResult['redirect']);
  129. return $aResult;
  130. }
  131. protected function _autoPassNodes($iProfileId, $iNodeId)
  132. {
  133. $aNode = $this->_oDb->getContentStructure([
  134. 'sample' => 'node_id',
  135. 'node_id' => $iNodeId,
  136. ]);
  137. if(empty($aNode) || !is_array($aNode))
  138. return;
  139. $iTotal = (int)$aNode['cn_l' . ($aNode['level'] + 1)];
  140. if(!$iTotal)
  141. return;
  142. $aUserTrack = $this->_oDb->getContentStructure([
  143. 'sample' => 'user_track',
  144. 'profile_id' => $iProfileId,
  145. 'entry_id' => $aNode['entry_id'],
  146. 'node_id' => $iNodeId
  147. ]);
  148. if(count($aUserTrack) == $iTotal) {
  149. $this->_oDb->insertContentNodes2Users([
  150. 'node_id' => $iNodeId,
  151. 'profile_id' => $iProfileId,
  152. 'date' => time()
  153. ]);
  154. if((int)$aNode['parent_id'] != 0)
  155. $this->_autoPassNodes($iProfileId, $aNode['parent_id']);
  156. }
  157. }
  158. public function serviceGetOptionsContentModulesSt()
  159. {
  160. return $this->_getOptionsContentModules();
  161. }
  162. public function serviceGetOptionsContentModulesAt()
  163. {
  164. return $this->_getOptionsContentModules();
  165. }
  166. public function serviceIsContentAvaliable($iProfileId)
  167. {
  168. if(!$this->_oConfig->isContent())
  169. return false;
  170. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  171. if($this->checkAllowedEdit($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  172. return false;
  173. return true;
  174. }
  175. public function serviceOnContentAdded($sContentType, $iContentId, $iContextId, $iContextNodeId, $iContextUsage)
  176. {
  177. $this->_oDb->insertContentData([
  178. 'entry_id' => $iContextId,
  179. 'node_id' => $iContextNodeId,
  180. 'content_type' => $sContentType,
  181. 'content_id' => $iContentId,
  182. 'usage' => $iContextUsage,
  183. 'added' => time(),
  184. 'order' => $this->_oDb->getContentDataOrderMax($iContextId, $iContextNodeId) + 1
  185. ]);
  186. $aNode = $this->_oDb->getContentNodes(['sample' => 'id', 'id' => $iContextNodeId]);
  187. $aCounters = [];
  188. if(!empty($aNode['counters']))
  189. $aCounters = json_decode($aNode['counters'], true);
  190. $sUsage = $this->_oConfig->getUsageI2S($iContextUsage);
  191. if(!isset($aCounters[$sUsage]))
  192. $aCounters[$sUsage] = [];
  193. if(!isset($aCounters[$sUsage][$sContentType]))
  194. $aCounters[$sUsage][$sContentType] = 0;
  195. $aCounters[$sUsage][$sContentType] += 1;
  196. $this->_oDb->updateContentNodes(['counters' => json_encode($aCounters)], ['id' => $iContextNodeId]);
  197. }
  198. public function serviceOnContentAddedRedirect($sContentType, $iContentId)
  199. {
  200. $CNF = &$this->_oConfig->CNF;
  201. $aData = $this->_oDb->getContentData(['sample' => 'content', 'content_type' => $sContentType, 'content_id' => $iContentId]);
  202. if(empty($aData) || !is_array($aData))
  203. return false;
  204. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY_CONTENT'] . '&id=' . $aData['entry_id'], [
  205. 'parent_id' => $aData['node_id']
  206. ]);
  207. return $this->_bIsApi ? '' : $sUrl;
  208. }
  209. public function serviceOnContentDeleted($sContentType, $iContentId, $iContextId)
  210. {
  211. $aData = $this->_oDb->getContentData(['sample' => 'content', 'content_type' => $sContentType, 'content_id' => $iContentId]);
  212. if(empty($aData) || !is_array($aData))
  213. return;
  214. $this->_oDb->deleteContentData([
  215. 'entry_id' => $iContextId,
  216. 'content_type' => $sContentType,
  217. 'content_id' => $iContentId,
  218. ]);
  219. $this->_oDb->deleteContentData2Users([
  220. 'data_id' => $aData['id']
  221. ]);
  222. $aNode = $this->_oDb->getContentNodes(['sample' => 'id', 'id' => $aData['node_id']]);
  223. if(!empty($aNode['counters'])) {
  224. $sUsage = $this->_oConfig->getUsageI2S($aData['usage']);
  225. $aCounters = json_decode($aNode['counters'], true);
  226. if(!empty($aCounters[$sUsage][$sContentType])) {
  227. if((int)$aCounters[$sUsage][$sContentType] > 1)
  228. $aCounters[$sUsage][$sContentType] -= 1;
  229. else
  230. unset($aCounters[$sUsage][$sContentType]);
  231. $this->_oDb->updateContentNodes(['counters' => json_encode($aCounters)], ['id' => $aData['node_id']]);
  232. }
  233. }
  234. }
  235. public function serviceEntityContentStructureBlock($iProfileId = 0)
  236. {
  237. $CNF = &$this->_oConfig->CNF;
  238. if(!$this->_oConfig->isContent())
  239. return '';
  240. if(!$iProfileId)
  241. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  242. if(!$iProfileId)
  243. return '';
  244. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  245. $sGridKey = 'OBJECT_GRID_CNT_STRUCTURE_' . ($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED ? 'MANAGE' : 'VIEW');
  246. $oGrid = BxDolGrid::getObjectInstance($CNF[$sGridKey]);
  247. if(!$oGrid)
  248. return '';
  249. $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
  250. if($this->_bIsApi)
  251. return ($aGrid = $oGrid->getCodeAPI()) ? [
  252. bx_api_get_block('grid', $aGrid)
  253. ] : [];
  254. return $oGrid->getCode();
  255. }
  256. public function serviceEntityContentDataBlock($iProfileId = 0)
  257. {
  258. $CNF = &$this->_oConfig->CNF;
  259. if(!$this->_oConfig->isContent())
  260. return '';
  261. if(!$iProfileId)
  262. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  263. if(!$iProfileId)
  264. return '';
  265. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iProfileId);
  266. $sGridKey = 'OBJECT_GRID_CNT_DATA_' . ($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED ? 'MANAGE' : 'VIEW');
  267. $oGrid = BxDolGrid::getObjectInstance($CNF[$sGridKey]);
  268. if(!$oGrid)
  269. return '';
  270. $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
  271. if($this->_bIsApi)
  272. return ($aGrid = $oGrid->getCodeAPI()) ? [
  273. bx_api_get_block('grid', $aGrid)
  274. ] : [];
  275. return $oGrid->getCode();
  276. }
  277. public function serviceEntityStructureL1Block($iContentId = 0)
  278. {
  279. if(!$this->_oConfig->isContent() || $this->_oConfig->getContentLevelMax() == 1)
  280. return $this->_bIsApi ? [] : '';
  281. $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByLevel', $iContentId, [
  282. 'level' => 1,
  283. 'selected' => ($iNodeId = bx_get('parent_id')) !== false ? (int)$iNodeId : 0,
  284. 'start' => ($iStart = bx_get('start')) !== false ? (int)$iStart : 0,
  285. 'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : 2,
  286. ]);
  287. return $this->_bIsApi ? [bx_api_get_block('course_structure', $mixedResult)] : $mixedResult;
  288. }
  289. public function serviceEntityStructureL2Block($iContentId = 0, $iParentId = 0)
  290. {
  291. if(!$this->_oConfig->isContent())
  292. return $this->_bIsApi ? [] : '';
  293. if(!$iParentId && ($_iParentId = bx_get('parent_id')) !== false)
  294. $iParentId = (int)$_iParentId;
  295. $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByParentMl' . $this->_oConfig->getContentLevelMax(), $iContentId, [
  296. 'parent_id' => $iParentId
  297. ]);
  298. return $this->_bIsApi ? [bx_api_get_block('module_structure', $mixedResult)] : $mixedResult;
  299. }
  300. public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage = false)
  301. {
  302. if(!$this->_oConfig->isContent())
  303. return $this->_bIsApi ? [] : '';
  304. if(!$iNodeId && ($_iNodeId = bx_get('node_id')) !== false)
  305. $iNodeId = (int)$_iNodeId;
  306. if($iUsage === false && ($_iUsage = bx_get('usage')) !== false)
  307. $iUsage = (int)$_iUsage;
  308. $mixedResult = $this->_serviceTemplateFuncEx('entryNode', $iContentId, [
  309. 'node_id' => $iNodeId,
  310. 'usage' => $iUsage
  311. ]);
  312. return $this->_bIsApi ? [bx_api_get_block('lesson_structure', $mixedResult)] : $mixedResult;
  313. }
  314. public function getNodeLevelByParent($aParentInfo)
  315. {
  316. return (is_array($aParentInfo) && !empty($aParentInfo['level']) ? (int)$aParentInfo['level'] : 0) + 1;
  317. }
  318. public function getDataTotalByNode($mixedNode, $iUsage = 0)
  319. {
  320. if(!is_array($mixedNode))
  321. $mixedNode = $this->_oDb->getContentNodes([
  322. 'sample' => 'id',
  323. 'id' => (int)$mixedNode
  324. ]);
  325. $iTotal = 0;
  326. $sUsage = $this->_oConfig->getUsageI2S($iUsage);
  327. if(!empty($mixedNode['counters']) && ($aCountes = json_decode($mixedNode['counters'], true)) && !empty($aCountes[$sUsage]) && is_array($aCountes[$sUsage]))
  328. $iTotal = array_sum($aCountes[$sUsage]);
  329. return $iTotal;
  330. }
  331. public function isNodeStarted($iProfileId, $mixedNode)
  332. {
  333. $iNodeId = is_array($mixedNode) ? $mixedNode['id'] : (int)$mixedNode;
  334. $aChildNodes = $this->_oDb->getContentStructure([
  335. 'sample' => 'parent_id',
  336. 'parent_id' => $iNodeId
  337. ]);
  338. if(!empty($aChildNodes) && is_array($aChildNodes)) {
  339. foreach($aChildNodes as $aChildNode)
  340. if($this->isNodePassed($iProfileId, $aChildNode['node_id']))
  341. return true;
  342. else
  343. return $this->isNodeStarted($iProfileId, $aChildNode['node_id']);
  344. }
  345. else {
  346. $aChildData = $this->_oDb->getContentData([
  347. 'sample' => 'node_id',
  348. 'node_id' => $iNodeId
  349. ]);
  350. if(!empty($aChildData) && is_array($aChildData))
  351. foreach($aChildData as $aChildData)
  352. if($this->isDataPassed($iProfileId, $aChildData['id']))
  353. return true;
  354. return false;
  355. }
  356. }
  357. public function isNodePassed($iProfileId, $mixedNode)
  358. {
  359. $aUserTrack = $this->_oDb->getContentStructure([
  360. 'sample' => 'user_passed',
  361. 'profile_id' => $iProfileId,
  362. 'node_id' => is_array($mixedNode) ? $mixedNode['id'] : (int)$mixedNode
  363. ]);
  364. return !empty($aUserTrack) && is_array($aUserTrack);
  365. }
  366. public function isDataPassed($iProfileId, $mixedData)
  367. {
  368. $aUserTrack = $this->_oDb->getContentData([
  369. 'sample' => 'user_passed',
  370. 'profile_id' => $iProfileId,
  371. 'data_id' => is_array($mixedData) ? $mixedData['id'] : (int)$mixedData
  372. ]);
  373. return !empty($aUserTrack) && is_array($aUserTrack);
  374. }
  375. public function getEntryPass($iProfileId, $iContentId)
  376. {
  377. $aChildren = $this->_oDb->getContentStructure([
  378. 'sample' => 'entry_id',
  379. 'entry_id' => $iContentId,
  380. 'level' => 1
  381. ]);
  382. $aPassDetails = [];
  383. foreach($aChildren as $aChild)
  384. $this->getNodePass($iProfileId, $iContentId, $aChild, $aPassDetails);
  385. $iPassPercent = 0;
  386. $sPassStatus = '_bx_courses_txt_status_not_started';
  387. $sPassTitle = '_bx_courses_txt_pass_start';
  388. $iLevelMax = $this->_oConfig->getContentLevelMax();
  389. if(isset($aPassDetails[$iLevelMax]) && ($aPassLevelMax = $aPassDetails[$iLevelMax])) {
  390. $iPassPercent = ($iTotal = (int)$aPassLevelMax['total']) != 0 ? (int)round(100 * $aPassLevelMax['passed']/$iTotal) : 0;
  391. if($aPassLevelMax['passed'] != 0) {
  392. if($aPassLevelMax['passed'] != $aPassLevelMax['total']) {
  393. $sPassStatus = '_bx_courses_txt_status_in_process';
  394. $sPassTitle = '_bx_courses_txt_pass_continue';
  395. }
  396. else {
  397. $sPassStatus = '_bx_courses_txt_status_completed';
  398. $sPassTitle = '_bx_courses_txt_pass_again';
  399. }
  400. }
  401. }
  402. return [
  403. $iPassPercent,
  404. $aPassDetails,
  405. _t($sPassStatus),
  406. _t($sPassTitle)
  407. ];
  408. }
  409. public function getNodePass($iProfileId, $iContentId, $aNode, &$aResults)
  410. {
  411. $iLevel = $aNode['level'];
  412. if(!isset($aResults[$iLevel]))
  413. $aResults[$iLevel] = [
  414. 'passed' => 0,
  415. 'total' => 0
  416. ];
  417. $aResults[$iLevel]['passed'] += $this->isNodePassed($iProfileId, $aNode['node_id']);
  418. $aResults[$iLevel]['total'] += 1;
  419. if($iLevel != $this->_oConfig->getContentLevelMax() && !empty($aNode['cn_l' . ($iLevel + 1)])) {
  420. $aChildren = $this->_oDb->getContentStructure([
  421. 'sample' => 'parent_id',
  422. 'parent_id' => $aNode['node_id']
  423. ]);
  424. foreach($aChildren as $aChild)
  425. $this->getNodePass($iProfileId, $iContentId, $aChild, $aResults);
  426. }
  427. }
  428. public function getNodePassByChildren($iProfileId, $iContentId, $aNode, &$aResults)
  429. {
  430. $aUserTrack = $this->_oDb->getContentStructure([
  431. 'sample' => 'user_track',
  432. 'entry_id' => $iContentId,
  433. 'node_id' => $aNode['node_id'],
  434. 'profile_id' => $iProfileId
  435. ]);
  436. $iLevelChildren = $aNode['level'] + 1;
  437. $iCountChildren = $aNode['cn_l' . $iLevelChildren];
  438. if(!isset($aResults[$iLevelChildren]))
  439. $aResults[$iLevelChildren] = [
  440. 'passed' => 0,
  441. 'total' => 0
  442. ];
  443. $aResults[$iLevelChildren]['passed'] += count($aUserTrack);
  444. $aResults[$iLevelChildren]['total'] += $iCountChildren;
  445. if($iCountChildren && $iLevelChildren != $this->_oConfig->getContentLevelMax()) {
  446. $aChildren = $this->_oDb->getContentStructure([
  447. 'sample' => 'parent_id',
  448. 'parent_id' => $aNode['node_id']
  449. ]);
  450. foreach($aChildren as $aChild)
  451. $this->getNodePassByChildren($iProfileId, $iContentId, $aChild, $aResults);
  452. }
  453. }
  454. public function getNodePassByData($iProfileId, $iContentId, $aNode)
  455. {
  456. $iTotal = 0;
  457. $iPassCount = $iPassPercent = 0;
  458. $sPassStatus = $sPassTitle = '';
  459. if(($iTotal = $this->getDataTotalByNode($aNode)) != 0) {
  460. $aUserTrack = $this->_oDb->getContentData([
  461. 'sample' => 'user_track',
  462. 'entry_id' => $iContentId,
  463. 'node_id' => $aNode['node_id'],
  464. 'profile_id' => $iProfileId
  465. ]);
  466. $iPassCount = count($aUserTrack);
  467. $iPassPercent = (int)round(100 * $iPassCount/$iTotal);
  468. if($iPassCount == 0) {
  469. $sPassStatus = '_bx_courses_txt_status_not_started';
  470. $sPassTitle = '_bx_courses_txt_pass_start';
  471. }
  472. else {
  473. if($iPassCount != $iTotal) {
  474. $sPassStatus = '_bx_courses_txt_status_in_process';
  475. $sPassTitle = '_bx_courses_txt_pass_continue';
  476. }
  477. else {
  478. $sPassStatus = '_bx_courses_txt_status_completed';
  479. $sPassTitle = '_bx_courses_txt_pass_again';
  480. }
  481. }
  482. }
  483. return [
  484. $iPassPercent,
  485. _t('_bx_courses_txt_n_m_steps', $iPassCount, $iTotal),
  486. _t($sPassStatus ? $sPassStatus : '_undefined'),
  487. _t($sPassTitle)
  488. ];
  489. }
  490. public function decodeDataAPI($aData, $aParams = [])
  491. {
  492. $CNF = $this->_oConfig->CNF;
  493. $aResult = parent::decodeDataAPI($aData, $aParams);
  494. $aResultAdd = [];
  495. $iEntryId = (int)$aData[$CNF['FIELD_ID']];
  496. $aLevelToNode = $this->_oConfig->getContentLevel2Node(false);
  497. if($this->isFan($iEntryId, $this->_iProfileId)) {
  498. $sTxtProgress = _t('_bx_courses_txt_n_m_progress');
  499. list($iPassPercent, $aPassDetails, $sPassStatus, $sPassTitle) = $this->getEntryPass($this->_iProfileId, $iEntryId);
  500. $aCounters = [];
  501. foreach($aPassDetails as $iLevel => $aDetails) {
  502. $aCounters[] = [
  503. 'level' => $iLevel,
  504. 'title' => $aLevelToNode[$iLevel],
  505. 'passed' => $aDetails['passed'],
  506. 'total' => $aDetails['total'],
  507. 'progress' => bx_replace_markers($sTxtProgress, $aDetails)
  508. ];
  509. }
  510. $aResultAdd = [
  511. 'percent' => $iPassPercent,
  512. 'counters' => $aCounters,
  513. 'status' => $sPassStatus,
  514. 'show_pass' => $iPassPercent > 0 && $iPassPercent < 100,
  515. ];
  516. if($aResultAdd['show_pass'])
  517. $aResultAdd = array_merge($aResultAdd, [
  518. 'pass_link' => $aResult['url'],
  519. 'pass_title' => $sPassTitle,
  520. ]);
  521. }
  522. else {
  523. $iLevelMax = $this->_oConfig->getContentLevelMax();
  524. $aEntryCounters = $this->_oDb->getContentStructure(['sample' => 'entry_id_counters', 'entry_id' => $iEntryId]);
  525. $aCounters = [];
  526. for($i = 1; $i <= $iLevelMax; $i++) {
  527. $aCounters[] = [
  528. 'level' => $i,
  529. 'title' => $aLevelToNode[$i],
  530. 'total' => $aEntryCounters['cn_l' . $i]
  531. ];
  532. }
  533. $aResultAdd = [
  534. 'counters' => $aCounters,
  535. ];
  536. }
  537. return array_merge($aResult, $aResultAdd);
  538. }
  539. protected function _getOptionsContentModules()
  540. {
  541. $aResult = [];
  542. $aModules = bx_srv('system', 'get_modules_by_type', ['content']);
  543. foreach($aModules as $aModule)
  544. $aResult[] = ['key' => $aModule['name'], 'value' => $aModule['title']];
  545. return $aResult;
  546. }
  547. }
  548. /** @} */