Skip to content

Commit 850a425

Browse files
committed
CommentNotification model
1 parent 12550b6 commit 850a425

5 files changed

Lines changed: 50 additions & 21 deletions

File tree

src/Controllers/NotificationsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PanicHD\PanicHD\Helpers\LaravelVersion;
99
use PanicHD\PanicHD\Models\Category;
1010
use PanicHD\PanicHD\Models\Comment;
11+
use PanicHD\PanicHD\Models\CommentNotification;
1112
use PanicHD\PanicHD\Models\Member;
1213
use PanicHD\PanicHD\Models\Setting;
1314
use PanicHD\PanicHD\Models\Ticket;
@@ -160,12 +161,11 @@ public function newComment(Comment $comment, $request)
160161
$recipient = Member::find($member_id);
161162
if (count($recipient) == 1){
162163
// Register the notified email
163-
\DB::table('panichd_comment_email')->insert([
164-
['comment_id' => $comment->id,
164+
$notification = CommentNotification::create([
165+
'comment_id' => $comment->id,
165166
'name' => $recipient->name,
166167
'email' => $recipient->email,
167168
'member_id' => $member_id
168-
]
169169
]);
170170

171171
// Add email to actual mail recipients

src/Controllers/TicketsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ public function show($id)
12551255

12561256
$agent_lists = $this->agentList($ticket->category_id);
12571257

1258-
$comments = $ticket->comments()->forLevel($member->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
1258+
$comments = $ticket->comments()->with('notifications')->forLevel($member->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
12591259

12601260
$c_members = \PanicHDMember::with('userDepartment')->where('email', '!=', auth()->user()->email);
12611261
if ($member->currentLevel() > 1){

src/Models/Comment.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace PanicHD\PanicHD\Models;
44

5-
use DB;
6-
use Illuminate\Database\Eloquent\Collection;
75
use Illuminate\Database\Eloquent\Model;
86
use PanicHD\PanicHD\Traits\ContentEllipse;
97

@@ -34,13 +32,24 @@ public function delete()
3432

3533
// Delete notifications
3634
\DB::table('panichd_comment_email')->where('comment_id', $this->id)->delete();
35+
3736

3837
$error = $a_errors ? implode('. ', $a_errors) : null;
3938
if ($error != "") return $error;
4039

4140
parent::delete();
4241
}
4342

43+
/**
44+
* Get emails | members whom notifications have been sent.
45+
*
46+
* Return @collection
47+
*/
48+
public function notifications()
49+
{
50+
return $this->hasMany('PanicHD\PanicHD\Models\CommentNotification')->orderBy('name');
51+
}
52+
4453
/**
4554
* Get related ticket.
4655
*
@@ -96,14 +105,4 @@ public function scopeCountable($query)
96105
{
97106
return $query->whereIN('type', ['reply', 'note', 'completetx']);
98107
}
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-
}
109108
}

src/Models/CommentNotification.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PanicHD\PanicHD\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class CommentNotification extends Model
8+
{
9+
protected $table = 'panichd_comment_email';
10+
11+
protected $fillable = ['comment_id', 'name', 'email', 'member_id'];
12+
13+
/**
14+
* primaryKey
15+
*
16+
* @var integer
17+
* @access protected
18+
*/
19+
protected $primaryKey = null;
20+
21+
/**
22+
* Indicates if the IDs are auto-incrementing.
23+
*
24+
* @var bool
25+
*/
26+
public $incrementing = false;
27+
28+
public $timestamps = false;
29+
30+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
$comment_title = trans('panichd::lang.comment-'.$comment->type.'-title');
55
66
if (in_array($comment->type, ['reply', 'note'])){
7-
$c_recipients = $comment->getNotifications();
8-
if (count($c_recipients) > 0){
9-
foreach ($c_recipients as $recipient){
7+
if (count($comment->notifications) > 0){
8+
$a_recipients = [];
9+
foreach ($comment->notifications as $recipient){
1010
$a_recipients[] = $recipient->name;
1111
}
1212
$recipients = implode(', ', $a_recipients);
@@ -16,7 +16,7 @@
1616
switch ($comment->type){
1717
case 'note':
1818
$icon_class = "fa fa-pencil-alt text-info";
19-
if (count($c_recipients) == 0){
19+
if (count($comment->notifications) == 0){
2020
$comment_header = trans('panichd::lang.comment-note-from-agent', ['agent' => $comment->owner->name]);
2121
}else{
2222
$comment_header = trans('panichd::lang.comment-note-from-agent-to', [
@@ -50,7 +50,7 @@
5050
}else{
5151
$icon_class .= "text-warning";
5252
}
53-
if (count($c_recipients) == 0){
53+
if (count($comment->notifications) == 0){
5454
$comment_header = trans('panichd::lang.comment-reply-from-owner', ['owner' => $comment->owner->name]);
5555
}else{
5656
$comment_header = trans('panichd::lang.reply-from-owner-to', [

0 commit comments

Comments
 (0)