BxMessengerLotMenu.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 BxMessengerLotMenu extends BxBaseModTextMenu
  15. {
  16. protected $_oModule;
  17. private $_sPopupTalOptions = '';
  18. private $_iProfileId = 0;
  19. private $_isBlockVersion = true;
  20. public function __construct($aObject, $oTemplate = false)
  21. {
  22. $this->MODULE = 'bx_messenger';
  23. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  24. $this->_iProfileId = bx_get_logged_profile_id();
  25. parent::__construct($aObject, $this->_oModule->_oTemplate);
  26. }
  27. public function setMessengerType($bType){
  28. $this->_isBlockVersion = $bType;
  29. }
  30. public function isActive($sName){
  31. if (!isset($this->_aObject['menu_items']))
  32. $this->_aObject['menu_items'] = $this->getMenuItemsRaw ();
  33. return !empty($sName) && isset($this->_aObject['menu_items'][$sName]) && (int)$this->_aObject['menu_items'][$sName]['active'];
  34. }
  35. public function _getMenuItem ($aMenu)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. $oModule = &$this->_oModule;
  39. switch($aMenu['name']){
  40. case 'mute':
  41. $bIsMuted = $oModule->_oDb->isMuted($this->_iContentId, $this->_iProfileId);
  42. $aMenu['title'] = $bIsMuted ? _t('_bx_messenger_lots_menu_mute_info_on') : _t('_bx_messenger_lots_menu_mute_info_off');
  43. $aMenu['icon'] = $bIsMuted ? $CNF['BELL_ICON_OFF'] : $CNF['BELL_ICON_ON'];
  44. $aMenu['value'] = +$bIsMuted;
  45. break;
  46. case 'star':
  47. $bIsFav = $oModule->_oDb->isStarred($this->_iContentId, $this->_iProfileId);
  48. $aMenu['icon'] = $CNF['STAR_ICON'] . ((int)$bIsFav ? ' fill' : '');
  49. $aMenu['title'] = !$bIsFav ? _t('_bx_messenger_lots_menu_star_on') : _t('_bx_messenger_lots_menu_star_off');
  50. $aMenu['value'] = +$bIsFav;
  51. break;
  52. default:
  53. $aMenu['value'] = '';
  54. }
  55. $mixedResult = parent::_getMenuItem($aMenu);
  56. // API: current state of toggles (star, mute) for the app.
  57. if($this->_bIsApi && is_array($mixedResult)) {
  58. $mixedResult['value'] = $aMenu['value'];
  59. }
  60. return $mixedResult;
  61. }
  62. public function getCode ()
  63. {
  64. return parent::getCode() . $this->_sPopupTalOptions;
  65. }
  66. public function setTemplateById ($iTemplateId)
  67. {
  68. if ($iTemplateId == BX_DB_MENU_TEMPLATE_TABS)
  69. $this->_aObject['template'] = 'menu_messenger_talk_header_hor.html';
  70. else
  71. $this->_aObject['template'] = 'menu_messenger_talk_header_ver.html';
  72. }
  73. protected function _isVisible ($a)
  74. {
  75. if (!$this->_iProfileId)
  76. return false;
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $oModule = &$this->_oModule;
  79. if(!parent::_isVisible($a) || !$this->_iContentId)
  80. return false;
  81. $aLotInfo = $this->_oModule->_oDb->getLotInfoById($this->_iContentId);
  82. $aLotMenuSettings = $this->_oModule->_oDb->getLotSettings($this->_iContentId, $CNF['FLS_SETTINGS']);
  83. if (!empty($aLotMenuSettings) && in_array($a['name'], $aLotMenuSettings))
  84. return false;
  85. $bAllowedEdit = $this->_oModule->_oDb->isAuthor($aLotInfo[$CNF['FIELD_ID']], $this->_iProfileId) || $this->_oModule->_oConfig->isAllowedAction(BX_MSG_ACTION_ADMINISTRATE_TALKS, $this->_iProfileId) === true;
  86. $bBroadcast = $aLotInfo[$CNF['FIELD_TYPE']] == BX_IM_TYPE_BROADCAST;
  87. if (!$bAllowedEdit && $bBroadcast)
  88. return false;
  89. switch ($a['name']) {
  90. case 'settings':
  91. // API: the app gets the talk info menu merged into one menu, no popup is needed.
  92. if ($this->_bIsApi) {
  93. return false;
  94. }
  95. if ($this->_iContentId)
  96. $this->addMarkers(array('lot_menu_id' => "lot-info-menu-{$this->_iContentId}"));
  97. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_TALK_INFO_MENU']);
  98. $oMenu->setContentId($this->_iContentId);
  99. $this->_sPopupTalOptions = $oMenu->getCode();
  100. return true;
  101. case 'parent':
  102. if (isset($aLotInfo[$CNF['FIELD_PARENT_JOT']]) && (int)$aLotInfo[$CNF['FIELD_PARENT_JOT']]) {
  103. $iMainLotId = $this->_oModule->_oDb->getLotByJotId((int)$aLotInfo[$CNF['FIELD_PARENT_JOT']]);
  104. $aType = $this->_oModule->_oDb->getLotType($iMainLotId);
  105. $this->addMarkers(array('id' => $iMainLotId, 'type' => $aType['type'], 'jot' => (int)$aLotInfo[$CNF['FIELD_PARENT_JOT']]));
  106. return true;
  107. }
  108. return false;
  109. case 'list':
  110. if (!$this->_isBlockVersion)
  111. return false;
  112. if (!($iGroupId = $this->_oModule->_oDb->getGroupIdByLotId($this->_iContentId)))
  113. return false;
  114. $aGroupsList = $this->_oModule->_oDb->getTalksByGroupId($iGroupId);
  115. unset($aGroupsList[$this->_iContentId]);
  116. if (empty($aGroupsList))
  117. return false;
  118. /*
  119. * if (!($this->_isBlockVersion && $aLotInfo[$CNF['FIELD_CLASS']] !== 'members'))
  120. return false;
  121. * */
  122. case 'mute':
  123. case 'star':
  124. $this->addMarkers(array('id' => $this->_iContentId));
  125. return true;
  126. case 'video_call':
  127. if (empty($aLotInfo) || $oModule->_oConfig->isJitsiAllowed($aLotInfo[$CNF['FIELD_TYPE']])) {
  128. if (!empty($aLotInfo)) {
  129. $aJVC = $oModule->_oDb->getJVC($this->_iContentId);
  130. $sRoom = empty($aJVC) ? $oModule->_oConfig->getRoomId($aLotInfo[$CNF['FIELD_ID']], $aLotInfo[$CNF['FIELD_AUTHOR']]) : $aJVC[$CNF['FJVC_ROOM']];
  131. } else
  132. $sRoom = $oModule->_oConfig->getRoomId();
  133. $this->addMarkers(array('room' => $sRoom, 'id' => $this->_iContentId));
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. }
  140. /** @} */