mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
no message
This commit is contained in:
1 parent
5eb0d8694f
commit
c3abef62a7
3 files changed
+85
-13
No files matched your search
@@ -46,11 +46,13 @@ class SendEditedSubTaskNotification implements ShouldQueue
|
||||
unset($editedSubTaskArray['updated_at']);
|
||||
unset($editedSubTaskArray['timesheets']);
|
||||
unset($editedSubTaskArray['timeblocks']);
|
||||
unset($editedSubTaskArray['notification_sent']);
|
||||
|
||||
unset($originalSubTaskArray['created_at']);
|
||||
unset($originalSubTaskArray['updated_at']);
|
||||
unset($originalSubTaskArray['timesheets']);
|
||||
unset($originalSubTaskArray['timeblocks']);
|
||||
unset($originalSubTaskArray['notification_sent']);
|
||||
|
||||
// get the difference between $subtask and $originalSubtask
|
||||
$modelDiff = array_diff_assoc($editedSubTaskArray, $originalSubTaskArray);
|
||||
|
||||
@@ -31,18 +31,57 @@ class SendNewSubTaskEmailNotification implements ShouldQueue
|
||||
*/
|
||||
public function handle(SubTaskCreated $event)
|
||||
{
|
||||
// ked je v subtasku viacej userov, tak poslem 1 email notifikaciu so vsetkymi usermi, ktori su v master tasku
|
||||
// if (count($event->subtask->mastertask->subtasks) > 1) {
|
||||
// $emails = $event->subtask->mastertask->all_users_in_master_task->pluck('email')->unique()->toArray();
|
||||
//
|
||||
// if (empty($emails)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Mail::to($emails)->send(new NewTask($event->subtask));
|
||||
// } else {
|
||||
// Mail::to($event->subtask->user->email)->send(new NewTask($event->subtask));
|
||||
// }
|
||||
Mail::to($event->subtask->user->email)->send(new NewTask($event->subtask));
|
||||
// flag na urovni subtasku - notification_sent
|
||||
// ak existuje este nejaky subtask v ramci master tasku, co ma prazdnu notification_sent, tak mu nastavim 0 a skippujem posielanie emailu
|
||||
// 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 (count($event->subtask->mastertask->subtasks) > 1) {
|
||||
$masterTaskSubtasks = $event->subtask->mastertask->subtasks;
|
||||
|
||||
// get last subtask
|
||||
$lastSubtask = $masterTaskSubtasks->last();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user