BxBaseModGroupsMenuSnippetMeta.php 3.9 KB

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