From caa1add43f35a503c67167332b840ca0cc682bcd Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 18 Jul 2012 12:11:00 -0400
Subject: [PATCH] Implemented followup controller plug-in.

---
 module/VuFind/config/module.config.php        |  5 ++
 .../src/VuFind/Controller/AbstractBase.php    |  4 +-
 .../src/VuFind/Controller/AbstractRecord.php  |  2 +-
 .../Controller/MyResearchController.php       | 12 +--
 .../src/VuFind/Controller/Plugin/Followup.php | 83 +++++++++++++++++++
 5 files changed, 94 insertions(+), 12 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/Controller/Plugin/Followup.php

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index 051033686d4..6d7b7b08183 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -66,6 +66,11 @@ $config = array(
             'worldcatrecord' => 'VuFind\Controller\WorldcatrecordController'
         ),
     ),
+    'controller_plugins' => array(
+        'invokables' => array(
+            'followup' => 'VuFind\Controller\Plugin\Followup'
+        )
+    ),
     'translator' => array(),
     'view_manager' => array(
         'display_not_found_reason' => APPLICATION_ENV == 'development',
diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php
index 9da37ba197c..d279422e93b 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractBase.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php
@@ -128,9 +128,7 @@ class AbstractBase extends AbstractActionController
         // Store the current URL as a login followup action unless we are in a
         // lightbox (since lightboxes use a different followup mechanism).
         if (!$this->inLightbox()) {
-            /* TODO:
-            $this->_helper->followup->store($extras);
-            */
+            $this->followup()->store($extras);
         }
         if (!empty($msg)) {
             $this->flashMessenger()->setNamespace('error')->addMessage($msg);
diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
index f37395f8f78..c060eb624f0 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
@@ -113,7 +113,7 @@ class AbstractRecord extends AbstractBase
         $comment = $this->_request->getParam('comment');
         if (empty($comment)) {
             // No comment?  Try to restore from session:
-            $session = $this->_helper->followup->retrieve();
+            $session = $this->followup()->retrieve();
             if (isset($session->comment)) {
                 $comment = $session->comment;
                 unset($session->comment);
diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 1a625e7eaaf..580ead39d6e 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -77,16 +77,14 @@ class MyResearchController extends AbstractBase
                 ->dispatch('MyResearch', array('action' => 'Login'));
         }
 
-        /* TODO
         // Logged in?  Forward user to followup action (if set) or default action
         // (if no followup provided):
-        $followup = $this->_helper->followup();
+        $followup = $this->followup()->retrieve();
         if (isset($followup->url)) {
             $url = $followup->url;
             unset($followup->url);
-            return $this->_redirect($url, array('prependBase' => false));
+            return $this->redirect()->toUrl($url);
         }
-         */
 
         $config = ConfigReader::getConfig();
         $page = isset($configArray->Site->defaultAccountPage)
@@ -108,15 +106,13 @@ class MyResearchController extends AbstractBase
                 ->dispatch('MyResearch', array('action' => 'Home'));
         }
 
-        /* TODO
         // We may have come in from a lightbox.  In this case, a prior module
         // will not have set the followup information.  We should grab the referer
         // so the user doesn't get lost.
-        $followup = $this->_helper->followup();
+        $followup = $this->followup()->retrieve();
         if (!isset($followup->url)) {
-            $followup->url = $this->getRequest()->getServer('HTTP_REFERER');
+            $followup->url = $this->getRequest()->getServer()->get('HTTP_REFERER');
         }
-         */
 
         // Process request, if necessary:
         if (!is_null($this->params()->fromPost('submit', null))) {
diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
new file mode 100644
index 00000000000..5f130049203
--- /dev/null
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * VuFind Action Helper - Followup
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  Action_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://www.vufind.org  Main Page
+ */
+namespace VuFind\Controller\Plugin;
+use Zend\Mvc\Controller\Plugin\AbstractPlugin, Zend\Session\Container,
+    Zend\View\Helper\ServerUrl;
+
+/**
+ * Zend action helper to deal with login followup; responsible for remembering URLs
+ * before login and then redirecting the user to the appropriate place afterwards.
+ *
+ * @category VuFind2
+ * @package  Action_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://www.vufind.org  Main Page
+ */
+class Followup extends AbstractPlugin
+{
+    protected $session;
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->session = new Container('Followup');
+    }
+
+    /**
+     * Retrieve the stored followup information.
+     *
+     * @return Zend_Session_Namespace
+     */
+    public function retrieve()
+    {
+        return $this->session;
+    }
+
+    /**
+     * Store the current URL (and optional additional information) in the session
+     * for use following a successful login.
+     *
+     * @param array $extras Associative array of extra fields to store.
+     *
+     * @return void
+     */
+    public function store($extras = array())
+    {
+        // Store the current URL:
+        $serverHelper = new ServerUrl();
+        $this->session->url = $serverHelper->__invoke(true);
+
+        // Store the extra parameters:
+        foreach ($extras as $key => $value) {
+            $this->session->$key = $value;
+        }
+    }
+}
\ No newline at end of file
-- 
GitLab