mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
email notifications
This commit is contained in:
1 parent
3a71b42c1f
commit
8a774dd4fa
12 files changed
+263
-9
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\SubTask;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SubTaskDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $subtask;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SubTask $subtask)
|
||||
{
|
||||
$this->subtask = $subtask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\SubTaskDeleted;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
// naschval nedavam implement ShouldQueue, pretoze bol problem s tym, ze subtask uz neexistoval
|
||||
class SendDeletedSubTaskNotification
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(SubTaskDeleted $event)
|
||||
{
|
||||
$receiversArray[] = $event->subtask->user->email;
|
||||
$receiversArray[] = \App\Models\User::find($event->subtask->created_by)->email;
|
||||
|
||||
Mail::to( $receiversArray )->send( new \App\Mail\SubTaskDeleted( $event->subtask ) );
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,9 @@ namespace App\Listeners;
|
||||
|
||||
use App\Events\MasterTaskEdited;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendEditedMasterTaskNotification
|
||||
class SendEditedMasterTaskNotification implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
@@ -29,11 +28,22 @@ class SendEditedMasterTaskNotification
|
||||
{
|
||||
$difference = [];
|
||||
|
||||
$editedMasterTaskArray = $event->mastertask->toArray();
|
||||
$originalMasterTaskArray = $event->originalMastertask;
|
||||
|
||||
// unset key from array
|
||||
unset($editedMasterTaskArray['created_at']);
|
||||
unset($editedMasterTaskArray['updated_at']);
|
||||
unset($editedMasterTaskArray['subtasks']);
|
||||
|
||||
unset($originalMasterTaskArray['created_at']);
|
||||
unset($originalMasterTaskArray['updated_at']);
|
||||
|
||||
// get the difference between $mastertask and $originalMastertask
|
||||
$modelDiff = array_diff($event->mastertask->toArray(), $event->originalMastertask);
|
||||
$modelDiff = array_diff_assoc($editedMasterTaskArray, $originalMasterTaskArray);
|
||||
|
||||
foreach ( $modelDiff as $key => $diff ) {
|
||||
if (in_array($key, ['created_at', 'updated_at', 'status'])) {
|
||||
if (in_array($key, ['status'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -41,7 +51,9 @@ class SendEditedMasterTaskNotification
|
||||
if ($key == 'is_finished' && $diff == 0) {
|
||||
foreach ( $event->mastertask->subtasks as $subtask ) {
|
||||
// Mail::to( $subtask->user->email )->send( new \App\Mail\MasterTaskEdited( $event->mastertask, $difference ) );
|
||||
Mail::to( 'feher@studiotem.com' )->send( new \App\Mail\MasterTaskEdited( $event->mastertask, $difference ) );
|
||||
Mail::to( 'feher@studiotem.com' )->send( new \App\Mail\MasterTaskReopened( $event->mastertask ) );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\SubTaskCreated;
|
||||
use App\Mail\NewTask;
|
||||
use App\Mail\PasswordReset;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendNewSubTaskEmailNotification implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\SubTaskCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(SubTaskCreated $event)
|
||||
{
|
||||
// Mail::to( $event->subtask->user->email )->send( new NewTask( $event->subtask ) );
|
||||
Mail::to( 'feher@studiotem.com' )->send( new NewTask( $event->subtask ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\MasterTask;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MasterTaskReopened extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $mastertask;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MasterTask $mastertask)
|
||||
{
|
||||
$this->mastertask = $mastertask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Master Task ' . $this->mastertask->title . ' was reopened',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.task.master_task_reopened',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class NewTask extends Mailable
|
||||
public function content()
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.task.new_task_created',
|
||||
view: 'emails.task.sub_task_created',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\SubTask;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SubTaskDeleted extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $subtask;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SubTask $subtask)
|
||||
{
|
||||
$this->subtask = $subtask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Sub Task ' . $this->subtask->mastertask->title . ' was deleted',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.task.sub_task_deleted',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\SubTaskCreated;
|
||||
use App\Events\SubTaskDeleted;
|
||||
use App\Models\SubTask;
|
||||
|
||||
class SubTaskObserver
|
||||
@@ -46,7 +47,7 @@ class SubTaskObserver
|
||||
*/
|
||||
public function deleted(SubTask $subTask)
|
||||
{
|
||||
//
|
||||
SubTaskDeleted::dispatch($subTask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,10 @@ namespace App\Providers;
|
||||
|
||||
use App\Events\MasterTaskEdited;
|
||||
use App\Events\SubTaskCreated;
|
||||
use App\Events\SubTaskDeleted;
|
||||
use App\Listeners\SendDeletedSubTaskNotification;
|
||||
use App\Listeners\SendEditedMasterTaskNotification;
|
||||
use App\Listeners\SendNewTaskEmailNotification;
|
||||
use App\Listeners\SendNewSubTaskEmailNotification;
|
||||
use App\Models\MasterTask;
|
||||
use App\Models\SubTask;
|
||||
use App\Observers\MasterTaskObserver;
|
||||
@@ -27,9 +29,12 @@ class EventServiceProvider extends ServiceProvider
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
SubTaskCreated::class => [
|
||||
SendNewTaskEmailNotification::class,
|
||||
SendNewSubTaskEmailNotification::class,
|
||||
//LogEvent::class,
|
||||
],
|
||||
SubTaskDeleted::class => [
|
||||
SendDeletedSubTaskNotification::class
|
||||
],
|
||||
MasterTaskEdited::class => [
|
||||
SendEditedMasterTaskNotification::class
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user