BxBaseAuditServices.php 5.4 KB

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