Skip to content

Commit

Permalink
add check if message type is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
catsoup11789 committed Jul 29, 2024
1 parent 522d510 commit 2ecb889
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/web/cron/sendILSNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$user = new User();
$user->id = $ilsMessage->userId;
if($user->find(true)) {
if($user->canReceiveNotifications('notifyAccount')) {
if($user->canReceiveNotifications('notifyAccount') && $user->canReceiveILSNotification($ilsMessage->type)) {
$tokens = $user->getNotificationPushToken();
foreach($tokens as $token => $patron) {
if($ilsMessage->title && $ilsMessage->content) {
Expand Down
25 changes: 25 additions & 0 deletions code/web/sys/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,31 @@ public function canReceiveNotifications($alertType): bool {
return false;
}

public function canReceiveILSNotification($code): bool {
$userHomeLocation = $this->homeLocationId;
$userLocation = new Location();
$userLocation->locationId = $this->homeLocationId;
if($userLocation->find(true)) {
$userLibrary = $userLocation->getParentLibrary();
if ($userLibrary) {
require_once ROOT_DIR . '/sys/AspenLiDA/NotificationSetting.php';
$settings = new NotificationSetting();
$settings->id = $userLibrary->lidaNotificationSettingId;
if ($settings->find(true)) {
$ilsMessageTypes = new ILSMessageType();
$ilsMessageTypes->ilsNotificationSettingId = $settings->ilsNotificationSettingId;
$ilsMessageTypes->code = $code;
$ilsMessageTypes->isEnabled = 1;
if($ilsMessageTypes->find(true)) {
return true;
}
}
}
}

return false;
}

public function saveNotificationPushToken($token, $device): bool {
require_once ROOT_DIR . '/sys/Account/UserNotificationToken.php';
$pushToken = new UserNotificationToken();
Expand Down

0 comments on commit 2ecb889

Please sign in to comment.