diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de32d4..230cbef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- Updated `os2forms_fbs_handler` to include and correct set phone number [#161](https://github.com/OS2Forms/os2forms/pull/161) + ## [3.22.0] 2025-02-03 - Removed modules ldap_auth, logging_alerts, maillog [#151](https://github.com/OS2Forms/os2forms/pull/151) diff --git a/modules/os2forms_fbs_handler/src/Client/FBS.php b/modules/os2forms_fbs_handler/src/Client/Fbs.php similarity index 95% rename from modules/os2forms_fbs_handler/src/Client/FBS.php rename to modules/os2forms_fbs_handler/src/Client/Fbs.php index 66c38b4..3cef598 100644 --- a/modules/os2forms_fbs_handler/src/Client/FBS.php +++ b/modules/os2forms_fbs_handler/src/Client/Fbs.php @@ -11,7 +11,7 @@ /** * Minimalistic client to create user with guardians at FBS. */ -class FBS { +class Fbs { /** * FBS session key. @@ -118,8 +118,14 @@ public function createPatronWithGuardian(Patron $patron, Guardian $guardian) { 'pincode' => $patron->pincode, 'preferredPickupBranch' => $patron->preferredPickupBranch, 'name' => 'Unknown Name', - 'emailAddresses' => $patron->emailAddresses, + 'emailAddresses' => $patron->emailAddresses ?? [], 'guardian' => $guardian->toArray(), + 'phoneNumbers' => $patron->phoneNumber ? [ + [ + 'receiveNotification' => TRUE, + 'phoneNumber' => $patron->phoneNumber, + ], + ] : [], ]; return $this->request($uri, $payload); @@ -148,12 +154,13 @@ public function getPatron(string $patronId): ?Patron { (bool) $json->patron->receiveSms, (bool) $json->patron->receivePostalMail, $json->patron->notificationProtocols, - $json->patron->phoneNumber, is_null($json->patron->onHold) ? $json->patron->onHold : (array) $json->patron->onHold, $json->patron->preferredLanguage, (bool) $json->patron->guardianVisibility, $json->patron->defaultInterestPeriod, (bool) $json->patron->resident, + $json->patron->phoneNumber, + [ [ 'emailAddress' => $json->patron->emailAddress, @@ -185,15 +192,15 @@ public function updatePatron(Patron $patron): bool { $payload = [ 'patron' => [ 'preferredPickupBranch' => $patron->preferredPickupBranch, - 'emailAddresses' => $patron->emailAddresses, + 'emailAddresses' => $patron->emailAddresses ?? [], 'guardianVisibility' => $patron->guardianVisibility, 'receivePostalMail' => $patron->receiveEmail, - 'phoneNumbers' => [ + 'phoneNumbers' => $patron->phoneNumber ? [ [ 'receiveNotification' => TRUE, 'phoneNumber' => $patron->phoneNumber, ], - ], + ] : [], ], 'pincodeChange' => [ 'pincode' => $patron->pincode, diff --git a/modules/os2forms_fbs_handler/src/Client/Model/Patron.php b/modules/os2forms_fbs_handler/src/Client/Model/Patron.php index db3e1d0..448b26d 100644 --- a/modules/os2forms_fbs_handler/src/Client/Model/Patron.php +++ b/modules/os2forms_fbs_handler/src/Client/Model/Patron.php @@ -19,13 +19,13 @@ public function __construct( public readonly ?bool $receiveSms = FALSE, public readonly ?bool $receivePostalMail = FALSE, public readonly ?array $notificationProtocols = NULL, - public readonly ?string $phoneNumber = NULL, public readonly ?array $onHold = NULL, public readonly ?string $preferredLanguage = NULL, public readonly ?bool $guardianVisibility = NULL, public readonly ?int $defaultInterestPeriod = NULL, public readonly ?bool $resident = NULL, // Allow these properties below to be updatable. + public ?string $phoneNumber = NULL, public ?array $emailAddresses = NULL, public ?bool $receiveEmail = NULL, public ?string $preferredPickupBranch = NULL, diff --git a/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php index d5de9af..4fca0d6 100644 --- a/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php +++ b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php @@ -8,7 +8,7 @@ use Drupal\advancedqueue\Job; use Drupal\advancedqueue\JobResult; use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase; -use Drupal\os2forms_fbs_handler\Client\FBS; +use Drupal\os2forms_fbs_handler\Client\Fbs; use Drupal\os2forms_fbs_handler\Client\Model\Guardian; use Drupal\os2forms_fbs_handler\Client\Model\Patron; use Drupal\os2web_audit\Service\Logger; @@ -84,7 +84,7 @@ public function process(Job $job): JobResult { $config = $payload['configuration']; try { - $fbs = new FBS($this->client, $config['endpoint_url'], $config['agency_id'], $config['username'], $config['password']); + $fbs = new Fbs($this->client, $config['endpoint_url'], $config['agency_id'], $config['username'], $config['password']); // Log into FBS and obtain session. $fbs->login(); @@ -110,12 +110,17 @@ public function process(Job $job): JobResult { if (!is_null($patron)) { // Create Patron object with updated values. $patron->preferredPickupBranch = $data['afhentningssted']; - $patron->emailAddresses = [ - [ - 'emailAddress' => $data['barn_mail'], - 'receiveNotification' => TRUE, - ], - ]; + if (!empty($data['barn_mail'])) { + $patron->emailAddresses = [ + [ + 'emailAddress' => $data['barn_mail'], + 'receiveNotification' => TRUE, + ], + ]; + } + if (!empty($data['barn_tlf'])) { + $patron->phoneNumber = $data['barn_tlf']; + } $patron->receiveEmail = TRUE; $patron->pincode = $data['pinkode']; @@ -127,15 +132,20 @@ public function process(Job $job): JobResult { // If "no" create child patron and guardian. $patron = new Patron(); $patron->preferredPickupBranch = $data['afhentningssted']; - $patron->emailAddresses = [ - [ - 'emailAddress' => $data['barn_mail'], - 'receiveNotification' => TRUE, - ], - ]; + if (!empty($data['barn_mail'])) { + $patron->emailAddresses = [ + [ + 'emailAddress' => $data['barn_mail'], + 'receiveNotification' => TRUE, + ], + ]; + } $patron->receiveEmail = TRUE; $patron->personId = $data['barn_cpr']; $patron->pincode = $data['pinkode']; + if (!empty($data['barn_tlf'])) { + $patron->phoneNumber = $data['barn_tlf']; + } $fbs->createPatronWithGuardian($patron, $guardian); } diff --git a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php index 1c2abad..aa1ae33 100644 --- a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php +++ b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php @@ -183,6 +183,7 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update 'afhentningssted', 'barn_cpr', 'barn_mail', + 'barn_tlf', 'cpr', 'email', 'navn',