Przeglądaj źródła

Ticket #659 - Basic changes.

AntonLV 9 lat temu
rodzic
commit
f37b325d19

+ 31 - 5
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -145,13 +145,39 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
 
     protected function redirectAfterAdd($aContentInfo)
     {
-        // if user just joined the redirect to the page where user comes from. 
-        // TODO: add an options to profile based modules: redirect to created profile, redirect to the last page, custom redirect
-        if ($sJoinReferrer = BxDolSession::getInstance()->getValue('join-referrer')) {
-            BxDolSession::getInstance()->unsetValue('join-referrer');
-            header('Location: ' . $sJoinReferrer);
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $sRedirectType = getParam($CNF['PARAM_REDIRECT_AADD']);
+        $sRedirectDefault = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
+
+        $sRedirectUrl = $sRedirectDefault;
+        switch ($sRedirectType) {
+            case BX_DOL_PROFILE_REDIRECT_PROFILE:
+                break;
+
+            // if user just joined the redirect to the page where user comes from. 
+            case BX_DOL_PROFILE_REDIRECT_LAST:
+                $oSession = BxDolSession::getInstance();
+
+                $sJoinReferrer = $oSession->getValue('join-referrer');
+                if($sJoinReferrer) {
+                    $sRedirectUrl = $sJoinReferrer;
+                    $oSession->unsetValue('join-referrer');
+                }
+                break;
+
+            case BX_DOL_PROFILE_REDIRECT_CUSTOM:
+                $sRedirectCustom = getParam($CNF['PARAM_REDIRECT_AADD_CUSTOM_URL']);
+                if($sRedirectCustom) 
+                    $sRedirectUrl = $sRedirectCustom;
+                break;
+        }
+
+        if($sRedirectUrl) {
+            header('Location: ' . $sRedirectUrl);
             exit;
         }
+
         parent::redirectAfterAdd($aContentInfo);
     }
 }

+ 16 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -9,6 +9,10 @@
  * @{
  */
 
+define('BX_DOL_PROFILE_REDIRECT_PROFILE', 'profile');
+define('BX_DOL_PROFILE_REDIRECT_LAST', 'last');
+define('BX_DOL_PROFILE_REDIRECT_CUSTOM', 'custom');
+
 /**
  * Base class for profile modules.
  */
@@ -50,6 +54,18 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     }
 
     // ====== SERVICE METHODS
+    public function serviceGetOptionsRedirectAfterAdd()
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aResult = array();
+        $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM);
+        foreach($aChoices as $sChoice) 
+            $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
+
+        return $aResult;
+    }
+
     public function serviceGetThumb ($iContentId, $sTranscoder = '') 
     {
         $CNF = &$this->_oConfig->CNF;