@@ -253,8 +253,8 @@ public function commentUpdate(Comment $original_comment, Comment $comment)
253253 */
254254 public function notificationResend (Request $ request )
255255 {
256- $ comment= Comment::findOrFail ($ request ->input ('comment_id ' ));
257- $ ticket= $ comment ->ticket ;
256+ $ comment = Comment::with ( ' notifications ' )-> findOrFail ($ request ->input ('comment_id ' ));
257+ $ ticket = $ comment ->ticket ;
258258 $ notification_owner = $ comment ->user ;
259259 $ template = 'panichd::emails.new_comment ' ;
260260 $ subject = trans ('panichd::lang.email-resend-abbr ' ) . trans ('panichd::lang.colon ' ) . $ this ->subject .$ ticket ->id . ' ' . trans ('panichd::email/globals.notify-new-note-by ' , ['name ' => $ comment ->user ->name ]) . trans ('panichd::lang.colon ' ) . $ ticket ->subject ;
@@ -265,30 +265,66 @@ public function notificationResend(Request $request)
265265 'notification_type ' => $ comment ->type
266266 ];
267267
268- $ a_to = [];
268+ if ( $ request -> has ( ' recipients ' )){
269269
270- if ($ request ->has ('to_agent ' )){
271- $ a_to [] = [
272- 'recipient ' => $ ticket ->agent ,
273- 'subject ' => $ subject ,
274- 'template ' => $ template
275- ];
276- }
277- if (!$ ticket ->hidden and $ request ->has ('to_owner ' ) and (!$ request ->has ('to_agent ' ) or ($ request ->has ('to_agent ' ) and $ ticket ->owner ->email !=$ ticket ->agent ->email ))){
278- $ a_to [] = [
279- 'recipient ' => $ ticket ->owner ,
280- 'subject ' => $ subject ,
281- 'template ' => $ template
282- ];
283- }
270+ foreach ($ request ->recipients as $ recipient_key ){
271+ // Search by member_id or by email address
272+ $ recipient = Member::where ('id ' , $ recipient_key )->orWhere ('email ' , $ recipient_key )->first ();
273+
274+ if (!is_null ($ recipient )){
275+ $ a_to [] = [
276+ 'recipient ' => $ recipient ,
277+ 'subject ' => $ subject ,
278+ 'template ' => $ template
279+ ];
280+
281+ $ notification = $ comment ->notifications ()->where ('member_id ' , $ recipient ->id )->first ();
282+ if (is_null ($ notification )){
283+ // Register the notified email
284+ $ notification = CommentNotification::create ([
285+ 'comment_id ' => $ comment ->id ,
286+ 'name ' => $ recipient ->name ,
287+ 'email ' => $ recipient ->email ,
288+ 'member_id ' => $ recipient ->id
289+ ]);
290+
291+ if ($ comment ->notifications ->count () == 0 ){
292+ // No previous registered notifications
293+ if ($ ticket ->agent ->id == $ comment ->owner ->id ){
294+ // Message from agent to owner, so we register the non registered past owner notification
295+ $ notification = CommentNotification::create ([
296+ 'comment_id ' => $ comment ->id ,
297+ 'name ' => $ ticket ->owner ->name ,
298+ 'email ' => $ ticket ->owner ->email ,
299+ 'member_id ' => $ ticket ->owner ->id
300+ ]);
301+ }elseif ($ ticket ->owner ->id == $ comment ->owner ->id ){
302+ // Message from owner to agent, so we register the non registered past agent notification
303+ $ notification = CommentNotification::create ([
304+ 'comment_id ' => $ comment ->id ,
305+ 'name ' => $ ticket ->agent ->name ,
306+ 'email ' => $ ticket ->agent ->email ,
307+ 'member_id ' => $ ticket ->agent ->id
308+ ]);
309+ }
310+ }
311+ }
312+ }
313+
314+
315+ }
316+ }
284317
285318 // Load $this->category for sendNotification
286319 $ this ->category = $ ticket ->category ;
287320
288321 // Send notifications
289- $ this ->sendNotification ($ a_to , $ data );
290-
291- return back ()->with ('status ' ,'Notificacions reenviades correctament ' );
322+ if (isset ($ a_to )){
323+ $ this ->sendNotification ($ a_to , $ data );
324+ return back ()->with ('status ' , trans ('panichd::lang.notification-resend-confirmation ' ));
325+ }else {
326+ return back ()->with ('warning ' , trans ('panichd::lang.notification-resend-no-recipients ' ));
327+ }
292328 }
293329
294330
0 commit comments