@@ -45,7 +45,10 @@ public function initialize()
45
45
public static function isEnabled (Apps $ app , UserInterface $ user , NotificationType $ notificationType ) : bool
46
46
{
47
47
$ 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 ' ,
49
52
'bind ' => [
50
53
'users_id ' => $ user ->getId (),
51
54
'apps_id ' => $ app ->getId (),
@@ -72,7 +75,10 @@ public static function isEnabled(Apps $app, UserInterface $user, NotificationTyp
72
75
public static function getByUserAndNotificationType (Apps $ app , UserInterface $ user , NotificationType $ notificationType ) : ?self
73
76
{
74
77
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 ' ,
76
82
'bind ' => [
77
83
'users_id ' => $ user ->getId (),
78
84
'apps_id ' => $ app ->getId (),
@@ -91,12 +97,27 @@ public static function getByUserAndNotificationType(Apps $app, UserInterface $us
91
97
*/
92
98
public function muteAll (Apps $ app , UserInterface $ user ) : bool
93
99
{
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 ;
100
121
}
101
122
102
123
/**
@@ -110,9 +131,10 @@ public function muteAll(Apps $app, UserInterface $user) : bool
110
131
*/
111
132
public static function listOfNotifications (Apps $ app , UserInterface $ user , int $ parent = 0 ) : array
112
133
{
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 ());
114
135
$ userNotificationList = [];
115
136
$ i = 0 ;
137
+
116
138
foreach ($ notificationType as $ notification ) {
117
139
$ userNotificationList [$ i ] = [
118
140
'name ' => $ notification ->name ,
0 commit comments