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.

58 lines
1.6 KiB

  1. <?php
  2. namespace App\Events;
  3. use Illuminate\Broadcasting\Channel;
  4. use Illuminate\Queue\SerializesModels;
  5. use Illuminate\Broadcasting\PrivateChannel;
  6. use Illuminate\Broadcasting\PresenceChannel;
  7. use Illuminate\Foundation\Events\Dispatchable;
  8. use Illuminate\Broadcasting\InteractsWithSockets;
  9. use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
  10. use App\Tweet;
  11. class NewTweetEvent implements ShouldBroadcast
  12. {
  13. use Dispatchable, InteractsWithSockets, SerializesModels;
  14. public $tweet_id;
  15. public $tweet_date;
  16. public $team_name;
  17. public $team_color;
  18. public $player_username;
  19. public $player_photo;
  20. public $text;
  21. public $photos;
  22. public $mission;
  23. public $mission_id;
  24. /**
  25. * Create a new event instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct(Tweet $tweet)
  30. {
  31. $this->tweet_id = $tweet->id;
  32. $this->tweet_date = strtotime($tweet->tweet_date);
  33. $this->team_name = ($tweet->team ? $tweet->team->name : null);
  34. $this->team_color = ($tweet->team ? $tweet->team->color : null);
  35. $this->player_username = ($tweet->player ? $tweet->player->twitter : null);
  36. $this->player_photo = ($tweet->player ? $tweet->player->photo : null);
  37. $this->text = $tweet->text;
  38. $this->photos = json_decode($tweet->photo);
  39. $this->mission = ($tweet->mission ? $tweet->mission->hashtag : null);
  40. $this->mission_id = $tweet->mission_id;
  41. }
  42. /**
  43. * Get the channels the event should broadcast on.
  44. *
  45. * @return Channel|array
  46. */
  47. public function broadcastOn()
  48. {
  49. return ['tweet-queue'];
  50. }
  51. }