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.

60 lines
1.7 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. public $twitter_id;
  25. /**
  26. * Create a new event instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct(Tweet $tweet)
  31. {
  32. $this->tweet_id = $tweet->id;
  33. $this->tweet_date = strtotime($tweet->tweet_date);
  34. $this->team_name = ($tweet->team ? $tweet->team->name : null);
  35. $this->team_color = ($tweet->team ? $tweet->team->color : null);
  36. $this->player_username = ($tweet->player ? $tweet->player->twitter : null);
  37. $this->player_photo = ($tweet->player ? $tweet->player->photo : null);
  38. $this->text = $tweet->text;
  39. $this->photos = json_decode($tweet->photo);
  40. $this->mission = ($tweet->mission ? $tweet->mission->hashtag : null);
  41. $this->mission_id = $tweet->mission_id;
  42. $this->twitter_id = $tweet->tweet_id;
  43. }
  44. /**
  45. * Get the channels the event should broadcast on.
  46. *
  47. * @return Channel|array
  48. */
  49. public function broadcastOn()
  50. {
  51. return ['tweet-queue'];
  52. }
  53. }