no message

This commit is contained in:
StudioTem committed 2025-08-20 12:21:25 +02:00
1 parent 5eb0d8694f
commit c3abef62a7
3 files changed
+84 -12

No files matched your search

@@ -46,11 +46,13 @@ class SendEditedSubTaskNotification implements ShouldQueue
unset($editedSubTaskArray['updated_at']); unset($editedSubTaskArray['updated_at']);
unset($editedSubTaskArray['timesheets']); unset($editedSubTaskArray['timesheets']);
unset($editedSubTaskArray['timeblocks']); unset($editedSubTaskArray['timeblocks']);
unset($editedSubTaskArray['notification_sent']);
unset($originalSubTaskArray['created_at']); unset($originalSubTaskArray['created_at']);
unset($originalSubTaskArray['updated_at']); unset($originalSubTaskArray['updated_at']);
unset($originalSubTaskArray['timesheets']); unset($originalSubTaskArray['timesheets']);
unset($originalSubTaskArray['timeblocks']); unset($originalSubTaskArray['timeblocks']);
unset($originalSubTaskArray['notification_sent']);
// get the difference between $subtask and $originalSubtask // get the difference between $subtask and $originalSubtask
$modelDiff = array_diff_assoc($editedSubTaskArray, $originalSubTaskArray); $modelDiff = array_diff_assoc($editedSubTaskArray, $originalSubTaskArray);
@@ -31,18 +31,57 @@ class SendNewSubTaskEmailNotification implements ShouldQueue
*/ */
public function handle(SubTaskCreated $event) public function handle(SubTaskCreated $event)
{ {
// ked je v subtasku viacej userov, tak poslem 1 email notifikaciu so vsetkymi usermi, ktori su v master tasku // flag na urovni subtasku - notification_sent
// if (count($event->subtask->mastertask->subtasks) > 1) { // ak existuje este nejaky subtask v ramci master tasku, co ma prazdnu notification_sent, tak mu nastavim 0 a skippujem posielanie emailu
// $emails = $event->subtask->mastertask->all_users_in_master_task->pluck('email')->unique()->toArray(); // az ked neexistuje uz iny subtask, co ma flag prazdny, tak poslem email a nastavim notification_sent na 1
// // v pripade, ze sa do existujuceho master tasku pridaju nove subtasky, tak opakujem to iste. akurat pri posielani pri notification_sent nastavim poslem iba na tych userov, co boli medzi poslednymi subtaskami, ktore mali notification_sent prazdny
// if (empty($emails)) {
// return; if (count($event->subtask->mastertask->subtasks) > 1) {
// } $masterTaskSubtasks = $event->subtask->mastertask->subtasks;
//
// Mail::to($emails)->send(new NewTask($event->subtask)); // get last subtask
// } else { $lastSubtask = $masterTaskSubtasks->last();
// Mail::to($event->subtask->user->email)->send(new NewTask($event->subtask));
// } if ($lastSubtask->id > $event->subtask->id) {
// skip sending email if this is not the last subtask
return;
}
$lastSubtaskWithNotificationSent = $masterTaskSubtasks->where('notification_sent', 1)->last();
if ( ! $lastSubtaskWithNotificationSent) {
// if there is no subtask with notification_sent = 1, set it to the first subtask
$firstSubtaskWithNotificationNotSent = $masterTaskSubtasks->first();
} else {
$firstSubtaskWithNotificationNotSent = $masterTaskSubtasks->where('notification_sent', 0)->where('id',
'>', $lastSubtaskWithNotificationSent->id)->first();
}
// get all the subtasks between the last subtask with notification_sent = 1 and the current subtask
$subtasksToNotify = $masterTaskSubtasks->where('notification_sent', 0)->where('id', '>=',
$firstSubtaskWithNotificationNotSent->id);
// if there are no subtasks to notify, skip sending email
if ($subtasksToNotify->isEmpty()) {
return;
}
// get unique emails from the subtasks to notify
$emails = $subtasksToNotify->pluck('user.email')->unique()->toArray();
if (empty($emails)) {
return;
}
Mail::to($emails)->send(new NewTask($event->subtask));
// set notification_sent to 1 for all the subtasks that were notified
$subtasksToNotify->each(function ($subtask) {
$subtask->notification_sent = 1;
$subtask->save();
});
} else {
Mail::to($event->subtask->user->email)->send(new NewTask($event->subtask)); Mail::to($event->subtask->user->email)->send(new NewTask($event->subtask));
} }
} }
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('sub_tasks', function (Blueprint $table) {
$table->tinyInteger('notification_sent')->after('is_finished')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('subtasks', function (Blueprint $table) {
//
});
}
};