Add superuser new customer email notification preferences
This commit is contained in:
@@ -18,6 +18,8 @@ class users_o extends db
|
||||
{
|
||||
use db_object_t;
|
||||
|
||||
public const KEY_SUPERUSER_NEW_CUSTOMER_EMAIL_NOTIFICATIONS = 'superuser_new_customer_email_notifications_enabled';
|
||||
|
||||
public object_property $customer_number;
|
||||
public object_property $display_name;
|
||||
public object_property $group_id;
|
||||
@@ -436,6 +438,7 @@ class users_o extends db
|
||||
'sms_notifications_enabled' => (bool)$this->sms_notifications_enabled->value(),
|
||||
'email_notifications_enabled' => (bool)$this->email_notifications_enabled->value(),
|
||||
'wash_certificate_email' => $this->wash_certificate_email->value(),
|
||||
self::KEY_SUPERUSER_NEW_CUSTOMER_EMAIL_NOTIFICATIONS => $this->isSuperuserNewCustomerEmailNotificationsEnabled(),
|
||||
],
|
||||
'created_at' => $this->created_at->value(),
|
||||
'updated_at' => $this->updated_at->value(),
|
||||
@@ -831,6 +834,53 @@ class users_o extends db
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSuperuserNewCustomerEmailNotificationsEnabled(): bool
|
||||
{
|
||||
self::requireSelected();
|
||||
$value = $this->keys->setUser($this->id)->getValue(self::KEY_SUPERUSER_NEW_CUSTOMER_EMAIL_NOTIFICATIONS);
|
||||
return in_array(strtolower((string)$value), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
public function setSuperuserNewCustomerEmailNotificationsEnabled(bool $enabled): void
|
||||
{
|
||||
self::requireSelected();
|
||||
$this->keys->setUser($this->id)->setValue(
|
||||
self::KEY_SUPERUSER_NEW_CUSTOMER_EMAIL_NOTIFICATIONS,
|
||||
$enabled ? '1' : '0'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id:int, customer_number:int, display_name:string|null, email:string}>
|
||||
*/
|
||||
public function getSuperuserNewCustomerEmailNotificationRecipients(): array
|
||||
{
|
||||
global $db;
|
||||
|
||||
$key = $db->escape_string(self::KEY_SUPERUSER_NEW_CUSTOMER_EMAIL_NOTIFICATIONS);
|
||||
$sql = "
|
||||
SELECT DISTINCT
|
||||
u.id,
|
||||
u.customer_number,
|
||||
u.display_name,
|
||||
u.email
|
||||
FROM users u
|
||||
INNER JOIN user_key_value_pairs kv
|
||||
ON kv.user_id = u.id
|
||||
AND kv.var = '$key'
|
||||
AND LOWER(kv.val) IN ('1', 'true', 'yes', 'on')
|
||||
LEFT JOIN groups_permissions gp
|
||||
ON gp.group_id = u.group_id
|
||||
AND gp.permission = 'superuser'
|
||||
WHERE u.deleted_at IS NULL
|
||||
AND u.email IS NOT NULL
|
||||
AND u.email <> ''
|
||||
AND (u.group_id = 1 OR gp.id IS NOT NULL)
|
||||
";
|
||||
|
||||
return $db->fetch_all($db->query($sql));
|
||||
}
|
||||
|
||||
public function setOpenInvoiceDraft(int $draftInvoiceNumber): void
|
||||
{
|
||||
// Set the open invoice draft (key = 'open_invoice_draft')
|
||||
|
||||
Reference in New Issue
Block a user