Skip to content

Commit f9c481f

Browse files
committed
Store comment notification recipients
1 parent 5d39050 commit f9c481f

3 files changed

Lines changed: 70 additions & 12 deletions

File tree

src/Controllers/CommentsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function store(Request $request)
194194
}
195195

196196
DB::commit();
197-
event(new CommentCreated(Models\Comment::find($comment->id), $request));
197+
event(new CommentCreated(clone $comment, $request));
198198

199199
session()->flash('status', trans('panichd::lang.comment-has-been-added-ok'));
200200

src/Controllers/NotificationsController.php

Lines changed: 36 additions & 11 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\Member;
1112
use PanicHD\PanicHD\Models\Setting;
1213
use PanicHD\PanicHD\Models\Ticket;
1314

@@ -143,26 +144,50 @@ public function newComment(Comment $comment, $request)
143144
'notification_type' => $comment->type
144145
];
145146

146-
// Notificate assigned agent
147-
$a_to = $this->defaultRecipients($ticket, $notification_owner, $subject, $template);
147+
$member = Member::find(auth()->user()->id);
148+
$category_level = $member->levelInCategory($ticket->category_id);
149+
$permission_level = ($member->currentLevel() > 1 and $category_level > 1) ? $category_level : 1;
150+
151+
if ($permission_level < 2){
152+
// Notificate assigned agent
153+
$a_to = $this->defaultRecipients($ticket, $notification_owner, $subject, $template);
154+
155+
}elseif($comment->type == 'note' or !$ticket->hidden){
156+
// Selected recipients
157+
$c_recipients = $comment->type == 'note' ? $request->note_recipients : $request->reply_recipients;
158+
159+
foreach($c_recipients as $member_id){
160+
$recipient = Member::find($member_id);
161+
if (count($recipient) == 1){
162+
// Register the notified email
163+
\DB::table('panichd_comment_email')->insert([
164+
['comment_id' => $comment->id,
165+
'name' => $recipient->name,
166+
'email' => $recipient->email,
167+
'member_id' => $member_id
168+
]
169+
]);
170+
171+
// Add email to actual mail recipients
172+
$a_to[] = [
173+
'recipient' => $recipient,
174+
'subject' => $subject,
175+
'template' => $template
176+
];
177+
}
178+
179+
}
148180

149-
// Notificate ticket owner
150-
if ($comment->type == 'reply' and !$ticket->hidden and !in_array($ticket->owner->email, [$notification_owner->email, $ticket->agent->email])){
151181
if ($request->has('add_in_user_notification_text') or (isset($comment->add_in_user_notification_text))){
152182
// Element in request comes from Comment modal
153183
// $comment property comes from an embedded comment when editing or creating a ticket
154184
$data['add_in_user_notification_text'] = true;
155185
}
156186

157-
$a_to[] = [
158-
'recipient' => $ticket->owner,
159-
'subject' => $subject,
160-
'template' => $template
161-
];
162-
}
187+
}
163188

164189
// Send notifications
165-
$this->sendNotification($a_to, $data);
190+
if(isset($a_to)) $this->sendNotification($a_to, $data);
166191
}
167192
}
168193

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreatePanichdCommentEmail extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('panichd_comment_email', function (Blueprint $table) {
17+
$table->integer('comment_id');
18+
$table->string('name');
19+
$table->string('email');
20+
$table->integer('member_id')->nullable();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('panichd_comment_email');
32+
}
33+
}

0 commit comments

Comments
 (0)