mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
timeblock finished email notification
This commit is contained in:
1 parent
86424d1b3d
commit
28a0bac095
6 files changed
+162
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Timeblock;
|
||||
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 TimeBlockFinished
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $timeblock;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Timeblock $timeblock)
|
||||
{
|
||||
$this->timeblock = $timeblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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\TimeBlockFinished;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendFinishedTimeBlockNotification implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(TimeBlockFinished $event)
|
||||
{
|
||||
$receiver = User::find($event->timeblock->subtask->created_by)->email;
|
||||
|
||||
Mail::to( $receiver )->send( new \App\Mail\TimeBlockFinished( $event->timeblock->subtask ) );
|
||||
}
|
||||
}
|
||||
@@ -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 TimeBlockFinished 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: 'Time block for subtask was finished'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.task.time_block_finished'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\TimeBlockFinished;
|
||||
use App\Models\Timeblock;
|
||||
|
||||
class TimeBlockObserver
|
||||
{
|
||||
|
||||
public function updating(Timeblock $timeblock)
|
||||
{
|
||||
if ($timeblock->getOriginal('is_finished') == 0 && $timeblock->is_finished == 1) {
|
||||
TimeBlockFinished::dispatch($timeblock);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,18 @@ use App\Events\MasterTaskEdited;
|
||||
use App\Events\SubTaskCreated;
|
||||
use App\Events\SubTaskDeleted;
|
||||
use App\Events\SubTaskEdited;
|
||||
use App\Events\TimeBlockFinished;
|
||||
use App\Listeners\SendDeletedSubTaskNotification;
|
||||
use App\Listeners\SendEditedMasterTaskNotification;
|
||||
use App\Listeners\SendEditedSubTaskNotification;
|
||||
use App\Listeners\SendFinishedTimeBlockNotification;
|
||||
use App\Listeners\SendNewSubTaskEmailNotification;
|
||||
use App\Models\MasterTask;
|
||||
use App\Models\SubTask;
|
||||
use App\Models\Timeblock;
|
||||
use App\Observers\MasterTaskObserver;
|
||||
use App\Observers\SubTaskObserver;
|
||||
use App\Observers\TimeBlockObserver;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
@@ -43,6 +47,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
MasterTaskEdited::class => [
|
||||
SendEditedMasterTaskNotification::class
|
||||
],
|
||||
TimeBlockFinished::class => [
|
||||
SendFinishedTimeBlockNotification::class
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -54,6 +61,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
MasterTask::observe( MasterTaskObserver::class);
|
||||
SubTask::observe( SubTaskObserver::class);
|
||||
Timeblock::observe( TimeBlockObserver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Timeblock for Sub Task {{$subtask->mastertask->title}} was finished.
|
||||
Reference in new issue
Block a user