File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88use PanicHD \PanicHD \Helpers \LaravelVersion ;
99use PanicHD \PanicHD \Models \Category ;
1010use PanicHD \PanicHD \Models \Comment ;
11+ use PanicHD \PanicHD \Models \CommentNotification ;
1112use PanicHD \PanicHD \Models \Member ;
1213use PanicHD \PanicHD \Models \Setting ;
1314use 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
Original file line number Diff line number Diff 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 ){
Original file line number Diff line number Diff line change 22
33namespace PanicHD \PanicHD \Models ;
44
5- use DB ;
6- use Illuminate \Database \Eloquent \Collection ;
75use Illuminate \Database \Eloquent \Model ;
86use 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 );
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' , [
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' , [
You can’t perform that action at this time.
0 commit comments