BxBaseReport.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. * @see BxDolReport
  11. */
  12. class BxBaseReport extends BxDolReport
  13. {
  14. protected $_bCssJsAdded;
  15. protected $_sJsObjClass;
  16. protected $_sJsObjName;
  17. protected $_sStylePrefix;
  18. protected $_aHtmlIds;
  19. protected $_aElementDefaults;
  20. protected $_aElementDefaultsApi;
  21. protected $_aElementParamsApi; //--- Params from DefaultsApi array to be passed to Api
  22. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  23. {
  24. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  25. $this->_bCssJsAdded = false;
  26. $this->_sJsObjClass = 'BxDolReport';
  27. $this->_sJsObjName = 'oReport' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  28. $this->_sStylePrefix = 'bx-report';
  29. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  30. $this->_aHtmlIds = array(
  31. 'main' => 'bx-report-' . $sHtmlId,
  32. 'counter' => 'bx-report-counter-' . $sHtmlId,
  33. 'do_link' => 'bx-report-do-link-' . $sHtmlId,
  34. 'do_popup' => 'bx-report-do-popup-' . $sHtmlId,
  35. 'do_form' => 'bx-report-do-form-' . $sHtmlId,
  36. 'by_popup' => 'bx-report-by-popup-' . $sHtmlId
  37. );
  38. $this->_aElementDefaults = array(
  39. 'show_do_report_as_button' => false,
  40. 'show_do_report_as_button_small' => false,
  41. 'show_do_report_icon' => true,
  42. 'show_do_report_label' => false,
  43. 'show_counter' => true,
  44. 'show_counter_only' => true
  45. );
  46. $this->_aElementDefaultsApi = array_merge($this->_aElementDefaults, [
  47. 'show_counter' => true,
  48. ]);
  49. $this->_aElementParamsApi = ['is_reported'];
  50. $this->_sTmplContentElementBlock = $this->_oTemplate->getHtml('report_element_block.html');
  51. $this->_sTmplContentElementInline = $this->_oTemplate->getHtml('report_element_inline.html');
  52. $this->_sTmplContentDoAction = $this->_oTemplate->getHtml('report_do_report.html');
  53. $this->_sTmplContentDoActionLabel = $this->_oTemplate->getHtml('report_do_report_label.html');
  54. }
  55. public function report($aParams = [])
  56. {
  57. if (!$this->isEnabled())
  58. return ['code' => 1, 'message' => _t('_report_err_not_enabled')];
  59. if(!$this->isAllowedReport())
  60. return ['code' => 2, 'message' => $this->msgErrAllowedReport()];
  61. $iAuthorId = $this->_getAuthorId();
  62. $iAuthorNip = bx_get_ip_hash($this->_getAuthorIp());
  63. $iObjectId = $this->_iId;
  64. $iObjectAuthorId = $this->_oQuery->getObjectAuthorId($iObjectId);
  65. $bPerformed = $this->isPerformed($iObjectId, $iAuthorId);
  66. if($bPerformed) {
  67. if(!$this->isUndo())
  68. return ['code' => 4, 'message' => _t('_report_err_duplicate_report')];
  69. if(($iId = $this->_oQuery->putReport($iObjectId, $iAuthorId, true)) !== false) {
  70. $this->_trigger();
  71. bx_alert($this->_sSystem, 'undoReport', $iObjectId, $iAuthorId, array('report_id' => $iId, 'report_author_id' => $iAuthorId, 'object_author_id' => $iObjectAuthorId));
  72. bx_alert('report', 'undo', $iId, $iAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iObjectId, 'object_author_id' => $iObjectAuthorId));
  73. $aReport = $this->_getReport($iObjectId, true);
  74. $aResult = $this->_returnReportData($iObjectId, $iAuthorId, $iId, $aReport, !$bPerformed);
  75. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  76. $oSockets->sendEvent($this->getSocketName(), $iObjectId, 'reported', json_encode($this->_returnReportDataForSocket($aResult)));
  77. return $aResult;
  78. }
  79. }
  80. $oForm = $this->_getFormObject();
  81. $oForm->setId($this->_aHtmlIds['do_form']);
  82. $oForm->setName($this->_aHtmlIds['do_form']);
  83. $oForm->aParams['db']['table'] = $this->_aSystem['table_track'];
  84. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  85. $oForm->aInputs['object_id']['value'] = $this->_iId;
  86. $oForm->aInputs['action']['value'] = 'Report';
  87. $oForm->initChecker();
  88. if($oForm->isSubmittedAndValid() || ($this->_bApi && !empty($aParams) && is_array($aParams))) {
  89. $iObjectId = $this->_bApi ? $this->_iId : $oForm->getCleanValue('object_id');
  90. $iObjectAuthorId = $this->_oQuery->getObjectAuthorId($iObjectId);
  91. if(!$this->isAllowedReport(true))
  92. return ['code' => 2, 'message' => $this->msgErrAllowedReport()];
  93. $sType = $this->_bApi ? $aParams['type'] : $oForm->getCleanValue('type');
  94. if(!in_array($sType, $this->_aTypes))
  95. return ['code' => 5, 'message' => _t('_report_err_wrong_type')];
  96. $sText = $this->_bApi ? $aParams['text'] : $oForm->getCleanValue('text');
  97. $sText = bx_process_input($sText, BX_DATA_TEXT_MULTILINE);
  98. $iId = (int)$oForm->insert(['object_id' => $iObjectId, 'author_id' => $iAuthorId, 'author_nip' => $iAuthorNip, 'type' => $sType, 'text' => $sText, 'date' => time()]);
  99. if($iId != 0 && $this->_oQuery->putReport($iObjectId, $iAuthorId)) {
  100. if(!empty($this->_sObjectCmts) && ($oCmts = BxDolCmts::getObjectInstance($this->_sObjectCmts, $this->getId()))) {
  101. $sCmtText = '_report_comment';
  102. if(!empty($sText))
  103. $sCmtText = '_report_comment_with_note';
  104. $aTypes = BxDolForm::getDataItems('sys_report_types');
  105. $oCmts->add(array(
  106. 'cmt_author_id' => $iAuthorId,
  107. 'cmt_parent_id' => 0,
  108. 'cmt_text' => _t($sCmtText, $aTypes[$sType], $sText)
  109. ));
  110. }
  111. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_Reported', array(
  112. 'report_type' => $sType,
  113. 'report_text' => $sText,
  114. 'report_url' => $this->getBaseUrl(),
  115. ));
  116. if($aTemplate)
  117. sendMail(getParam('site_email'), $aTemplate['Subject'], $aTemplate['Body']);
  118. $mixedParams = $this->_prepareAuditParams($iObjectId, array('type' => $sType, 'text' => $sText));
  119. if($mixedParams) {
  120. $sActionName = $mixedParams['action_name'];
  121. $iAuditObjectId = $mixedParams['object_id'];
  122. unset($mixedParams['action_name']);
  123. unset($mixedParams['object_id']);
  124. bx_audit($iAuditObjectId, $this->_sSystem, $sActionName, $mixedParams);
  125. }
  126. $aReport = $this->_getReport($iObjectId, true);
  127. $iBlockContentAfter = (int)getParam('sys_security_block_content_after_n_reports');
  128. if ($iBlockContentAfter > 0 && $aReport['count'] >= $iBlockContentAfter){
  129. $oModule = BxDolModule::getInstance($this->_aSystem['module_name']);
  130. if($oModule)
  131. $oModule->_oDb->updateStatusAdmin($iObjectId, false);
  132. }
  133. $this->_trigger();
  134. bx_alert($this->_sSystem, 'doReport', $iObjectId, $iAuthorId, array('report_id' => $iId, 'report_author_id' => $iAuthorId, 'object_author_id' => $iObjectAuthorId, 'type' => $sType, 'text' => $sText));
  135. bx_alert('report', 'do', $iId, $iAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iObjectId, 'object_author_id' => $iObjectAuthorId, 'type' => $sType, 'text' => $sText));
  136. $aResult = $this->_returnReportData($iObjectId, $iAuthorId, $iId, $aReport, !$bPerformed);
  137. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  138. $oSockets->sendEvent($this->getSocketName(), $iObjectId, 'reported', json_encode($this->_returnReportDataForSocket($aResult)));
  139. return $aResult;
  140. }
  141. return ['code' => 3, 'message' => _t('_report_err_cannot_perform_action')];
  142. }
  143. $sPopupId = $this->_aHtmlIds['do_popup'];
  144. $sPopupContent = BxTemplFunctions::getInstance()->transBox($sPopupId, $this->_oTemplate->parseHtmlByName('report_do_report_form.html', array(
  145. 'style_prefix' => $this->_sStylePrefix,
  146. 'js_object' => $this->getJsObjectName(),
  147. 'form' => $oForm->getCode(),
  148. 'form_id' => $oForm->id,
  149. )));
  150. return ['popup' => $sPopupContent, 'popup_id' => $sPopupId];
  151. }
  152. public function getJsObjectName()
  153. {
  154. return $this->_sJsObjName;
  155. }
  156. public function getJsScript($bDynamicMode = false)
  157. {
  158. $aParams = array(
  159. 'sObjName' => $this->_sJsObjName,
  160. 'sSystem' => $this->getSystemName(),
  161. 'iAuthorId' => $this->_getAuthorId(),
  162. 'iObjId' => $this->getId(),
  163. 'sRootUrl' => BX_DOL_URL_ROOT,
  164. 'sSocket' => $this->getSocketName(),
  165. 'sStylePrefix' => $this->_sStylePrefix,
  166. 'aHtmlIds' => $this->_aHtmlIds,
  167. 'sUnreportConfirm' => bx_js_string(_t('_report_do_unreport_confirm'))
  168. );
  169. $sCode = "var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . ");";
  170. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  171. }
  172. public function getJsClick()
  173. {
  174. return $this->getJsObjectName() . '.report(this)';
  175. }
  176. public function getCounter($aParams = [])
  177. {
  178. $aParams = array_merge($this->_aElementDefaults, $aParams);
  179. $bShowDoReportAsButtonSmall = isset($aParams['show_do_report_as_button_small']) && $aParams['show_do_report_as_button_small'] == true;
  180. $bShowDoReportAsButton = !$bShowDoReportAsButtonSmall && isset($aParams['show_do_report_as_button']) && $aParams['show_do_report_as_button'] == true;
  181. $aReport = $this->_getReport($this->getId());
  182. $sClass = 'sys-action-counter';
  183. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  184. $sClass .= ' sys-ac-only';
  185. $sClass .= ' ' . $this->_sStylePrefix . '-counter';
  186. if($bShowDoReportAsButtonSmall)
  187. $sClass .= ' bx-btn-small-height';
  188. if($bShowDoReportAsButton)
  189. $sClass .= ' bx-btn-height';
  190. return $this->_oTemplate->parseLink('javascript:void(0)', (int)$aReport['count'] > 0 ? $this->_getCounterLabel($aReport['count']) : '', array(
  191. 'id' => $this->_aHtmlIds['counter'],
  192. 'class' => $sClass,
  193. 'title' => _t('_report_do_report_by'),
  194. 'onclick' => 'javascript:' . $this->getJsObjectName() . '.toggleByPopup(this)'
  195. ));
  196. }
  197. public function getCounterAPI($aParams = [])
  198. {
  199. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  200. return $this->_getReport();
  201. }
  202. public function getElementBlock($aParams = array())
  203. {
  204. $aParams['usage'] = BX_DOL_REPORT_USAGE_BLOCK;
  205. return $this->getElement($aParams);
  206. }
  207. public function getElementInline($aParams = array())
  208. {
  209. $aParams['usage'] = BX_DOL_REPORT_USAGE_INLINE;
  210. return $this->getElement($aParams);
  211. }
  212. public function getElement($aParams = array())
  213. {
  214. $aParams = array_merge($this->_aElementDefaults, $aParams);
  215. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  216. $bShowDoReportAsButtonSmall = isset($aParams['show_do_report_as_button_small']) && $aParams['show_do_report_as_button_small'] == true;
  217. $bShowDoReportAsButton = !$bShowDoReportAsButtonSmall && isset($aParams['show_do_report_as_button']) && $aParams['show_do_report_as_button'] == true;
  218. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true && $this->isAllowedReportView();
  219. $iObjectId = $this->getId();
  220. $iAuthorId = $this->_getAuthorId();
  221. $aReport = $this->_getReport($iObjectId);
  222. if(!$this->isAllowedReport() && (!$this->isAllowedReportView() || (int)$aReport['count'] == 0))
  223. return '';
  224. $aParams['is_reported'] = $this->isPerformed($iObjectId, $iAuthorId) ? true : false;
  225. $sTmplName = $this->{'_getTmplContentElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_REPORT_USAGE_DEFAULT)}();
  226. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  227. 'style_prefix' => $this->_sStylePrefix,
  228. 'html_id' => $this->_aHtmlIds['main'],
  229. 'class' => $this->_sStylePrefix . ($bShowDoReportAsButton ? '-button' : '') . ($bShowDoReportAsButtonSmall ? '-button-small' : ''),
  230. 'count' => $aReport['count'],
  231. 'do_report' => $this->_getDoReport($aParams),
  232. 'bx_if:show_counter' => array(
  233. 'condition' => $bShowCounter,
  234. 'content' => array(
  235. 'style_prefix' => $this->_sStylePrefix,
  236. 'bx_if:show_hidden' => array(
  237. 'condition' => (int)$aReport['count'] == 0,
  238. 'content' => array()
  239. ),
  240. 'counter' => $this->getCounter(array_merge($aParams, [
  241. 'show_counter_only' => false
  242. ]))
  243. )
  244. ),
  245. 'script' => $this->getJsScript($bDynamicMode)
  246. ));
  247. }
  248. public function getElementAPI($aParams = [])
  249. {
  250. if(!$this->_bApi)
  251. return;
  252. if(!$this->isEnabled())
  253. return bx_api_get_msg('_report_err_not_enabled');
  254. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  255. $iObjectId = $this->getId();
  256. $iAuthorId = $this->_getAuthorId();
  257. $bCount = $this->_isCount();
  258. $isAllowedReport = $this->isAllowedReport();
  259. $isAllowedReportView = $this->isAllowedReportView();
  260. $aParams['is_reported'] = $this->isPerformed($iObjectId, $iAuthorId);
  261. $aParams['track'] = $aParams['is_reported'] ? $this->_getTrack($iObjectId, $iAuthorId) : [];
  262. //--- Do Report
  263. $bDoReport = $this->_isShowDoReport($aParams, $isAllowedReport, $bCount);
  264. $aDoReport = $bDoReport ? $this->_getDoReport($aParams, $isAllowedReport) : [];
  265. //--- Counter
  266. $bCounter = $this->_isShowCounter($aParams, $isAllowedReport, $isAllowedReportView, $bCount);
  267. $aCounter = $bCounter ? $this->getCounterAPI(array_merge($aParams, [
  268. 'show_counter_only' => false,
  269. 'show_script' => false
  270. ])) : [];
  271. if(!$bDoReport && !$bCounter)
  272. return bx_api_get_msg('');
  273. return [
  274. 'type' => 'reports',
  275. 'system' => $this->_sSystem,
  276. 'object_id' => $this->_iId,
  277. 'params' => array_intersect_key($aParams, array_flip($this->_aElementParamsApi)),
  278. 'action' => $aDoReport,
  279. 'counter' => $aCounter
  280. ];
  281. }
  282. public function getReportedByWithComments($sObjectNotes)
  283. {
  284. $aTmplReports = array();
  285. $aTypes = BxDolForm::getDataItems('sys_report_types');
  286. $aReports = $this->_oQuery->getPerformedBy($this->getId());
  287. foreach($aReports as $aReport) {
  288. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($aReport['author_id']);
  289. $sText = bx_process_output($aReport['text'], BX_DATA_TEXT_MULTILINE);
  290. $oCmtsNotes = BxDolCmts::getObjectInstance($sObjectNotes, -$aReport['id'], true, $this->_oTemplate);
  291. $aCmtsNotes = $oCmtsNotes->getCommentsBlock(array(), array('in_designbox' => false));
  292. $iCmtsNotesCount = $oCmtsNotes->getCommentsCount();
  293. $aTmplReports[] = array(
  294. 'style_prefix' => $this->_sStylePrefix,
  295. 'user_name' => $sUserName,
  296. 'id' => $aReport['id'],
  297. 'user_url' => $sUserUrl,
  298. 'type' => $aTypes[$aReport['type']],
  299. 'comments_count' => _t('_report_comments_count', $iCmtsNotesCount),
  300. 'comments' => $aCmtsNotes['content'],
  301. 'date' => bx_time_js($aReport['date']),
  302. 'bx_if:show_text' => array(
  303. 'condition' => strlen($sText) > 0,
  304. 'content' => array(
  305. 'text' => $sText
  306. )
  307. )
  308. );
  309. }
  310. if(empty($aTmplReports))
  311. return '';
  312. return $this->_oTemplate->parseHtmlByName('report_by_list_with_comments.html', array(
  313. 'style_prefix' => $this->_sStylePrefix,
  314. 'bx_repeat:list' => $aTmplReports
  315. ));
  316. }
  317. protected function _getDoReport($aParams = array())
  318. {
  319. $bReported = isset($aParams['is_reported']) && $aParams['is_reported'] === true;
  320. $bShowDoReportAsButtonSmall = isset($aParams['show_do_report_as_button_small']) && $aParams['show_do_report_as_button_small'] == true;
  321. $bShowDoReportAsButton = !$bShowDoReportAsButtonSmall && isset($aParams['show_do_report_as_button']) && $aParams['show_do_report_as_button'] == true;
  322. $bDisabled = !$this->isAllowedReport() || ($bReported && !$this->isUndo());
  323. $sTitle = call_user_func_array('_t', $this->_getTitleDoReport($bReported));
  324. if($this->_bApi)
  325. return [
  326. 'is_undo' => $this->isUndo(),
  327. 'is_reported' => $bReported,
  328. 'is_disabled' => $bDisabled,
  329. 'title' => $sTitle,
  330. ];
  331. $sClass = '';
  332. if($bShowDoReportAsButton)
  333. $sClass = 'bx-btn';
  334. else if ($bShowDoReportAsButtonSmall)
  335. $sClass = 'bx-btn bx-btn-small';
  336. if($bDisabled)
  337. $sClass .= $bShowDoReportAsButton || $bShowDoReportAsButtonSmall ? ' bx-btn-disabled' : 'bx-report-disabled';
  338. if($bReported)
  339. $sClass .= ' bx-report-reported';
  340. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoAction(), array(
  341. 'style_prefix' => $this->_sStylePrefix,
  342. 'html_id' => $this->_aHtmlIds['do_link'],
  343. 'class' => $sClass,
  344. 'title' => bx_html_attribute($sTitle),
  345. 'bx_if:show_onclick' => array(
  346. 'condition' => !$bDisabled,
  347. 'content' => array(
  348. 'js_object' => $this->getJsObjectName()
  349. )
  350. ),
  351. 'do_report' => $this->_getLabelDoReport($aParams),
  352. ));
  353. }
  354. protected function _getCounterLabel($iCount)
  355. {
  356. return _t('_report_counter', $iCount);
  357. }
  358. protected function _getLabelDoReport($aParams = array())
  359. {
  360. $bReported = isset($aParams['is_reported']) && $aParams['is_reported'] === true;
  361. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoActionLabel(), array(
  362. 'style_prefix' => $this->_sStylePrefix,
  363. 'bx_if:show_icon' => array(
  364. 'condition' => isset($aParams['show_do_report_icon']) && $aParams['show_do_report_icon'] == true,
  365. 'content' => array(
  366. 'style_prefix' => $this->_sStylePrefix,
  367. 'name' => $this->_getIconDoReport($bReported)
  368. )
  369. ),
  370. 'bx_if:show_text' => array(
  371. 'condition' => isset($aParams['show_do_report_label']) && $aParams['show_do_report_label'] == true,
  372. 'content' => array(
  373. 'style_prefix' => $this->_sStylePrefix,
  374. 'text' => call_user_func_array('_t', $this->_getTitleDoReport($bReported))
  375. )
  376. )
  377. ));
  378. }
  379. protected function _getReportedBy()
  380. {
  381. $aTmplReports = array();
  382. $aTypes = BxDolForm::getDataItems('sys_report_types');
  383. $aReports = $this->_oQuery->getPerformedBy($this->getId());
  384. foreach($aReports as $aReport) {
  385. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($aReport['author_id']);
  386. $sText = bx_process_output($aReport['text'], BX_DATA_TEXT_MULTILINE);
  387. $aTmplReports[] = array(
  388. 'style_prefix' => $this->_sStylePrefix,
  389. 'user_unit' => $sUserUnit,
  390. 'type' => $aTypes[$aReport['type']],
  391. 'bx_if:show_text' => array(
  392. 'condition' => strlen($sText) > 0,
  393. 'content' => array(
  394. 'text' => $sText
  395. )
  396. )
  397. );
  398. }
  399. if(empty($aTmplReports))
  400. $aTmplReports = MsgBox(_t('_Empty'));
  401. return $this->_oTemplate->parseHtmlByName('report_by_list.html', array(
  402. 'style_prefix' => $this->_sStylePrefix,
  403. 'bx_repeat:list' => $aTmplReports
  404. ));
  405. }
  406. protected function _returnReportData($iObjectId, $iAuthorId, $iReportId, $aData, $bPerformed)
  407. {
  408. $bUndo = $this->isUndo();
  409. if(empty($aData) || !is_array($aData))
  410. $aData = $this->_getReport($iObjectId);
  411. $aResult = array(
  412. 'eval' => $this->getJsObjectName() . '.onReport(oData, oElement)',
  413. 'code' => 0,
  414. 'id' => $iReportId,
  415. 'count' => $aData['count'],
  416. 'countf' => (int)$aData['count'] > 0 ? $this->_getCounterLabel($aData['count']) : '',
  417. 'label_icon' => $this->_getIconDoReport($bPerformed),
  418. 'label_title' => call_user_func_array('_t', $this->_getTitleDoReport($bPerformed)),
  419. 'reported' => $bPerformed,
  420. 'disabled' => $bPerformed && !$bUndo,
  421. );
  422. $aResult['api'] = [
  423. 'performer_id' => $iAuthorId,
  424. 'is_reported' => $aResult['reported'],
  425. 'is_disabled' => $aResult['disabled'],
  426. 'icon' => $aResult['label_icon'],
  427. 'title' => $aResult['label_title'],
  428. 'counter' => $this->_getReport()
  429. ];
  430. return $aResult;
  431. }
  432. protected function _returnReportDataForSocket($aData, $aMask = [])
  433. {
  434. if(empty($aMask) || !is_array($aMask))
  435. $aMask = ['code', 'count', 'countf', 'api'];
  436. return array_intersect_key($aData, array_flip($aMask));
  437. }
  438. private function _prepareAuditParams($iObjectId, $aData)
  439. {
  440. $sModule = $this->_sSystem;
  441. $sKeyObjectContentInfo = 'OBJECT_CONTENT_INFO';
  442. $sActionName = '_sys_audit_action_report';
  443. if ($this->_sSystem == 'sys_cmts'){
  444. $aCommentData = BxDolCmtsQuery::getInfoByUniqId($iObjectId);
  445. $oComment = BxDolCmts::getObjectInstance($aCommentData['system_name'], $aCommentData['cmt_object_id']);
  446. $aComment = $oComment->getCommentSimple($aCommentData['cmt_id']);
  447. $aSystem = $oComment->getSystemInfo();
  448. $sModule = $aSystem['module'];
  449. $aData['comment_id'] = $aCommentData['cmt_id'];
  450. $aData['comment_author_id'] = $aComment['cmt_author_id'];
  451. $aData['comment_text'] = $aComment['cmt_text'];
  452. $iObjectId = $aCommentData['cmt_object_id'];
  453. $sKeyObjectContentInfo = 'OBJECT_CMTS_CONTENT_INFO';
  454. $sActionName = '_sys_audit_action_report_comment';
  455. }
  456. $oModule = BxDolModule::getInstance($sModule);
  457. if ($oModule) {
  458. $CNF = $oModule->_oConfig->CNF;
  459. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iObjectId))) : array();
  460. return [
  461. 'content_title' => !empty($CNF['FIELD_TITLE']) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  462. 'content_info_object' => !empty($CNF[$sKeyObjectContentInfo]) ? $CNF[$sKeyObjectContentInfo] : '',
  463. 'data' => $aData,
  464. 'action_name' => $sActionName,
  465. 'object_id' => $iObjectId
  466. ];
  467. }
  468. return false;
  469. }
  470. protected function _isShowDoReport($aParams, $isAllowedVote, $bCount)
  471. {
  472. return !isset($aParams['show_do_report']) || (bool)$aParams['show_do_report'] === true;
  473. }
  474. protected function _isShowCounter($aParams, $isAllowedVote, $isAllowedVoteView, $bCount)
  475. {
  476. return isset($aParams['show_counter']) && (bool)$aParams['show_counter'] === true && $isAllowedVoteView && ($isAllowedVote || $bCount);
  477. }
  478. }
  479. /** @} */