BxCoursesModule.php 21 KB

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