Skip to content

Commit 12550b6

Browse files
committed
View comment recipients
1 parent f9c481f commit 12550b6

5 files changed

Lines changed: 57 additions & 24 deletions

File tree

src/Models/Comment.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PanicHD\PanicHD\Models;
44

5+
use DB;
56
use Illuminate\Database\Eloquent\Collection;
67
use Illuminate\Database\Eloquent\Model;
78
use PanicHD\PanicHD\Traits\ContentEllipse;
@@ -11,7 +12,7 @@ class Comment extends Model
1112
use ContentEllipse;
1213

1314
protected $table = 'panichd_comments';
14-
15+
1516
/**
1617
* All of the relationships to be touched.
1718
*
@@ -25,18 +26,21 @@ class Comment extends Model
2526
public function delete()
2627
{
2728
$a_errors = [];
28-
foreach($this->attachments()->get() as $att){
29+
// Delete attachments
30+
foreach($this->attachments()->get() as $att){
2931
$error = $att->delete();
3032
if($error) $a_errors[] = $error;
3133
}
32-
34+
35+
// Delete notifications
36+
\DB::table('panichd_comment_email')->where('comment_id', $this->id)->delete();
37+
3338
$error = $a_errors ? implode('. ', $a_errors) : null;
3439
if ($error != "") return $error;
35-
40+
3641
parent::delete();
3742
}
38-
39-
43+
4044
/**
4145
* Get related ticket.
4246
*
@@ -57,7 +61,7 @@ public function user()
5761
{
5862
return $this->belongsTo('\PanicHDMember', 'user_id');
5963
}
60-
64+
6165
/**
6266
* Get Comment owner as PanicHDMember model
6367
*
@@ -72,24 +76,34 @@ public function attachments()
7276
{
7377
return $this->hasMany(Attachment::class, 'comment_id')->orderByRaw('CASE when mimetype LIKE "image/%" then 1 else 2 end');
7478
}
75-
79+
7680
/**
7781
* Filter visible comments depending on member level
7882
*/
7983
public function scopeForLevel($query, $level)
8084
{
8185
// User level
8286
if ($level < 2) return $query->whereIN('type', ['reply', 'complete', 'completetx', 'reopen']);
83-
87+
8488
// For agent or admin
8589
return $query;
8690
}
87-
91+
8892
/**
8993
* Filter comment entries that are countable as real comments (complete and reopen comments are excluded)
9094
*/
9195
public function scopeCountable($query)
9296
{
9397
return $query->whereIN('type', ['reply', 'note', 'completetx']);
9498
}
99+
100+
/**
101+
* Get emails | members whom notifications have been sent.
102+
*
103+
* Return @collection
104+
*/
105+
public function getNotifications()
106+
{
107+
return \DB::table('panichd_comment_email')->where('comment_id', $this->id)->orderBy('name')->get();
108+
}
95109
}

src/Translations/ca/lang.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,13 @@
297297
// Comentaris
298298
'comment' => 'Comentari',
299299
'note' => 'Nota interna',
300-
'comment-reply-title' => 'Missatges entre el propietari i els tècnics',
300+
'comment-reply-title' => 'Missatge visibles pels usuaris',
301301
'comment-reply-from-owner' => 'Resposta de <b>:owner</b>',
302-
'reply-from-owner-to-owner' => 'Resposta de <b>:owner1</b> a <b>:owner2</b>',
302+
'reply-from-owner-to' => 'Resposta de <b>:owner</b> a <b>:recipients</b>',
303303

304304
'comment-note-title' => 'Nota oculta per a l\'usuari',
305305
'comment-note-from-agent' => 'Nota de <b>:agent</b>',
306+
'comment-note-from-agent-to' => 'Nota de <b>:agent</b> a <b>:recipients</b>',
306307

307308
'comment-completetx-title' => 'Tiquet tancat',
308309
'comment-complete-by' => 'Tancat per <b>:owner</b>',

