Files
fdn2/private/lib/dao/mediaModels/MediaModel.php
T
Lorenzo Giacomelli 8c87460645 editBanner completato, da testare;
editBanner eliminata la funzione di deleteMedia;
addMultimedia eliminato il parametro path dai media;
listBanner e bannerTableBackend aggiunto alla table il campo type
2016-02-18 17:22:29 +01:00

98 lines
2.4 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"=>"Image"),
self::TYPE_HTML5=>array("label"=>"Html5"),
self::TYPE_PDF=>array("label"=>"Pdf"),
self::TYPE_LOCALVIDEO=>array("label"=>"Local Video")
);
private $mediaRenderer;
public function __construct($saveableObject = null){
parent::__construct($saveableObject);
$this->setMediaRenderer();
}
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(){
return $this->mediaRenderer->asText();
}
public function renderMedia(){
// var_dump($this->mediaRenderer);
$this->mediaRenderer->render();
}
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";
}
}
}
?>