BxBaseModGroupsMenuSnippetMeta.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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->getUnitMetaItemButton(_t('_bx_groups_menu_item_title_pay_and_join'), [
  38. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_JOIN_ENTRY'], [
  39. 'profile_id' => $this->_oContentProfile->id()
  40. ])
  41. ]),
  42. 'bx-menu-item-button'
  43. ];
  44. }
  45. protected function _getMenuItemJoin($aItem)
  46. {
  47. if (isset($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS']))
  48. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'add', $aItem);
  49. return false;
  50. }
  51. protected function _getMenuItemLeave($aItem)
  52. {
  53. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'remove', $aItem);
  54. }
  55. protected function _getMenuItemPrivacy($aItem)
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $sField = 'FIELD_ALLOW_VIEW_TO';
  59. if(empty($CNF[$sField]) || empty($this->_aContentInfo[$CNF[$sField]]))
  60. return false;
  61. if($this->_aContentInfo[$CNF[$sField]] == BX_DOL_PG_ALL)
  62. return false;
  63. return $this->getUnitMetaItemText(_t($CNF['T']['txt_private_group']));
  64. }
  65. protected function _getMenuItemMembers($aItem)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  69. return false;
  70. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  71. if(!$oConnection)
  72. return false;
  73. $iMembers = $oConnection->getConnectedInitiatorsCount($this->_oContentProfile->id(), true);
  74. if(!$iMembers && !$this->_bShowZeros)
  75. return false;
  76. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  77. return $this->getUnitMetaItemCustom($oConnection->getCounter($this->_oContentProfile->id(), true, [
  78. 'caption' => '_sys_menu_item_title_sm_members',
  79. 'custom_icon' => $sIcon
  80. ], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS));
  81. }
  82. protected function _getMenuItemConnectionsTitle($sAction, &$oConnection)
  83. {
  84. $iProfile = bx_get_logged_profile_id();
  85. $iContentProfile = $this->_oContentProfile->id();
  86. $aResult = array();
  87. if($oConnection->isConnectedNotMutual($iProfile, $iContentProfile))
  88. $aResult = array(
  89. 'add' => '',
  90. 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
  91. );
  92. else if($oConnection->isConnectedNotMutual($iContentProfile, $iProfile))
  93. $aResult = array(
  94. 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
  95. 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
  96. );
  97. else if($oConnection->isConnected($iProfile, $iContentProfile, true))
  98. $aResult = array(
  99. 'add' => '',
  100. 'remove' => _t('_sys_menu_item_title_sm_leave'),
  101. );
  102. else
  103. $aResult = array(
  104. 'add' => _t('_sys_menu_item_title_sm_join'),
  105. 'remove' => '',
  106. );
  107. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  108. }
  109. protected function _getMenuItemCountry($aItem)
  110. {
  111. return $this->_getMenuItemLocation($aItem, true);
  112. }
  113. protected function _getMenuItemCountryCity($aItem)
  114. {
  115. return $this->_getMenuItemLocation($aItem, false);
  116. }
  117. protected function _getMenuItemLocation($aItem, $bCountryOnly = false)
  118. {
  119. $CNF = &$this->_oModule->_oConfig->CNF;
  120. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  121. return false;
  122. $oMeta = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  123. if(!$oMeta)
  124. return false;
  125. if (!($sLocation = $oMeta->locationsString($this->_iContentId, false, $bCountryOnly ? array('country_only' => 1) : array('country_city_only' => 1))))
  126. return false;
  127. return $this->getUnitMetaItemText($sLocation);
  128. }
  129. }
  130. /** @} */