BxBaseCmtsServices.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services related to Comments.
  11. */
  12. class BxBaseCmtsServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceGetBlockView($sSystem = '', $iObjectId = 0, $iCommentId = 0)
  19. {
  20. if(empty($sSystem) && ($sSystem = bx_get('sys')) !== false)
  21. $sSystem = bx_process_input($sSystem);
  22. if(empty($iObjectId) && ($iObjectId = bx_get('id')) !== false)
  23. $iObjectId = bx_process_input($iObjectId, BX_DATA_INT);
  24. if(empty($iCommentId) && ($iCommentId = bx_get('cmt_id')) !== false)
  25. $iCommentId = bx_process_input($iCommentId, BX_DATA_INT);
  26. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iObjectId, true);
  27. if(!$oCmts)
  28. return '';
  29. return $oCmts->getCommentBlock($iCommentId);
  30. }
  31. public function serviceAlertResponseSysCmtsImagesFileDeleted($oAlert)
  32. {
  33. $iUniqId = (int)$oAlert->aExtras['ghost']['content_id'];
  34. $aCmt = BxDolCmts::getGlobalInfo($iUniqId);
  35. if(empty($aCmt) || !is_array($aCmt))
  36. return;
  37. $oCmts = BxDolCmts::getObjectInstance($aCmt['system_name'], 0, false);
  38. if(!$oCmts)
  39. return;
  40. $oCmts->getQueryObject()->deleteImages($aCmt['system_id'], false, $oAlert->iObject);
  41. }
  42. public function serviceGetMenuItemAddonVote($sSystem, $iId, $iCmtId)
  43. {
  44. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  45. $oVote = $oCmts->getVoteObject($iCmtId);
  46. if($oVote !== false)
  47. return $oVote->getCounter();
  48. return '';
  49. }
  50. public function serviceGetLiveUpdate($sSystem, $iContentId, $iProfileId, $iCount = 0)
  51. {
  52. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  53. if(!$oCmts || !$oCmts->isEnabled())
  54. return false;
  55. $sKey = $oCmts->getNotificationId();
  56. bx_import('BxDolSession');
  57. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  58. return false;
  59. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  60. if($iCountNew == $iCount)
  61. return false;
  62. return array(
  63. 'count' => $iCountNew, // required
  64. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdate(oData)', // required
  65. 'data' => array(
  66. 'code' => $oCmts->getLiveUpdate($iCount, $iCountNew)
  67. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  68. );
  69. }
  70. public function serviceGetLiveUpdates($sSystem, $iContentId, $iProfileId, $iCount = 0)
  71. {
  72. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  73. if(!$oCmts || !$oCmts->isEnabled())
  74. return false;
  75. $sKey = $oCmts->getNotificationId();
  76. bx_import('BxDolSession');
  77. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  78. return false;
  79. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  80. if($iCountNew == $iCount)
  81. return false;
  82. return array(
  83. 'count' => $iCountNew, // required
  84. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdates(oData)', // required
  85. 'data' => array(
  86. 'code' => $oCmts->getLiveUpdates($iCount, $iCountNew)
  87. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  88. );
  89. }
  90. public function serviceManageTools($sType = 'common')
  91. {
  92. $oGrid = BxDolGrid::getObjectInstance('sys_cmts_administration');
  93. if(!$oGrid)
  94. return '';
  95. $oTemplate = BxDolTemplate::getInstance();
  96. $oTemplate->addJs(array('BxDolCmtsManageTools.js'));
  97. $oTemplate->addCss(array('cmts_manage_tools.css'));
  98. $oTemplate->addJsTranslation(array('_sys_grid_search'));
  99. return array(
  100. 'content' => $oGrid->getCode()
  101. );
  102. }
  103. public function serviceGetMenuAddonManageTools()
  104. {
  105. $iNumTotal = BxDolCmts::getGlobalNumByParams();
  106. $iNum1 = BxDolCmts::getGlobalNumByParams([[
  107. 'key' => 'status_admin',
  108. 'value' => 'pending',
  109. 'operator' => '='
  110. ]]);
  111. $iNum2 = BxDolCmts::getGlobalNumByParams([[
  112. 'key' => 'reports',
  113. 'value' => '0',
  114. 'operator' => '>'
  115. ]]);
  116. return [
  117. 'counter1_value' => $iNum1,
  118. 'counter1_caption' => _t('_sys_menu_dashboard_manage_tools_addon_counter1_caption_profile_default'),
  119. 'counter2_value' => $iNum2,
  120. 'counter3_value' => $iNumTotal
  121. ];
  122. }
  123. /**
  124. * Comment Added for Timeline module
  125. */
  126. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  127. {
  128. $bCache = true;
  129. $iCmtUniqId = $aEvent['object_id'];
  130. $oCmts = BxDolCmts::getObjectInstanceByUniqId($iCmtUniqId);
  131. if(!$oCmts)
  132. return false;
  133. $aCmt = BxDolCmtsQuery::getCommentExtendedByUniqId($iCmtUniqId);
  134. if(empty($aCmt) || !is_array($aCmt))
  135. return false;
  136. $iCmtId = (int)$aCmt['cmt_id'];
  137. $iUserId = bx_get_logged_profile_id();
  138. $iAuthorId = (int)$aCmt['cmt_author_id'];
  139. $iAuthorIdAbs = abs($iAuthorId);
  140. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id']))) && $iAuthorIdAbs != $iUserId)
  141. return false;
  142. $sCmtUrl = $oCmts->getViewUrl($iCmtId);
  143. $sSample = '_cmt_txt_sample_comment_single_with_article';
  144. $sSampleWoArticle = '_cmt_txt_sample_comment_single';
  145. $sAction = '';
  146. $sActionCustom = '_cmt_txt_added_sample_custom';
  147. $aActionCustomMarkers = array(
  148. 'sample' => $sSample,
  149. 'sample_url' => $sCmtUrl,
  150. 'psample' => strip_tags($oCmts->getObjectTitle()),
  151. 'psample_url' => $oCmts->getBaseUrl(),
  152. );
  153. $iOwnerId = $iAuthorIdAbs;
  154. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  155. $iOwnerId = abs($aEvent['object_privacy_view']);
  156. //--- Votes
  157. $aVotes = array();
  158. if(($oVotes = $oCmts->getVoteObject($iCmtUniqId)) !== false)
  159. $aVotes = array(
  160. 'system' => $oVotes->getSystemName(),
  161. 'object_id' => $iCmtUniqId,
  162. 'count' => $aCmt['votes']
  163. );
  164. //--- Reactions
  165. $aReactions = array();
  166. if(($oReactions = $oCmts->getReactionObject($iCmtUniqId)) !== false)
  167. $aReactions = array(
  168. 'system' => $oReactions->getSystemName(),
  169. 'object_id' => $iCmtUniqId,
  170. 'count' => $aCmt['rvotes']
  171. );
  172. //--- Scores
  173. $aScores = array();
  174. if(($oScores = $oCmts->getScoreObject($iCmtUniqId)) !== false)
  175. $aScores = array(
  176. 'system' => $oScores->getSystemName(),
  177. 'object_id' => $iCmtUniqId,
  178. 'score' => $aCmt['score']
  179. );
  180. //--- Reports
  181. $aReports = array();
  182. if(($oReports = $oCmts->getReportObject($iCmtUniqId)) !== false)
  183. $aReports = array(
  184. 'system' => $oReports->getSystemName(),
  185. 'object_id' => $iCmtUniqId,
  186. 'count' => $aCmt['reports']
  187. );
  188. return array(
  189. '_cache' => $bCache,
  190. 'owner_id' => $iOwnerId,
  191. 'object_owner_id' => $iAuthorId,
  192. 'icon' => 'comments',
  193. 'sample' => $sSample,
  194. 'sample_wo_article' => $sSampleWoArticle,
  195. 'sample_action' => $sAction,
  196. 'sample_action_custom' => array(
  197. 'content' => $sActionCustom,
  198. 'markers' => $aActionCustomMarkers
  199. ),
  200. 'url' => $sCmtUrl,
  201. 'content' => array(
  202. 'sample' => $sSample,
  203. 'sample_wo_article' => $sSampleWoArticle,
  204. 'sample_action' => $sAction,
  205. 'url' => $sCmtUrl,
  206. 'title' => '',
  207. 'text' => $oCmts->getViewText($aCmt),
  208. 'images' => array(),
  209. 'images_attach' => array(),
  210. 'videos' => array(),
  211. 'videos_attach' => array(),
  212. 'files' => array(),
  213. 'files_attach' => $oCmts->getAttachments($iCmtId)
  214. ), //a string to display or array to parse default template before displaying.
  215. 'date' => $aCmt['cmt_time'],
  216. 'views' => array(),
  217. 'votes' => $aVotes,
  218. 'reactions' => $aReactions,
  219. 'scores' => $aScores,
  220. 'reports' => $aReports,
  221. 'comments' => array(),
  222. 'title' => !empty($aCmt['cmt_text']) ? $aCmt['cmt_text'] : '', //may be empty.
  223. 'description' => '' //may be empty.
  224. );
  225. }
  226. /**
  227. * Comment added for Notifications module
  228. */
  229. public function serviceGetNotificationsCommentAdded($aEvent)
  230. {
  231. $aCommentGi = BxDolCmts::getGlobalInfo($aEvent['subobject_id']);
  232. if(empty($aCommentGi) || !is_array($aCommentGi))
  233. return [];
  234. $iContentId = (int)$aEvent['object_id'];
  235. $oComment = BxDolCmts::getObjectInstance($aCommentGi['system_name'], $iContentId);
  236. if(!$oComment)
  237. return [];
  238. $aCommentSystem = $oComment->getSystemInfo();
  239. $oContentModule = BxDolModule::getInstance($aCommentSystem['module']);
  240. if(!$oContentModule)
  241. return [];
  242. $aContentInfo = $oContentModule->_oDb->getContentInfoById($iContentId);
  243. if(empty($aContentInfo) || !is_array($aContentInfo))
  244. return [];
  245. $CNF = &$oContentModule->_oConfig->CNF;
  246. if(empty($CNF['FIELD_ID']) || empty($CNF['FIELD_AUTHOR']) || !(isset($CNF['FIELD_TITLE']) || isset($CNF['FIELD_TEXT'])) || empty($CNF['URI_VIEW_ENTRY']))
  247. return [];
  248. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  249. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  250. return array(
  251. 'entry_sample' => $CNF['T']['txt_sample_single'],
  252. 'entry_url' => $sEntryUrl,
  253. 'entry_caption' => $sEntryCaption,
  254. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  255. 'subentry_url' => '{bx_url_root}' . $oComment->getViewUrl((int)$aCommentGi['cmt_id'], false),
  256. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  257. );
  258. }
  259. /**
  260. * Comment vote for Notifications module
  261. */
  262. public function serviceGetNotificationsVote($aEvent)
  263. {
  264. $iCmtIdUnique = (int)$aEvent['object_id'];
  265. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  266. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  267. return array();
  268. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  269. if(!$oCmts || !$oCmts->isEnabled())
  270. return array();
  271. $oVote = $oCmts->getVoteObject($iCmtIdUnique);
  272. if(!$oVote)
  273. return array();
  274. $iCmtId = (int)$aCmtInfo['cmt_id'];
  275. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  276. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  277. return array(
  278. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  279. 'entry_url' => $sCmtUrl,
  280. 'entry_caption' => $sCmtCaption,
  281. 'entry_author' => $aCmtInfo['author_id'],
  282. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
  283. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  284. );
  285. }
  286. /**
  287. * Comment reaction for Notifications module
  288. */
  289. public function serviceGetNotificationsReaction($aEvent)
  290. {
  291. $iCmtIdUnique = (int)$aEvent['object_id'];
  292. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  293. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  294. return array();
  295. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  296. if(!$oCmts || !$oCmts->isEnabled())
  297. return array();
  298. $oReaction = $oCmts->getReactionObject($iCmtIdUnique);
  299. if(!$oReaction)
  300. return array();
  301. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  302. if(empty($aSubentry) || !is_array($aSubentry))
  303. return array();
  304. $aSubentrySampleParams = array();
  305. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  306. if(!empty($aReaction['title']))
  307. $aSubentrySampleParams[] = $aReaction['title'];
  308. else
  309. $aSubentrySampleParams[] = '_undefined';
  310. $iCmtId = (int)$aCmtInfo['cmt_id'];
  311. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  312. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  313. return array(
  314. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  315. 'entry_url' => $sCmtUrl,
  316. 'entry_caption' => $sCmtCaption,
  317. 'entry_author' => $aCmtInfo['author_id'],
  318. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
  319. 'subentry_sample_params' => $aSubentrySampleParams,
  320. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  321. );
  322. }
  323. /**
  324. * Comment score -> vote up for Notifications module
  325. */
  326. public function serviceGetNotificationsScoreUp($aEvent)
  327. {
  328. return $this->_serviceGetNotificationsScore('up', $aEvent);
  329. }
  330. /**
  331. * Comment score -> vote down for Notifications module
  332. */
  333. public function serviceGetNotificationsScoreDown($aEvent)
  334. {
  335. return $this->_serviceGetNotificationsScore('down', $aEvent);
  336. }
  337. protected function _serviceGetNotificationsScore($sType, $aEvent)
  338. {
  339. $iCmtIdUnique = (int)$aEvent['object_id'];
  340. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  341. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  342. return array();
  343. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  344. if(!$oCmts || !$oCmts->isEnabled())
  345. return array();
  346. $oScore = $oCmts->getScoreObject($iCmtIdUnique);
  347. if(!$oScore)
  348. return array();
  349. $iCmtId = (int)$aCmtInfo['cmt_id'];
  350. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  351. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  352. return array(
  353. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  354. 'entry_url' => $sCmtUrl,
  355. 'entry_caption' => $sCmtCaption,
  356. 'entry_author' => $aCmtInfo['author_id'],
  357. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
  358. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  359. );
  360. }
  361. /**
  362. * @page service Service Calls
  363. * @section bx_system_cmts System Services
  364. * @subsection bx_system_cmts-general General
  365. * @subsubsection bx_system_cmts-get_data_api get_data_api
  366. *
  367. * @code bx_srv('system', 'get_data_api', [], 'TemplCmtsServices'); @endcode
  368. *
  369. * Get comments data
  370. * @param $aParams array with paramenters :
  371. * "module":"bx_posts","object_id":3,"start_from":5,"order_way":"desc","is_form":false
  372. *
  373. * @see TemplCmtsServices::serviceGetDataApi
  374. */
  375. /**
  376. * @ref bx_system_cmts-get_data_api "get_data_api"
  377. * @api @ref bx_system_cmts-get_data_api "get_data_api"
  378. */
  379. public function serviceGetDataApi($aParams)
  380. {
  381. if(is_string($aParams))
  382. $aParams = json_decode($aParams, true);
  383. $aParams['parent_id'] = !isset($aParams['parent_id']) ? 0 : $aParams['parent_id'];
  384. $aParams['start_from'] = !isset($aParams['start_from']) ? 0 : $aParams['start_from'];
  385. $aParams['order_way'] = !isset($aParams['order_way']) ? 'desc' : $aParams['order_way'];
  386. $aParams['is_form'] = !isset($aParams['is_form']) ? true : $aParams['is_form'];
  387. $aParams['insert'] = 'before';
  388. $oCmts = BxDolCmts::getObjectInstance($aParams['module'], $aParams['object_id']);
  389. if (!$oCmts || !$oCmts->isEnabled())
  390. return false;
  391. $aRv = [
  392. 'id' => '1',
  393. 'url' => '/api.php?r=system/get_data_api/TemplCmtsServices/&params[]=',
  394. 'type' => 'comments'
  395. ];
  396. $oForm = $oCmts->getFormPost($aParams['parent_id']);
  397. $bIsList = false;
  398. if (isset($oForm['form']) && $aParams['is_form']){
  399. $aForm = $oForm['form']->getCodeAPI();
  400. $aForm['inputs']['cmt_text']['numLines'] = 1;
  401. $aForm['inputs']['cmt_text']['autoheight'] = true;
  402. $aForm['inputs']['cmt_submit']['icon'] = 'contact';
  403. $aForm['inputs']['cmt_submit']['rounded'] = true;
  404. $aForm['inputs']['cmt_submit']['value'] = '';
  405. // add view (form + new comment)
  406. if($oForm['form']->isSubmittedAndValid()){
  407. $aParams['insert'] = $aParams['order_way'] == 'desc' ? 'after' : 'before';
  408. $aParams['comment_id'] = $oForm['res'];
  409. $bIsList = true;
  410. $aForm['inputs']['cmt_parent_id']['value'] = 0;
  411. }
  412. $aRv['form'] = ['id' => 'cmt_form', 'type' => 'form', 'name' => 'comment', 'data' => $aForm, 'request' => ['immutable' => true]];
  413. // default view (form + list)
  414. if (!$oForm['form']->isSubmitted()){
  415. $bIsList = true;
  416. }
  417. }
  418. else{
  419. // list only view
  420. $bIsList = true;
  421. $aParams['insert'] = 'before';
  422. }
  423. if ($bIsList)
  424. $aRv['browse'] = $this->serviceGetCommentsApi($oCmts, $aParams);
  425. return $aRv;
  426. }
  427. public function serviceGetCommentsApi($oCmts, $aParams)
  428. {
  429. $mixedResult = $oCmts->isViewAllowed();
  430. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  431. return $mixedResult; // TODO: error checking
  432. $aBp = !isset($aParams['aBp']) ? [] : $aParams['aBp'];
  433. $aDp = ['in_designbox' => false, 'show_empty' => false];
  434. $aBp['type'] = 'head';
  435. $oCmts->getParams($aBp, $aDp);
  436. $oCmts->prepareParams($aBp, $aDp);
  437. $aBp['order']['way'] = $aParams['order_way'];
  438. $aBp['order_way'] = $aParams['order_way'];
  439. $aBp['start'] = $aParams['start_from'] ;
  440. $aPp = $aBp['per_view'];
  441. $aBp['per_view'] = $aBp['per_view'] + 1;
  442. if (isset($aParams['per_view'])){
  443. $aBp['per_view'] = $aParams['per_view'];
  444. }
  445. $aCmts = isset($aParams['comment_id']) ? [['cmt_id' => $aParams['comment_id']]] : $oCmts->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  446. $aParams['start_from'] = 0;
  447. if (count($aCmts) == $aBp['per_view']){
  448. $aBp['per_view'] = $aPp;
  449. $aCmts = array_slice($aCmts, 0, $aBp['per_view']);
  450. $aParams['start_from'] = $aBp['start'] + $aBp['per_view'];
  451. }
  452. $aCmtsRv = [];
  453. foreach ($aCmts as $aCmt) {
  454. $aCmtsRv[] = $oCmts->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
  455. }
  456. $aData = [
  457. 'unit' => 'comments',
  458. 'start' => $aParams['start_from'],
  459. 'count' => count($aCmts),
  460. 'per_view' => $aBp['per_view'],
  461. 'total_count' => $aBp['count'],
  462. 'order' => $aParams['order_way'],
  463. 'module' => $oCmts->getSystemName(),
  464. 'object_id' => $oCmts->getId(),
  465. 'data' => $aCmtsRv
  466. ];
  467. if (isset($aParams['mode']) && $aParams['mode'] == 'feed')
  468. return $aData;
  469. $aRv = [
  470. 'id' => 'cmt_list',
  471. 'type' => 'browse',
  472. 'insert' => $aParams['insert'],
  473. 'data' => $aData
  474. ];
  475. if (isset($aParams['comment_id'])){
  476. $aRv['new'] = $aParams['comment_id'];
  477. }
  478. return $aRv;
  479. }
  480. }
  481. /** @} */