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.

44 lines
1.2 KiB

  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Events\NewTweetEvent;
  5. use DB;
  6. class Tweet extends Model
  7. {
  8. protected $fillable = [
  9. 'tweet_id', 'player_id', 'team_id', 'text', 'photo', 'claimed_at', 'processed', 'mission_id', 'tweet_date',
  10. 'm1_transit_line_id', 'm1_non_trimet',
  11. 'm2_transit_center_id', 'm2_with_other_team',
  12. 'm3_complete', 'm4_complete', 'm5_complete', 'm5_tip',
  13. 'm6_complete', 'm7_document_id'
  14. ];
  15. public function team() {
  16. return $this->belongsTo('\App\Team');
  17. }
  18. public function player() {
  19. return $this->belongsTo('\App\Player');
  20. }
  21. public function mission() {
  22. return $this->belongsTo('\App\Mission');
  23. }
  24. public static function claimed_timeout() {
  25. // time out tweets if they aren't processed after the specified time
  26. $timeout = 520;
  27. $tweets = Tweet::where('claimed_at', '<', date('Y-m-d H:i:s', time()-$timeout))->get();
  28. foreach($tweets as $tweet) {
  29. $tweet->claimed_at = null;
  30. $tweet->save();
  31. event(new NewTweetEvent($tweet));
  32. }
  33. }
  34. public static function queued() {
  35. return Tweet::whereNull('claimed_at')->where('processed', 0)->where('mission_id', '>', 0)->orderBy('tweet_date', 'asc');
  36. }
  37. }