From d3157e75173eb14767bf2f9abc7d72a148fc8aaa Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 7 Apr 2015 19:56:16 +0200 Subject: [PATCH] Links beetween Type/Categorie/Pays <-> Video --- classes/class.Categorie.php | 56 +++++++++++++++++++++++++++++++ classes/class.Pays.php | 66 ++++++++++++++++++++++++++++++++++++- classes/class.Type.php | 56 +++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 1 deletion(-) diff --git a/classes/class.Categorie.php b/classes/class.Categorie.php index 01f9fac..0ce9dd3 100644 --- a/classes/class.Categorie.php +++ b/classes/class.Categorie.php @@ -12,6 +12,11 @@ class Categorie */ protected $lib; + /** + * @var mixed[] $videos Vidéos + */ + protected $videos = []; + /** * @param string $lib Lib de la catégorie */ @@ -61,4 +66,55 @@ class Categorie { return $this->lib; } + + /** + * @param Video $video + * @return boolean La catégorie est associé à la vidéo + */ + public function hasVideo(Video $video) + { + foreach ($this->getVideos() as $p) { + if ($p === $video) { + return true; + } + } + + return false; + } + + /** + * @return Type + */ + public function addVideo(Video $video) + { + if ($this->hasVideo($video)) { + return $this; + } + + $video->addCategorie($this); + + $this->videos[] = $video; + + return $this; + } + + /** + * @param mixed[] $videos + * @return Type + */ + public function setVideos(array $videos) + { + $this->videos = []; + + foreach ($this->getVideos() as $v) { + $this->addVideo($v); + } + + return $this; + } + + public function getVideos() + { + return $this->videos; + } } diff --git a/classes/class.Pays.php b/classes/class.Pays.php index 1def153..87eba95 100644 --- a/classes/class.Pays.php +++ b/classes/class.Pays.php @@ -22,6 +22,11 @@ class Pays */ protected $participants = []; + /** + * @var mixed[] $videos Vidéos + */ + protected $videos = []; + /** * @param string $nom Nom du pays * @param string $symbole Symbole du pays @@ -111,6 +116,10 @@ class Pays } } + if ($this !== $participant->getPays()) { + $participant->setPays($this); + } + $this->participants[] = $participant; return $this; @@ -122,7 +131,11 @@ class Pays */ public function setParticipants(array $participants) { - $this->participants = $participants; + $this->participants = []; + + foreach ($participants as $participant) { + $this->addParticipant($participant); + } return $this; } @@ -131,4 +144,55 @@ class Pays { return $this->participants; } + + /** + * @param Video $video + * @return boolean Le pays est associé à la vidéo + */ + public function hasVideo(Video $video) + { + foreach ($this->getVideos() as $p) { + if ($p === $video) { + return true; + } + } + + return false; + } + + /** + * @return Pays + */ + public function addVideo(Video $video) + { + if ($this->hasVideo($video)) { + return $this; + } + + $video->addPays($this); + + $this->videos[] = $video; + + return $this; + } + + /** + * @param mixed[] $videos + * @return Pays + */ + public function setVideos(array $videos) + { + $this->videos = []; + + foreach ($this->getVideos() as $v) { + $this->addVideo($v); + } + + return $this; + } + + public function getVideos() + { + return $this->videos; + } } diff --git a/classes/class.Type.php b/classes/class.Type.php index ae712ca..28b4efd 100644 --- a/classes/class.Type.php +++ b/classes/class.Type.php @@ -12,6 +12,11 @@ class Type */ protected $lib; + /** + * @var mixed[] $videos Vidéos + */ + protected $videos = []; + /** * @param string $lib Lib du type */ @@ -61,4 +66,55 @@ class Type { return $this->lib; } + + /** + * @param Video $video + * @return boolean Le type est associé à la vidéo + */ + public function hasVideo(Video $video) + { + foreach ($this->getVideos() as $p) { + if ($p === $video) { + return true; + } + } + + return false; + } + + /** + * @return Type + */ + public function addVideo(Video $video) + { + if ($this->hasVideo($video)) { + return $this; + } + + $video->addType($this); + + $this->videos[] = $video; + + return $this; + } + + /** + * @param mixed[] $videos + * @return Type + */ + public function setVideos(array $videos) + { + $this->videos = []; + + foreach ($this->getVideos() as $v) { + $this->addVideo($v); + } + + return $this; + } + + public function getVideos() + { + return $this->videos; + } }