BxCoursesModule.php 22 KB

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