@@ -149,14 +149,27 @@ public function sendNotification($account_id, $strType, $aMailData) {
149
149
return false ;
150
150
}
151
151
// Check if this user wants strType notifications
152
- $ stmt = $ this ->mysqli ->prepare ("SELECT account_id FROM $ this ->tableSettings WHERE type = ? AND active = 1 AND account_id = ? " );
153
- if ($ stmt && $ stmt ->bind_param ('si ' , $ strType , $ account_id ) && $ stmt ->execute () && $ stmt ->bind_result ($ id ) && $ stmt ->fetch ()) {
154
- if ($ stmt ->close () && $ this ->sendMail ('notifications/ ' . $ strType , $ aMailData ) && $ this ->addNotification ($ account_id , $ strType , $ aMailData )) {
155
- return true ;
156
- } else {
157
- $ this ->setErrorMessage ('SendMail call failed: ' . $ this ->getError ());
158
- return false ;
159
- }
152
+ $ stmt = $ this ->mysqli ->prepare ("SELECT type FROM $ this ->tableSettings WHERE type IN (?, ?) AND active = 1 AND account_id = ? " );
153
+ if ($ stmt && $ stmt ->bind_param ('ssi ' , $ strType , substr ('push_ ' .$ strType , 0 , 15 ), $ account_id ) && $ stmt ->execute () && $ result = $ stmt ->get_result ()) {
154
+ $ types = array_map (function ($ a ){ return reset ($ a );}, $ result ->fetch_all (MYSQLI_ASSOC ));
155
+ $ stmt ->close ();
156
+ $ result = true ;
157
+ foreach ($ types as $ type ){
158
+ if (strpos ($ type , 'push_ ' ) === 0 ){
159
+ if (PushNotification::Instance () instanceof PushNotification){
160
+ $ result &= PushNotification::Instance ()->sendNotification ($ account_id , $ strType , $ aMailData );
161
+ }
162
+ } else {
163
+ $ result &= $ this ->sendMail ('notifications/ ' . $ strType , $ aMailData );
164
+ }
165
+ }
166
+ if ($ result ){
167
+ $ this ->addNotification ($ account_id , $ strType , $ aMailData );
168
+ return true ;
169
+ } else {
170
+ $ this ->setErrorMessage ('SendMail call failed: ' . $ this ->getError ());
171
+ return false ;
172
+ }
160
173
} else {
161
174
$ this ->setErrorMessage ('User disabled ' . $ strType . ' notifications ' );
162
175
return true ;
0 commit comments