Skip to content

Commit 9129723

Browse files
committed
Notification resend can reuse all sent notifications plus ticket owner and assigned agent
1 parent 729e77e commit 9129723

6 files changed

Lines changed: 116 additions & 40 deletions

File tree

src/Controllers/NotificationsController.php

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Controllers/TicketsController.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,44 @@ public function show($id)
13001300

13011301
$c_members = $this->members_collection($member, false);
13021302

1303+
// Recipients for notification resend
1304+
$a_resend_notifications = [];
1305+
foreach ($all_comments->get() as $comment){
1306+
if ($comment->type == 'reply'){
1307+
1308+
$a_comment_email_recipients = [$ticket->agent->email];
1309+
$a_resend_notifications[$comment->id][] = (object)[
1310+
'member_id' => $ticket->agent->id,
1311+
'email' => $ticket->agent->email,
1312+
'name' => $ticket->agent->name
1313+
];
1314+
1315+
if (!$ticket->hidden and $ticket->agent->email != $ticket->owner->email){
1316+
$a_comment_email_recipients[] = $ticket->owner->email;
1317+
$a_resend_notifications[$comment->id][] = (object)[
1318+
'member_id' => $ticket->owner->id,
1319+
'email' => $ticket->owner->email,
1320+
'name' => $ticket->owner->name
1321+
];
1322+
}
1323+
1324+
if (count($comment->notifications) > 0){
1325+
foreach ($comment->notifications as $notification){
1326+
if (!in_array($notification->email, $a_comment_email_recipients)){
1327+
$a_comment_email_recipients[] = $notification->email;
1328+
$a_resend_notifications[$comment->id][] = (object)[
1329+
'member_id' => $notification->member_id,
1330+
'email' => $notification->email,
1331+
'name' => $notification->name
1332+
];
1333+
}
1334+
}
1335+
}
1336+
}
1337+
}
1338+
13031339
$data = compact('ticket', 'a_reasons', 'a_tags_selected', 'status_lists', 'complete_status_list', 'agent_lists', 'tag_lists',
1304-
'comments', 'a_notifications', 'c_members', 'close_perm', 'reopen_perm');
1340+
'comments', 'a_notifications', 'c_members', 'a_resend_notifications', 'close_perm', 'reopen_perm');
13051341
$data['menu'] = 'show';
13061342
return view('panichd::tickets.show', $data);
13071343
}

src/Translations/ca/lang.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@
327327
'show-ticket-delete-comment' => 'Eliminar comentari',
328328
'show-ticket-delete-comment-msg' => 'Estàs segur que vols eliminar aquest comentari?',
329329
'show-ticket-email-resend' => 'Reenviar notificacions',
330-
'show-ticket-email-resend-user' => 'A l\'usuari: ',
331-
'show-ticket-email-resend-agent' => 'Al tècnic: ',
330+
'show-ticket-email-resend-agent' => '(Tècnic del tiquet)',
331+
'show-ticket-email-resend-owner' => '(Propietari del tiquet)',
332+
'notification-resend-confirmation' => 'Notificacions reenviades correctament',
333+
'notification-resend-no-recipients'=> 'No s\'ha marcat cap destinatari',
332334

333335
// Validacions
334336
'validation-error' => 'Aquest formulari no s\'ha enviat',

src/Translations/en/lang.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@
327327
'show-ticket-delete-comment' => 'Delete comment',
328328
'show-ticket-delete-comment-msg' => 'Are you sure you want to delete this comment?',
329329
'show-ticket-email-resend' => 'Resend email',
330-
'show-ticket-email-resend-user' => 'To user: ',
331-
'show-ticket-email-resend-agent' => 'To agent: ',
330+
'show-ticket-email-resend-agent' => '(Ticket agent)',
331+
'show-ticket-email-resend-owner' => '(Ticket owner)',
332+
'notification-resend-confirmation' => 'Notifications were correctly resended',
333+
'notification-resend-no-recipients'=> 'No recipients were selected',
332334

333335
// Validations
334336
'validation-error' => 'This form has not been sent',

src/Translations/pt_BR/lang.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@
404404

405405
'show-ticket-email-resend' => 'Reenviar email',
406406

407-
'show-ticket-email-resend-user' => 'Ao usuário:',
407+
'show-ticket-email-resend-agent' => '(Agente do ticket)',
408408

409-
'show-ticket-email-resend-agent' => 'Para agente:',
409+
'show-ticket-email-resend-owner' => '(Usuário do ticket)',
410410

411411
'validation-error' => 'Este formulário não foi enviado',
412412

src/Views/tickets/partials/comments/modal_resend_emails.blade.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
</div>
1010
<div class="modal-body">
1111
<fieldset>
12-
<div class="form-group row">
13-
<div class="col-lg-12">
14-
<label><input type="checkbox" name="to_agent" value="yes"> {{ trans('panichd::lang.show-ticket-email-resend-agent') . $ticket->agent->name}}</label>
15-
</div>
16-
</div>
17-
@if(!$ticket->hidden)
18-
<div class="form-group row">
19-
<div class="col-lg-12">
20-
<label><input type="checkbox" name="to_owner" value="yes" checked="checked"> {{ trans('panichd::lang.show-ticket-email-resend-user') }}<span id="owner"></span></label>
21-
</div>
22-
</div>
23-
@endif
24-
<div class="text-right col-md-12">
12+
@foreach($a_resend_notifications[$comment->id] as $recipient)
13+
<div class="form-group form-check">
14+
<label><input type="checkbox" class="form-check-input" name="recipients[]" value="{{ ($recipient->member_id == "" ? $recipient->email : $recipient->member_id) }}"> {{ $recipient->name . ' - ' . $recipient->email }}
15+
@if($recipient->email == $ticket->agent->email)
16+
{{ trans('panichd::lang.show-ticket-email-resend-agent') }}
17+
@elseif($recipient->email == $ticket->owner->email)
18+
{{ trans('panichd::lang.show-ticket-email-resend-owner') }}
19+
@endif
20+
</label>
21+
</div>
22+
@endforeach
23+
24+
<div class="text-right">
2525
{!! CollectiveForm::submit( trans('panichd::lang.btn-submit'), ['class' => 'btn btn-primary']) !!}
2626
</div>
2727

0 commit comments

Comments
 (0)