Skip to content

Commit c6ff64b

Browse files
authoredApr 24, 2022
Merge pull request #796 from bakaphp/fix-notification-mute-all
fix : mute all
2 parents 672c62a + f4e5c5e commit c6ff64b

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed
 

‎src/Models/Notifications/UserSettings.php

+31-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function initialize()
4545
public static function isEnabled(Apps $app, UserInterface $user, NotificationType $notificationType) : bool
4646
{
4747
$setting = self::findFirst([
48-
'conditions' => 'users_id = :users_id: AND apps_id = :apps_id: AND \notifications_types_id = :notifications_types_id: AND is_deleted = 0',
48+
'conditions' => 'users_id = :users_id:
49+
AND apps_id = :apps_id:
50+
AND \notifications_types_id = :notifications_types_id:
51+
AND is_deleted = 0',
4952
'bind' => [
5053
'users_id' => $user->getId(),
5154
'apps_id' => $app->getId(),
@@ -72,7 +75,10 @@ public static function isEnabled(Apps $app, UserInterface $user, NotificationTyp
7275
public static function getByUserAndNotificationType(Apps $app, UserInterface $user, NotificationType $notificationType) : ?self
7376
{
7477
return self::findFirst([
75-
'conditions' => 'users_id = :users_id: AND apps_id = :apps_id: AND \notifications_types_id = :notifications_types_id: AND is_deleted = 0',
78+
'conditions' => 'users_id = :users_id:
79+
AND apps_id = :apps_id:
80+
AND \notifications_types_id = :notifications_types_id:
81+
AND is_deleted = 0',
7682
'bind' => [
7783
'users_id' => $user->getId(),
7884
'apps_id' => $app->getId(),
@@ -91,12 +97,27 @@ public static function getByUserAndNotificationType(Apps $app, UserInterface $us
9197
*/
9298
public function muteAll(Apps $app, UserInterface $user) : bool
9399
{
94-
return $this->di->get('db')->prepare(
95-
'UPDATE users_notification_settings SET is_enabled = 0 WHERE users_id = :users_id AND apps_id = :apps_id AND is_deleted = 0',
96-
)->execute([
97-
'users_id' => $user->getId(),
98-
'apps_id' => $app->getId()
99-
]);
100+
$notificationTypes = NotificationType::find('is_published = 1 AND apps_id =' . $app->getId());
101+
102+
foreach ($notificationTypes as $notificationType) {
103+
self::updateOrCreate([
104+
'conditions' => 'users_id = :users_id:
105+
AND apps_id = :apps_id:
106+
AND \notifications_types_id = :notifications_types_id:',
107+
'bind' => [
108+
'users_id' => $user->getId(),
109+
'apps_id' => $notificationType->apps_id,
110+
'notifications_types_id' => $notificationType->getId(),
111+
],
112+
], [
113+
'is_enabled' => 0,
114+
'users_id' => $user->getId(),
115+
'apps_id' => $notificationType->apps_id,
116+
'notifications_types_id' => $notificationType->getId()
117+
]);
118+
}
119+
120+
return true;
100121
}
101122

102123
/**
@@ -110,9 +131,10 @@ public function muteAll(Apps $app, UserInterface $user) : bool
110131
*/
111132
public static function listOfNotifications(Apps $app, UserInterface $user, int $parent = 0) : array
112133
{
113-
$notificationType = NotificationType::find('is_published = 1 AND parent_id = ' . $parent . ' and apps_id =' . $app->getId());
134+
$notificationType = NotificationType::find('is_published = 1 AND parent_id = ' . $parent . ' AND apps_id =' . $app->getId());
114135
$userNotificationList = [];
115136
$i = 0;
137+
116138
foreach ($notificationType as $notification) {
117139
$userNotificationList[$i] = [
118140
'name' => $notification->name,

0 commit comments

Comments
 (0)
Please sign in to comment.