mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
Merge branch 'main' of bitbucket.org:studiotem/jandl-taskmanager-app
This commit is contained in:
commit
d93e356265
7 files changed
+191
-2
No files matched your search
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\MasterTask;
|
||||||
|
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 MasterTaskEdited
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $mastertask;
|
||||||
|
public $originalMastertask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(MasterTask $mastertask, array $originalMastertask)
|
||||||
|
{
|
||||||
|
$this->mastertask = $mastertask;
|
||||||
|
$this->originalMastertask = $originalMastertask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the channels the event should broadcast on.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Broadcasting\Channel|array
|
||||||
|
*/
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return new PrivateChannel('channel-name');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\MasterTaskEdited;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendEditedMasterTaskNotification
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(MasterTaskEdited $event)
|
||||||
|
{
|
||||||
|
$difference = [];
|
||||||
|
|
||||||
|
// get the difference between $mastertask and $originalMastertask
|
||||||
|
$modelDiff = array_diff($event->mastertask->toArray(), $event->originalMastertask);
|
||||||
|
|
||||||
|
foreach ( $modelDiff as $key => $diff ) {
|
||||||
|
if (in_array($key, ['created_at', 'updated_at', 'status'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// znovuotvorenie tasku
|
||||||
|
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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ukoncenie master tasku - neposielame notifikaciu
|
||||||
|
if ($key == 'is_finished' && $diff == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$difference[$key] = $diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($difference)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send notification to all users
|
||||||
|
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 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?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 MasterTaskEdited extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $mastertask;
|
||||||
|
public $difference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(MasterTask $mastertask, $difference)
|
||||||
|
{
|
||||||
|
$this->mastertask = $mastertask;
|
||||||
|
$this->difference = $difference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Mail\Mailables\Envelope
|
||||||
|
*/
|
||||||
|
public function envelope()
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: 'Master Task Edited',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Mail\Mailables\Content
|
||||||
|
*/
|
||||||
|
public function content()
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.task.master_task_edited',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function attachments()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Observers;
|
namespace App\Observers;
|
||||||
|
|
||||||
|
use App\Events\MasterTaskEdited;
|
||||||
use App\Models\MasterTask;
|
use App\Models\MasterTask;
|
||||||
|
|
||||||
class MasterTaskObserver
|
class MasterTaskObserver
|
||||||
@@ -15,5 +16,8 @@ class MasterTaskObserver
|
|||||||
{
|
{
|
||||||
// to prevent updating created_by field. this field cannot be updated once created.
|
// to prevent updating created_by field. this field cannot be updated once created.
|
||||||
$mastertask->created_by = $mastertask->getOriginal('created_by');
|
$mastertask->created_by = $mastertask->getOriginal('created_by');
|
||||||
|
|
||||||
|
MasterTaskEdited::dispatch($mastertask, $mastertask->getOriginal());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Events\MasterTaskEdited;
|
||||||
use App\Events\SubTaskCreated;
|
use App\Events\SubTaskCreated;
|
||||||
|
use App\Listeners\SendEditedMasterTaskNotification;
|
||||||
use App\Listeners\SendNewTaskEmailNotification;
|
use App\Listeners\SendNewTaskEmailNotification;
|
||||||
use App\Models\MasterTask;
|
use App\Models\MasterTask;
|
||||||
use App\Models\SubTask;
|
use App\Models\SubTask;
|
||||||
@@ -28,6 +30,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
SendNewTaskEmailNotification::class,
|
SendNewTaskEmailNotification::class,
|
||||||
//LogEvent::class,
|
//LogEvent::class,
|
||||||
],
|
],
|
||||||
|
MasterTaskEdited::class => [
|
||||||
|
SendEditedMasterTaskNotification::class
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Master Task edited. <br><br>
|
||||||
|
|
||||||
|
Edited fields: <br> <br>
|
||||||
|
@foreach($difference as $key => $diff)
|
||||||
|
{{ $key }}: {{ $diff }} <br>
|
||||||
|
@endforeach
|
||||||
+1
-2
@@ -111,10 +111,9 @@ Route::middleware(['auth:sanctum', 'abilities:full-access'])->group(function ()
|
|||||||
|
|
||||||
$userIDs = User::where('firstname', 'like', '%' . $search . '%')->orWhere('lastname', 'like', '%' . $search . '%')->get()->pluck('id');
|
$userIDs = User::where('firstname', 'like', '%' . $search . '%')->orWhere('lastname', 'like', '%' . $search . '%')->get()->pluck('id');
|
||||||
|
|
||||||
|
|
||||||
$teams = Team::whereHas('users', function($q) use($userIDs) {
|
$teams = Team::whereHas('users', function($q) use($userIDs) {
|
||||||
$q->whereIn('user_id', $userIDs);
|
$q->whereIn('user_id', $userIDs);
|
||||||
})->get();
|
})->orWhere('name', 'like', '%' . $search . '%' )->get();
|
||||||
|
|
||||||
$mastertasks = MasterTask::with('subtasks')->where('title', 'like', '%' . $search . '%')->orWhereIn('project_id', $projectIDs)->orWhereIn('team_id', $teams->pluck('id'))->get();
|
$mastertasks = MasterTask::with('subtasks')->where('title', 'like', '%' . $search . '%')->orWhereIn('project_id', $projectIDs)->orWhereIn('team_id', $teams->pluck('id'))->get();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user