| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class CalendarGame extends Model
- {
- protected $fillable = [
- 'calendar_id',
- 'home_team_id',
- 'away_team_id',
- 'date',
- 'day',
- 'type',
- 'home_goals',
- 'away_goals',
- 'home_points',
- 'away_points',
- 'played'
- ];
- public function homeTeam()
- {
- return $this->belongsTo('App\Team');
- }
- public function awayTeam()
- {
- return $this->belongsTo('App\Team');
- }
- public function getHomeTeam()
- {
- $team_id = $this->home_team_id;
- //if ($this->type == 'RITORNO')
- // $team_id = $this->away_team_id;
- if ($team_id == null)
- {
- $t = new Team();
- $t->name = 'Riposo';
- }
- else
- {
- $t = Team::findOrFail($team_id); // $this->belongsTo('App\Team');
- if (($t->type != '' && $t->type != '-') || $t->excluded)
- {
- if ($t->type == 'andata')
- {
- // $t->name = 'Riposo';
- }
-
- }
-
- }
- return $t;
- }
- public function getAwayTeam()
- {
- $team_id = $this->away_team_id;
- //if ($this->type == 'RITORNO')
- // $team_id = $this->home_team_id;
- if ($team_id == null)
- {
- $t = new Team();
- $t->name = 'Riposo';
- }
- else
- {
- $t = Team::findOrFail($team_id); // $this->belongsTo('App\Team');
- if (($t->type != '' && $t->type != '-') || $t->excluded)
- {
- if ($t->type == 'andata')
- {
- // $t->name = 'Riposo';
- }
- }
- /*
- if ($t->excluded)
- {
- $t->name = 'Riposo';
- }
- else
- {
- if (strtoupper($t->type) == 'ANDATA')
- {
- if ($this->type == 'ANDATA')
- {
- if ($this->day > $t->day)
- {
- $t->name = 'Riposo';
- }
- }
- }
- }*/
- }
- return $t;
- }
- public function getResult()
- {
- $res = '';
- //if ($this->played)
- //{
- if($this->away_team_id != null && $this->home_team_id != null)
- {
- // Controllo se una squadra è stata esclusa
- $exc = false;
- $t = Team::findOrFail($this->home_team_id);
- if (strtoupper($t->type) == 'ANDATA') // && $t->type != '-') || $t->excluded)
- $exc = true;
- $t = Team::findOrFail($this->away_team_id);
- if (strtoupper($t->type) == 'ANDATA') // && $t->type != '-') || $t->excluded)
- $exc = true;
- if ($exc)
- $res = "NV";
- else
- $res = $this->home_goals . " - " . $this->away_goals;
- }
- //}
- //$res = $this->home_goals . " - " . $this->away_goals;
- return $res;
- }
- }
|