Skip to content

Commit

Permalink
Merge pull request #868 from bakaphp/fix-notifications-settings
Browse files Browse the repository at this point in the history
add enabled status for all current channels
  • Loading branch information
rwhite27 authored May 14, 2024
2 parents 1af378f + 67356f2 commit 2c046a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Dto/Notifications/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ class UserSettings
public ?string $description = null;
public int $notifications_types_id;
public int $is_enabled = 1;
public int $is_email_enabled = 1;
public int $is_push_enabled = 1;
public int $is_realtime_enabled = 1;
public array $channels;
}
8 changes: 7 additions & 1 deletion src/Mapper/Notifications/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ class UserSettings extends CustomMapper
*/
public function mapToObject($userSettings, $userSettingsDto, array $context = [])
{
$decodedChannels = !empty($userSettings->channels) && isJson($userSettings->channels) ? json_decode($userSettings->channels, true) : [];

//decode channel json to determine if push. email or realtime are enabled
$userSettingsDto->users_id = $userSettings->users_id;
$userSettingsDto->notifications_types_id = $userSettings->notifications_types_id;
$userSettingsDto->name = $userSettings->notification->name;
$userSettingsDto->description = $userSettings->notification->description;
$userSettingsDto->is_enabled = $userSettings->is_enabled;
$userSettingsDto->channels = !empty($userSettings->channels) && isJson($userSettings->channels) ? json_decode($userSettings->channels, true) : [];
$userSettingsDto->is_email_enabled = (int)array_key_exists("email",$decodedChannels);
$userSettingsDto->is_push_enabled = (int)array_key_exists("push",$decodedChannels);
$userSettingsDto->is_realtime_enabled = (int)array_key_exists("realtime",$decodedChannels);
$userSettingsDto->channels = $decodedChannels;

return $userSettingsDto;
}
Expand Down

0 comments on commit 2c046a3

Please sign in to comment.