mmi-correction-tp03/classes/class.Pays.php
2015-04-07 21:25:31 +02:00

202 lines
3.5 KiB
PHP

<?php
class Pays
{
/**
* @var integer $id Identifiant du pays
*/
protected $id;
/**
* @var string $nom Nom du pays
*/
protected $nom;
/**
* @var string $symbole Symbole du pays
*/
protected $symbole;
/**
* @var mixed[] $participants Participants
*/
protected $participants = [];
/**
* @var mixed[] $videos Vidéos
*/
protected $videos = [];
/**
* @param string $nom Nom du pays
* @param string $symbole Symbole du pays
*/
public function __construct($nom, $symbole = null)
{
$this->setNom($nom);
if (null !== $symbole) {
$this->setSymbole($symbole);
}
}
/**
* @param integer|null $id
* @return Pays
*/
public function setId($id)
{
$this->id = (int) $id;
return $this;
}
/**
* @return integer|null
*/
public function getId()
{
return $this->id;
}
/**
* @param string $nom
* @return Pays
*/
public function setNom($nom)
{
if ('' === trim((string) $nom)) {
throw new InvalidArgumentException('Le nom ne peut pas être vide.');
}
$this->nom = $nom;
return $this;
}
/**
* @return string|null
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string $symbole
* @return Pays
*/
public function setSymbole($symbole)
{
if ('' === trim((string) $symbole)) {
throw new InvalidArgumentException('Le symbole ne peut pas être vide.');
}
$this->symbole = $symbole;
return $this;
}
/**
* @return string|null
*/
public function getSymbole()
{
return $this->symbole;
}
/**
* @return Pays
*/
public function addParticipant(Participant $participant)
{
foreach ($this->getParticipants() as $p) {
if ($p === $participant) {
return $this;
}
}
$this->participants[] = $participant;
if ($this !== $participant->getPays()) {
$participant->setPays($this);
}
return $this;
}
/**
* @param mixed[] $participants
* @return Pays
*/
public function setParticipants(array $participants)
{
$this->participants = [];
foreach ($participants as $participant) {
$this->addParticipant($participant);
}
return $this;
}
public function getParticipants()
{
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;
}
$this->videos[] = $video;
$video->addPays($this);
return $this;
}
/**
* @param mixed[] $videos
* @return Pays
*/
public function setVideos(array $videos)
{
$this->videos = [];
foreach ($videos as $v) {
$this->addVideo($v);
}
return $this;
}
/**
* @return mixed[] $videos
*/
public function getVideos()
{
return $this->videos;
}
}