Add methods to handle user notification preferences and update booking notification logic

- Introduced `wantsSmsNotifications`, `wantsEmailNotifications`, and `getWashCertificateEmail` methods in `users_o`.
- Updated `order_bookings_o` to incorporate user notification preferences for sending SMS and email confirmations.
This commit is contained in:
Jeppe Bundgaard
2025-11-11 14:48:32 +01:00
parent eca3b79f26
commit 8b2aa76070
2 changed files with 33 additions and 3 deletions
@@ -135,11 +135,13 @@ class order_bookings_o extends db
// Check if the customer has a phone number
$country_code = $customer->phone_country_code->value();
$customer_phone = $customer->phone->value();
$customer_email = $customer->email->value();
$customer_email = !empty($customer->wash_certificate_email->value())
? $customer->wash_certificate_email->value()
: $customer->email->value();
if (empty($customer_phone) && empty($customer_email)) {
return;
}
if (!empty($customer_phone)) {
if (!empty($customer_phone) && $customer->wantsSmsNotifications()) {
// Send an SMS confirmation to the customer
$gatewayapi = new gatewayapi();
$message = "Tak for din booking hos " . $branding->name->value() . ". Dit bookingnummer er " . $this->id . ". "
@@ -164,7 +166,7 @@ class order_bookings_o extends db
}
}
// Check if the customer has an email
if (!empty($customer_email)) {
if (!empty($customer_email) && $customer->wantsEmailNotifications()) {
// Send an email confirmation to the customer
$email = new email();
$email->sendOrderBookingConfirmationEmail($this);
+28
View File
@@ -176,6 +176,34 @@ class users_o extends db
return false;
}
/**
* @throws Exception
*/
public function wantsSmsNotifications(): bool
{
self::requireSelected();
return (bool)$this->sms_notifications_enabled->value();
}
/**
* @throws Exception
*/
public function wantsEmailNotifications(): bool
{
self::requireSelected();
return (bool)$this->email_notifications_enabled->value();
}
/**
* @throws Exception
*/
public function getWashCertificateEmail(): string|null
{
self::requireSelected();
return $this->wash_certificate_email->value();
}
public function add(string $customer_number, mixed $password, int $role = 0): void
{
global $db;