src/Translations/en/lang.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,13 @@
297297
// Comments
298298
'comment' => 'Comment',
299299
'note' => 'Internal note',
300-
'comment-reply-title' => 'Messages between owner and agents',
300+
'comment-reply-title' => 'Message visible for users',
301301
'comment-reply-from-owner' => 'Reply from <b>:owner</b>',
302-
'reply-from-owner-to-owner' => 'Reply from <b>:owner1</b> to <b>:owner2</b>',
302+
'reply-from-owner-to' => 'Reply from <b>:owner</b> to <b>:recipients</b>',
303303

304304
'comment-note-title' => 'User hidden note',
305305
'comment-note-from-agent' => 'Note from <b>:agent</b>',
306+
'comment-note-from-agent-to' => 'Note from <b>:agent</b> to <b>:recipients</b>',
306307

307308
'comment-completetx-title' => 'Ticket complete',
308309
'comment-complete-by' => 'Tancat per <b>:owner</b>',

src/Translations/pt_BR/lang.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return [
44

5-
5+
66
'nav-new-tickets' => 'Novo',
77

88
'nav-new-tickets-title' => 'Novos tickets',
@@ -167,10 +167,10 @@
167167
'date-format' => 'Y-m-d',
168168

169169
'datetime-format' => 'Y-m-d H: i',
170-
170+
171171
'datetimepicker-format' => 'YYYY-MM-DD HH: mm',
172172

173-
173+
174174
'department' => 'Departamento',
175175

176176
'department-shortening' => 'Dept.',
@@ -360,11 +360,11 @@
360360

361361
'ticket-hidden-1-comment' => 'O boletim é agora <b> escondido </b> para proprietário',
362362

363-
'comment-reply-title' => 'Mensagens entre dono e agentes',
363+
'comment-reply-title' => 'Mensage visível para usuários',
364364

365365
'comment-reply-from-owner' => 'Responda do <b>:owner </b>',
366366

367-
'reply-from-owner-to-owner' => 'Responda de <b>:owner1 </b> para <b>:owner2 </b>',
367+
'reply-from-owner-to' => 'Responda de <b>:owner</b> para <b>:recipients</b>',
368368

369369
'comment-note-title' => 'Nota escondida do usuário',
370370

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
<?php
44
$comment_title = trans('panichd::lang.comment-'.$comment->type.'-title');
55
6+
if (in_array($comment->type, ['reply', 'note'])){
7+
$c_recipients = $comment->getNotifications();
8+
if (count($c_recipients) > 0){
9+
foreach ($c_recipients as $recipient){
10+
$a_recipients[] = $recipient->name;
11+
}
12+
$recipients = implode(', ', $a_recipients);
13+
}
14+
}
15+
616
switch ($comment->type){
717
case 'note':
818
$icon_class = "fa fa-pencil-alt text-info";
9-
$comment_header = trans('panichd::lang.comment-note-from-agent', ['agent' => $comment->owner->name]);
19+
if (count($c_recipients) == 0){
20+
$comment_header = trans('panichd::lang.comment-note-from-agent', ['agent' => $comment->owner->name]);
21+
}else{
22+
$comment_header = trans('panichd::lang.comment-note-from-agent-to', [
23+
'agent' => $comment->owner->name,
24+
'recipients' => $recipients
25+
]);
26+
}
1027
break;
1128
case 'complete': // Simple complete box
1229
case 'completetx': // Complete with comment text
@@ -33,12 +50,12 @@
3350
}else{
3451
$icon_class .= "text-warning";
3552
}
36-
if ($ticket->owner->id == $comment->owner->id){
53+
if (count($c_recipients) == 0){
3754
$comment_header = trans('panichd::lang.comment-reply-from-owner', ['owner' => $comment->owner->name]);
3855
}else{
39-
$comment_header = trans('panichd::lang.reply-from-owner-to-owner', [
40-
'owner1' => $comment->owner->name,
41-
'owner2' => $ticket->owner->name
56+
$comment_header = trans('panichd::lang.reply-from-owner-to', [
57+
'owner' => $comment->owner->name,
58+
'recipients' => $recipients
4259
]);
4360
}
4461
break;

0 commit comments

Comments
 (0)