1
0

BxBaseModGroupsMenuSnippetMeta.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 _getMenuItemJoin($aItem)
  26. {
  27. if (isset($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS']))
  28. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'add', $aItem);
  29. return false;
  30. }
  31. protected function _getMenuItemLeave($aItem)
  32. {
  33. return $this->_getMenuItemConnection($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'], 'remove', $aItem);
  34. }
  35. protected function _getMenuItemPrivacy($aItem)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. $sField = 'FIELD_ALLOW_VIEW_TO';
  39. if(empty($CNF[$sField]) || empty($this->_aContentInfo[$CNF[$sField]]))
  40. return false;
  41. if($this->_aContentInfo[$CNF[$sField]] == BX_DOL_PG_ALL)
  42. return false;
  43. return $this->getUnitMetaItemText(_t($CNF['T']['txt_private_group']));
  44. }
  45. protected function _getMenuItemMembers($aItem)
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  49. return false;
  50. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  51. if(!$oConnection)
  52. return false;
  53. $iFriends = $oConnection->getConnectedInitiatorsCount($this->_oContentProfile->id(), true);
  54. if(!$iFriends)
  55. return false;
  56. return $this->getUnitMetaItemText(_t('_sys_menu_item_title_sm_members', $iFriends));
  57. }
  58. protected function _getMenuItemConnectionsTitle($sAction, &$oConnection)
  59. {
  60. $iProfile = bx_get_logged_profile_id();
  61. $iContentProfile = $this->_oContentProfile->id();
  62. $aResult = array();
  63. if($oConnection->isConnectedNotMutual($iProfile, $iContentProfile))
  64. $aResult = array(
  65. 'add' => '',
  66. 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
  67. );
  68. else if($oConnection->isConnectedNotMutual($iContentProfile, $iProfile))
  69. $aResult = array(
  70. 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
  71. 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
  72. );
  73. else if($oConnection->isConnected($iProfile, $iContentProfile, true))
  74. $aResult = array(
  75. 'add' => '',
  76. 'remove' => _t('_sys_menu_item_title_sm_leave'),
  77. );
  78. else
  79. $aResult = array(
  80. 'add' => _t('_sys_menu_item_title_sm_join'),
  81. 'remove' => '',
  82. );
  83. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  84. }
  85. protected function _getMenuItemCountry($aItem)
  86. {
  87. return $this->_getMenuItemLocation($aItem, true);
  88. }
  89. protected function _getMenuItemCountryCity($aItem)
  90. {
  91. return $this->_getMenuItemLocation($aItem, false);
  92. }
  93. protected function _getMenuItemLocation($aItem, $bCountryOnly = false)
  94. {
  95. $CNF = &$this->_oModule->_oConfig->CNF;
  96. if(!$this->_bContentPublic || !$this->_oContentProfile || empty($CNF['OBJECT_CONNECTIONS']))
  97. return false;
  98. $oMeta = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  99. if(!$oMeta)
  100. return false;
  101. if (!($sLocation = $oMeta->locationsString($this->_iContentId, false, $bCountryOnly ? array('country_only' => 1) : array('country_city_only' => 1))))
  102. return false;
  103. return $this->getUnitMetaItemText($sLocation);
  104. }
  105. }
  106. /** @} */