BxBaseAuditServices.php 5.6 KB

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