BxBaseReport.php 27 KB

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