Skip to content

Commit

Permalink
[FINNA-2235] Quria: Add support for multiple emails/phone numbers (#3022
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rajaro authored Jan 15, 2025
1 parent 804eb79 commit c753aba
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 46 deletions.
8 changes: 6 additions & 2 deletions local/config/finna/Quria.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ fields[] = Address:address1
fields[] = Zip:zip
fields[] = City:city
fields[] = Country:country
;fields[] = Phone:phone
;fields[] = Email:email
fields[] = Phone:phone
fields[] = Email:email
;fields[] = Additional info:info

; Array of fields that can be set active/inactive
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
Expand Down
2 changes: 2 additions & 0 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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"
Expand Down Expand Up @@ -887,6 +888,7 @@ Performers = "Performers"
Performing Ensembles = "Performing Ensembles"
Personal details maintained by the library = "Personal details maintained by the library"
Phone = "Phone"
phone_use_for_sms = "Use for SMS"
Photo Info = "Photo Info"
pick_up_location = "Pickup Location"
pickup_location_home_address = "Delivery to home address"
Expand Down
2 changes: 2 additions & 0 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,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"
Expand Down Expand Up @@ -880,6 +881,7 @@ Performers = "Esiintyjät"
Performing Ensembles = "Esiintyjäkokoonpanot"
Personal details maintained by the library = "Kirjaston ylläpitämät henkilötiedot"
Phone = "Puhelin"
phone_use_for_sms = "Käytä tekstiviesteille"
Photo Info = "Kuvaustiedot"
pickup_location_home_address = "Toimitus kotiosoitteeseen"
pickup_location_work_address = "Toimitus työosoitteeseen"
Expand Down
2 changes: 2 additions & 0 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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"
Expand Down Expand Up @@ -877,6 +878,7 @@ Performers = "Uppträdare"
Performing Ensembles = "Uppträdande ensembler"
Personal details maintained by the library = "Personuppgifter som biblioteket upprätthåller"
Phone = "Telefonnummer"
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"
Expand Down
177 changes: 133 additions & 44 deletions module/Finna/src/Finna/ILS/Driver/Quria.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,15 @@ public function patronLogin($username, $password)
if (!empty($info->emailAddresses->emailAddress)) {
$emailAddresses
= $this->objectToArray($info->emailAddresses->emailAddress);
foreach ($emailAddresses as $emailAddress) {
if ($emailAddress->isActive == 'yes' || empty($userCached['email'])) {
$userCached['email'] = $emailAddress->address ?? '';
$userCached['emailId'] = $emailAddress->id ?? '';
break;
$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';
}
}
if (isset($info->addresses->address)) {
Expand All @@ -691,19 +694,15 @@ public function patronLogin($username, $password)
}
if (isset($info->phoneNumbers->phoneNumber)) {
$phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber);
foreach ($phoneNumbers as $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;
}
break;
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';
}
}

Expand Down Expand Up @@ -1126,34 +1125,42 @@ 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
*
* @return array Associative array of the results
*/
public function updateAddress($patron, $details)
{
if (isset($details['email'])) {
$result = $this->updateEmail($patron, $details['email']);
if (!$result['success']) {
return $result;
}
}
$user = $this->getMyProfile($patron);

if (isset($details['phone'])) {
$result = $this->updatePhone($patron, $details['phone']);
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->updateEmailAddress($patron, $detail, $ind, $active)
: $this->updatePhoneNumber($patron, $detail, $ind, $active);
if (!$result['success']) {
return $result;
}
}
}
}

$username = $patron['cat_username'];
$password = $patron['cat_password'];

$user = $this->getMyProfile($patron);

$conf = [
'arenaMember' => $this->arenaMember,
'language' => $this->getLanguage(),
Expand Down Expand Up @@ -1607,15 +1614,33 @@ 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 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)
protected function updateEmailAddress($patron, $email, $emailId = null, $active = false)
{
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'];

Expand All @@ -1637,11 +1662,10 @@ public function updateEmail($patron, $email)
'password' => $password,
'patronId' => $patron['patronId'],
'address' => $email,
'isActive' => 'yes',
'isActive' => $active ? 'yes' : 'no',
];

if (!empty($user['email'])) {
$conf['id'] = $user['emailId'];
if (!empty($user['email_0'])) {
$conf['id'] = $user['email_' . $emailId . '_id'] ?? '';
$function = 'changeEmail';
$functionResult = 'changeEmailAddressResult';
$functionParam = 'changeEmailAddressParam';
Expand Down Expand Up @@ -1685,15 +1709,24 @@ 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
* @param bool $active Whether to set the phone active
*
* @throws ILSException
*
* @return array Associative array of the results
*/
public function updatePhone($patron, $phone)
protected function updatePhoneNumber($patron, $phone, $phoneId = null, $active = false)
{
if (empty($phone) || $phoneId === null) {
return [
'success' => true,
'status' => 'No data to update',
'sys_message' => '',
];
}
$username = $patron['cat_username'];
$password = $patron['cat_password'];
$user = $this->getMyProfile($patron);
Expand All @@ -1711,11 +1744,11 @@ public function updatePhone($patron, $phone)
'areaCode' => '',
'country' => $user['phoneCountry'] ?? 'FI',
'localCode' => $phone,
'useForSms' => 'yes',
'useForSms' => $active ? 'yes' : 'no',
];

if (!empty($user['phone'])) {
$conf['id'] = $user['phoneId'];
if (!empty($user['phone_0'])) {
$conf['id'] = $user['phone_' . $phoneId . '_id'] ?? '';
$function = 'changePhone';
$functionResult = 'changePhoneNumberResult';
$functionParam = 'changePhoneNumberParam';
Expand Down Expand Up @@ -1894,4 +1927,60 @@ 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);
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 === 'email'
? $fieldId . '_active'
: $fieldId . '_use_for_sms',
'type' => 'boolean',
];
$extraFields[] = $extraActiveField;
}
}
}
unset($config['fields'][$i]);
}
}
$config['fields'] = array_merge($config['fields'], $extraFields);
}
}
return $config;
}
}
10 changes: 10 additions & 0 deletions themes/finna2/templates/myresearch/profile.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@
<?php else: ?>
<div class="my-profile-col profile-title"><?=$this->transEsc('Phone') ?>:</div>
<div class="profile-text-value"><?=$this->escapeHtml($this->profile['phone']) ?></div>
<?php foreach ($this->profile as $key => $value): ?>
<?php if (preg_match('/^phone_\d+$/', $key) && $value !== $this->profile['phone']): ?>
<div class="my-profile-col profile-title"></div><div class="profile-text-value"><?=$this->escapeHtml($value) ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php if (!empty($this->profile['smsnumber']) || $updateSmsNumber): ?>
Expand All @@ -201,6 +206,11 @@
</div>
<?php else: ?>
<div class="profile-text-value"><?=$this->escapeHtml($this->profile['email']) ?></div>
<?php foreach ($this->profile as $key => $value): ?>
<?php if (preg_match('/^email_\d+$/', $key) && $value !== $this->profile['email']): ?>
<div class="my-profile-col profile-title"></div><div class="profile-text-value"><?=$this->escapeHtml($value) ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php if (!empty($this->profile['hold_identifier'])): ?>
Expand Down

0 comments on commit c753aba

Please sign in to comment.