From 40b70fb59776b161db4328c7413ef848e52f8a10 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 18 Oct 2017 21:20:21 +0300
Subject: [PATCH] Display mobile number in profile (#1050)

- Adds support for new profile field.
- Improves Voyager driver to allow smarter selection of phone numbers for display.
---
 config/vufind/Voyager.ini                     |  8 ++++++++
 config/vufind/VoyagerRestful.ini              | 10 +++++++++-
 languages/en.ini                              |  1 +
 languages/fi.ini                              |  1 +
 languages/sv.ini                              |  1 +
 module/VuFind/src/VuFind/ILS/Driver/Demo.php  |  1 +
 .../VuFind/src/VuFind/ILS/Driver/Voyager.php  | 20 +++++++++++++++----
 .../templates/myresearch/profile.phtml        |  1 +
 8 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/config/vufind/Voyager.ini b/config/vufind/Voyager.ini
index fac3b6b4c09..e855a5447f9 100644
--- a/config/vufind/Voyager.ini
+++ b/config/vufind/Voyager.ini
@@ -99,3 +99,11 @@ login_field = LAST_NAME
 ; This regular expression controls which status messages are displayed on the
 ; Checked Out Items list.
 show_statuses = "/lost|missing|claim/i"
+
+[Profile]
+; This setting can be used to define which Voyager phone type is used as the primary
+; phone number. Default is "Primary".
+;primary_phone = Primary
+; This setting can be used to define which Voyager phone type is used as the mobile
+; phone number. Default is "Mobile".
+;mobile_phone = Mobile
\ No newline at end of file
diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini
index ea1727d1488..82e2f248410 100644
--- a/config/vufind/VoyagerRestful.ini
+++ b/config/vufind/VoyagerRestful.ini
@@ -317,4 +317,12 @@ show_statuses = "/lost|missing|claim/i"
 ; of config.ini for notes on these settings. When set here, these will override the
 ; config.ini defaults when Voyager is used for authentication.
 ;pattern = "alphanumeric"
-;hint = "Your optional custom hint can go here."
\ No newline at end of file
+;hint = "Your optional custom hint can go here."
+
+[Profile]
+; This setting can be used to define which Voyager phone type is used as the primary
+; phone number. Default is "Primary".
+;primary_phone = Primary
+; This setting can be used to define which Voyager phone type is used as the mobile
+; phone number. Default is "Mobile".
+;mobile_phone = Mobile
\ No newline at end of file
diff --git a/languages/en.ini b/languages/en.ini
index 377ac6bb34c..fb5fadb133f 100644
--- a/languages/en.ini
+++ b/languages/en.ini
@@ -607,6 +607,7 @@ Message From Sender = "Message From Sender"
 Metadata Prefix = "Metadata Prefix"
 Microfilm = "Microfilm"
 MLA Citation = "MLA Citation"
+Mobile Number = "Mobile Number"
 mobile_link = "You appear to be on a mobile device; switch to mobile view?"
 Monograph Title = "Monograph Title"
 more = "more"
diff --git a/languages/fi.ini b/languages/fi.ini
index a024e5bcfdb..f5855eeab32 100644
--- a/languages/fi.ini
+++ b/languages/fi.ini
@@ -612,6 +612,7 @@ Message From Sender = "Viesti lähettäjältä"
 Metadata Prefix = "Metadatan etuliite"
 Microfilm = "Mikrofilmi"
 MLA Citation = "MLA-viite"
+Mobile Number = "Matkapuhelin"
 mobile_link = "Vaikuttaa siltä, että käytät mobiililaitetta. Siirrytäänkö mobiiliversioon?"
 Monograph Title = "Kirjan nimi"
 more = "lisää"
diff --git a/languages/sv.ini b/languages/sv.ini
index 0d40848a35a..ad1a1de0bc5 100644
--- a/languages/sv.ini
+++ b/languages/sv.ini
@@ -607,6 +607,7 @@ Message From Sender = "Meddelande från"
 Metadata Prefix = "Metadata Prefix"
 Microfilm = "Mikrofilm"
 MLA Citation = "MLA-referens"
+Mobile Number = "Mobiltelefon"
 mobile_link = "You appear to be on a mobile device; switch to mobile view?"
 Monograph Title = "Monografis titel"
 more = "mer"
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
index 13ae7dbed14..64c15e8943d 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
@@ -721,6 +721,7 @@ class Demo extends AbstractBase
             'city'            => 'City',
             'country'         => 'Country',
             'phone'           => '1900 CALL ME',
+            'mobile_phone'    => '1234567890',
             'group'           => 'Library Staff',
             'expiration_date' => 'Someday'
         ];
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index def6f4d681b..0ad30c1379c 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -1973,16 +1973,24 @@ EOT;
                "PATRON.HISTORICAL_CHARGES, PATRON_ADDRESS.ADDRESS_LINE1, " .
                "PATRON_ADDRESS.ADDRESS_LINE2, PATRON_ADDRESS.ZIP_POSTAL, " .
                "PATRON_ADDRESS.CITY, PATRON_ADDRESS.COUNTRY, " .
