2026-06-16 18:05:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
2026-08-28 13:04:28 +02:00
|
|
|
use App\Models\Feature;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
2026-08-31 12:16:56 +02:00
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
2026-08-31 12:16:56 +02:00
|
|
|
class FeatureCompletedNotification extends Notification implements ShouldBroadcast
|
2026-06-16 18:05:53 +02:00
|
|
|
{
|
|
|
|
|
use Queueable;
|
|
|
|
|
|
|
|
|
|
public function __construct(public Feature $feature) {}
|
|
|
|
|
|
|
|
|
|
public function via($notifiable): array
|
|
|
|
|
{
|
2026-08-31 12:16:56 +02:00
|
|
|
return ['database', 'broadcast'];
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray($notifiable): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-08-28 13:04:28 +02:00
|
|
|
'type' => 'feature_completed',
|
|
|
|
|
'feature_id' => $this->feature->id,
|
|
|
|
|
'project_id' => $this->feature->layer?->phase?->project_id,
|
2026-06-16 18:05:53 +02:00
|
|
|
'feature_name' => $this->feature->name,
|
2026-08-28 13:04:28 +02:00
|
|
|
'progress' => 100,
|
|
|
|
|
'message' => "Elemento '{$this->feature->name}' marcado como completado",
|
2026-06-16 18:05:53 +02:00
|
|
|
];
|
|
|
|
|
}
|
2026-08-31 12:16:56 +02:00
|
|
|
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->feature->layer?->phase?->project_id;
|
|
|
|
|
if (! $projectId) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
$userIds = \App\Models\Project::find($projectId)?->users->pluck('id')->toArray() ?? [];
|
|
|
|
|
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), $userIds);
|
|
|
|
|
}
|
|
|
|
|
}
|