BxBaseModGroupsMenuSnippetMeta.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsMenuSnippetMeta extends BxBaseModProfileMenuSnippetMeta
  12. {
  13. public function __construct($aObject, $oTemplate = false)
  14. {
  15. parent::__construct($aObject, $oTemplate);
  16. $CNF = &$this->_oModule->_oConfig->CNF;
  17. if (isset($CNF['OBJECT_CONNECTIONS'])){
  18. $this->_aConnectionToFunctionCheck[$CNF['OBJECT_CONNECTIONS']] = array(
  19. 'add' => 'checkAllowedFanAdd',
  20. 'remove' => 'checkAllowedFanRemove'
  21. );
  22. $this->_aConnectionToFunctionTitle[$CNF['OBJECT_CONNECTIONS']] = '_getMenuItemConnectionsTitle';
  23. }
  24. }
  25. protected function _getMenuItemJoinPaid($aItem)
  26. {
  27. $CNF = &$this->_oModule->_oConfig->CNF;
  28. if(!isLogged() || $this->_oModule->checkAllowedFanAdd($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  29. return false;
  30. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  31. if(!$oConnection)
  32. return false;
  33. $sTitle = $this->_getMenuItemConnectionsTitle('add', $oConnection);
  34. if(empty($sTitle))
  35. return false;
  36. return [
  37. $this->getUnitMetaItemButtonSmall(_t('_bx_groups_menu_item_title_pay_and_join'), [
  38. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', [
  39. 'i' => $CNF['URI_JOIN_ENTRY'],
  40. 'profile_id' => $this->_oContentProfile->id()
  41. ])
  42. ]),
  43. 'bx-menu-item-button'
  44. ];
  45. }
  46. protected function _getMenuItemJoin($aItem)
  47. {
  48. if (isset($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS']))
  49. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'add', $aItem);
  50. return false;
  51. }
  52. protected function _getMenuItemLeave($aItem)
  53. {
  54. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'remove', $aItem);
  55. }
  56. protected function _getMenuItemPrivacy($aItem)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. $sField = 'FIELD_ALLOW_VIEW_TO';
  60. if(empty($CNF[$sField]) || empty($this->_aContentInfo[$CNF[$sField]]))
  61. return false;
  62. if($this->_aContentInfo[$CNF[$sField]] == BX_DOL_PG_ALL)
  63. return false;
  64. return $this->getUnitMetaItemText(_t($CNF['T']['txt_private_group']));
  65. }
  66. protected function _getMenuItemMembers($aItem)
  67. {
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  70. return false;
  71. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  72. if(!$oConnection)
  73. return false;
  74. $iMembers = $oConnection->getConnectedInitiatorsCount($this->_oContentProfile->id(), true);
  75. if(!$iMembers && !$this->_bShowZeros)
  76. return false;
  77. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  78. return $this->getUnitMetaItemCustom($oConnection->getCounter($this->_oContentProfile->id(), true, [
  79. 'caption' => '_sys_menu_item_title_sm_members',
  80. 'custom_icon' => $sIcon
  81. ], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS));
  82. }
  83. protected function _getMenuItemConnectionsTitle($sAction, &$oConnection)
  84. {
  85. $iProfile = bx_get_logged_profile_id();
  86. $iContentProfile = $this->_oContentProfile->id();
  87. $aResult = array();
  88. if($oConnection->isConnectedNotMutual($iProfile, $iContentProfile))
  89. $aResult = array(
  90. 'add' => '',
  91. 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
  92. );
  93. else if($oConnection->isConnectedNotMutual($iContentProfile, $iProfile))
  94. $aResult = array(
  95. 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
  96. 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
  97. );
  98. else if($oConnection->isConnected($iProfile, $iContentProfile, true))
  99. $aResult = array(
  100. 'add' => '',
  101. 'remove' => _t('_sys_menu_item_title_sm_leave'),
  102. );
  103. else
  104. $aResult = array(
  105. 'add' => _t('_sys_menu_item_title_sm_join'),
  106. 'remove' => '',
  107. );
  108. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  109. }
  110. protected function _getMenuItemCountry($aItem)
  111. {
  112. return $this->_getMenuItemLocation($aItem, true);
  113. }
  114. protected function _getMenuItemCountryCity($aItem)
  115. {
  116. return $this->_getMenuItemLocation($aItem, false);
  117. }
  118. protected function _getMenuItemLocation($aItem, $bCountryOnly = false)
  119. {
  120. $CNF = &$this->_oModule->_oConfig->CNF;
  121. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  122. return false;
  123. $oMeta = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  124. if(!$oMeta)
  125. return false;
  126. if (!($sLocation = $oMeta->locationsString($this->_iContentId, false, $bCountryOnly ? array('country_only' => 1) : array('country_city_only' => 1))))
  127. return false;
  128. return $this->getUnitMetaItemText($sLocation);
  129. }
  130. }
  131. /** @} */