BxForumAlertsResponse.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxForumAlertsResponse extends BxBaseModTextAlertsResponse
  12. {
  13. public function __construct()
  14. {
  15. $this->MODULE = 'bx_forum';
  16. parent::__construct();
  17. }
  18. public function response($oAlert)
  19. {
  20. $sMethod = 'process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
  21. if(method_exists($this, $sMethod))
  22. $this->$sMethod($oAlert);
  23. parent::response($oAlert);
  24. }
  25. protected function processBxForumCommentPost($oAlert)
  26. {
  27. $this->updateCommentsSummary($oAlert->iObject);
  28. $this->_oModule->serviceTriggerCommentPost($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id'], 0, $oAlert->aExtras['comment_text']);
  29. }
  30. protected function processBxForumCommentUpdated($oAlert)
  31. {
  32. $this->updateCommentsSummary($oAlert->iObject);
  33. }
  34. protected function processBxForumCommentRemoved($oAlert)
  35. {
  36. $CNF = &$this->_oModule->_oConfig->CNF;
  37. $this->updateCommentsSummary($oAlert->iObject);
  38. $aEntry = $this->_oModule->_oDb->getContentInfoById($oAlert->iObject);
  39. if((int)$aEntry['lr_comment_id'] == (int)$oAlert->aExtras['comment_id']) {
  40. $iLrCommentId = $iLrTimestamp = $iLrProfileId = 0;
  41. $aComment = $this->_oModule->_oDb->getComments(array('type' => 'entry_last', 'entry_id' => $oAlert->iObject));
  42. if(!empty($aComment) && is_array($aComment)) {
  43. $iLrCommentId = $aComment['cmt_id'];
  44. $iLrTimestamp = $aComment['cmt_time'];
  45. $iLrProfileId = $aComment['cmt_author_id'];
  46. }
  47. $this->_oModule->_oDb->updateEntries(array(
  48. 'lr_timestamp' => $iLrTimestamp,
  49. 'lr_profile_id' => $iLrProfileId,
  50. 'lr_comment_id' => $iLrCommentId
  51. ), array($CNF['FIELD_ID'] => $oAlert->iObject));
  52. }
  53. }
  54. protected function processBxForumFilesCmtsFileDeleted($oAlert)
  55. {
  56. return bx_srv('system', 'alert_response_sys_cmts_images_file_deleted', array($oAlert), 'TemplCmtsServices');
  57. }
  58. protected function updateCommentsSummary($iContentId)
  59. {
  60. $CNF = &$this->_oModule->_oConfig->CNF;
  61. $aCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId)->getQueryObject()->getCommentsBy(array(
  62. 'type' => 'object_id',
  63. 'object_id' => $iContentId
  64. ));
  65. if(empty($aCmts) || !is_array($aCmts))
  66. return;
  67. $sResult = '';
  68. foreach($aCmts as $aCmt)
  69. $sResult .= strip_tags($aCmt['cmt_text']) . "\n\r";
  70. if(empty($sResult))
  71. return;
  72. $this->_oModule->_oDb->updateEntries(array($CNF['FIELD_TEXT_COMMENTS'] => $sResult), array($CNF['FIELD_ID'] => $iContentId));
  73. }
  74. }
  75. /** @} */