ExportCompleted.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // File: app/Events/ExportCompleted.php
  3. namespace App\Events;
  4. use Illuminate\Broadcasting\Channel;
  5. use Illuminate\Broadcasting\InteractsWithSockets;
  6. use Illuminate\Broadcasting\PresenceChannel;
  7. use Illuminate\Broadcasting\PrivateChannel;
  8. use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
  9. use Illuminate\Foundation\Events\Dispatchable;
  10. use Illuminate\Queue\SerializesModels;
  11. class ExportCompleted implements ShouldBroadcast
  12. {
  13. use Dispatchable, InteractsWithSockets, SerializesModels;
  14. public $userId;
  15. public $filename;
  16. public $emailAddress;
  17. public $message;
  18. /**
  19. * Create a new event instance.
  20. */
  21. public function __construct($userId, $filename, $emailAddress)
  22. {
  23. $this->userId = $userId;
  24. $this->filename = $filename;
  25. $this->emailAddress = $emailAddress;
  26. $this->message = 'Export completato! Controlla la tua email.';
  27. }
  28. /**
  29. * Get the channels the event should broadcast on.
  30. */
  31. public function broadcastOn()
  32. {
  33. return new PrivateChannel('exports.' . $this->userId);
  34. }
  35. /**
  36. * Get the data to broadcast.
  37. */
  38. public function broadcastWith()
  39. {
  40. return [
  41. 'type' => 'export_completed',
  42. 'message' => $this->message,
  43. 'filename' => $this->filename,
  44. 'email' => $this->emailAddress,
  45. 'timestamp' => now()->toISOString()
  46. ];
  47. }
  48. /**
  49. * The event's broadcast name.
  50. */
  51. public function broadcastAs()
  52. {
  53. return 'export.completed';
  54. }
  55. }