BxBaseCmtsServices.php 8.0 KB

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