| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php use Symfony\Component\Finder\Tests\FakeAdapter\DummyAdapter;
- defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseProfile Base classes for profile modules
- * @ingroup UnaModules
- *
- * @{
- */
- class BxBaseModProfileMenuSnippetMeta extends BxBaseModGeneralMenuSnippetMeta
- {
- protected $_bContentPublic;
- protected $_oContentProfile;
- protected $_aConnectionToFunctionCheck;
- protected $_aConnectionToFunctionTitle;
- public function __construct($aObject, $oTemplate = false)
- {
- parent::__construct($aObject, $oTemplate);
- $this->_bShowZeros = true;
- $this->_bContentPublic = false;
- $this->_aConnectionToFunctionCheck = array(
- 'sys_profiles_friends' => array(
- 'add' => 'checkAllowedFriendAdd',
- 'remove' => 'checkAllowedFriendRemove'
- ),
- 'sys_profiles_subscriptions' => array(
- 'add' => 'checkAllowedSubscribeAdd',
- 'remove' => 'checkAllowedSubscribeRemove'
- )
- );
- $this->_aConnectionToFunctionTitle = array(
- 'sys_profiles_friends' => '_getMenuItemProfilesFriendsTitle',
- 'sys_profiles_subscriptions' => '_getMenuItemProfilesSubscriptionsTitle'
- );
- }
- public function setContentId($iContentId)
- {
- parent::setContentId($iContentId);
- if(!empty($this->_iContentId))
- $this->_oContentProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_sModule);
- }
- public function setContentPublic($bContentPublic)
- {
- $this->_bContentPublic = $bContentPublic;
- }
- protected function _getMenuItemBefriend($aItem)
- {
- return $this->_getMenuItemConnection('sys_profiles_friends', 'add', $aItem);
- }
- protected function _getMenuItemUnfriend($aItem)
- {
- return $this->_getMenuItemConnection('sys_profiles_friends', 'remove', $aItem);
- }
- protected function _getMenuItemSubscribe($aItem)
- {
- return $this->_getMenuItemConnection('sys_profiles_subscriptions', 'add', $aItem);
- }
- protected function _getMenuItemUnsubscribe($aItem)
- {
- return $this->_getMenuItemConnection('sys_profiles_subscriptions', 'remove', $aItem);
- }
- protected function _getMenuItemFriends($aItem)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!$this->_bContentPublic || !$this->_oContentProfile)
- return false;
- $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
- if(!$oConnection)
- return false;
- $iFriends = $oConnection->getConnectedInitiatorsCount($this->_oContentProfile->id(), true);
- if(!$iFriends && !$this->_bShowZeros)
- return false;
- return $this->_oTemplate->getUnitMetaItemText(_t('_sys_menu_item_title_sm_friends', $iFriends));
- }
- protected function _getMenuItemSubscribers($aItem)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!$this->_bContentPublic || !$this->_oContentProfile)
- return false;
- $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
- if(!$oConnection)
- return false;
-
- $iSubscribers = $oConnection->getConnectedInitiatorsCount($this->_oContentProfile->id());
- if(!$iSubscribers && !$this->_bShowZeros)
- return false;
- return $this->_oTemplate->getUnitMetaItemText(_t('_sys_menu_item_title_sm_subscribers', $iSubscribers));
- }
- protected function _getMenuItemConnection($sConnection, $sAction, &$aItem)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!isLogged() || $this->_oModule->{$this->_aConnectionToFunctionCheck[$sConnection][$sAction]}($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
- return false;
- $iProfile = bx_get_logged_profile_id();
- $iContentProfile = $this->_oContentProfile->id();
- $oConnection = BxDolConnection::getObjectInstance($sConnection);
- if(!$oConnection)
- return false;
- $sTitle = $this->{$this->_aConnectionToFunctionTitle[$sConnection]}($sAction, $oConnection);
- if(empty($sTitle))
- return false;
- return $this->_oTemplate->getUnitMetaItemButtonSmall($sTitle, array(
- 'onclick' => "bx_conn_action(this, '" . $sConnection . "', '" . $sAction . "', '" . $iContentProfile . "')"
- ));
- }
- protected function _getMenuItemProfilesFriendsTitle($sAction, &$oConnection)
- {
- $iProfile = bx_get_logged_profile_id();
- $iContentProfile = $this->_oContentProfile->id();
- $aResult = array();
- if($oConnection->isConnectedNotMutual($iProfile, $iContentProfile))
- $aResult = array(
- 'add' => '',
- 'remove' => _t('_sys_menu_item_title_sm_unfriend_cancel'),
- );
- else if($oConnection->isConnectedNotMutual($iContentProfile, $iProfile))
- $aResult = array(
- 'add' => _t('_sys_menu_item_title_sm_befriend_confirm'),
- 'remove' => _t('_sys_menu_item_title_sm_unfriend_reject'),
- );
- else if($oConnection->isConnected($iProfile, $iContentProfile, true))
- $aResult = array(
- 'add' => '',
- 'remove' => _t('_sys_menu_item_title_sm_unfriend'),
- );
- else
- $aResult = array(
- 'add' => _t('_sys_menu_item_title_sm_befriend'),
- 'remove' => '',
- );
- return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
- }
- protected function _getMenuItemProfilesSubscriptionsTitle($sAction, &$oConnection)
- {
- $iProfile = bx_get_logged_profile_id();
- $iContentProfile = $this->_oContentProfile->id();
- $aResult = array();
- if($oConnection->isConnected($iProfile, $iContentProfile))
- $aResult = array(
- 'add' => '',
- 'remove' => _t('_sys_menu_item_title_sm_unsubscribe'),
- );
- else
- $aResult = array(
- 'add' => _t('_sys_menu_item_title_sm_subscribe'),
- 'remove' => '',
- );
- return !empty($sAction) && !empty($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
- }
- protected function _getMenuItemMembership($aItem)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!$this->_bContentPublic || !$this->_oContentProfile)
- return false;
- $aMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($this->_oContentProfile->id());
- return $aMembership ? $this->_oTemplate->getUnitMetaItemText(_t($aMembership['name'])) : false;
- }
- }
- /** @} */
|