BxMessengerJotMenu.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Messenger Messenger
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View block menu.
  13. */
  14. class BxMessengerJotMenu extends BxTemplMenuCustom
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. protected $_iContentId;
  19. private $_aContentInfo;
  20. private $_iProfileId;
  21. public function __construct($aObject, $oTemplate = false)
  22. {
  23. $this->_sModule = 'bx_messenger';
  24. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  25. $this->_iProfileId = bx_get_logged_profile_id();
  26. parent::__construct($aObject, $this->_oModule->_oTemplate);
  27. }
  28. public function setContentId($iContentId)
  29. {
  30. $this->_iContentId = (int)$iContentId;
  31. $this->_aContentInfo = $this->_oModule->_oDb->getJotById($this->_iContentId);
  32. if(!empty($this->_aContentInfo))
  33. $this->addMarkers(array('content_id' => $this->_iContentId));
  34. }
  35. public function getMenuItemByName($sName)
  36. {
  37. if (!isset($this->_aObject['menu_items']))
  38. $this->_aObject['menu_items'] = $this->getMenuItemsRaw ();
  39. return $this->_aObject['menu_items'][$sName];
  40. }
  41. public function isActive($sName){
  42. if (!isset($this->_aObject['menu_items']))
  43. $this->_aObject['menu_items'] = $this->getMenuItemsRaw ();
  44. return !empty($sName) && isset($this->_aObject['menu_items'][$sName]) && (int)$this->_aObject['menu_items'][$sName]['active'];
  45. }
  46. protected function _isVisible ($a)
  47. {
  48. $aInfo = $this->_aContentInfo;
  49. if (!$this->_iProfileId)
  50. return false;
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. $oModule = &$this->_oModule;
  53. if(!parent::_isVisible($a))
  54. return false;
  55. if (in_array($a['name'], $CNF['JOT-MENU-TO-SHOW']))
  56. return false;
  57. $iJotAuthor = !empty($aInfo) ? (int)$aInfo[$CNF['FIELD_MESSAGE_AUTHOR']] : (int)$this->_iProfileId;
  58. $iJotId = !empty($aInfo) ? (int)$aInfo[$CNF['FIELD_MESSAGE_ID']] : 0;
  59. $bAllowToDelete = $oModule->_oDb->isAllowedToDeleteJot($iJotId, $this->_iProfileId, $iJotAuthor);
  60. $bAllowToEdit = $oModule->_oDb->isAllowedToEditJot($iJotId, $this->_iProfileId) || empty($aInfo);
  61. $bVC = !empty($aJot) ? (int)$aJot[$CNF['FIELD_MESSAGE_VIDEOC']] : false;
  62. $aLotMenuSettings = $this->_oModule->_oDb->getLotSettings($this->_iContentId, $CNF['FLS_SETTINGS']);
  63. if (!empty($aLotMenuSettings) && in_array($a['name'], $aLotMenuSettings))
  64. return false;
  65. switch ($a['name']) {
  66. case 'edit':
  67. return !$bVC && $bAllowToEdit;
  68. case 'remove':
  69. return $bAllowToDelete;
  70. case 'save':
  71. return !$CNF['USE-UNIQUE-MODE'];
  72. case 'thread':
  73. return !$CNF['USE-UNIQUE-MODE'] && ($oModule->_oDb->isAuthor($this->_iContentId, $this->_iProfileId) || ($oModule->_oConfig->isAllowedAction(BX_MSG_ACTION_ADMINISTRATE_TALKS, $this->_iProfileId) === true));
  74. }
  75. return true;
  76. }
  77. protected function _getMenuItem ($a){
  78. if ($a['name'] === 'save' && $this->_oModule->_oDb->isJotSaved($this->_iContentId, $this->_iProfileId))
  79. $a['title'] = _t('_bx_messenger_jot_menu_remove_save');
  80. return parent::_getMenuItem($a);
  81. }
  82. public function getMenuItems ()
  83. {
  84. $aItems = parent::getMenuItems();
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. $oModule = &$this->_oModule;
  87. if (!empty($this->_aContentInfo))
  88. $aItems[] = [
  89. "name" => "time-info",
  90. "class" => " px-4 pt-2 text-sm ",
  91. "item" => $oModule->_oConfig->getSeparatorTime($this->_aContentInfo[$CNF['FIELD_MESSAGE_ADDED']])
  92. ];
  93. return $aItems;
  94. }
  95. public function getCode(){
  96. return $this->_oTemplate->parseHtmlByName('popup_trans.html', [
  97. 'id' => "jot-menu-" . genRndPwd(8, false),
  98. 'wrapper_class' => 'bx-popup-menu',
  99. 'wrapper_style' => 'display:none;',
  100. 'content' => parent::getCode()]);
  101. }
  102. }
  103. /** @} */