mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
subtask edited email notification
This commit is contained in:
1 parent
c3bf06a9b0
commit
e1a8a3fe1a
8 files changed
+222
No files matched your search
@@ -0,0 +1,41 @@
|
|||||||
|
<?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 SubTaskEdited
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $subtask;
|
||||||
|
public $originalSubtask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(SubTask $subtask, array $originalSubtask)
|
||||||
|
{
|
||||||
|
$this->subtask = $subtask;
|
||||||
|
$this->originalSubtask = $originalSubtask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the channels the event should broadcast on.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Broadcasting\Channel|array
|
||||||
|
*/
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return new PrivateChannel('channel-name');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -222,6 +222,7 @@ class SubTaskController extends Controller
|
|||||||
$data['data'] = $request->all()['data'];
|
$data['data'] = $request->all()['data'];
|
||||||
$data['data']['user_id'] = $request->all()['data']['employee_id'];
|
$data['data']['user_id'] = $request->all()['data']['employee_id'];
|
||||||
$data['data']['estimated_time'] = $request->all()['data']['duration'];
|
$data['data']['estimated_time'] = $request->all()['data']['duration'];
|
||||||
|
$data['data']['updated_by'] = User::getUserIdFromBearerToken($request->bearerToken());
|
||||||
|
|
||||||
$request->merge($data);
|
$request->merge($data);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\SubTaskEdited;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendEditedSubTaskNotification
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(SubTaskEdited $event)
|
||||||
|
{
|
||||||
|
// emailova notifikacia sa posiela len ak subtask bol upraveny inym uzivatelom
|
||||||
|
if ($event->subtask->updated_by == $event->subtask->user_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$difference = [];
|
||||||
|
|
||||||
|
$editedSubTaskArray = $event->subtask->toArray();
|
||||||
|
$originalSubTaskArray = $event->originalSubtask;
|
||||||
|
|
||||||
|
// unset key from array
|
||||||
|
unset($editedSubTaskArray['created_at']);
|
||||||
|
unset($editedSubTaskArray['updated_at']);
|
||||||
|
unset($editedSubTaskArray['timesheets']);
|
||||||
|
unset($editedSubTaskArray['timeblocks']);
|
||||||
|
|
||||||
|
unset($originalSubTaskArray['created_at']);
|
||||||
|
unset($originalSubTaskArray['updated_at']);
|
||||||
|
unset($originalSubTaskArray['timesheets']);
|
||||||
|
unset($originalSubTaskArray['timeblocks']);
|
||||||
|
|
||||||
|
// get the difference between $subtask and $originalSubtask
|
||||||
|
$modelDiff = array_diff_assoc($editedSubTaskArray, $originalSubTaskArray);
|
||||||
|
|
||||||
|
foreach ( $modelDiff as $key => $diff ) {
|
||||||
|
if (in_array($key, ['status', 'tracked_time'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$difference[$key] = $diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($difference)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mail::to( $subtask->user->email )->send( new \App\Mail\SubTaskEdited( $event->subtask, $difference ) );
|
||||||
|
Mail::to( 'feher@studiotem.com' )->send( new \App\Mail\SubTaskEdited( $event->subtask, $difference ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?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 SubTaskEdited extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $subtask;
|
||||||
|
public $difference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(SubTask $subtask, array $difference)
|
||||||
|
{
|
||||||
|
$this->subtask = $subtask;
|
||||||
|
$this->difference = $difference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Mail\Mailables\Envelope
|
||||||
|
*/
|
||||||
|
public function envelope()
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: 'Sub Task Edited',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Mail\Mailables\Content
|
||||||
|
*/
|
||||||
|
public function content()
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.task.sub_task_edited',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function attachments()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Observers;
|
|||||||
|
|
||||||
use App\Events\SubTaskCreated;
|
use App\Events\SubTaskCreated;
|
||||||
use App\Events\SubTaskDeleted;
|
use App\Events\SubTaskDeleted;
|
||||||
|
use App\Events\SubTaskEdited;
|
||||||
use App\Models\SubTask;
|
use App\Models\SubTask;
|
||||||
|
|
||||||
class SubTaskObserver
|
class SubTaskObserver
|
||||||
@@ -25,6 +26,8 @@ class SubTaskObserver
|
|||||||
$subTask->created_by = $subTask->getOriginal('created_by');
|
$subTask->created_by = $subTask->getOriginal('created_by');
|
||||||
|
|
||||||
$subTask->tracked_time = $subTask->timesheets->sum('time');
|
$subTask->tracked_time = $subTask->timesheets->sum('time');
|
||||||
|
|
||||||
|
SubTaskEdited::dispatch($subTask, $subTask->getOriginal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ namespace App\Providers;
|
|||||||
use App\Events\MasterTaskEdited;
|
use App\Events\MasterTaskEdited;
|
||||||
use App\Events\SubTaskCreated;
|
use App\Events\SubTaskCreated;
|
||||||
use App\Events\SubTaskDeleted;
|
use App\Events\SubTaskDeleted;
|
||||||
|
use App\Events\SubTaskEdited;
|
||||||
use App\Listeners\SendDeletedSubTaskNotification;
|
use App\Listeners\SendDeletedSubTaskNotification;
|
||||||
use App\Listeners\SendEditedMasterTaskNotification;
|
use App\Listeners\SendEditedMasterTaskNotification;
|
||||||
|
use App\Listeners\SendEditedSubTaskNotification;
|
||||||
use App\Listeners\SendNewSubTaskEmailNotification;
|
use App\Listeners\SendNewSubTaskEmailNotification;
|
||||||
use App\Models\MasterTask;
|
use App\Models\MasterTask;
|
||||||
use App\Models\SubTask;
|
use App\Models\SubTask;
|
||||||
@@ -35,6 +37,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
SubTaskDeleted::class => [
|
SubTaskDeleted::class => [
|
||||||
SendDeletedSubTaskNotification::class
|
SendDeletedSubTaskNotification::class
|
||||||
],
|
],
|
||||||
|
SubTaskEdited::class => [
|
||||||
|
SendEditedSubTaskNotification::class
|
||||||
|
],
|
||||||
MasterTaskEdited::class => [
|
MasterTaskEdited::class => [
|
||||||
SendEditedMasterTaskNotification::class
|
SendEditedMasterTaskNotification::class
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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->foreignIdFor( \App\Models\User::class, 'updated_by')->after('updated_at')->nullable()->default(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('subtask', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Sub Task edited. <br><br>
|
||||||
|
|
||||||
|
Edited fields: <br> <br>
|
||||||
|
@foreach($difference as $key => $diff)
|
||||||
|
{{ $key }}: {{ $diff }} <br>
|
||||||
|
@endforeach
|
||||||
Reference in new issue
Block a user