You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\ProjectUserCreate;
|
|
use App\Models\Project;
|
|
use App\Models\User;
|
|
use App\Utilities\HelperClass\NotificationHelper;
|
|
|
|
class ProjectUserCreateNotif
|
|
{
|
|
/**
|
|
* @var NotificationHelper
|
|
*/
|
|
public $helper;
|
|
|
|
/**
|
|
* Create the event listener.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(NotificationHelper $helper)
|
|
{
|
|
$this->helper = $helper;
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param ProjectUserCreate $event
|
|
* @return void
|
|
*/
|
|
public function handle(ProjectUserCreate $event)
|
|
{
|
|
$payload = $event->message;
|
|
|
|
$new_user = User::findOrFail($payload->data->original->user_id);
|
|
$project = Project::findOrFail($payload->data->original->project_id);
|
|
$owners_id = request('_business_info')['info']['projects'][$project->id]['members']->reject(function ($item, $key) use ($new_user) {
|
|
return $item['level'] < enum('levels.owner.id') || $key === $new_user->id || $key === auth()->id();
|
|
})->toArray();
|
|
|
|
$owners = User::whereIn('id', array_keys($owners_id))->get();
|
|
|
|
$users = $owners->prepend($new_user);
|
|
|
|
$this->helper->makeNotif($payload, null,
|
|
['project' => $project->name, 'user' => $new_user->name]
|
|
)->sendNotifications($users, 'critical');
|
|
}
|
|
}
|