From adc096e7b498c00252d5d946665ab9456d6d75dd Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 21 Mar 2018 14:28:19 +0200
Subject: [PATCH] Display local profile information even when no ILS account
 established. (#1147)

---
 .../Controller/MyResearchController.php       | 57 ++++++++++---------
 .../templates/myresearch/menu.phtml           |  8 ---
 .../templates/myresearch/profile.phtml        | 56 ++++++++++++------
 3 files changed, 67 insertions(+), 54 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index ff2024c9ac4..b96a9f96a0f 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -386,38 +386,39 @@ class MyResearchController extends AbstractBase
      */
     public function profileAction()
     {
-        // Stop now if the user does not have valid catalog credentials available:
-        if (!is_array($patron = $this->catalogLogin())) {
-            return $patron;
-        }
-
-        // User must be logged in at this point, so we can assume this is non-false:
-        $user = $this->getUser();
-
-        // Process home library parameter (if present):
-        $homeLibrary = $this->params()->fromPost('home_library', false);
-        if (!empty($homeLibrary)) {
-            $user->changeHomeLibrary($homeLibrary);
-            $this->getAuthManager()->updateSession($user);
-            $this->flashMessenger()->addMessage('profile_update', 'success');
+        if (!($user = $this->getUser())) {
+            return $this->forceLogin();
         }
 
         // Begin building view object:
-        $view = $this->createViewModel();
+        $view = $this->createViewModel(['user' => $user]);
+
+        $patron = $this->catalogLogin();
+        if (is_array($patron)) {
+            // Process home library parameter (if present):
+            $homeLibrary = $this->params()->fromPost('home_library', false);
+            if (!empty($homeLibrary)) {
+                $user->changeHomeLibrary($homeLibrary);
+                $this->getAuthManager()->updateSession($user);
+                $this->flashMessenger()->addMessage('profile_update', 'success');
+            }
 
-        // Obtain user information from ILS:
-        $catalog = $this->getILS();
-        $this->addAccountBlocksToFlashMessenger($catalog, $patron);
-        $profile = $catalog->getMyProfile($patron);
-        $profile['home_library'] = $user->home_library;
-        $view->profile = $profile;
-        try {
-            $view->pickup = $catalog->getPickUpLocations($patron);
-            $view->defaultPickupLocation
-                = $catalog->getDefaultPickUpLocation($patron);
-        } catch (\Exception $e) {
-            // Do nothing; if we're unable to load information about pickup
-            // locations, they are not supported and we should ignore them.
+            // Obtain user information from ILS:
+            $catalog = $this->getILS();
+            $this->addAccountBlocksToFlashMessenger($catalog, $patron);
+            $profile = $catalog->getMyProfile($patron);
+            $profile['home_library'] = $user->home_library;
+            $view->profile = $profile;
+            try {
+                $view->pickup = $catalog->getPickUpLocations($patron);
+                $view->defaultPickupLocation
+                    = $catalog->getDefaultPickUpLocation($patron);
+            } catch (\Exception $e) {
+                // Do nothing; if we're unable to load information about pickup
+                // locations, they are not supported and we should ignore them.
+            }
+        } else {
+            $view->patronLoginView = $patron;
         }
 
         return $view;
diff --git a/themes/bootstrap3/templates/myresearch/menu.phtml b/themes/bootstrap3/templates/myresearch/menu.phtml
index 89a90645647..76afa8f2cd1 100644
--- a/themes/bootstrap3/templates/myresearch/menu.phtml
+++ b/themes/bootstrap3/templates/myresearch/menu.phtml
@@ -63,14 +63,6 @@
     </a>
   <?php endif; ?>
 </div>
-<?php if ($user && $this->auth()->getManager()->supportsPasswordChange()): ?>
-  <h4><?=$this->transEsc('Preferences')?></h4>
-  <div class="myresearch-menu">
-    <a href="<?=$this->url('myresearch-changepassword') ?>"<?=$this->active == 'newpassword' ? ' class="active"' : ''?>>
-      <i class="fa fa-fw fa-lock" aria-hidden="true"></i> <?=$this->transEsc('Change Password') ?>
-    </a>
-  </div>
-<?php endif; ?>
 <?php if ($user && $this->userlist()->getMode() !== 'disabled'): ?>
   <h4><?=$this->transEsc('Your Lists')?></h4>
   <div class="myresearch-menu">
diff --git a/themes/bootstrap3/templates/myresearch/profile.phtml b/themes/bootstrap3/templates/myresearch/profile.phtml
index d082dc1b054..3cea4b68163 100644
--- a/themes/bootstrap3/templates/myresearch/profile.phtml
+++ b/themes/bootstrap3/templates/myresearch/profile.phtml
@@ -12,14 +12,13 @@
   <h2><?=$this->transEsc('Your Profile')?></h2>
   <?=$this->flashmessages();?>
 
-  <?=$this->context($this)->renderInContext('librarycards/selectcard.phtml', ['user' => $this->auth()->isLoggedIn()]); ?>
-
   <table class="table table-striped">
     <?=$this->renderArray(
-      $arrTemplate, $this->profile,
+      $arrTemplate, $this->user,
       [
         $this->transEsc('First Name') => 'firstname',
-        $this->transEsc('Last Name') => 'lastname'
+        $this->transEsc('Last Name') => 'lastname',
+        $this->transEsc('Email') => 'email',
       ]
     )?>
     <?php if (count($this->pickup ?? []) > 1): // Skip form if only one location: ?>
@@ -39,21 +38,42 @@
         </form>
       </td>
     <?php endif; ?>
-    <?=$this->renderArray(
-      $arrTemplate, $this->profile,
-      [
-        $this->transEsc('Address') . ' 1' => 'address1',
-        $this->transEsc('Address') . ' 2' => 'address2',
-        $this->transEsc('Zip') => 'zip',
-        $this->transEsc('City') => 'city',
-        $this->transEsc('Country') => 'country',
-        $this->transEsc('Phone Number') => 'phone',
-        $this->transEsc('Mobile Number') => 'mobile_phone',
-        $this->transEsc('Group') => 'group',
-        $this->transEsc('Expires') => 'expiration_date'
-      ]
-    )?>
   </table>
+
+  <?php if ($this->auth()->getManager()->supportsPasswordChange()): ?>
+    <p>
+      <a class="btn btn-default" href="<?=$this->url('myresearch-changepassword') ?>">
+        <i class="fa fa-fw fa-lock" aria-hidden="true"></i> <?=$this->transEsc('Change Password') ?>
+      </a>
+    </p>
+  <?php endif; ?>
+
+  <?php if (is_array($this->profile)): ?>
+    <h3><?=$this->transEsc('Library Catalog Profile')?></h3>
+    <p>
+      <?=$this->context($this)->renderInContext('librarycards/selectcard.phtml', ['user' => $this->user]); ?>
+    </p>
+    <table class="table table-striped">
+      <?=$this->renderArray(
+        $arrTemplate, $this->profile,
+        [
+          $this->transEsc('First Name') => 'firstname',
+          $this->transEsc('Last Name') => 'lastname',
+          $this->transEsc('Address') . ' 1' => 'address1',
+          $this->transEsc('Address') . ' 2' => 'address2',
+          $this->transEsc('Zip') => 'zip',
+          $this->transEsc('City') => 'city',
+          $this->transEsc('Country') => 'country',
+          $this->transEsc('Phone Number') => 'phone',
+          $this->transEsc('Mobile Number') => 'mobile_phone',
+          $this->transEsc('Group') => 'group',
+          $this->transEsc('Expires') => 'expiration_date'
+        ]
+      )?>
+    </table>
+  <?php elseif ('ils-none' !== $this->ils()->getOfflineMode()): ?>
+    <?=$this->partial($this->patronLoginView);?>
+  <?php endif; ?>
 </div>
 
 <div class="<?=$this->layoutClass('sidebar')?>">
-- 
GitLab