1
0

BxBaseAuditServices.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 BxBaseAuditServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceManageTools()
  19. {
  20. $oGrid = BxDolGrid::getObjectInstance('sys_audit_administration');
  21. if(!$oGrid)
  22. return '';
  23. return [
  24. 'content' => $oGrid->getCode()
  25. ];
  26. }
  27. public function serviceGetMenuAddonManageTools()
  28. {
  29. return [];
  30. }
  31. public function serviceGetMemberships()
  32. {
  33. $aLevels = BxDolAcl::getInstance()->getMemberships(false, false, true, false);
  34. unset($aLevels[MEMBERSHIP_ID_NON_MEMBER]);
  35. return $aLevels;
  36. }
  37. /**
  38. * Comment vote for Notifications module
  39. */
  40. public function serviceGetNotificationsVote($aEvent)
  41. {
  42. $iCmtIdUnique = (int)$aEvent['object_id'];
  43. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  44. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  45. return array();
  46. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  47. if(!$oCmts || !$oCmts->isEnabled())
  48. return array();
  49. $oVote = $oCmts->getVoteObject($iCmtIdUnique);
  50. if(!$oVote)
  51. return array();
  52. $iCmtId = (int)$aCmtInfo['cmt_id'];
  53. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  54. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  55. return array(
  56. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  57. 'entry_url' => $sCmtUrl,
  58. 'entry_caption' => $sCmtCaption,
  59. 'entry_author' => $aCmtInfo['author_id'],
  60. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
  61. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  62. );
  63. }
  64. /**
  65. * Comment reaction for Notifications module
  66. */
  67. public function serviceGetNotificationsReaction($aEvent)
  68. {
  69. $iCmtIdUnique = (int)$aEvent['object_id'];
  70. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  71. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  72. return array();
  73. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  74. if(!$oCmts || !$oCmts->isEnabled())
  75. return array();
  76. $oReaction = $oCmts->getReactionObject($iCmtIdUnique);
  77. if(!$oReaction)
  78. return array();
  79. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  80. if(empty($aSubentry) || !is_array($aSubentry))
  81. return array();
  82. $aSubentrySampleParams = array();
  83. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  84. if(!empty($aReaction['title']))
  85. $aSubentrySampleParams[] = $aReaction['title'];
  86. else
  87. $aSubentrySampleParams[] = '_undefined';
  88. $iCmtId = (int)$aCmtInfo['cmt_id'];
  89. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  90. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  91. return array(
  92. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  93. 'entry_url' => $sCmtUrl,
  94. 'entry_caption' => $sCmtCaption,
  95. 'entry_author' => $aCmtInfo['author_id'],
  96. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
  97. 'subentry_sample_params' => $aSubentrySampleParams,
  98. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  99. );
  100. }
  101. /**
  102. * Comment score -> vote up for Notifications module
  103. */
  104. public function serviceGetNotificationsScoreUp($aEvent)
  105. {
  106. return $this->_serviceGetNotificationsScore('up', $aEvent);
  107. }
  108. /**
  109. * Comment score -> vote down for Notifications module
  110. */
  111. public function serviceGetNotificationsScoreDown($aEvent)
  112. {
  113. return $this->_serviceGetNotificationsScore('down', $aEvent);
  114. }
  115. protected function _serviceGetNotificationsScore($sType, $aEvent)
  116. {
  117. $iCmtIdUnique = (int)$aEvent['object_id'];
  118. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  119. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  120. return array();
  121. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  122. if(!$oCmts || !$oCmts->isEnabled())
  123. return array();
  124. $oScore = $oCmts->getScoreObject($iCmtIdUnique);
  125. if(!$oScore)
  126. return array();
  127. $iCmtId = (int)$aCmtInfo['cmt_id'];
  128. $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
  129. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  130. return array(
  131. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  132. 'entry_url' => $sCmtUrl,
  133. 'entry_caption' => $sCmtCaption,
  134. 'entry_author' => $aCmtInfo['author_id'],
  135. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
  136. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  137. );
  138. }
  139. }
  140. /** @} */