BxCnvCmts.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Convos Convos
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCnvCmts extends BxTemplCmts
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. /**
  16. * Silent Mode for Notification based modules.
  17. */
  18. protected $_iSilentMode;
  19. function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  20. {
  21. $this->_sModule = 'bx_convos';
  22. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  23. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  24. $this->_iSilentMode = 21; //--- Absolute for Timeline module only.
  25. $this->_aT = array_merge($this->_aT, array(
  26. 'txt_min_form_placeholder' => '_bx_cnv_txt_min_form_placeholder'
  27. ));
  28. }
  29. public function getObjectTitle ($iObjectId = 0)
  30. {
  31. $sResult = parent::getObjectTitle($iObjectId);
  32. if(!empty($sResult))
  33. return strmaxtextlen($sResult, 20, '...');
  34. return $sResult;
  35. }
  36. public function addCssJs($aBp = [], $aDp = [])
  37. {
  38. parent::addCssJs($aBp, $aDp);
  39. $this->_oModule->_oTemplate->addCss(array('cmts.css'));
  40. }
  41. /**
  42. * Comments are enabled for collaborators only
  43. */
  44. public function isEnabled ()
  45. {
  46. if (!parent::isEnabled ())
  47. return false;
  48. if (!$this->_oModule->_oDb->getContentInfoById((int)$this->getId()))
  49. return false;
  50. $aCollaborators = $this->_oModule->_oDb->getCollaborators((int)$this->getId());
  51. if (!isset($aCollaborators[bx_get_logged_profile_id()]))
  52. return false;
  53. return true;
  54. }
  55. public function isRemoveAllowed ($aCmt, $isPerformAction = false)
  56. {
  57. if (isAdmin())
  58. return true;
  59. return false;
  60. }
  61. public function msgErrRemoveAllowed ()
  62. {
  63. return _t('_sys_txt_access_denied');
  64. }
  65. public function isEditAllowed ($aCmt, $isPerformAction = false)
  66. {
  67. return $this->isRemoveAllowed ($aCmt, $isPerformAction);
  68. }
  69. public function msgErrEditAllowed ()
  70. {
  71. return $this->msgErrRemoveAllowed ();
  72. }
  73. public function getCommentsBlock($aBp = array(), $aDp = array())
  74. {
  75. $mixedBlock = parent::getCommentsBlock($aBp, $aDp);
  76. if (is_array($mixedBlock) && isset($mixedBlock['title']))
  77. $mixedBlock['title'] = _t('_bx_cnv_page_block_title_entry_comments', $this->getCommentsCount());
  78. return $mixedBlock;
  79. }
  80. public function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  81. {
  82. if(!$this->isEnabled())
  83. return '';
  84. return parent::getCommentBlock($iCmtId, $aBp, $aDp);
  85. }
  86. protected function _getFormObject($sAction = BX_CMT_ACTION_POST)
  87. {
  88. $oForm = parent::_getFormObject($sAction);
  89. $oForm->aInputs['cmt_submit']['value'] = _t('_sys_send');
  90. return $oForm;
  91. }
  92. protected function _prepareAlertParams($aCmt)
  93. {
  94. $aParams = parent::_prepareAlertParams($aCmt);
  95. $aParams['silent_mode'] = $this->_iSilentMode;
  96. return $aParams;
  97. }
  98. protected function _prepareAlertParamsReply($aCmt, $aCmtPrnt)
  99. {
  100. $aParams = parent::_prepareAlertParamsReply($aCmt, $aCmtPrnt);
  101. $aParams['silent_mode'] = $this->_iSilentMode;
  102. return $aParams;
  103. }
  104. }
  105. /** @} */