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.

57 lines
1.5 KiB

7 years ago
  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 function transit_line() {
  25. return $this->belongsTo('\App\TransitLine', 'm1_transit_line_id');
  26. }
  27. public function transit_center() {
  28. return $this->belongsTo('\App\TransitCenter', 'm2_transit_center_id');
  29. }
  30. public function document() {
  31. return $this->belongsTo('\App\Document', 'm7_document_id');
  32. }
  33. public static function claimed_timeout() {
  34. // time out tweets if they aren't processed after the specified time
  35. $timeout = 520;
  36. $tweets = Tweet::where('claimed_at', '<', date('Y-m-d H:i:s', time()-$timeout))->where('processed', 0)->get();
  37. foreach($tweets as $tweet) {
  38. $tweet->claimed_at = null;
  39. $tweet->save();
  40. event(new NewTweetEvent($tweet));
  41. }
  42. }
  43. public static function queued() {
  44. return Tweet::whereNull('claimed_at')->where('processed', 0)
  45. ->where('mission_id', '>', 0)->orderBy('tweet_date', 'asc');
  46. }
  47. }