فهرست منبع

Ticket #975 - Possibility to overwrite 'Switch to Context'

AntonLV 9 سال پیش
والد
کامیت
64a0502c03
3فایلهای تغییر یافته به همراه16 افزوده شده و 8 حذف شده
  1. 7 3
      inc/classes/BxDolProfile.php
  2. 1 1
      modules/base/profile/classes/BxBaseModProfilePageEntry.php
  3. 8 4
      template/scripts/BxBasePageAccount.php

+ 7 - 3
inc/classes/BxDolProfile.php

@@ -504,13 +504,17 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         if (!$iViewerAccountId || !$iViewerProfileId)
         if (!$iViewerAccountId || !$iViewerProfileId)
             return;
             return;
 
 
-        if ($iViewerAccountId != $this->getAccountId() ||  $iViewerProfileId == $this->id())
+        $iSwitchToAccountId = $this->getAccountId();
+        $iSwitchToProfileId = $this->id();
+        $bCanSwitch = $iSwitchToAccountId == $iViewerAccountId;
+        bx_alert('account', 'check_switch_context', $iSwitchToAccountId, $iViewerProfileId, array('switch_to_profile' => $iSwitchToProfileId, 'viewer_account' => $iViewerAccountId, 'override_result' => &$bCanSwitch));
+
+        if (!$bCanSwitch ||  $iViewerProfileId == $iSwitchToProfileId)
             return;
             return;
 
 
         $oInformer = BxDolInformer::getInstance($oTemplate);
         $oInformer = BxDolInformer::getInstance($oTemplate);
         if ($oInformer)
         if ($oInformer)
-            $oInformer->add('sys-switch-profile-context', _t('_sys_txt_account_profile_context_change_suggestion', BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher', array('switch_to_profile' => $this->id()))), BX_INFORMER_INFO);
-
+            $oInformer->add('sys-switch-profile-context', _t('_sys_txt_account_profile_context_change_suggestion', BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher', array('switch_to_profile' => $this->id(), 'redirect_back' => 1))), BX_INFORMER_INFO);
     }
     }
 
 
 	/**
 	/**

+ 1 - 1
modules/base/profile/classes/BxBaseModProfilePageEntry.php

@@ -97,7 +97,7 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
 
 
         // display message if it is possible to switch to this profile
         // display message if it is possible to switch to this profile
         if ($this->_oModule->serviceActAsProfile()) {
         if ($this->_oModule->serviceActAsProfile()) {
-            $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
+            $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentAndType($this->_aContentInfo['id'], $this->MODULE) : false;
             if ($oProfile)
             if ($oProfile)
                 $oProfile->checkSwitchToProfile($this->_oTemplate);
                 $oProfile->checkSwitchToProfile($this->_oTemplate);
         }
         }

+ 8 - 4
template/scripts/BxBasePageAccount.php

@@ -53,13 +53,16 @@ class BxBasePageAccount extends BxTemplPage
 
 
         // switch profile context
         // switch profile context
         if ($iSwitchToProfileId = (int)bx_get('switch_to_profile')) {
         if ($iSwitchToProfileId = (int)bx_get('switch_to_profile')) {
-            $oInformer = BxDolInformer::getInstance($this->_oTemplate);
             $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
             $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
-            $aProfile = $oProfile->getInfo();
             $sInformerMsg = '';            
             $sInformerMsg = '';            
 
 
-            if (BxDolService::call($aProfile['type'], 'act_as_profile')) {
-                if ($oProfile && $oProfile->getAccountId() == getLoggedId()) {
+            if ($oProfile && BxDolService::call($oProfile->getModule(), 'act_as_profile')) {
+                $iViewerAccountId = getLoggedId();
+                $iSwitchToAccountId = $oProfile->getAccountId();
+                $bCanSwitch = $iSwitchToAccountId == $iViewerAccountId;
+                bx_alert('account', 'check_switch_context', $iSwitchToAccountId, bx_get_logged_profile_id(), array('switch_to_profile' => $iSwitchToProfileId, 'viewer_account' => $iViewerAccountId, 'override_result' => &$bCanSwitch));
+
+                if ($bCanSwitch) {
                     $oAccount = BxDolAccount::getInstance();
                     $oAccount = BxDolAccount::getInstance();
                     if ($oAccount->updateProfileContext($iSwitchToProfileId)) {
                     if ($oAccount->updateProfileContext($iSwitchToProfileId)) {
                         $sInformerMsg = _t('_sys_txt_account_profile_context_changed_success', $oProfile->getDisplayName());
                         $sInformerMsg = _t('_sys_txt_account_profile_context_changed_success', $oProfile->getDisplayName());
@@ -70,6 +73,7 @@ class BxBasePageAccount extends BxTemplPage
                     }
                     }
                 }
                 }
 
 
+                $oInformer = BxDolInformer::getInstance($this->_oTemplate);
                 if ($oInformer)
                 if ($oInformer)
                     $oInformer->add('sys-account-profile-context-change-result', $sInformerMsg ? $sInformerMsg : _t('_error occured'), $sInformerMsg ? BX_INFORMER_INFO : BX_INFORMER_ERROR);
                     $oInformer->add('sys-account-profile-context-change-result', $sInformerMsg ? $sInformerMsg : _t('_error occured'), $sInformerMsg ? BX_INFORMER_INFO : BX_INFORMER_ERROR);
             }
             }