Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajaro committed Dec 12, 2024
1 parent ef2390f commit 5fcc4f7
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 137 deletions.
10 changes: 4 additions & 6 deletions local/config/finna/Quria.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <a href="%%link%%" target="_blank">online service of the organisation that provides it</a> (external link).'
external_rating_link_aoe_html = 'You can evaluate educational resources on the Library of Open Educational Resources website (<a href="%%link%%" target="_blank">aoe.fi</a>).'
extraEmails_active = "Active"
extraPhones_active = "Use for SMS"
facet_list_empty = "No data available"
Feedback = "Feedback"
feedback_captcha_answer = "55"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -343,8 +344,6 @@ external_link_kyppi_rpr = "Kohde rakennusperintörekisterissä"
external_online_link = "Ulkoinen linkki aineistoon"
external_rating_link_html = 'Voit arvioida oppimateriaaleja <a href="%%link%%" target="_blank">aineistontarjoajan omassa verkkopalvelussa</a> (ulkoinen linkki).'
external_rating_link_aoe_html = 'Voit arvioida oppimateriaaleja Avointen oppimateriaalien kirjaston sivustolla (<a href="%%link%%" target="_blank">aoe.fi</a>).'
extraEmails_active = "Aktiivinen"
extraPhones_active = "Käytä tekstiviesteille"
facet_list_empty = "Ei tietoja"
Feedback = "Palaute"
feedback_captcha_answer = "55"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <a href="%%link%%" target="_blank">leverantörens egen nättjänst</a> (extern länk).'
external_rating_link_aoe_html = 'Du kan utvärdera lärresurser på webbplatsen för Biblioteket för öppna lärresurser (<a href="%%link%%" target="_blank">aoe.fi</a>).'
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."
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions module/Finna/src/Finna/Controller/MyResearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
156 changes: 94 additions & 62 deletions module/Finna/src/Finna/ILS/Driver/Quria.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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';
}
}

Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -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'];

Expand All @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -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';
Expand Down Expand Up @@ -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);

Check failure on line 1933 in module/Finna/src/Finna/ILS/Driver/Quria.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method Finna\ILS\Driver\AxiellWebServices::getConfig() invoked with 2 parameters, 1 required.
if ('updateAddress' === $function && isset($config['fields'])) {

Check failure on line 1934 in module/Finna/src/Finna/ILS/Driver/Quria.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method Finna\ILS\Driver\Quria::getConfig() should return array but return statement is missing.
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;
}
}
}
Loading

0 comments on commit 5fcc4f7

Please sign in to comment.