1
0

BxBaseCmtsServices.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 BxBaseCmtsServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceGetMenuItemAddonVote($sSystem, $iId, $iCmtId)
  19. {
  20. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  21. $oVote = $oCmts->getVoteObject($iCmtId);
  22. if($oVote !== false)
  23. return $oVote->getCounter();
  24. return '';
  25. }
  26. public function serviceGetLiveUpdate($sSystem, $iContentId, $iProfileId, $iCount = 0)
  27. {
  28. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  29. if(!$oCmts || !$oCmts->isEnabled())
  30. return false;
  31. $sKey = $oCmts->getNotificationId();
  32. bx_import('BxDolSession');
  33. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  34. return false;
  35. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  36. if($iCountNew == $iCount)
  37. return false;
  38. return array(
  39. 'count' => $iCountNew, // required
  40. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdate(oData)', // required
  41. 'data' => array(
  42. 'code' => $oCmts->getLiveUpdate($iCount, $iCountNew)
  43. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  44. );
  45. }
  46. public function serviceGetLiveUpdates($sSystem, $iContentId, $iProfileId, $iCount = 0)
  47. {
  48. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  49. if(!$oCmts || !$oCmts->isEnabled())
  50. return false;
  51. $sKey = $oCmts->getNotificationId();
  52. bx_import('BxDolSession');
  53. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  54. return false;
  55. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  56. if($iCountNew == $iCount)
  57. return false;
  58. return array(
  59. 'count' => $iCountNew, // required
  60. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdates(oData)', // required
  61. 'data' => array(
  62. 'code' => $oCmts->getLiveUpdates($iCount, $iCountNew)
  63. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  64. );
  65. }
  66. public function serviceManageTools($sType = 'common')
  67. {
  68. $oGrid = BxDolGrid::getObjectInstance('sys_cmts_administration');
  69. if(!$oGrid)
  70. return '';
  71. $oTemplate = BxDolTemplate::getInstance();
  72. $oTemplate->addJs(array('BxDolCmtsManageTools.js'));
  73. $oTemplate->addCss(array('cmts_manage_tools.css'));
  74. $oTemplate->addJsTranslation(array('_sys_grid_search'));
  75. return array(
  76. 'content' => $oGrid->getCode()
  77. );
  78. }
  79. /**
  80. * Comment vote for Notifications module
  81. */
  82. public function serviceGetNotificationsVote($aEvent)
  83. {
  84. $iCmtIdUnique = (int)$aEvent['object_id'];
  85. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  86. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  87. return array();
  88. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  89. if(!$oCmts || !$oCmts->isEnabled())
  90. return array();
  91. $oVote = $oCmts->getVoteObject($iCmtIdUnique);
  92. if(!$oVote)
  93. return array();
  94. $iCmtId = (int)$aCmtInfo['cmt_id'];
  95. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  96. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  97. return array(
  98. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  99. 'entry_url' => $sCmtUrl,
  100. 'entry_caption' => $sCmtCaption,
  101. 'entry_author' => $aCmtInfo['author_id'],
  102. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
  103. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  104. );
  105. }
  106. /**
  107. * Comment reaction for Notifications module
  108. */
  109. public function serviceGetNotificationsReaction($aEvent)
  110. {
  111. $iCmtIdUnique = (int)$aEvent['object_id'];
  112. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  113. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  114. return array();
  115. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  116. if(!$oCmts || !$oCmts->isEnabled())
  117. return array();
  118. $oReaction = $oCmts->getReactionObject($iCmtIdUnique);
  119. if(!$oReaction)
  120. return array();
  121. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  122. if(empty($aSubentry) || !is_array($aSubentry))
  123. return array();
  124. $aSubentrySampleParams = array();
  125. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  126. if(!empty($aReaction['title']))
  127. $aSubentrySampleParams[] = $aReaction['title'];
  128. else
  129. $aSubentrySampleParams[] = '_undefined';
  130. $iCmtId = (int)$aCmtInfo['cmt_id'];
  131. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  132. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  133. return array(
  134. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  135. 'entry_url' => $sCmtUrl,
  136. 'entry_caption' => $sCmtCaption,
  137. 'entry_author' => $aCmtInfo['author_id'],
  138. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
  139. 'subentry_sample_params' => $aSubentrySampleParams,
  140. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  141. );
  142. }
  143. /**
  144. * Comment score -> vote up for Notifications module
  145. */
  146. public function serviceGetNotificationsScoreUp($aEvent)
  147. {
  148. return $this->_serviceGetNotificationsScore('up', $aEvent);
  149. }
  150. /**
  151. * Comment score -> vote down for Notifications module
  152. */
  153. public function serviceGetNotificationsScoreDown($aEvent)
  154. {
  155. return $this->_serviceGetNotificationsScore('down', $aEvent);
  156. }
  157. protected function _serviceGetNotificationsScore($sType, $aEvent)
  158. {
  159. $iCmtIdUnique = (int)$aEvent['object_id'];
  160. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  161. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  162. return array();
  163. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  164. if(!$oCmts || !$oCmts->isEnabled())
  165. return array();
  166. $oScore = $oCmts->getScoreObject($iCmtIdUnique);
  167. if(!$oScore)
  168. return array();
  169. $iCmtId = (int)$aCmtInfo['cmt_id'];
  170. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  171. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  172. return array(
  173. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  174. 'entry_url' => $sCmtUrl,
  175. 'entry_caption' => $sCmtCaption,
  176. 'entry_author' => $aCmtInfo['author_id'],
  177. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
  178. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  179. );
  180. }
  181. }
  182. /** @} */