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

148 lines
2.4 KiB
PHP

<?php
class Format
{
/**
* @var integer $id Identifiant du format
*/
protected $id;
/**
* @var string $lib Lib du format
*/
protected $lib;
/**
* @var boolean $normalise
*/
protected $normalise;
/**
* @var mixed[] $videos Vidéos
*/
protected $videos = [];
/**
* @param string $lib Lib du format
*/
public function __construct($lib)
{
$this->setLib($lib);
}
/**
* @param integer|null $id
* @return Format
*/
public function setId($id)
{
$this->id = (int) $id;
return $this;
}
/**
* @return integer|null
*/
public function getId()
{
return $this->id;
}
/**
* @param string $lib
* @return Format
*/
public function setLib($lib)
{
if ('' === trim((string) $lib)) {
throw new InvalidArgumentException('La lib ne peut pas être vide.');
}
$this->lib = $lib;
return $this;
}
/**
* @return string|null
*/
public function getLib()
{
return $this->lib;
}
/**
* @param string $lib
* @return Format
*/
public function setNormalise($normalise)
{
$this->normalise = (bool) $normalise;
return $this;
}
/**
* @return boolean
*/
public function getNormalise()
{
return (bool) $this->normalise;
}
/**
* @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 Format
*/
public function addVideo(Video $video)
{
if ($this->hasVideo($video)) {
return $this;
}
$this->videos[] = $video;
$video->addFormat($this);
return $this;
}
/**
* @param mixed[] $videos
* @return Format
*/
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;
}
}