Media model e interfaces (in lavorazione)

This commit is contained in:
Lorenzo Giacomelli
2016-01-12 15:35:37 +01:00
parent 9ab9016142
commit 9657a5aedb
17 changed files with 311 additions and 1 deletions
+11
View File
@@ -0,0 +1,11 @@
<?php
interface MediaHandlerInterface{
public function getMedias($model);
public function addMedia($model,$media);
public function deleteMedia($model,$media);
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaModelHtml5 extends MediaModel{
private $link;
public function __construct($link){
parent::__construct(self::TYPE_HTML5);
$this->link = $link;
}
}
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaModelImage extends MediaModel{
private $path;
private $destination;
public function __construct($origin){
parent::__construct(self::TYPE_IMAGE);
$this->path = $origin;
$this->destination = $config->paths->media;
$this->destination .= $this->_id;
}
public function onSave(){
try{
if(!is_dir($this->destination)){
SFSManager::createDirectory($this->destination);
}
SFSManager::copyFile($this->path, $this->destination.=$this->_id);
}catch(SFSException $ex){
throw new CoreException("Error while saving model with id '".$this->_id. "' ".$ex->getMessage());
}
}
}
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaModelLocalVideo extends MediaModel{
private $path;
private $destination;
public function __construct($origin){
parent::__construct(self::TYPE_LOCALVIDEO);
$this->path = $origin;
$this->destination = $config->paths->media;
$this->destination .= $this->_id;
}
public function onSave(){
try{
if(!is_dir($this->destination)){
SFSManager::createDirectory($this->destination);
}
SFSManager::copyFile($this->path, $this->destination.=$this->_id);
}catch(SFSException $ex){
throw new CoreException("Error while saving model with id '".$this->_id. "' ".$ex->getMessage());
}
}
}
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaModelPdf extends MediaModel{
private $path;
private $destination;
public function __construct($origin){
parent::__construct(self::TYPE_PDF);
$this->path = $origin;
$this->destination = $config->paths->media;
$this->destination .= $this->_id;
}
public function onSave(){
try{
if(!is_dir($this->destination)){
SFSManager::createDirectory($this->destination);
}
SFSManager::copyFile($this->path, $this->destination.=$this->_id);
}catch(SFSException $ex){
throw new CoreException("Error while saving model with id '".$this->_id. "' ".$ex->getMessage());
}
}
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaModelYoutube extends MediaModel{
private $link;
public function __construct($link){
parent::__construct(self::TYPE_YOUTUBE);
$this->link = $link;
}
}
?>
@@ -0,0 +1,7 @@
<?php
class MediaHandlerModel extends Model implements MediaHandlerInterface{
}
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
class MediaModel extends Model{
private $type;
public $id;
public $details;
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")
);
public function __construct($mediaType){
if(array_key_exists($mediaType, self::$MEDIA_TYPES)){
$this->type = $mediaType;
}
else{
throw new MediaException("Invalid media type for Media; mediatype '".$mediaType."'");
}
}
abstract public function onSave();
}
?>
+1 -1
View File
@@ -26,7 +26,7 @@ require_once(dirname(__FILE__)."/system/lib.inclusion.php");
require_once(dirname(__FILE__)."/dao/lib.inclusion.php");
require_once(dirname(__FILE__)."/media/lib.inclusion.php");
// require_once(dirname(__FILE__)."/Status.php");
+31
View File
@@ -0,0 +1,31 @@
<?php
class Media implements MediaInterface{
private $type;
public $id;
public $details;
public function __construct($mediaType){
if(array_key_exists($mediaType, Media::$MEDIA_TYPES)){
$this->type = $mediaType;
}
else{
throw new MediaException("Invalid media type for Media; mediatype '".$mediaType."'");
}
}
abstract public function asText();
public function renderMedia(){
echo $this->asText();
}
public function getType(){
return $this->type;
}
public function getTitle(){
return $this->details;
}
}
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
class MediaException extends CoreException{
}
?>
+28
View File
@@ -0,0 +1,28 @@
<?php
/*
interface 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")
);
public function asText();
public function renderMedia();
public function getType();
public function getTitle();
}*/
?>
+19
View File
@@ -0,0 +1,19 @@
<?php
/*
Author: Lorenzo Giacomelli
Creation Date: 08/gen/2016
*/
// Inclue Media
require_once(dirname(__FILE__)."/MediaException.php");
require_once(dirname(__FILE__)."/MediaInterface.php");
require_once(dirname(__FILE__)."/Media.php");
require_once(dirname(__FILE__)."/../dao/MediaModel.php");
require_once(dirname(__FILE__)."/mediaTypes/MediaYoutube.php");
require_once(dirname(__FILE__)."/mediaTypes/MediaImage.php");
require_once(dirname(__FILE__)."/mediaTypes/MediaHTML5.php");
require_once(dirname(__FILE__)."/mediaTypes/MediaPDF.php");
require_once(dirname(__FILE__)."/mediaTypes/MediaLocalVideo.php");
?>
@@ -0,0 +1,15 @@
<?php
class MediaHtml5 extends Media{
private $code;
public function __construct($code){
parent::__construct(self::TYPE_HTML5);
$this->code = $code;
}
public function asText(){
echo $this->code;
}
}
?>
@@ -0,0 +1,14 @@
<?php
class MediaImage extends Media{
private $path;
public function __construct($path){
parent::__construct(self::TYPE_IMAGE);
$this->path = $path;
}
public function asText(){
echo $this->path;
}
}
?>
@@ -0,0 +1 @@
<?php
@@ -0,0 +1,15 @@
<?php
class MediaYoutube extends Media{
private $link;
public function __construct($link){
parent::__construct(self::TYPE_YOUTUBE);
$this->link = $link;
}
public function asText(){
echo "iframe ".$this->link;
}
}
?>