BxBaseModGroupsMenuSnippetMeta.php 5.5 KB

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