BxMessengerLotInfoMenu.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 BxMessengerLotInfoMenu extends BxBaseModTextMenu
  15. {
  16. protected $_oModule;
  17. public function __construct($aObject, $oTemplate = false)
  18. {
  19. $this-> MODULE = 'bx_messenger';
  20. $this->_oModule = BxDolModule::getInstance($this-> MODULE);
  21. parent::__construct($aObject, $this->_oModule->_oTemplate);
  22. }
  23. public function setContentId($iContentId)
  24. {
  25. parent::setContentId($iContentId);
  26. $this->_aContentParams = array_merge((array)$this->_aContentParams, ['lot' => (int)$this->_iContentId]);
  27. }
  28. public function initContentParams()
  29. {
  30. parent::initContentParams();
  31. $this->_aContentParams['lot'] = (int)$this->_iContentId;
  32. }
  33. /**
  34. * API: the menu is requested on demand (system/get_menu) with the talk in params.
  35. */
  36. public function setContentParams($aParams)
  37. {
  38. if(empty($aParams['lot'])) {
  39. return false;
  40. }
  41. $this->setContentId((int)$aParams['lot']);
  42. return parent::setContentParams($aParams);
  43. }
  44. /**
  45. * API: one menu for the talk header. Items of the talk menu (video call, star, mute, ...) go first,
  46. * its 'settings' item (which opens this menu on the site) is left out. The site keeps both menus as they are.
  47. */
  48. public function getCodeAPI ()
  49. {
  50. $aResult = parent::getCodeAPI();
  51. if(!$this->_iContentId) {
  52. return $aResult;
  53. }
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $oMenuLot = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_TALK_MENU']);
  56. if(!$oMenuLot) {
  57. return $aResult;
  58. }
  59. $oMenuLot->setContentId($this->_iContentId);
  60. $aMenuLot = $oMenuLot->getCodeAPI();
  61. if(empty($aMenuLot['items']) || !is_array($aMenuLot['items'])) {
  62. return $aResult;
  63. }
  64. $aItems = array_values(array_filter($aMenuLot['items'], function($aItem) {
  65. return $aItem['name'] != 'settings';
  66. }));
  67. $aResult['items'] = array_merge($aItems, is_array($aResult['items']) ? $aResult['items'] : []);
  68. return $aResult;
  69. }
  70. protected function _isVisible ($a)
  71. {
  72. $iProfileId = bx_get_logged_profile_id();
  73. $aLotInfo = $this->_oModule->_oDb->getLotInfoById($this->_iContentId);
  74. if (!$iProfileId || empty($aLotInfo))
  75. return false;
  76. $oModule = &$this->_oModule;
  77. if(!parent::_isVisible($a) || !$this->_iContentId)
  78. return false;
  79. $this->addMarkers(array('id' => $this->_iContentId));
  80. switch ($a['name']) {
  81. case 'add_participants':
  82. case 'delete':
  83. case 'clear':
  84. case 'settings':
  85. return $oModule->_oDb->isAuthor($this->_iContentId, $iProfileId) || ($oModule->_oConfig->isAllowedAction(BX_MSG_ACTION_ADMINISTRATE_TALKS, $iProfileId) === true);
  86. }
  87. return true;
  88. }
  89. public function getCode(){
  90. return $this->_oTemplate->parseHtmlByName('popup_trans.html', [
  91. 'id' => "lot-info-menu-{$this->_iContentId}",
  92. 'wrapper_class' => 'bx-popup-menu',
  93. 'wrapper_style' => 'display:none;',
  94. 'content' => parent::getCode()]);
  95. }
  96. }
  97. /** @} */