CalendarGame.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class CalendarGame extends Model
  5. {
  6. protected $fillable = [
  7. 'calendar_id',
  8. 'home_team_id',
  9. 'away_team_id',
  10. 'date',
  11. 'day',
  12. 'type',
  13. 'home_goals',
  14. 'away_goals',
  15. 'home_points',
  16. 'away_points',
  17. 'played'
  18. ];
  19. public function homeTeam()
  20. {
  21. return $this->belongsTo('App\Team');
  22. }
  23. public function awayTeam()
  24. {
  25. return $this->belongsTo('App\Team');
  26. }
  27. public function getHomeTeam()
  28. {
  29. $team_id = $this->home_team_id;
  30. //if ($this->type == 'RITORNO')
  31. // $team_id = $this->away_team_id;
  32. if ($team_id == null)
  33. {
  34. $t = new Team();
  35. $t->name = 'Riposo';
  36. }
  37. else
  38. {
  39. $t = Team::findOrFail($team_id); // $this->belongsTo('App\Team');
  40. if (($t->type != '' && $t->type != '-') || $t->excluded)
  41. {
  42. if ($t->type == 'andata')
  43. {
  44. // $t->name = 'Riposo';
  45. }
  46. }
  47. }
  48. return $t;
  49. }
  50. public function getAwayTeam()
  51. {
  52. $team_id = $this->away_team_id;
  53. //if ($this->type == 'RITORNO')
  54. // $team_id = $this->home_team_id;
  55. if ($team_id == null)
  56. {
  57. $t = new Team();
  58. $t->name = 'Riposo';
  59. }
  60. else
  61. {
  62. $t = Team::findOrFail($team_id); // $this->belongsTo('App\Team');
  63. if (($t->type != '' && $t->type != '-') || $t->excluded)
  64. {
  65. if ($t->type == 'andata')
  66. {
  67. // $t->name = 'Riposo';
  68. }
  69. }
  70. /*
  71. if ($t->excluded)
  72. {
  73. $t->name = 'Riposo';
  74. }
  75. else
  76. {
  77. if (strtoupper($t->type) == 'ANDATA')
  78. {
  79. if ($this->type == 'ANDATA')
  80. {
  81. if ($this->day > $t->day)
  82. {
  83. $t->name = 'Riposo';
  84. }
  85. }
  86. }
  87. }*/
  88. }
  89. return $t;
  90. }
  91. public function getResult()
  92. {
  93. $res = '';
  94. //if ($this->played)
  95. //{
  96. if($this->away_team_id != null && $this->home_team_id != null)
  97. {
  98. // Controllo se una squadra è stata esclusa
  99. $exc = false;
  100. $t = Team::findOrFail($this->home_team_id);
  101. if (strtoupper($t->type) == 'ANDATA') // && $t->type != '-') || $t->excluded)
  102. $exc = true;
  103. $t = Team::findOrFail($this->away_team_id);
  104. if (strtoupper($t->type) == 'ANDATA') // && $t->type != '-') || $t->excluded)
  105. $exc = true;
  106. if ($exc)
  107. $res = "NV";
  108. else
  109. $res = $this->home_goals . " - " . $this->away_goals;
  110. }
  111. //}
  112. //$res = $this->home_goals . " - " . $this->away_goals;
  113. return $res;
  114. }
  115. }