BxBaseAuditServices.php 5.5 KB

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