-               "PATRON_PHONE.PHONE_NUMBER, PATRON_GROUP.PATRON_GROUP_NAME " .
+               "PATRON_PHONE.PHONE_NUMBER, PHONE_TYPE.PHONE_DESC, " .
+               "PATRON_GROUP.PATRON_GROUP_NAME " .
                "FROM $this->dbName.PATRON, $this->dbName.PATRON_ADDRESS, " .
-               "$this->dbName.PATRON_PHONE, $this->dbName.PATRON_BARCODE, " .
-               "$this->dbName.PATRON_GROUP " .
+               "$this->dbName.PATRON_PHONE, $this->dbName.PHONE_TYPE, " .
+               "$this->dbName.PATRON_BARCODE, $this->dbName.PATRON_GROUP " .
                "WHERE PATRON.PATRON_ID = PATRON_ADDRESS.PATRON_ID (+) " .
                "AND PATRON_ADDRESS.ADDRESS_ID = PATRON_PHONE.ADDRESS_ID (+) " .
                "AND PATRON.PATRON_ID = PATRON_BARCODE.PATRON_ID (+) " .
                "AND PATRON_BARCODE.PATRON_GROUP_ID = " .
                "PATRON_GROUP.PATRON_GROUP_ID (+) " .
+               "AND PATRON_PHONE.PHONE_TYPE = PHONE_TYPE.PHONE_TYPE (+) " .
                "AND PATRON.PATRON_ID = :id";
+        $primaryPhoneType = isset($this->config['Profile']['primary_phone'])
+            ? $this->config['Profile']['primary_phone']
+            : 'Primary';
+        $mobilePhoneType = isset($this->config['Profile']['mobile_phone'])
+            ? $this->config['Profile']['mobile_phone']
+            : 'Mobile';
         try {
             $sqlStmt = $this->executeSQL($sql, [':id' => $patron['id']]);
             $patron = [];
@@ -1994,7 +2002,11 @@ EOT;
                     $patron['lastname'] = utf8_encode($row['LAST_NAME']);
                 }
                 if (!empty($row['PHONE_NUMBER'])) {
-                    $patron['phone'] = utf8_encode($row['PHONE_NUMBER']);
+                    if ($primaryPhoneType === $row['PHONE_DESC']) {
+                        $patron['phone'] = utf8_encode($row['PHONE_NUMBER']);
+                    } elseif ($mobilePhoneType === $row['PHONE_DESC']) {
+                        $patron['mobile_phone'] = utf8_encode($row['PHONE_NUMBER']);
+                    }
                 }
                 if (!empty($row['PATRON_GROUP_NAME'])) {
                     $patron['group'] = utf8_encode($row['PATRON_GROUP_NAME']);
diff --git a/themes/bootstrap3/templates/myresearch/profile.phtml b/themes/bootstrap3/templates/myresearch/profile.phtml
index ca1d2ef556f..495f97ba352 100644
--- a/themes/bootstrap3/templates/myresearch/profile.phtml
+++ b/themes/bootstrap3/templates/myresearch/profile.phtml
@@ -54,6 +54,7 @@
           $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'
         ]
-- 
GitLab