BxTasksCmts.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * @defgroup Tasks Tasks
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. class BxTasksCmts extends BxTemplCmts
  11. {
  12. protected $_sModule;
  13. protected $_oModule;
  14. protected $_iAuthorAuto;
  15. public function __construct($sSystem, $iId, $iInit = 1)
  16. {
  17. $this->_sModule = 'bx_tasks';
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. $this->_sTableImages = 'bx_tasks_files';
  20. parent::__construct($sSystem, $iId, $iInit, $this->_oModule->_oTemplate);
  21. $this->_iAuthorAuto = (int)getParam('sys_profile_bot');
  22. $this->_aT = array_merge($this->_aT, [
  23. 'block_comments_title' => '_bx_tasks_page_block_title_entry_comments'
  24. ]);
  25. }
  26. public function addAuto($aText)
  27. {
  28. $aValues = [
  29. 'cmt_author_id' => $this->_iAuthorAuto,
  30. 'cmt_parent_id' => 0,
  31. 'cmt_text' => json_encode($aText)
  32. ];
  33. return $this->add($aValues);
  34. }
  35. public function getViewText($mixedItem)
  36. {
  37. if(!is_array($mixedItem))
  38. $mixedItem = $this->getCommentSimple((int)$mixedItem);
  39. if(empty($mixedItem) || !is_array($mixedItem))
  40. return '';
  41. if($this->_isAutoComment($mixedItem) && isset($mixedItem['cmt_text']))
  42. $mixedItem['cmt_text'] = $this->_getAutoCommentText($mixedItem['cmt_text']);
  43. return $this->_prepareTextForOutput($mixedItem['cmt_text'], (int)$mixedItem['cmt_id']);
  44. }
  45. public function getComment($mixedCmt, $aBp = [], $aDp = [])
  46. {
  47. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  48. if(!$aCmt)
  49. return '';
  50. if($this->_isAutoComment($aCmt))
  51. $aDp = array_merge($aDp ?? [], [
  52. 'class_comment' => $this->_sStylePrefix . '-auto'
  53. ]);
  54. return parent::getComment($aCmt, $aBp, $aDp);
  55. }
  56. public function getDataAPI($aData, $aParams = [])
  57. {
  58. $aResult = parent::getDataAPI($aData, $aParams);
  59. if($this->_isAutoComment($aData)) {
  60. if(isset($aResult['cmt_text']))
  61. $aResult['cmt_text'] = $this->_getAutoCommentText($aResult['cmt_text']);
  62. unset($aResult['menu_actions'], $aResult['menu_manage']);
  63. }
  64. return $aResult;
  65. }
  66. protected function _getHeaderBox(&$aCmt, $aBp = [], $aDp = [])
  67. {
  68. return !$this->_isAutoComment($aCmt) ? parent::_getHeaderBox($aCmt, $aBp, $aDp) : '';
  69. }
  70. protected function _getCountersBox(&$aCmt, $aBp = [], $aDp = [])
  71. {
  72. return !$this->_isAutoComment($aCmt) ? parent::_getCountersBox($aCmt, $aBp, $aDp) : '';
  73. }
  74. protected function _getActionsBox(&$aCmt, $aBp = [], $aDp = [])
  75. {
  76. return !$this->_isAutoComment($aCmt) ? parent::_getActionsBox($aCmt, $aBp, $aDp) : '';
  77. }
  78. protected function _getAttachments($aCmt)
  79. {
  80. return !$this->_isAutoComment($aCmt) ? parent::_getAttachments($aCmt) : ($this->_bIsApi ? [] : '');
  81. }
  82. protected function _getTmplVarsAuthor($aCmt)
  83. {
  84. return !$this->_isAutoComment($aCmt) ? parent::_getTmplVarsAuthor($aCmt) : [
  85. 'author_unit' => ''
  86. ];
  87. }
  88. protected function _getTmplVarsText($aCmt)
  89. {
  90. $aTmplVarsText = parent::_getTmplVarsText($aCmt);
  91. if($this->_isAutoComment($aCmt) && isset($aTmplVarsText['text']))
  92. $aTmplVarsText['text'] = $this->_getAutoCommentText($aTmplVarsText['text'], $aCmt['cmt_time']);
  93. return $aTmplVarsText;
  94. }
  95. protected function _callAlert($sUnit, $sAction, $iObjectId, $iSender = false, $aExtras = [])
  96. {
  97. if($iSender && $iSender == $this->_iAuthorAuto)
  98. return;
  99. return bx_alert($sUnit, $sAction, $iObjectId, $iSender, $aExtras);
  100. }
  101. protected function _prepareAlertParams($aCmt)
  102. {
  103. $aResult = parent::_prepareAlertParams($aCmt);
  104. if($this->_isAutoComment($aCmt) && isset($aResult['comment_text']))
  105. $aResult['comment_text'] = $this->_getAutoCommentText($aResult['comment_text']);
  106. return $aResult;
  107. }
  108. protected function _isAutoComment($aCmt)
  109. {
  110. return (int)$aCmt['cmt_author_id'] == $this->_iAuthorAuto;
  111. }
  112. protected function _getAutoCommentText($sTextCode, $iDate = false)
  113. {
  114. $aText = json_decode($sTextCode, true);
  115. $sText = isset($aText['key']) ? _t($aText['key']) : '';
  116. if(($aMarkers = $aText['markers'] ?? false) && is_array($aMarkers)) {
  117. if(($sValue = $aMarkers['value'] ?? false) && substr($sValue, 0, 1) == '_')
  118. $aMarkers['value'] = _t($sValue);
  119. $sText = bx_replace_markers($sText, $aMarkers);
  120. }
  121. if($iDate !== false)
  122. $sText = _t('_bx_tasks_txt_msg_format', $sText, bx_time_js((int)$iDate, BX_FORMAT_DATE, true));
  123. return $sText;
  124. }
  125. protected function _getFormObject($sAction = BX_CMT_ACTION_POST)
  126. {
  127. $CNF = &$this->_oModule->_oConfig->CNF;
  128. $sFldImage = 'cmt_image';
  129. $oResult = parent::_getFormObject($sAction);
  130. if(!isset($oResult->aInputs[$sFldImage]))
  131. return $oResult;
  132. $oResult->aInputs[$sFldImage] = array_merge($oResult->aInputs[$sFldImage], [
  133. 'storage_object' => $CNF['OBJECT_STORAGE_CMTS'],
  134. 'images_transcoder' => '',
  135. 'upload_buttons_titles' => ['HTML5' => 'paperclip']
  136. ]);
  137. return $oResult;
  138. }
  139. }
  140. /** @} */