Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FINNA-2235] Quria: Add support for multiple emails/phone numbers #3022

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions module/Finna/src/Finna/Controller/MyResearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,27 @@ protected function processLibraryDataUpdate($patron, $values)
}
}
}
// Update extra emails
if (isset($values->profile_extra_email) && isset($values->profile_extra_email_id)) {
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
foreach ($values->profile_extra_email as $i => $extraEmail) {
$validator = new \Laminas\Validator\EmailAddress();
if (
$validator->isValid($extraEmail)
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
&& $catalog->checkFunction('updateEmail', compact('patron'))
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
&& !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)
Expand All @@ -1514,6 +1535,22 @@ 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(
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
$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)
Expand Down
80 changes: 60 additions & 20 deletions module/Finna/src/Finna/ILS/Driver/Quria.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} elseif ($emailActive) {
$userCached['extraEmails'][]
= [
'email' => $emailAddress->address ?? '',
'emailId' => $emailAddress->id ?? '',
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
];
}
}
}
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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 = '';
Expand All @@ -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';
Expand Down Expand Up @@ -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 = '';
Expand All @@ -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';
Expand Down
17 changes: 17 additions & 0 deletions themes/finna2/templates/myresearch/profile.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
<div>
<input class="form-control" type="tel" name="profile_tel" value="<?=empty($this->profile['phone']) ? '' : $this->escapeHtmlAttr($this->profile['phone']) ?>" title="<?=$this->transEscAttr('Phone') ?>">
</div>
<?php if (!empty($this->profile['extraPhones'])): ?>
<?php foreach ($this->profile['extraPhones'] as $i => $extraPhone): ?>
<div class="my-profile-col profile-title"></div>
<div>
<input class="form-control" type="tel" name="profile_extra_tel[<?=$i?>]" value="<?=empty($extraPhone['phone']) ? '' : $this->escapeHtmlAttr($extraPhone['phone']) ?>" title="<?=$this->transEscAttr('SMS Number') ?>">
<input class="form-control" type="hidden" name="profile_extra_tel_id[<?=$i?>]" value="<?=empty($extraPhone['phoneId']) ? '' : $this->escapeHtmlAttr($extraPhone['phoneId'])?>">
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php else: ?>
<div class="my-profile-col profile-title"><?=$this->transEsc('Phone') ?>:</div>
<div class="profile-text-value"><?=$this->escapeHtml($this->profile['phone']) ?></div>
Expand All @@ -199,6 +208,14 @@
<div>
<input class="form-control" type="email" name="profile_email" value="<?=empty($this->profile['email']) ? '' : $this->escapeHtmlAttr($this->profile['email']) ?>" title="<?=$this->transEscAttr('Email') ?>">
</div>
<?php if (!empty($this->profile['extraEmails'])): ?>
<?php foreach ($this->profile['extraEmails'] as $i => $extraEmail): ?>
<div>
<div class="my-profile-col profile-title"></div><input class="form-control profile-extra-email" type="email" name="profile_extra_email[<?=$i?>]" value="<?=empty($extraEmail['email']) ? '' : $this->escapeHtmlAttr($extraEmail['email']) ?>" title="<?=$this->transEscAttr('Email') ?>">
<input type="hidden" class="form-control" type="email_id" name="profile_extra_email_id[<?=$i?>]" value="<?=empty($extraEmail['emailId']) ? '' : $this->escapeHtmlAttr($extraEmail['emailId']) ?>">
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php else: ?>
<div class="profile-text-value"><?=$this->escapeHtml($this->profile['email']) ?></div>
<?php endif; ?>
Expand Down
Loading