105 lines
2.6 KiB
PHP
105 lines
2.6 KiB
PHP
<?php
|
|
|
|
class MediaModel extends Model implements MediaInterface{
|
|
const TYPE_YOUTUBE = 1;
|
|
const TYPE_IMAGE = 2;
|
|
const TYPE_HTML5 = 3;
|
|
const TYPE_PDF = 4;
|
|
const TYPE_LOCALVIDEO = 5;
|
|
|
|
public static $MEDIA_TYPES = array(
|
|
self::TYPE_YOUTUBE=>array("label"=>"Youtube"),
|
|
self::TYPE_IMAGE=>array("label"=>"Immagine"),
|
|
self::TYPE_HTML5=>array("label"=>"Html5"),
|
|
self::TYPE_PDF=>array("label"=>"Pdf"),
|
|
self::TYPE_LOCALVIDEO=>array("label"=>"Video")
|
|
);
|
|
|
|
|
|
private $mediaRenderer;
|
|
|
|
|
|
public function __construct($saveableObject = null){
|
|
parent::__construct($saveableObject);
|
|
$this->setMediaRenderer();
|
|
}
|
|
|
|
public function __set($attr,$value){
|
|
if (strcmp("mediaType", $attr)==0){
|
|
$value = intval($value);
|
|
}
|
|
return parent::__set($attr, $value);
|
|
}
|
|
|
|
public function setMediaRenderer(){
|
|
if($this->hasProperty("mediaType")){
|
|
if ($this->mediaType == self::TYPE_HTML5){
|
|
if ($this->hasProperty("code")){
|
|
$this->mediaRenderer = new MediaHtml5($this->code);
|
|
}
|
|
else {
|
|
throw new MediaException("Media of type 'HTML5' has no code field");
|
|
}
|
|
}
|
|
if ($this->mediaType == self::TYPE_LOCALVIDEO){
|
|
$this->mediaRenderer = new MediaLocalVideo($this);
|
|
}
|
|
if ($this->mediaType == self::TYPE_IMAGE){
|
|
$this->mediaRenderer = new MediaImage($this->id);
|
|
}
|
|
if ($this->mediaType == self::TYPE_PDF){
|
|
$this->mediaRenderer = new MediaPdf($this);
|
|
}
|
|
if ($this->mediaType == self::TYPE_YOUTUBE){
|
|
$this->mediaRenderer = new MediaYoutube($this);
|
|
}
|
|
}
|
|
else{
|
|
throw new MediaException("Missing mediatype for Media in MediaModel construct");
|
|
}
|
|
}
|
|
|
|
public function asText(array $opts = array()){
|
|
return $this->mediaRenderer->asText($opts);
|
|
}
|
|
|
|
public function renderMedia(array $opts = array()){
|
|
// var_dump($this->mediaRenderer);
|
|
$this->mediaRenderer->render($opts);
|
|
}
|
|
|
|
public function getType(){
|
|
return $this->mediaType;
|
|
}
|
|
|
|
public static function getCollectionName(){
|
|
return "media";
|
|
}
|
|
|
|
public function setOwnerReference(HasMediaInterface $model){
|
|
$this->owner = $model->getReference();
|
|
}
|
|
|
|
public function getOwnerReference(){
|
|
return $this->owner;
|
|
}
|
|
|
|
public function getReference(){
|
|
return $this->id;
|
|
}
|
|
|
|
public function updateFromSaveableObj($saveableObject){
|
|
parent::updateFromSaveableObj($saveableObject);
|
|
$this->setMediaRenderer();
|
|
}
|
|
|
|
public function getPath(){
|
|
if(($this->mediaType == self::TYPE_IMAGE) || ($this->mediaType == self::TYPE_PDF) || ($this->mediaType == self::TYPE_LOCALVIDEO)){
|
|
return $this->mediaRenderer->getPath();
|
|
}
|
|
else{
|
|
return "questo media non è presente all'interno dell'applicativo";
|
|
}
|
|
}
|
|
}
|
|
?>
|