From 82330bc45285ae4d9ca1766d7501fb14127888a5 Mon Sep 17 00:00:00 2001 From: rajaro Date: Wed, 11 Sep 2024 15:04:40 +0300 Subject: [PATCH 01/18] Add support for multiple emails/phones --- .../Finna/Controller/MyResearchController.php | 32 ++++++++ module/Finna/src/Finna/ILS/Driver/Quria.php | 80 ++++++++++++++----- .../finna2/templates/myresearch/profile.phtml | 17 ++++ 3 files changed, 109 insertions(+), 20 deletions(-) diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 9626f04b5d5..299ae0618bf 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -1503,6 +1503,24 @@ protected function processLibraryDataUpdate($patron, $values) } } } + // Update extra emails + if (isset($values->profile_extra_email) && isset($values->profile_extra_email_id)) { + foreach ($values->profile_extra_email as $i => $extraEmail) { + $validator = new \Laminas\Validator\EmailAddress(); + if ($validator->isValid($extraEmail) + && $catalog->checkFunction('updateEmail', compact('patron')) + && !empty($values->profile_extra_email_id[$i]) + ) { + $result = $catalog->updateEmail( + $patron, $extraEmail, $values->profile_extra_email_id[$i] + ); + if (!$result['success']) { + $this->flashMessenger()->addErrorMessage($result['status']); + $success = false; + } + } + } + } // Update phone if ( isset($values->profile_tel) @@ -1514,6 +1532,20 @@ protected function processLibraryDataUpdate($patron, $values) $success = false; } } + // Update extra phones + if (isset($values->profile_extra_tel) && isset($values->profile_extra_tel_id)) { + foreach ($values->profile_extra_tel as $i => $extraPhone) { + if (!empty($values->profile_extra_tel_id[$i])) { + $result = $catalog->updatePhone( + $patron, $extraPhone->phone, $values->profile_extra_tel_id[$i] + ); + if (!$result['success']) { + $this->flashMessenger()->addErrorMessage($result['status']); + $success = false; + } + } + } + } // Update SMS Number if ( isset($values->profile_sms_number) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 22bdc60d99c..334857a41e4 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -599,11 +599,19 @@ public function patronLogin($username, $password) if (!empty($info->emailAddresses->emailAddress)) { $emailAddresses = $this->objectToArray($info->emailAddresses->emailAddress); + $activeEmailFound = false; foreach ($emailAddresses as $emailAddress) { - if ($emailAddress->isActive == 'yes' || empty($userCached['email'])) { + $emailActive = $emailAddress->isActive == 'yes'; + if (empty($userCached['email']) || !$activeEmailFound) { $userCached['email'] = $emailAddress->address ?? ''; $userCached['emailId'] = $emailAddress->id ?? ''; - break; + $activeEmailFound = $emailActive; + } else if ($emailActive) { + $userCached['extraEmails'][] + = [ + 'email' => $emailAddress->address ?? '', + 'emailId' => $emailAddress->id ?? '' + ]; } } } @@ -622,18 +630,25 @@ public function patronLogin($username, $password) } if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); - foreach ($phoneNumbers as $phoneNumber) { + foreach ($phoneNumbers as $i => $phoneNumber) { if ($phoneNumber->sms->useForSms == 'yes') { - $userCached['phone'] = $phoneNumber->areaCode ?? ''; - $userCached['phoneAreaCode'] = $userCached['phone']; - if (isset($phoneNumber->localCode)) { - $userCached['phone'] .= $phoneNumber->localCode; - $userCached['phoneLocalCode'] = $phoneNumber->localCode; - } - if (isset($phoneNumber->id)) { - $userCached['phoneId'] = $phoneNumber->id; + if ($i === 0) { + $userCached['phone'] = $phoneNumber->areaCode ?? ''; + $userCached['phoneAreaCode'] = $userCached['phone']; + if (isset($phoneNumber->localCode)) { + $userCached['phone'] .= $phoneNumber->localCode; + $userCached['phoneLocalCode'] = $phoneNumber->localCode; + } + if (isset($phoneNumber->id)) { + $userCached['phoneId'] = $phoneNumber->id; + } + } else { + $userCached['extraPhones'][] + = [ + 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', + 'phoneId' => $phoneNumber->id ?? '' + ]; } - break; } } } @@ -1526,20 +1541,32 @@ public function placeHold($holdDetails) /** * Update patron's email address * - * @param array $patron Patron array - * @param String $email Email address + * @param array $patron Patron array + * @param String $email Email address + * @param String $emailId Email ID * * @throws ILSException * * @return array Associative array of the results */ - public function updateEmail($patron, $email) + public function updateEmail($patron, $email, $emailId = null) { $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); + if ($emailId) { + foreach ($user['extraEmails'] as $extraEmail) { + if ($extraEmail['emailId'] === $emailId && $extraEmail['email'] === $email) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '' + ]; + } + } + } $function = ''; $functionResult = ''; $functionParam = ''; @@ -1560,7 +1587,7 @@ public function updateEmail($patron, $email) ]; if (!empty($user['email'])) { - $conf['id'] = $user['emailId']; + $conf['id'] = $emailId ?? $user['emailId']; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; @@ -1604,19 +1631,32 @@ public function updateEmail($patron, $email) /** * Update patron's phone number * - * @param array $patron Patron array - * @param string $phone Phone number + * @param array $patron Patron array + * @param string $phone Phone number + * @param string $phoneId Phone ID * * @throws ILSException * * @return array Associative array of the results */ - public function updatePhone($patron, $phone) + public function updatePhone($patron, $phone, $phoneId = null) { $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); + if ($phoneId) { + foreach ($user['extraPhones'] as $extraPhone) { + if ($extraPhone['phoneId'] === $phoneId && $extraPhone['phone'] === $phone) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '' + ]; + } + } + } + $function = ''; $functionResult = ''; $functionParam = ''; @@ -1634,7 +1674,7 @@ public function updatePhone($patron, $phone) ]; if (!empty($user['phone'])) { - $conf['id'] = $user['phoneId']; + $conf['id'] = $phoneId ?? $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 1bb7a73d074..18e91a853fd 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -177,6 +177,15 @@
+ profile['extraPhones'])): ?> + profile['extraPhones'] as $i => $extraPhone): ?> +
+
+ + +
+ +
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
@@ -199,6 +208,14 @@
+ profile['extraEmails'])): ?> + profile['extraEmails'] as $i => $extraEmail): ?> +
+
+ +
+ +
escapeHtml($this->profile['email']) ?>
From 0af8b17d01ea1a671eabcce2fc19add301787bf8 Mon Sep 17 00:00:00 2001 From: rajaro Date: Wed, 11 Sep 2024 15:36:05 +0300 Subject: [PATCH 02/18] Codestyle fixes --- .../src/Finna/Controller/MyResearchController.php | 11 ++++++++--- module/Finna/src/Finna/ILS/Driver/Quria.php | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 299ae0618bf..1ae35203b65 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -1507,12 +1507,15 @@ protected function processLibraryDataUpdate($patron, $values) if (isset($values->profile_extra_email) && isset($values->profile_extra_email_id)) { foreach ($values->profile_extra_email as $i => $extraEmail) { $validator = new \Laminas\Validator\EmailAddress(); - if ($validator->isValid($extraEmail) + if ( + $validator->isValid($extraEmail) && $catalog->checkFunction('updateEmail', compact('patron')) && !empty($values->profile_extra_email_id[$i]) ) { $result = $catalog->updateEmail( - $patron, $extraEmail, $values->profile_extra_email_id[$i] + $patron, + $extraEmail, + $values->profile_extra_email_id[$i] ); if (!$result['success']) { $this->flashMessenger()->addErrorMessage($result['status']); @@ -1537,7 +1540,9 @@ protected function processLibraryDataUpdate($patron, $values) foreach ($values->profile_extra_tel as $i => $extraPhone) { if (!empty($values->profile_extra_tel_id[$i])) { $result = $catalog->updatePhone( - $patron, $extraPhone->phone, $values->profile_extra_tel_id[$i] + $patron, + $extraPhone->phone, + $values->profile_extra_tel_id[$i] ); if (!$result['success']) { $this->flashMessenger()->addErrorMessage($result['status']); diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 334857a41e4..047a445f8c8 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -606,7 +606,7 @@ public function patronLogin($username, $password) $userCached['email'] = $emailAddress->address ?? ''; $userCached['emailId'] = $emailAddress->id ?? ''; $activeEmailFound = $emailActive; - } else if ($emailActive) { + } elseif ($emailActive) { $userCached['extraEmails'][] = [ 'email' => $emailAddress->address ?? '', @@ -1633,7 +1633,7 @@ public function updateEmail($patron, $email, $emailId = null) * * @param array $patron Patron array * @param string $phone Phone number - * @param string $phoneId Phone ID + * @param string $phoneId Phone ID * * @throws ILSException * From 1eee0c8dcf8f2e564c6900a72e1f09449f81571a Mon Sep 17 00:00:00 2001 From: rajaro Date: Wed, 11 Sep 2024 15:50:04 +0300 Subject: [PATCH 03/18] trailing commas --- module/Finna/src/Finna/ILS/Driver/Quria.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 047a445f8c8..b2bc52d50aa 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -610,7 +610,7 @@ public function patronLogin($username, $password) $userCached['extraEmails'][] = [ 'email' => $emailAddress->address ?? '', - 'emailId' => $emailAddress->id ?? '' + 'emailId' => $emailAddress->id ?? '', ]; } } @@ -646,7 +646,7 @@ public function patronLogin($username, $password) $userCached['extraPhones'][] = [ 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', - 'phoneId' => $phoneNumber->id ?? '' + 'phoneId' => $phoneNumber->id ?? '', ]; } } @@ -1562,7 +1562,7 @@ public function updateEmail($patron, $email, $emailId = null) return [ 'success' => true, 'status' => 'No data to update', - 'sys_message' => '' + 'sys_message' => '', ]; } } @@ -1651,7 +1651,7 @@ public function updatePhone($patron, $phone, $phoneId = null) return [ 'success' => true, 'status' => 'No data to update', - 'sys_message' => '' + 'sys_message' => '', ]; } } From 555a3d2971747fd1880cb8f11d3256359d2c45f1 Mon Sep 17 00:00:00 2001 From: rajaro Date: Tue, 8 Oct 2024 16:32:10 +0300 Subject: [PATCH 04/18] dont expose email/phone ids --- .../Finna/Controller/MyResearchController.php | 4 +- module/Finna/src/Finna/ILS/Driver/Quria.php | 38 +++++++++---------- .../finna2/templates/myresearch/profile.phtml | 4 +- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 1ae35203b65..0dcfec8de25 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -1510,7 +1510,7 @@ protected function processLibraryDataUpdate($patron, $values) if ( $validator->isValid($extraEmail) && $catalog->checkFunction('updateEmail', compact('patron')) - && !empty($values->profile_extra_email_id[$i]) + && isset($values->profile_extra_email_id[$i]) ) { $result = $catalog->updateEmail( $patron, @@ -1538,7 +1538,7 @@ protected function processLibraryDataUpdate($patron, $values) // Update extra phones if (isset($values->profile_extra_tel) && isset($values->profile_extra_tel_id)) { foreach ($values->profile_extra_tel as $i => $extraPhone) { - if (!empty($values->profile_extra_tel_id[$i])) { + if (isset($values->profile_extra_tel_id[$i])) { $result = $catalog->updatePhone( $patron, $extraPhone->phone, diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index b2bc52d50aa..28971db244c 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -1556,17 +1556,16 @@ public function updateEmail($patron, $email, $emailId = null) $user = $this->getMyProfile($patron); - if ($emailId) { - foreach ($user['extraEmails'] as $extraEmail) { - if ($extraEmail['emailId'] === $emailId && $extraEmail['email'] === $email) { - return [ - 'success' => true, - 'status' => 'No data to update', - 'sys_message' => '', - ]; - } + if ($updateExtraEmail = isset($emailId) && !empty($user['extraEmails'][$emailId]['email'])) { + if ($user['extraEmails'][$emailId]['email'] === $email) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '', + ]; } } + $function = ''; $functionResult = ''; $functionParam = ''; @@ -1587,7 +1586,7 @@ public function updateEmail($patron, $email, $emailId = null) ]; if (!empty($user['email'])) { - $conf['id'] = $emailId ?? $user['emailId']; + $conf['id'] = $updateExtraEmail ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; @@ -1645,18 +1644,15 @@ public function updatePhone($patron, $phone, $phoneId = null) $password = $patron['cat_password']; $user = $this->getMyProfile($patron); - if ($phoneId) { - foreach ($user['extraPhones'] as $extraPhone) { - if ($extraPhone['phoneId'] === $phoneId && $extraPhone['phone'] === $phone) { - return [ - 'success' => true, - 'status' => 'No data to update', - 'sys_message' => '', - ]; - } + if ($updateExtraPhone = isset($phoneId) && !empty($user['extraPhones'][$phoneId]['phone'])) { + if ($user['extraPhones'][$phoneId]['phone'] === $phone) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '', + ]; } } - $function = ''; $functionResult = ''; $functionParam = ''; @@ -1674,7 +1670,7 @@ public function updatePhone($patron, $phone, $phoneId = null) ]; if (!empty($user['phone'])) { - $conf['id'] = $phoneId ?? $user['phoneId']; + $conf['id'] = $updateExtraPhone ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 18e91a853fd..9d7930f731e 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -182,7 +182,7 @@
- +
@@ -212,7 +212,7 @@ profile['extraEmails'] as $i => $extraEmail): ?>
- +
From 966dba21907da28319f1b80c7c28327c924b45c1 Mon Sep 17 00:00:00 2001 From: Ravila Date: Wed, 6 Nov 2024 13:05:05 +0200 Subject: [PATCH 05/18] save progress --- .../Finna/Controller/MyResearchController.php | 36 ++++- module/Finna/src/Finna/ILS/Driver/Quria.php | 140 ++++++++++++++---- .../myresearch/change-address-settings.phtml | 61 ++++++-- .../finna2/templates/myresearch/profile.phtml | 49 +++--- 4 files changed, 221 insertions(+), 65 deletions(-) diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 0dcfec8de25..24a739223d0 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -1504,6 +1504,16 @@ protected function processLibraryDataUpdate($patron, $values) } } // Update extra emails + if (isset($values->profile_activate_email)) { + $result = $catalog->activateEmail( + $patron, + $values->profile_activate_email + ); + if (!$result) { + $this->flashMessenger()->addErrorMessage($result['status']); + $success = false; + } + } if (isset($values->profile_extra_email) && isset($values->profile_extra_email_id)) { foreach ($values->profile_extra_email as $i => $extraEmail) { $validator = new \Laminas\Validator\EmailAddress(); @@ -1525,17 +1535,27 @@ protected function processLibraryDataUpdate($patron, $values) } } // Update phone - if ( - isset($values->profile_tel) - && $catalog->checkFunction('updatePhone', compact('patron')) - ) { - $result = $catalog->updatePhone($patron, $values->profile_tel); - if (!$result['success']) { + // if ( + // isset($values->profile_tel) + // && $catalog->checkFunction('updatePhone', compact('patron')) + // ) { + // $result = $catalog->updatePhone($patron, $values->profile_tel); + // if (!$result['success']) { + // $this->flashMessenger()->addErrorMessage($result['status']); + // $success = false; + // } + // } + // Update extra phones + if (isset($values->profile_activate_phone)) { + $result = $catalog->activatePhone( + $patron, + $values->profile_activate_phone + ); + if (!$result) { $this->flashMessenger()->addErrorMessage($result['status']); $success = false; } } - // Update extra phones if (isset($values->profile_extra_tel) && isset($values->profile_extra_tel_id)) { foreach ($values->profile_extra_tel as $i => $extraPhone) { if (isset($values->profile_extra_tel_id[$i])) { @@ -1544,7 +1564,7 @@ protected function processLibraryDataUpdate($patron, $values) $extraPhone->phone, $values->profile_extra_tel_id[$i] ); - if (!$result['success']) { + if (!$result) { $this->flashMessenger()->addErrorMessage($result['status']); $success = false; } diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 28971db244c..39a0f60b006 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -601,6 +601,12 @@ public function patronLogin($username, $password) = $this->objectToArray($info->emailAddresses->emailAddress); $activeEmailFound = false; foreach ($emailAddresses as $emailAddress) { + $userCached['extraEmails'][] + = [ + 'email' => $emailAddress->address ?? '', + 'emailId' => $emailAddress->id ?? '', + 'active' => $emailAddress->isActive == 'yes', + ]; $emailActive = $emailAddress->isActive == 'yes'; if (empty($userCached['email']) || !$activeEmailFound) { $userCached['email'] = $emailAddress->address ?? ''; @@ -631,6 +637,12 @@ public function patronLogin($username, $password) if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); foreach ($phoneNumbers as $i => $phoneNumber) { + $userCached['extraPhones'][] + = [ + 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', + 'phoneId' => $phoneNumber->id ?? '', + 'active' => ($phoneNumber->sms->userForSms ?? '') == 'yes' + ]; if ($phoneNumber->sms->useForSms == 'yes') { if ($i === 0) { $userCached['phone'] = $phoneNumber->areaCode ?? ''; @@ -1084,7 +1096,33 @@ public function updateAddress($patron, $details) return $result; } } + if (isset($details['extraEmails'])) { + foreach ($details['extraEmails'] as $i => $extraEmail) { + $active = $details['active_extraEmails'] ?? false; + $result = $this->updateEmail($patron, $extraEmail, $i, $active); + } + } + if (!empty($details['add_extraEmails'])) { + $result = $this->updateEmail($patron, $details['add_extraEmails'], null, false, true); + if (!$result['success']) { + return $result; + } + } + + if (!empty($details['extraPhones'])) { + foreach ($details['extraPhones'] as $i => $extraPhone) { + $active = (int)($details['active_extraPhones'] ?? -1) === $i; + $result = $this->updatePhone($patron, $extraPhone, $i, $active); + } + } + if (!empty($details['add_extraPhones'])) { + $result = $this->updatePhone($patron, $details['add_extraPhones'], null, false, true); + if (!$result['success']) { + return $result; + } + } + if (isset($details['phone'])) { $result = $this->updatePhone($patron, $details['phone']); if (!$result['success']) { @@ -1544,28 +1582,19 @@ public function placeHold($holdDetails) * @param array $patron Patron array * @param String $email Email address * @param String $emailId Email ID + * @param bool $active Whether to set the email active * * @throws ILSException * * @return array Associative array of the results */ - public function updateEmail($patron, $email, $emailId = null) + public function updateEmail($patron, $email, $emailId = null, $active = true, $addNew = false) { $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); - if ($updateExtraEmail = isset($emailId) && !empty($user['extraEmails'][$emailId]['email'])) { - if ($user['extraEmails'][$emailId]['email'] === $email) { - return [ - 'success' => true, - 'status' => 'No data to update', - 'sys_message' => '', - ]; - } - } - $function = ''; $functionResult = ''; $functionParam = ''; @@ -1582,18 +1611,21 @@ public function updateEmail($patron, $email, $emailId = null) 'password' => $password, 'patronId' => $patron['patronId'], 'address' => $email, - 'isActive' => 'yes', + 'isActive' => $active ? 'yes' : 'no', ]; - - if (!empty($user['email'])) { - $conf['id'] = $updateExtraEmail ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; + if (!empty($user['extraEmails']) && !$addNew && !empty($email)) { + $conf['id'] = $emailId ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; - } else { + } elseif ((empty($user['extraEmails']) || $addNew) && !empty($email)) { $function = 'addEmail'; $functionResult = 'addEmailAddressResult'; $functionParam = 'addEmailAddressParam'; + } else { + $function = 'removeEmailAddress'; + $functionResult = 'removeEmailAddressResult'; + $functionParam = 'removeEmailAddressParam'; } $result = $this->doSOAPRequest( @@ -1627,6 +1659,29 @@ public function updateEmail($patron, $email, $emailId = null) ]; } + /** + * Set email address to active and deactivate + * other email addresses + * + * @param array $patron Patron array + * @param int $ind Index of the email in patrons extraEmails array + * + * @return bool + */ + public function activateEmail($patron, $ind) + { + $user = $this->getMyProfile($patron); + $success = true; + foreach ($user['extraEmails'] as $i => $extraEmail) { + $activate = $i === (int)$ind; + $result = $this->updateEmail($patron, $extraEmail['email'], $i, $activate); + if (!$result['success']) { + $success = false; + } + } + return $success; + } + /** * Update patron's phone number * @@ -1638,21 +1693,21 @@ public function updateEmail($patron, $email, $emailId = null) * * @return array Associative array of the results */ - public function updatePhone($patron, $phone, $phoneId = null) + public function updatePhone($patron, $phone, $phoneId = null, $active = false, $addNew = false) { $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); - if ($updateExtraPhone = isset($phoneId) && !empty($user['extraPhones'][$phoneId]['phone'])) { - if ($user['extraPhones'][$phoneId]['phone'] === $phone) { - return [ - 'success' => true, - 'status' => 'No data to update', - 'sys_message' => '', - ]; - } - } + // if ($updateExtraPhone = isset($phoneId) && !empty($user['extraPhones'][$phoneId]['phone'])) { + // if ($user['extraPhones'][$phoneId]['phone'] === $phone) { + // return [ + // 'success' => true, + // 'status' => 'No data to update', + // 'sys_message' => '', + // ]; + // } + // } $function = ''; $functionResult = ''; $functionParam = ''; @@ -1666,18 +1721,22 @@ public function updatePhone($patron, $phone, $phoneId = null) 'areaCode' => '', 'country' => $user['phoneCountry'] ?? 'FI', 'localCode' => $phone, - 'useForSms' => 'yes', + 'useForSms' => $active ? 'yes' : 'no', ]; - if (!empty($user['phone'])) { + if (!empty($user['extraPhones']) && !$addNew && !empty($phone)) { $conf['id'] = $updateExtraPhone ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; - } else { + } elseif ((empty($user['extraPhones']) || $addNew) && !empty($phone)) { $function = 'addPhone'; $functionResult = 'addPhoneNumberResult'; $functionParam = 'addPhoneNumberParam'; + } else { + $function = 'removePhone'; + $functionResult = 'removePhoneNumberResult'; + $functionParam = 'removePhoneNumerParam'; } $result = $this->doSOAPRequest( @@ -1713,6 +1772,29 @@ public function updatePhone($patron, $phone, $phoneId = null) ]; } + /** + * Set phone number to active (use for sms) and deactivate + * other email addresses + * + * @param array $patron Patron array + * @param int $ind Index of the email in patrons extraEmails array + * + * @return bool + */ + public function activatePhone($patron, $ind) + { + $user = $this->getMyProfile($patron); + $success = true; + foreach ($user['extraPhones'] as $i => $extraPhone) { + $activate = $i === (int)$ind; + $result = $this->updatePhone($patron, $extraPhone['phone'], $i, $activate); + if (!$result['success']) { + $success = false; + } + } + return $success; + } + /** * Cancel Holds * diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index cfeb715d12c..815782dab27 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -95,23 +95,62 @@ >
transEsc('password_only_numeric') ?>
- - $field, - 'name' => $field, - 'type' => $data['type'], - 'value' => $value, - 'class' => 'form-control', - ]; + + $extraInfo) { + $attrs = [ + 'id' => $field, + 'name' => $field . '[' . $i . ']', + 'type' => $data['type'], + 'value' => $isEmail ? $extraInfo['email'] : $extraInfo['phone'], + 'class' => 'form-control', + ]; + $extraValues[] = [ + 'attrs' => $attrs, + 'active' => $extraInfo['active'], + // Save the position in the original extraEmails/extraPhones array + 'pos' => $i, + ]; + } if ($data['required']) { $attrs['required'] = true; } if ($data['pattern']) { $attrs['pattern'] = $data['pattern']; } - echo $this->makeTag('input', '', $attrs); - ?> + usort($extraValues, function ($a, $b) { + return $b['active'] <=> $a['active']; + }); + ?> + + + + + + + makeTag('input', '', $extraValue['attrs']); ?> + + + + $field, + 'name' => $field, + 'type' => $data['type'], + 'value' => $value, + 'class' => 'form-control', + ]; + if ($data['required']) { + $attrs['required'] = true; + } + if ($data['pattern']) { + $attrs['pattern'] = $data['pattern']; + } + echo $this->makeTag('input', '', $attrs); + ?> +
transEsc($data['hint'])?>
diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 9d7930f731e..c5aae47db03 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -17,6 +17,7 @@ $needsApproval = $updateAddress['needsApproval'] ?? true; $updateLoanHistory = $this->ils()->checkFunction('updateTransactionHistoryState', $capabilityParams); $updateAddressLink = ''; + $updateAddress['method'] = 'driver'; if ($updateAddress) { $linkText = $this->translate(($updatePhone || $updateEmail || $updateSmsNumber) ? 'request_address_change' : 'request_contact_information_change'); ob_start(); @@ -174,17 +175,20 @@ profile['phone']) || $updatePhone): ?>
+
- profile['extraPhones'])): ?> - profile['extraPhones'] as $i => $extraPhone): ?> -
-
- - -
- + + profile['extraPhones'])): ?> + +
transEsc('Phone') ?>:
@@ -202,19 +206,30 @@
escapeHtml($this->profile['smsnumber']) ?>
- profile['email']) || $updateEmail): ?> + profile['email']) || $updateEmail || true): ?>
- + + profile['extraEmails'])): ?>
- profile['extraEmails'])): ?> - profile['extraEmails'] as $i => $extraEmail): ?> -
-
- -
- + + profile['extraEmails']) > 1 || true): ?> + + +
+
+ +
+ +
escapeHtml($this->profile['email']) ?>
From 4ffd1948e24dcf4853c51a55d8b21825ff14cc6c Mon Sep 17 00:00:00 2001 From: Ravila Date: Wed, 6 Nov 2024 16:58:48 +0200 Subject: [PATCH 06/18] Fix removing phone numbers --- module/Finna/src/Finna/ILS/Driver/Quria.php | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 39a0f60b006..db28299b624 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -1081,8 +1081,8 @@ public function getMyHolds($user) /** * Update patron contact information * - * @param array $patron Patron array - * @param String $details Associative array of patron contact information + * @param array $patron Patron array + * @param array $details Associative array of patron contact information * * @throws ILSException * @@ -1096,10 +1096,13 @@ public function updateAddress($patron, $details) return $result; } } - if (isset($details['extraEmails'])) { + if (!empty($details['extraEmails'])) { foreach ($details['extraEmails'] as $i => $extraEmail) { - $active = $details['active_extraEmails'] ?? false; + $active = (int)($details['active_extraEmails'] ?? -1) === $i; $result = $this->updateEmail($patron, $extraEmail, $i, $active); + if (!$result['success']) { + return $result; + } } } if (!empty($details['add_extraEmails'])) { @@ -1113,6 +1116,9 @@ public function updateAddress($patron, $details) foreach ($details['extraPhones'] as $i => $extraPhone) { $active = (int)($details['active_extraPhones'] ?? -1) === $i; $result = $this->updatePhone($patron, $extraPhone, $i, $active); + if (!$result['success']) { + return $result; + } } } @@ -1623,7 +1629,8 @@ public function updateEmail($patron, $email, $emailId = null, $active = true, $a $functionResult = 'addEmailAddressResult'; $functionParam = 'addEmailAddressParam'; } else { - $function = 'removeEmailAddress'; + $conf['id'] = $emailId ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; + $function = 'removeEmail'; $functionResult = 'removeEmailAddressResult'; $functionParam = 'removeEmailAddressParam'; } @@ -1725,7 +1732,7 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false, $ ]; if (!empty($user['extraPhones']) && !$addNew && !empty($phone)) { - $conf['id'] = $updateExtraPhone ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; + $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; @@ -1734,9 +1741,10 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false, $ $functionResult = 'addPhoneNumberResult'; $functionParam = 'addPhoneNumberParam'; } else { + $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'removePhone'; $functionResult = 'removePhoneNumberResult'; - $functionParam = 'removePhoneNumerParam'; + $functionParam = 'removePhoneNumberParam'; } $result = $this->doSOAPRequest( From 9e1603ade8ae447bdb099d9bf8df90c83d99f374 Mon Sep 17 00:00:00 2001 From: Ravila Date: Thu, 21 Nov 2024 12:18:19 +0200 Subject: [PATCH 07/18] List all emails/phones on profile page and change address form, add activation checkboxes to form --- .../Finna/Controller/MyResearchController.php | 76 ++--------- module/Finna/src/Finna/ILS/Driver/Quria.php | 122 +++--------------- .../myresearch/change-address-settings.phtml | 19 +-- .../finna2/templates/myresearch/profile.phtml | 53 +++----- 4 files changed, 57 insertions(+), 213 deletions(-) diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 24a739223d0..b48d2bf341c 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -905,7 +905,12 @@ public function changeProfileAddressAction() // Extract field name from single or array style key (e.g. addresses[0][types]) $fieldNames[strtok($field, '[')] = true; } - + if (isset($fieldNames['extraEmails'])) { + $fieldNames['active_extraEmails'] = true; + } + if (isset($fieldNames['extraPhones'])) { + $fieldNames['active_extraPhones'] = true; + } // Filter any undefined fields and bad values from the request: $data = array_intersect_key( filter_input_array(INPUT_POST), @@ -1503,74 +1508,17 @@ protected function processLibraryDataUpdate($patron, $values) } } } - // Update extra emails - if (isset($values->profile_activate_email)) { - $result = $catalog->activateEmail( - $patron, - $values->profile_activate_email - ); - if (!$result) { - $this->flashMessenger()->addErrorMessage($result['status']); - $success = false; - } - } - if (isset($values->profile_extra_email) && isset($values->profile_extra_email_id)) { - foreach ($values->profile_extra_email as $i => $extraEmail) { - $validator = new \Laminas\Validator\EmailAddress(); - if ( - $validator->isValid($extraEmail) - && $catalog->checkFunction('updateEmail', compact('patron')) - && isset($values->profile_extra_email_id[$i]) - ) { - $result = $catalog->updateEmail( - $patron, - $extraEmail, - $values->profile_extra_email_id[$i] - ); - if (!$result['success']) { - $this->flashMessenger()->addErrorMessage($result['status']); - $success = false; - } - } - } - } // Update phone - // if ( - // isset($values->profile_tel) - // && $catalog->checkFunction('updatePhone', compact('patron')) - // ) { - // $result = $catalog->updatePhone($patron, $values->profile_tel); - // if (!$result['success']) { - // $this->flashMessenger()->addErrorMessage($result['status']); - // $success = false; - // } - // } - // Update extra phones - if (isset($values->profile_activate_phone)) { - $result = $catalog->activatePhone( - $patron, - $values->profile_activate_phone - ); - if (!$result) { + if ( + isset($values->profile_tel) + && $catalog->checkFunction('updatePhone', compact('patron')) + ) { + $result = $catalog->updatePhone($patron, $values->profile_tel); + if (!$result['success']) { $this->flashMessenger()->addErrorMessage($result['status']); $success = false; } } - if (isset($values->profile_extra_tel) && isset($values->profile_extra_tel_id)) { - foreach ($values->profile_extra_tel as $i => $extraPhone) { - if (isset($values->profile_extra_tel_id[$i])) { - $result = $catalog->updatePhone( - $patron, - $extraPhone->phone, - $values->profile_extra_tel_id[$i] - ); - if (!$result) { - $this->flashMessenger()->addErrorMessage($result['status']); - $success = false; - } - } - } - } // Update SMS Number if ( isset($values->profile_sms_number) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index db28299b624..dce6ea88f2e 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -641,27 +641,8 @@ public function patronLogin($username, $password) = [ 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', 'phoneId' => $phoneNumber->id ?? '', - 'active' => ($phoneNumber->sms->userForSms ?? '') == 'yes' + 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes' ]; - if ($phoneNumber->sms->useForSms == 'yes') { - if ($i === 0) { - $userCached['phone'] = $phoneNumber->areaCode ?? ''; - $userCached['phoneAreaCode'] = $userCached['phone']; - if (isset($phoneNumber->localCode)) { - $userCached['phone'] .= $phoneNumber->localCode; - $userCached['phoneLocalCode'] = $phoneNumber->localCode; - } - if (isset($phoneNumber->id)) { - $userCached['phoneId'] = $phoneNumber->id; - } - } else { - $userCached['extraPhones'][] - = [ - 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', - 'phoneId' => $phoneNumber->id ?? '', - ]; - } - } } } @@ -1098,23 +1079,17 @@ public function updateAddress($patron, $details) } if (!empty($details['extraEmails'])) { foreach ($details['extraEmails'] as $i => $extraEmail) { - $active = (int)($details['active_extraEmails'] ?? -1) === $i; + $active = isset($details['active_extraEmails'][$i]); $result = $this->updateEmail($patron, $extraEmail, $i, $active); if (!$result['success']) { return $result; } } } - if (!empty($details['add_extraEmails'])) { - $result = $this->updateEmail($patron, $details['add_extraEmails'], null, false, true); - if (!$result['success']) { - return $result; - } - } if (!empty($details['extraPhones'])) { foreach ($details['extraPhones'] as $i => $extraPhone) { - $active = (int)($details['active_extraPhones'] ?? -1) === $i; + $active = isset($details['active_extraPhones'][$i]) ? true : false; $result = $this->updatePhone($patron, $extraPhone, $i, $active); if (!$result['success']) { return $result; @@ -1122,13 +1097,6 @@ public function updateAddress($patron, $details) } } - if (!empty($details['add_extraPhones'])) { - $result = $this->updatePhone($patron, $details['add_extraPhones'], null, false, true); - if (!$result['success']) { - return $result; - } - } - if (isset($details['phone'])) { $result = $this->updatePhone($patron, $details['phone']); if (!$result['success']) { @@ -1585,17 +1553,24 @@ public function placeHold($holdDetails) /** * Update patron's email address * - * @param array $patron Patron array - * @param String $email Email address - * @param String $emailId Email ID - * @param bool $active Whether to set the email active + * @param array $patron Patron array + * @param String $email Email address + * @param int|null $emailId Email ID + * @param bool $active Whether to set the email active * * @throws ILSException * * @return array Associative array of the results */ - public function updateEmail($patron, $email, $emailId = null, $active = true, $addNew = false) + public function updateEmail($patron, $email, $emailId = null, $active = false) { + if (empty($email)) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '', + ]; + } $username = $patron['cat_username']; $password = $patron['cat_password']; @@ -1619,12 +1594,12 @@ public function updateEmail($patron, $email, $emailId = null, $active = true, $a 'address' => $email, 'isActive' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraEmails']) && !$addNew && !empty($email)) { - $conf['id'] = $emailId ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; + if (!empty($user['extraEmails'])) { + $conf['id'] = $emailId !== null ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; - } elseif ((empty($user['extraEmails']) || $addNew) && !empty($email)) { + } elseif ((empty($user['extraEmails']))) { $function = 'addEmail'; $functionResult = 'addEmailAddressResult'; $functionParam = 'addEmailAddressParam'; @@ -1666,29 +1641,6 @@ public function updateEmail($patron, $email, $emailId = null, $active = true, $a ]; } - /** - * Set email address to active and deactivate - * other email addresses - * - * @param array $patron Patron array - * @param int $ind Index of the email in patrons extraEmails array - * - * @return bool - */ - public function activateEmail($patron, $ind) - { - $user = $this->getMyProfile($patron); - $success = true; - foreach ($user['extraEmails'] as $i => $extraEmail) { - $activate = $i === (int)$ind; - $result = $this->updateEmail($patron, $extraEmail['email'], $i, $activate); - if (!$result['success']) { - $success = false; - } - } - return $success; - } - /** * Update patron's phone number * @@ -1700,21 +1652,12 @@ public function activateEmail($patron, $ind) * * @return array Associative array of the results */ - public function updatePhone($patron, $phone, $phoneId = null, $active = false, $addNew = false) + public function updatePhone($patron, $phone, $phoneId = null, $active = false) { $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); - // if ($updateExtraPhone = isset($phoneId) && !empty($user['extraPhones'][$phoneId]['phone'])) { - // if ($user['extraPhones'][$phoneId]['phone'] === $phone) { - // return [ - // 'success' => true, - // 'status' => 'No data to update', - // 'sys_message' => '', - // ]; - // } - // } $function = ''; $functionResult = ''; $functionParam = ''; @@ -1731,12 +1674,12 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false, $ 'useForSms' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraPhones']) && !$addNew && !empty($phone)) { + if (!empty($user['extraPhones']) && !empty($phone)) { $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; - } elseif ((empty($user['extraPhones']) || $addNew) && !empty($phone)) { + } elseif ((empty($user['extraPhones'])) && !empty($phone)) { $function = 'addPhone'; $functionResult = 'addPhoneNumberResult'; $functionParam = 'addPhoneNumberParam'; @@ -1780,29 +1723,6 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false, $ ]; } - /** - * Set phone number to active (use for sms) and deactivate - * other email addresses - * - * @param array $patron Patron array - * @param int $ind Index of the email in patrons extraEmails array - * - * @return bool - */ - public function activatePhone($patron, $ind) - { - $user = $this->getMyProfile($patron); - $success = true; - foreach ($user['extraPhones'] as $i => $extraPhone) { - $activate = $i === (int)$ind; - $result = $this->updatePhone($patron, $extraPhone['phone'], $i, $activate); - if (!$result['success']) { - $success = false; - } - } - return $success; - } - /** * Cancel Holds * diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index 815782dab27..711d58011b9 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -109,9 +109,7 @@ ]; $extraValues[] = [ 'attrs' => $attrs, - 'active' => $extraInfo['active'], - // Save the position in the original extraEmails/extraPhones array - 'pos' => $i, + 'active' => $extraInfo['active'] ?? false, ]; } if ($data['required']) { @@ -120,17 +118,14 @@ if ($data['pattern']) { $attrs['pattern'] = $data['pattern']; } - usort($extraValues, function ($a, $b) { - return $b['active'] <=> $a['active']; - }); ?> - - - - - - + + makeTag('input', '', $extraValue['attrs']); ?> +
+ > + transEsc('contact_info_active') ?> +
diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index c5aae47db03..906f97bcb18 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -175,21 +175,14 @@ profile['phone']) || $updatePhone): ?>
- -
- -
- - profile['extraPhones'])): ?> - - - + + + profile['extraPhones'])): ?> +
transEsc('Phone') ?>:
+ profile['extraPhones'] as $i => $extraPhone): ?> +
+
escapeHtml($extraPhone['phone']) ?>
+
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
@@ -206,33 +199,21 @@
escapeHtml($this->profile['smsnumber']) ?>
- profile['email']) || $updateEmail || true): ?> + profile['email']) || $updateEmail): ?>
- - profile['extraEmails'])): ?> +
+ + profile['extraEmails'])): ?> + profile['extraEmails'] as $i => $extraEmail): ?> +
+
escapeHtml($extraEmail['email']) ?>
+ - profile['extraEmails']) > 1 || true): ?> - - -
-
- -
- - +
escapeHtml($this->profile['email']) ?>
- -
escapeHtml($this->profile['email']) ?>
profile['hold_identifier'])): ?> From aeb3728536ae3256395833c9f316e4d5eb54b892 Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 3 Dec 2024 11:32:35 +0200 Subject: [PATCH 08/18] Fix bugs, cleanup, add translations --- local/languages/finna/en-gb.ini | 2 + local/languages/finna/fi.ini | 2 + local/languages/finna/sv.ini | 2 + module/Finna/src/Finna/ILS/Driver/Quria.php | 60 +++++++------------ .../myresearch/change-address-settings.phtml | 2 +- 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/local/languages/finna/en-gb.ini b/local/languages/finna/en-gb.ini index 6ee91623ff4..b5f36746093 100644 --- a/local/languages/finna/en-gb.ini +++ b/local/languages/finna/en-gb.ini @@ -349,6 +349,8 @@ external_link_kyppi_rpr = "Record in Built Heritage Register" external_online_link = "External link to material" external_rating_link_html = 'You can evaluate the materials in the online service of the organisation that provides it (external link).' external_rating_link_aoe_html = 'You can evaluate educational resources on the Library of Open Educational Resources website (aoe.fi).' +extraEmails_active = "Active" +extraPhones_active = "Use for SMS" facet_list_empty = "No data available" Feedback = "Feedback" feedback_captcha_answer = "55" diff --git a/local/languages/finna/fi.ini b/local/languages/finna/fi.ini index 49457eb14fe..9f5ee31f1df 100644 --- a/local/languages/finna/fi.ini +++ b/local/languages/finna/fi.ini @@ -343,6 +343,8 @@ external_link_kyppi_rpr = "Kohde rakennusperintörekisterissä" external_online_link = "Ulkoinen linkki aineistoon" external_rating_link_html = 'Voit arvioida oppimateriaaleja aineistontarjoajan omassa verkkopalvelussa (ulkoinen linkki).' external_rating_link_aoe_html = 'Voit arvioida oppimateriaaleja Avointen oppimateriaalien kirjaston sivustolla (aoe.fi).' +extraEmails_active = "Aktiivinen" +extraPhones_active = "Käytä tekstiviesteille" facet_list_empty = "Ei tietoja" Feedback = "Palaute" feedback_captcha_answer = "55" diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index fd87e1c5ade..ed786ef5420 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -341,6 +341,8 @@ external_link_kyppi_rpr = "Posten i byggnadsminnesregistret" external_online_link = "Extern länk till materialet" external_rating_link_html = 'Du kan utvärdera materialen i leverantörens egen nättjänst (extern länk).' external_rating_link_aoe_html = 'Du kan utvärdera lärresurser på webbplatsen för Biblioteket för öppna lärresurser (aoe.fi).' +extraEmails_active = "Aktiv" +extraPhones_active = "Använda för SMS" Feedback = "Respons" feedback_captcha_answer = "55" feedback_captcha_error = "Kontrollera svaret på säkerhetsfrågan." diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 4b006bb8ef5..a2b364e0bee 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -667,7 +667,6 @@ public function patronLogin($username, $password) if (!empty($info->emailAddresses->emailAddress)) { $emailAddresses = $this->objectToArray($info->emailAddresses->emailAddress); - $activeEmailFound = false; foreach ($emailAddresses as $emailAddress) { $userCached['extraEmails'][] = [ @@ -675,19 +674,6 @@ public function patronLogin($username, $password) 'emailId' => $emailAddress->id ?? '', 'active' => $emailAddress->isActive == 'yes', ]; - $emailActive = $emailAddress->isActive == 'yes'; - if (empty($userCached['email']) || !$activeEmailFound) { - $userCached['email'] = $emailAddress->address ?? ''; - $userCached['emailId'] = $emailAddress->id ?? ''; - $activeEmailFound = $emailActive; - } elseif ($emailActive) { - $userCached['extraEmails'][] - = [ - 'email' => $emailAddress->address ?? '', - 'emailId' => $emailAddress->id ?? '', - ]; - } - } } if (isset($info->addresses->address)) { $addresses = $this->objectToArray($info->addresses->address); @@ -704,7 +690,7 @@ public function patronLogin($username, $password) } if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); - foreach ($phoneNumbers as $i => $phoneNumber) { + foreach ($phoneNumbers as $phoneNumber) { $userCached['extraPhones'][] = [ 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', @@ -1142,6 +1128,8 @@ public function getMyHolds($user) */ public function updateAddress($patron, $details) { + $user = $this->getMyProfile($patron); + if (isset($details['email'])) { $result = $this->updateEmail($patron, $details['email']); if (!$result['success']) { @@ -1150,20 +1138,28 @@ public function updateAddress($patron, $details) } if (!empty($details['extraEmails'])) { foreach ($details['extraEmails'] as $i => $extraEmail) { - $active = isset($details['active_extraEmails'][$i]); - $result = $this->updateEmail($patron, $extraEmail, $i, $active); - if (!$result['success']) { - return $result; + if (!empty($extraEmail)) { + $active = isset($details['active_extraEmails'][$i]); + if (($user['extraEmails'][$i]['email'] !== $extraEmail) || ($active !== $user['extraEmails'][$i]['active'])) { + $result = $this->updateEmail($patron, $extraEmail, $i, $active); + if (!$result['success']) { + return $result; + } + } } } } if (!empty($details['extraPhones'])) { foreach ($details['extraPhones'] as $i => $extraPhone) { - $active = isset($details['active_extraPhones'][$i]) ? true : false; - $result = $this->updatePhone($patron, $extraPhone, $i, $active); - if (!$result['success']) { - return $result; + if (!empty($extraPhone)) { + $active = isset($details['active_extraPhones'][$i]); + if (($user['extraPhones'][$i]['phone'] !== $extraPhone) || ($active !== $user['extraPhones'][$i]['active'])) { + $result = $this->updatePhone($patron, $extraPhone, $i, $active); + if (!$result['success']) { + return $result; + } + } } } } @@ -1178,8 +1174,6 @@ public function updateAddress($patron, $details) $username = $patron['cat_username']; $password = $patron['cat_password']; - $user = $this->getMyProfile($patron); - $conf = [ 'arenaMember' => $this->arenaMember, 'language' => $this->getLanguage(), @@ -1679,15 +1673,10 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; - } elseif ((empty($user['extraEmails']))) { + } else { $function = 'addEmail'; $functionResult = 'addEmailAddressResult'; $functionParam = 'addEmailAddressParam'; - } else { - $conf['id'] = $emailId ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; - $function = 'removeEmail'; - $functionResult = 'removeEmailAddressResult'; - $functionParam = 'removeEmailAddressParam'; } $result = $this->doSOAPRequest( @@ -1754,20 +1743,15 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false) 'useForSms' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraPhones']) && !empty($phone)) { + if (!empty($user['extraPhones'])) { $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; - } elseif ((empty($user['extraPhones'])) && !empty($phone)) { + } else { $function = 'addPhone'; $functionResult = 'addPhoneNumberResult'; $functionParam = 'addPhoneNumberParam'; - } else { - $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; - $function = 'removePhone'; - $functionResult = 'removePhoneNumberResult'; - $functionParam = 'removePhoneNumberParam'; } $result = $this->doSOAPRequest( diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index 711d58011b9..fd30f6c72b8 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -124,7 +124,7 @@ makeTag('input', '', $extraValue['attrs']); ?>
> - transEsc('contact_info_active') ?> + transEsc($field . '_active') ?>
From e5ac4e3906bb6f5d12e8e8b3c21cce66d6cba5aa Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 3 Dec 2024 14:19:13 +0200 Subject: [PATCH 09/18] Fix typo --- module/Finna/src/Finna/ILS/Driver/Quria.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index a2b364e0bee..eb59500164f 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -674,6 +674,7 @@ public function patronLogin($username, $password) 'emailId' => $emailAddress->id ?? '', 'active' => $emailAddress->isActive == 'yes', ]; + } } if (isset($info->addresses->address)) { $addresses = $this->objectToArray($info->addresses->address); From 1674525e2918ae6ba3b353f18007b3b3da4f65e9 Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 10 Dec 2024 16:56:19 +0200 Subject: [PATCH 10/18] Make activation fields configurable, fix layout, update .sample --- local/config/finna/Quria.ini.sample | 4 +++ .../Finna/Controller/MyResearchController.php | 11 ++++---- module/Finna/src/Finna/ILS/Driver/Quria.php | 2 +- .../myresearch/change-address-settings.phtml | 12 ++++++--- .../finna2/templates/myresearch/profile.phtml | 26 ++++++++----------- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/local/config/finna/Quria.ini.sample b/local/config/finna/Quria.ini.sample index 0a3eac11081..cb566bb4750 100644 --- a/local/config/finna/Quria.ini.sample +++ b/local/config/finna/Quria.ini.sample @@ -118,6 +118,10 @@ fields[] = Address:address1 fields[] = Zip:zip fields[] = City:city fields[] = Country:country +fields[] = Email:extraEmails +fields[] = Phone:extraPhones +contactInfoActivation[] = extraPhones +contactInfoActivation[] = extraEmails ;fields[] = Phone:phone ;fields[] = Email:email ;fields[] = Additional info:info diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 883286e44d6..12e25ea303f 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -903,11 +903,12 @@ public function changeProfileAddressAction() // Extract field name from single or array style key (e.g. addresses[0][types]) $fieldNames[strtok($field, '[')] = true; } - if (isset($fieldNames['extraEmails'])) { - $fieldNames['active_extraEmails'] = true; - } - if (isset($fieldNames['extraPhones'])) { - $fieldNames['active_extraPhones'] = true; + + // Add contact info activation fields to accepted field names + if (!empty($updateConfig['contactInfoActivation'])) { + foreach ($updateConfig['contactInfoActivation'] as $contactField) { + $fieldNames['active_' . $contactField] = true; + } } // Filter any undefined fields and bad values from the request: $data = array_intersect_key( diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index eb59500164f..4a26e0904de 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -696,7 +696,7 @@ public function patronLogin($username, $password) = [ 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', 'phoneId' => $phoneNumber->id ?? '', - 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes' + 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes', ]; } } diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index fd30f6c72b8..39e641223dc 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -120,12 +120,16 @@ } ?> +
makeTag('input', '', $extraValue['attrs']); ?> -
- > - transEsc($field . '_active') ?> -
+ config['contactInfoActivation'] ?? [])): ?> +
+ > + transEsc($field . '_active') ?> +
+ +
diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 906f97bcb18..1361794f354 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -175,19 +175,17 @@ profile['phone']) || $updatePhone): ?>
- - - profile['extraPhones'])): ?> -
transEsc('Phone') ?>:
- profile['extraPhones'] as $i => $extraPhone): ?> -
-
escapeHtml($extraPhone['phone']) ?>
-
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
+ profile['extraPhones'])): ?> + profile['extraPhones'] as $i => $extraPhone): ?> +
transEsc('Phone') : ''?>
+
escapeHtml($extraPhone['phone']) ?>
+ + profile['smsnumber']) || $updateSmsNumber): ?>
@@ -206,15 +204,13 @@ - profile['extraEmails'])): ?> - profile['extraEmails'] as $i => $extraEmail): ?> -
-
escapeHtml($extraEmail['email']) ?>
- -
escapeHtml($this->profile['email']) ?>
- + profile['extraEmails'])): ?> + profile['extraEmails'] as $i => $extraEmail): ?> +
transEsc('Email') : ''?>
+
escapeHtml($extraEmail['email']) ?>
+ profile['hold_identifier'])): ?>
transEsc('Hold Identifier') ?>:
From 3bea58e139c050896057330e3744c8db5c3b8cf1 Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 10 Dec 2024 17:09:52 +0200 Subject: [PATCH 11/18] minor tweak --- module/Finna/src/Finna/ILS/Driver/Quria.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 4a26e0904de..347311cf3a5 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -670,8 +670,8 @@ public function patronLogin($username, $password) foreach ($emailAddresses as $emailAddress) { $userCached['extraEmails'][] = [ - 'email' => $emailAddress->address ?? '', - 'emailId' => $emailAddress->id ?? '', + 'email' => $emailAddress->address ?? null, + 'emailId' => $emailAddress->id ?? null, 'active' => $emailAddress->isActive == 'yes', ]; } @@ -694,8 +694,8 @@ public function patronLogin($username, $password) foreach ($phoneNumbers as $phoneNumber) { $userCached['extraPhones'][] = [ - 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? '', - 'phoneId' => $phoneNumber->id ?? '', + 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null, + 'phoneId' => $phoneNumber->id ?? null, 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes', ]; } From 24aaac4488d4d9b3b955f640712f932c3f02a1bc Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 10 Dec 2024 17:34:02 +0200 Subject: [PATCH 12/18] Some style changes and cleanup --- local/config/finna/Quria.ini.sample | 6 ++++-- local/languages/finna/sv.ini | 2 +- module/Finna/src/Finna/ILS/Driver/Quria.php | 14 +++++++++++--- themes/finna2/templates/myresearch/profile.phtml | 6 ++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/local/config/finna/Quria.ini.sample b/local/config/finna/Quria.ini.sample index cb566bb4750..f61b6cea6bc 100644 --- a/local/config/finna/Quria.ini.sample +++ b/local/config/finna/Quria.ini.sample @@ -120,11 +120,13 @@ fields[] = City:city fields[] = Country:country fields[] = Email:extraEmails fields[] = Phone:extraPhones -contactInfoActivation[] = extraPhones -contactInfoActivation[] = extraEmails ;fields[] = Phone:phone ;fields[] = Email:email ;fields[] = Additional info:info + +; Array of fields that can be set active/inactive +contactInfoActivation[] = extraPhones +contactInfoActivation[] = extraEmails ; url is required for the url method. url can be a single address or an array of ; language-specific addresses. First example is a single one: ;url = http://address.of.change.form diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index ed786ef5420..130bd76ddf0 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -342,7 +342,7 @@ external_online_link = "Extern länk till materialet" external_rating_link_html = 'Du kan utvärdera materialen i leverantörens egen nättjänst (extern länk).' external_rating_link_aoe_html = 'Du kan utvärdera lärresurser på webbplatsen för Biblioteket för öppna lärresurser (aoe.fi).' extraEmails_active = "Aktiv" -extraPhones_active = "Använda för SMS" +extraPhones_active = "Använd för SMS" Feedback = "Respons" feedback_captcha_answer = "55" feedback_captcha_error = "Kontrollera svaret på säkerhetsfrågan." diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 347311cf3a5..0153c43f0d2 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -1639,7 +1639,7 @@ public function placeHold($holdDetails) */ public function updateEmail($patron, $email, $emailId = null, $active = false) { - if (empty($email)) { + if (empty($email) || empty($emailId)) { return [ 'success' => true, 'status' => 'No data to update', @@ -1670,7 +1670,7 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) 'isActive' => $active ? 'yes' : 'no', ]; if (!empty($user['extraEmails'])) { - $conf['id'] = $emailId !== null ? $user['extraEmails'][$emailId]['emailId'] : $user['emailId']; + $conf['id'] = $user['extraEmails'][$emailId]['emailId']; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; @@ -1717,6 +1717,7 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) * @param array $patron Patron array * @param string $phone Phone number * @param string $phoneId Phone ID + * @param bool $active Whether to set the phone active * * @throws ILSException * @@ -1724,6 +1725,13 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) */ public function updatePhone($patron, $phone, $phoneId = null, $active = false) { + if (empty($phone) || empty($phoneId)) { + return [ + 'success' => true, + 'status' => 'No data to update', + 'sys_message' => '', + ]; + } $username = $patron['cat_username']; $password = $patron['cat_password']; $user = $this->getMyProfile($patron); @@ -1745,7 +1753,7 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false) ]; if (!empty($user['extraPhones'])) { - $conf['id'] = $phoneId !== null ? $user['extraPhones'][$phoneId]['phoneId'] : $user['phoneId']; + $conf['id'] = $user['extraPhones'][$phoneId]['phoneId']; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 1361794f354..e7907340932 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -17,7 +17,6 @@ $needsApproval = $updateAddress['needsApproval'] ?? true; $updateLoanHistory = $this->ils()->checkFunction('updateTransactionHistoryState', $capabilityParams); $updateAddressLink = ''; - $updateAddress['method'] = 'driver'; if ($updateAddress) { $linkText = $this->translate(($updatePhone || $updateEmail || $updateSmsNumber) ? 'request_address_change' : 'request_contact_information_change'); ob_start(); @@ -175,6 +174,9 @@ profile['phone']) || $updatePhone): ?>
+
+ +
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
@@ -204,7 +206,7 @@ -
escapeHtml($this->profile['email']) ?>
+
escapeHtml($this->profile['email']) ?>
profile['extraEmails'])): ?> profile['extraEmails'] as $i => $extraEmail): ?> From ef2390f93535dd20f428a54c8d7b770bfd7c1f52 Mon Sep 17 00:00:00 2001 From: Ravila Date: Tue, 10 Dec 2024 17:42:32 +0200 Subject: [PATCH 13/18] codestyle fix --- module/Finna/src/Finna/ILS/Driver/Quria.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 0153c43f0d2..cdb129143ed 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -1141,7 +1141,10 @@ public function updateAddress($patron, $details) foreach ($details['extraEmails'] as $i => $extraEmail) { if (!empty($extraEmail)) { $active = isset($details['active_extraEmails'][$i]); - if (($user['extraEmails'][$i]['email'] !== $extraEmail) || ($active !== $user['extraEmails'][$i]['active'])) { + if ( + ($user['extraEmails'][$i]['email'] !== $extraEmail) + || ($active !== $user['extraEmails'][$i]['active']) + ) { $result = $this->updateEmail($patron, $extraEmail, $i, $active); if (!$result['success']) { return $result; @@ -1155,7 +1158,10 @@ public function updateAddress($patron, $details) foreach ($details['extraPhones'] as $i => $extraPhone) { if (!empty($extraPhone)) { $active = isset($details['active_extraPhones'][$i]); - if (($user['extraPhones'][$i]['phone'] !== $extraPhone) || ($active !== $user['extraPhones'][$i]['active'])) { + if ( + ($user['extraPhones'][$i]['phone'] !== $extraPhone) + || ($active !== $user['extraPhones'][$i]['active']) + ) { $result = $this->updatePhone($patron, $extraPhone, $i, $active); if (!$result['success']) { return $result; @@ -1628,10 +1634,10 @@ public function placeHold($holdDetails) /** * Update patron's email address * - * @param array $patron Patron array - * @param String $email Email address - * @param int|null $emailId Email ID - * @param bool $active Whether to set the email active + * @param array $patron Patron array + * @param String $email Email address + * @param int|null $emailId Email ID + * @param bool $active Whether to set the email active * * @throws ILSException * From 5fcc4f7f24e51cda4c2ced5cf800e890619af491 Mon Sep 17 00:00:00 2001 From: Ravila Date: Thu, 12 Dec 2024 13:29:52 +0200 Subject: [PATCH 14/18] requested changes --- local/config/finna/Quria.ini.sample | 10 +- local/languages/finna/en-gb.ini | 4 +- local/languages/finna/fi.ini | 4 +- local/languages/finna/sv.ini | 4 +- .../Finna/Controller/MyResearchController.php | 6 - module/Finna/src/Finna/ILS/Driver/Quria.php | 156 +++++++++++------- .../myresearch/change-address-settings.phtml | 58 ++----- .../finna2/templates/myresearch/profile.phtml | 25 ++- 8 files changed, 130 insertions(+), 137 deletions(-) diff --git a/local/config/finna/Quria.ini.sample b/local/config/finna/Quria.ini.sample index f61b6cea6bc..844273c42f7 100644 --- a/local/config/finna/Quria.ini.sample +++ b/local/config/finna/Quria.ini.sample @@ -118,15 +118,13 @@ fields[] = Address:address1 fields[] = Zip:zip fields[] = City:city fields[] = Country:country -fields[] = Email:extraEmails -fields[] = Phone:extraPhones -;fields[] = Phone:phone -;fields[] = Email:email +fields[] = Email:email +fields[] = Phone:phone ;fields[] = Additional info:info ; Array of fields that can be set active/inactive -contactInfoActivation[] = extraPhones -contactInfoActivation[] = extraEmails +contactInfoActivation[] = phone +contactInfoActivation[] = email ; url is required for the url method. url can be a single address or an array of ; language-specific addresses. First example is a single one: ;url = http://address.of.change.form diff --git a/local/languages/finna/en-gb.ini b/local/languages/finna/en-gb.ini index b5f36746093..054a4ee3200 100644 --- a/local/languages/finna/en-gb.ini +++ b/local/languages/finna/en-gb.ini @@ -308,6 +308,7 @@ Educational Level = "Educational Level" Educational Role = "Educational Role" Educational Subject = "Educational Subject" Educational Use = "Educational Use" +email_active = "Active" email_from = "Sender's address" email_info = "Your email address is needed for the following Finna features: due date reminders, scheduled alerts, send records by email, recovery of a forgotten password" email_info_without_ddr = "Your email address is needed for the following Finna features: scheduled alerts, send records by email, recovery of a forgotten password" @@ -349,8 +350,6 @@ external_link_kyppi_rpr = "Record in Built Heritage Register" external_online_link = "External link to material" external_rating_link_html = 'You can evaluate the materials in the online service of the organisation that provides it (external link).' external_rating_link_aoe_html = 'You can evaluate educational resources on the Library of Open Educational Resources website (aoe.fi).' -extraEmails_active = "Active" -extraPhones_active = "Use for SMS" facet_list_empty = "No data available" Feedback = "Feedback" feedback_captcha_answer = "55" @@ -884,6 +883,7 @@ Performers = "Performers" Performing Ensembles = "Performing Ensembles" Personal details maintained by the library = "Personal details maintained by the library" Phone = "Phone" +phone_active = "Use for SMS" Photo Info = "Photo Info" pick_up_location = "Pickup Location" pickup_location_home_address = "Delivery to home address" diff --git a/local/languages/finna/fi.ini b/local/languages/finna/fi.ini index 9f5ee31f1df..152888d67a4 100644 --- a/local/languages/finna/fi.ini +++ b/local/languages/finna/fi.ini @@ -300,6 +300,7 @@ Educational Level = "Koulutusaste" Educational Role = "Kohderyhmä" Educational Subject = "Oppiaine / tutkinto / tieteenala" Educational Use = "Pääasiallinen käyttötarkoitus" +email_active = "Aktiivinen" email_from = "Lähettäjän sähköpostiosoite" email_info = "Tarvitset sähköpostiosoitetta seuraaviin Finna-toimintoihin: eräpäivämuistutukset, uutuusvahti, aineiston tietojen lähettäminen sähköpostilla, unohtuneen salasanan palauttaminen" email_info_without_ddr = "Tarvitset sähköpostiosoitetta seuraaviin Finna-toimintoihin: uutuusvahti, aineiston tietojen lähettäminen sähköpostilla, unohtuneen salasanan palauttaminen" @@ -343,8 +344,6 @@ external_link_kyppi_rpr = "Kohde rakennusperintörekisterissä" external_online_link = "Ulkoinen linkki aineistoon" external_rating_link_html = 'Voit arvioida oppimateriaaleja aineistontarjoajan omassa verkkopalvelussa (ulkoinen linkki).' external_rating_link_aoe_html = 'Voit arvioida oppimateriaaleja Avointen oppimateriaalien kirjaston sivustolla (aoe.fi).' -extraEmails_active = "Aktiivinen" -extraPhones_active = "Käytä tekstiviesteille" facet_list_empty = "Ei tietoja" Feedback = "Palaute" feedback_captcha_answer = "55" @@ -877,6 +876,7 @@ Performers = "Esiintyjät" Performing Ensembles = "Esiintyjäkokoonpanot" Personal details maintained by the library = "Kirjaston ylläpitämät henkilötiedot" Phone = "Puhelin" +phone_active = "Käytä tekstiviesteille" Photo Info = "Kuvaustiedot" pickup_location_home_address = "Toimitus kotiosoitteeseen" pickup_location_work_address = "Toimitus työosoitteeseen" diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index 130bd76ddf0..41d980bfae0 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -299,6 +299,7 @@ Educational Level = "Utbildningsstadium" Educational Role = "Målgrupp" Educational Subject = "Undervisningsämne" Educational Use = "Användningsområde" +email_active = "Aktiv" email_from = "Avsändarens e-postadress" email_info = "Du behöver en e-postadress för att kunna använda följande funktioner i Finna: förfallodagspåminnelser, sökbevakningen, att skicka uppgifter om material per e-post, att återställa ditt lösenord" email_info_without_ddr = "Du behöver en e-postadress för att kunna använda följande funktioner i Finna: sökbevakningen, att skicka uppgifter om material per e-post, att återställa ditt lösenord" @@ -341,8 +342,6 @@ external_link_kyppi_rpr = "Posten i byggnadsminnesregistret" external_online_link = "Extern länk till materialet" external_rating_link_html = 'Du kan utvärdera materialen i leverantörens egen nättjänst (extern länk).' external_rating_link_aoe_html = 'Du kan utvärdera lärresurser på webbplatsen för Biblioteket för öppna lärresurser (aoe.fi).' -extraEmails_active = "Aktiv" -extraPhones_active = "Använd för SMS" Feedback = "Respons" feedback_captcha_answer = "55" feedback_captcha_error = "Kontrollera svaret på säkerhetsfrågan." @@ -874,6 +873,7 @@ Performers = "Uppträdare" Performing Ensembles = "Uppträdande ensembler" Personal details maintained by the library = "Personuppgifter som biblioteket upprätthåller" Phone = "Telefonnummer" +phone_active = "Använd för SMS" Photo Info = "Bildinformation" pick_up_location = "Hämtas från" pickup_location_home_address = "Leverans till hemadress" diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 12e25ea303f..b5e9fa9fca0 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -904,12 +904,6 @@ public function changeProfileAddressAction() $fieldNames[strtok($field, '[')] = true; } - // Add contact info activation fields to accepted field names - if (!empty($updateConfig['contactInfoActivation'])) { - foreach ($updateConfig['contactInfoActivation'] as $contactField) { - $fieldNames['active_' . $contactField] = true; - } - } // Filter any undefined fields and bad values from the request: $data = array_intersect_key( filter_input_array(INPUT_POST), diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index cdb129143ed..c55097e23b1 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -667,13 +667,10 @@ public function patronLogin($username, $password) if (!empty($info->emailAddresses->emailAddress)) { $emailAddresses = $this->objectToArray($info->emailAddresses->emailAddress); - foreach ($emailAddresses as $emailAddress) { - $userCached['extraEmails'][] - = [ - 'email' => $emailAddress->address ?? null, - 'emailId' => $emailAddress->id ?? null, - 'active' => $emailAddress->isActive == 'yes', - ]; + foreach ($emailAddresses as $i => $emailAddress) { + $userCached['email_' . $i] = $emailAddress->address ?? null; + $userCached['email_' . $i . '_id'] = $emailAddress->id ?? null; + $userCached['email_' . $i . '_active'] = $emailAddress->isActive == 'yes'; } } if (isset($info->addresses->address)) { @@ -691,13 +688,10 @@ public function patronLogin($username, $password) } if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); - foreach ($phoneNumbers as $phoneNumber) { - $userCached['extraPhones'][] - = [ - 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null, - 'phoneId' => $phoneNumber->id ?? null, - 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes', - ]; + foreach ($phoneNumbers as $i => $phoneNumber) { + $userCached['phone_' . $i] = ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null; + $userCached['phone_' . $i . '_id'] = $phoneNumber->id ?? null; + $userCached['phone_' . $i . '_active'] = ($phoneNumber->sms->useForSms ?? '') == 'yes'; } } @@ -1131,53 +1125,28 @@ public function updateAddress($patron, $details) { $user = $this->getMyProfile($patron); - if (isset($details['email'])) { - $result = $this->updateEmail($patron, $details['email']); - if (!$result['success']) { - return $result; - } - } - if (!empty($details['extraEmails'])) { - foreach ($details['extraEmails'] as $i => $extraEmail) { - if (!empty($extraEmail)) { - $active = isset($details['active_extraEmails'][$i]); - if ( - ($user['extraEmails'][$i]['email'] !== $extraEmail) - || ($active !== $user['extraEmails'][$i]['active']) - ) { - $result = $this->updateEmail($patron, $extraEmail, $i, $active); - if (!$result['success']) { - return $result; - } - } - } - } - } - - if (!empty($details['extraPhones'])) { - foreach ($details['extraPhones'] as $i => $extraPhone) { - if (!empty($extraPhone)) { - $active = isset($details['active_extraPhones'][$i]); - if ( - ($user['extraPhones'][$i]['phone'] !== $extraPhone) - || ($active !== $user['extraPhones'][$i]['active']) - ) { - $result = $this->updatePhone($patron, $extraPhone, $i, $active); - if (!$result['success']) { - return $result; - } + // Handle phones and emails + foreach ($details as $field => $detail) { + $parts = explode('_', $field); + $fieldName = $parts[0]; + $ind = $parts[1] ?? null; + $activeSuffix = $parts[2] ?? null; + if (in_array($fieldName, ['email', 'phone']) && $activeSuffix === null) { + $active = isset($details[$field . '_active']); + if ( + $user[$field] !== $detail + || $user[$field . '_active'] !== $active + ) { + $result = $fieldName === 'email' + ? $this->updateEmail($patron, $detail, $ind, $active) + : $this->updatePhone($patron, $detail, $ind, $active); + if (!$result['success']) { + return $result; } } } } - if (isset($details['phone'])) { - $result = $this->updatePhone($patron, $details['phone']); - if (!$result['success']) { - return $result; - } - } - $username = $patron['cat_username']; $password = $patron['cat_password']; @@ -1645,13 +1614,22 @@ public function placeHold($holdDetails) */ public function updateEmail($patron, $email, $emailId = null, $active = false) { - if (empty($email) || empty($emailId)) { + if (empty($email) || $emailId === null) { return [ 'success' => true, 'status' => 'No data to update', 'sys_message' => '', ]; } + $validator = new \Laminas\Validator\EmailAddress(); + if (!$validator->isValid($email)) { + return [ + 'success' => false, + 'status' => 'Invalid email', + 'sys_message' => '', + ]; + } + $username = $patron['cat_username']; $password = $patron['cat_password']; @@ -1675,8 +1653,8 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) 'address' => $email, 'isActive' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraEmails'])) { - $conf['id'] = $user['extraEmails'][$emailId]['emailId']; + if (!empty($user['email_0'])) { + $conf['id'] = $user['email_' . $emailId . '_id'] ?? ''; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; @@ -1731,7 +1709,7 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) */ public function updatePhone($patron, $phone, $phoneId = null, $active = false) { - if (empty($phone) || empty($phoneId)) { + if (empty($phone) || $phoneId === null) { return [ 'success' => true, 'status' => 'No data to update', @@ -1758,8 +1736,8 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false) 'useForSms' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraPhones'])) { - $conf['id'] = $user['extraPhones'][$phoneId]['phoneId']; + if (!empty($user['phone_0'])) { + $conf['id'] = $user['phone_' . $phoneId . '_id'] ?? ''; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; @@ -1938,4 +1916,58 @@ public function renewMyItems($renewDetails) } return $results; } + + /** + * Public Function which retrieves renew, hold and cancel settings from the + * driver ini file. + * + * @param string $function The name of the feature to be checked + * @param array $params Optional feature-specific parameters (array) + * + * @return array An array with key-value pairs. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getConfig($function, $params = null) + { + $config = parent::getConfig($function, $params); + if ('updateAddress' === $function && isset($config['fields'])) { + if (isset($params['patron'])) { + $profile = $this->getMyProfile($params['patron']); + $extraFields = []; + foreach ($config['fields'] as $i => $field) { + [$label, $fieldId] = explode(':', $field); + if (in_array($fieldId, ['email', 'phone'])) { + // Create a new field for every email/phone the user has + foreach ($profile as $profileField => $value) { + $pattern = "/^{$fieldId}_\d+$/"; + if (preg_match($pattern, $profileField)) { + $activation = in_array( + $fieldId, + $this->config['updateAddress']['contactInfoActivation'] ?? [] + ); + $extraField = [ + 'field' => $profileField, + 'label' => $label, + 'type' => 'text', + ]; + $extraFields[] = $extraField; + if ($activation) { + $extraActiveField = [ + 'field' => $profileField . '_active', + 'label' => $fieldId . '_active', + 'type' => 'boolean', + ]; + $extraFields[] = $extraActiveField; + } + } + } + unset($config['fields'][$i]); + } + } + $config['fields'] = array_merge($config['fields'], $extraFields); + } + return $config; + } + } } diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index 39e641223dc..d0c4196c88a 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -95,61 +95,23 @@ >
transEsc('password_only_numeric') ?>
- - $extraInfo) { - $attrs = [ - 'id' => $field, - 'name' => $field . '[' . $i . ']', - 'type' => $data['type'], - 'value' => $isEmail ? $extraInfo['email'] : $extraInfo['phone'], - 'class' => 'form-control', - ]; - $extraValues[] = [ - 'attrs' => $attrs, - 'active' => $extraInfo['active'] ?? false, - ]; - } + + $field, + 'name' => $field, + 'type' => $data['type'], + 'value' => $value, + 'class' => 'form-control', + ]; if ($data['required']) { $attrs['required'] = true; } if ($data['pattern']) { $attrs['pattern'] = $data['pattern']; } + echo $this->makeTag('input', '', $attrs); ?> - -
- - makeTag('input', '', $extraValue['attrs']); ?> - config['contactInfoActivation'] ?? [])): ?> -
- > - transEsc($field . '_active') ?> -
- -
- - - - $field, - 'name' => $field, - 'type' => $data['type'], - 'value' => $value, - 'class' => 'form-control', - ]; - if ($data['required']) { - $attrs['required'] = true; - } - if ($data['pattern']) { - $attrs['pattern'] = $data['pattern']; - } - echo $this->makeTag('input', '', $attrs); - ?> -
transEsc($data['hint'])?>
diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index e7907340932..8702e3b37aa 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -181,11 +181,14 @@
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
- - profile['extraPhones'])): ?> - profile['extraPhones'] as $i => $extraPhone): ?> -
transEsc('Phone') : ''?>
-
escapeHtml($extraPhone['phone']) ?>
+ profile['phone_0'])): ?> + + profile as $key => $value): ?> + +
transEsc('Phone') : ''?>
+
escapeHtml($value) ?>
+ + profile['smsnumber']) || $updateSmsNumber): ?> @@ -208,10 +211,14 @@
escapeHtml($this->profile['email']) ?>
- profile['extraEmails'])): ?> - profile['extraEmails'] as $i => $extraEmail): ?> -
transEsc('Email') : ''?>
-
escapeHtml($extraEmail['email']) ?>
+ profile['email_0'])): ?> + + profile as $key => $value): ?> + +
transEsc('Email') : ''?>
+
escapeHtml($value) ?>
+ + profile['hold_identifier'])): ?> From 26696b4abc639aec8e1a02eaf8061221c33b009c Mon Sep 17 00:00:00 2001 From: Ravila Date: Thu, 12 Dec 2024 13:36:59 +0200 Subject: [PATCH 15/18] undo unintended change --- .../finna2/templates/myresearch/change-address-settings.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index d0c4196c88a..cfeb715d12c 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -111,7 +111,7 @@ $attrs['pattern'] = $data['pattern']; } echo $this->makeTag('input', '', $attrs); - ?> + ?>
transEsc($data['hint'])?>
From e1d00985d9a706e53102ff1e4df90c7984e5730b Mon Sep 17 00:00:00 2001 From: Ravila Date: Thu, 12 Dec 2024 13:48:25 +0200 Subject: [PATCH 16/18] Fix getConfig --- module/Finna/src/Finna/ILS/Driver/Quria.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index c55097e23b1..73c01255c2c 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -1930,7 +1930,7 @@ public function renewMyItems($renewDetails) */ public function getConfig($function, $params = null) { - $config = parent::getConfig($function, $params); + $config = parent::getConfig($function); if ('updateAddress' === $function && isset($config['fields'])) { if (isset($params['patron'])) { $profile = $this->getMyProfile($params['patron']); @@ -1967,7 +1967,7 @@ public function getConfig($function, $params = null) } $config['fields'] = array_merge($config['fields'], $extraFields); } - return $config; } + return $config; } } From f67eda54707a642b90f37ebea6417acb74f42d28 Mon Sep 17 00:00:00 2001 From: Ravila Date: Thu, 12 Dec 2024 13:59:18 +0200 Subject: [PATCH 17/18] small .ini.sample tweak --- local/config/finna/Quria.ini.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local/config/finna/Quria.ini.sample b/local/config/finna/Quria.ini.sample index 844273c42f7..28ac14891d9 100644 --- a/local/config/finna/Quria.ini.sample +++ b/local/config/finna/Quria.ini.sample @@ -118,8 +118,8 @@ fields[] = Address:address1 fields[] = Zip:zip fields[] = City:city fields[] = Country:country -fields[] = Email:email fields[] = Phone:phone +fields[] = Email:email ;fields[] = Additional info:info ; Array of fields that can be set active/inactive From cb74875b8902ddfffb0709a1788d2d6ff43050e3 Mon Sep 17 00:00:00 2001 From: Ravila Date: Wed, 8 Jan 2025 16:34:39 +0200 Subject: [PATCH 18/18] requested changes --- local/languages/finna/en-gb.ini | 2 +- local/languages/finna/fi.ini | 2 +- local/languages/finna/sv.ini | 2 +- module/Finna/src/Finna/ILS/Driver/Quria.php | 22 +++++++++++---- .../finna2/templates/myresearch/profile.phtml | 28 +++++++------------ 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/local/languages/finna/en-gb.ini b/local/languages/finna/en-gb.ini index 054a4ee3200..3b30d84c4ce 100644 --- a/local/languages/finna/en-gb.ini +++ b/local/languages/finna/en-gb.ini @@ -883,7 +883,7 @@ Performers = "Performers" Performing Ensembles = "Performing Ensembles" Personal details maintained by the library = "Personal details maintained by the library" Phone = "Phone" -phone_active = "Use for SMS" +phone_use_for_sms = "Use for SMS" Photo Info = "Photo Info" pick_up_location = "Pickup Location" pickup_location_home_address = "Delivery to home address" diff --git a/local/languages/finna/fi.ini b/local/languages/finna/fi.ini index 152888d67a4..70f21694719 100644 --- a/local/languages/finna/fi.ini +++ b/local/languages/finna/fi.ini @@ -876,7 +876,7 @@ Performers = "Esiintyjät" Performing Ensembles = "Esiintyjäkokoonpanot" Personal details maintained by the library = "Kirjaston ylläpitämät henkilötiedot" Phone = "Puhelin" -phone_active = "Käytä tekstiviesteille" +phone_use_for_sms = "Käytä tekstiviesteille" Photo Info = "Kuvaustiedot" pickup_location_home_address = "Toimitus kotiosoitteeseen" pickup_location_work_address = "Toimitus työosoitteeseen" diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index 41d980bfae0..f9e9f0d28bf 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -873,7 +873,7 @@ Performers = "Uppträdare" Performing Ensembles = "Uppträdande ensembler" Personal details maintained by the library = "Personuppgifter som biblioteket upprätthåller" Phone = "Telefonnummer" -phone_active = "Använd för SMS" +phone_use_for_sms = "Använd för SMS" Photo Info = "Bildinformation" pick_up_location = "Hämtas från" pickup_location_home_address = "Leverans till hemadress" diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index 73c01255c2c..6ffd0e03b1a 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -667,7 +667,12 @@ public function patronLogin($username, $password) if (!empty($info->emailAddresses->emailAddress)) { $emailAddresses = $this->objectToArray($info->emailAddresses->emailAddress); + $activeFound = false; foreach ($emailAddresses as $i => $emailAddress) { + if (empty($userCached['email']) || !$activeFound) { + $userCached['email'] = $emailAddress->address; + $activeFound = $emailAddress->isActive == 'yes'; + } $userCached['email_' . $i] = $emailAddress->address ?? null; $userCached['email_' . $i . '_id'] = $emailAddress->id ?? null; $userCached['email_' . $i . '_active'] = $emailAddress->isActive == 'yes'; @@ -689,6 +694,11 @@ public function patronLogin($username, $password) if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); foreach ($phoneNumbers as $i => $phoneNumber) { + $activeFound = false; + if (empty($userCached['phone']) || !$activeFound) { + $userCached['phone'] = ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null; + $activeFound = $phoneNumber->sms->useForSms == 'yes'; + } $userCached['phone_' . $i] = ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null; $userCached['phone_' . $i . '_id'] = $phoneNumber->id ?? null; $userCached['phone_' . $i . '_active'] = ($phoneNumber->sms->useForSms ?? '') == 'yes'; @@ -1138,8 +1148,8 @@ public function updateAddress($patron, $details) || $user[$field . '_active'] !== $active ) { $result = $fieldName === 'email' - ? $this->updateEmail($patron, $detail, $ind, $active) - : $this->updatePhone($patron, $detail, $ind, $active); + ? $this->updateEmailAddress($patron, $detail, $ind, $active) + : $this->updatePhoneNumber($patron, $detail, $ind, $active); if (!$result['success']) { return $result; } @@ -1612,7 +1622,7 @@ public function placeHold($holdDetails) * * @return array Associative array of the results */ - public function updateEmail($patron, $email, $emailId = null, $active = false) + protected function updateEmailAddress($patron, $email, $emailId = null, $active = false) { if (empty($email) || $emailId === null) { return [ @@ -1707,7 +1717,7 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) * * @return array Associative array of the results */ - public function updatePhone($patron, $phone, $phoneId = null, $active = false) + protected function updatePhoneNumber($patron, $phone, $phoneId = null, $active = false) { if (empty($phone) || $phoneId === null) { return [ @@ -1955,7 +1965,9 @@ public function getConfig($function, $params = null) if ($activation) { $extraActiveField = [ 'field' => $profileField . '_active', - 'label' => $fieldId . '_active', + 'label' => $fieldId === 'email' + ? $fieldId . '_active' + : $fieldId . '_use_for_sms', 'type' => 'boolean', ]; $extraFields[] = $extraActiveField; diff --git a/themes/finna2/templates/myresearch/profile.phtml b/themes/finna2/templates/myresearch/profile.phtml index 8702e3b37aa..e02fd98ff5f 100644 --- a/themes/finna2/templates/myresearch/profile.phtml +++ b/themes/finna2/templates/myresearch/profile.phtml @@ -180,16 +180,12 @@
transEsc('Phone') ?>:
escapeHtml($this->profile['phone']) ?>
+ profile as $key => $value): ?> + profile['phone']): ?> +
escapeHtml($value) ?>
+ + - profile['phone_0'])): ?> - - profile as $key => $value): ?> - -
transEsc('Phone') : ''?>
-
escapeHtml($value) ?>
- - - profile['smsnumber']) || $updateSmsNumber): ?> @@ -210,16 +206,12 @@
escapeHtml($this->profile['email']) ?>
+ profile as $key => $value): ?> + profile['email']): ?> +
escapeHtml($value) ?>
+ + - profile['email_0'])): ?> - - profile as $key => $value): ?> - -
transEsc('Email') : ''?>
-
escapeHtml($value) ?>
- - - profile['hold_identifier'])): ?>
transEsc('Hold Identifier') ?>: