summaryrefslogtreecommitdiff
path: root/app/Rugby/Model
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-06-20 21:07:45 +0100
committerFbenas <philbeansburton@gmail.com>2020-06-20 21:07:45 +0100
commit8d6e8b306d7836e4075a13ad98617bfe5afaa1a0 (patch)
tree99c44e28da231cac0d9e513aabc1ee0768972426 /app/Rugby/Model
parent897b68ac107f2fb0d4dc1d31ce96ce24c862eb27 (diff)
Add new scripts for youtube downloading and syncing with existing matches
Diffstat (limited to 'app/Rugby/Model')
-rw-r--r--app/Rugby/Model/Match.php25
-rw-r--r--app/Rugby/Model/Team.php16
-rw-r--r--app/Rugby/Model/Tournament.php20
-rw-r--r--app/Rugby/Model/Video.php34
4 files changed, 88 insertions, 7 deletions
diff --git a/app/Rugby/Model/Match.php b/app/Rugby/Model/Match.php
index 5447ef5..58a3dd9 100644
--- a/app/Rugby/Model/Match.php
+++ b/app/Rugby/Model/Match.php
@@ -2,19 +2,13 @@
namespace App\Rugby\Model;
-use App\Rugby\Model\Team;
-use App\Rugby\Model\Tournament;
-use App\Rugby\Model\Venue;
-
use Illuminate\Database\Eloquent\Model;
class Match extends Model
{
protected $table = 'matches';
-
protected $casts = ['date' => 'datetime:Y-m-d'];
-
- protected $fillable = ['score', 'half_score', 'referee', 'date'];
+ protected $fillable = ['score', 'half_score', 'referee', 'date'];
public function teams()
{
@@ -42,6 +36,17 @@ class Match extends Model
return (new \Carbon\Carbon($this->date))->format('M d Y');
}
+ public function getVideoUrl()
+ {
+ $video = $this->videos()->first();
+
+ if (! $video) {
+ return '';
+ }
+
+ return $video->getUrl();
+ }
+
public function homeTeam()
{
return $this->teams()->wherePivot('is_home', '=', true);
@@ -56,4 +61,10 @@ class Match extends Model
{
return $this->belongsToMany(Tournament::class, 'match_tournament');
}
+
+ public function videos()
+ {
+ return $this->hasMany(Video::class, 'match_id');
+ }
+
}
diff --git a/app/Rugby/Model/Team.php b/app/Rugby/Model/Team.php
index 2582f33..2dbfea6 100644
--- a/app/Rugby/Model/Team.php
+++ b/app/Rugby/Model/Team.php
@@ -2,12 +2,15 @@
namespace App\Rugby\Model;
+use App\Rugby\Concerns\Matchable;
use Illuminate\Database\Eloquent\Model;
use App\Rugby\Model\Match;
class Team extends Model
{
+ use Matchable;
+
protected $table = 'teams';
protected $fillable = ['name'];
@@ -31,4 +34,17 @@ class Team extends Model
{
return $this->name ?: '';
}
+
+ public function matchableFilters()
+ {
+ $name_parts = collect(explode(' ', $this->name));
+
+ $out = $name_parts->map(
+ function ($value) {
+ return ['string', $value];
+ }
+ );
+
+ return $out;
+ }
}
diff --git a/app/Rugby/Model/Tournament.php b/app/Rugby/Model/Tournament.php
index 64d9a45..3ab6352 100644
--- a/app/Rugby/Model/Tournament.php
+++ b/app/Rugby/Model/Tournament.php
@@ -2,16 +2,36 @@
namespace App\Rugby\Model;
+use App\Rugby\Concerns\Matchable;
use App\Rugby\Model\Match;
use Illuminate\Database\Eloquent\Model;
class Tournament extends Model
{
+ use Matchable;
+
protected $table = 'tournaments';
protected $fillable = ['name'];
+ public function matchableFilters()
+ {
+ $name_parts = collect(explode(' ', $this->name));
+
+ $out = $name_parts->map(
+ function ($value) {
+ if ($this->isDate($value)) {
+ return ['date', $value];
+ }
+
+ return ['string', $value];
+ }
+ );
+
+ return $out;
+ }
+
public function matches()
{
return $this->belongsToMany(Match::class);
diff --git a/app/Rugby/Model/Video.php b/app/Rugby/Model/Video.php
new file mode 100644
index 0000000..2182b65
--- /dev/null
+++ b/app/Rugby/Model/Video.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Rugby\Model;
+
+use App\Rugby\Model\Match;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Storage;
+
+class Video extends Model
+{
+ protected $table = 'videos';
+ protected $casts = ['date' => 'datetime:Y-m-d'];
+ protected $fillable = ['path'];
+
+ public function match()
+ {
+ return $this->belongsTo(Match::class);
+ }
+
+ public function getFilename(): string
+ {
+ $parts = explode('/', $this->path);
+
+ return $parts[count($parts) - 1];
+ }
+
+ public function getUrl(): string
+ {
+ return asset('storage/matches/' . $this->getFilename());
+ // return Storage::disk('local')->url(
+ // 'matches/' . $this->getFilename()
+ // );
+ }
+}