Merge branch 'master' of
ssh://gitolite@asdynamics.com:50005/projects/fdn2.git Conflicts: public/index.php
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
MediaLocalVideo,MediaImage,Mediapdf {path}
|
||||
MediaYoutube {link}
|
||||
MediaHtml5 {code}
|
||||
@@ -18,7 +18,6 @@ interface DaoSaveable {
|
||||
|
||||
/**
|
||||
* Costruisce l'oggetto a partire dai dati raw di mongo
|
||||
* @param string $collectionName Nome della collezione da cui proviene l'oggetto
|
||||
* @param stdClass $obj dati raw di mongo
|
||||
*/
|
||||
public static function buildFromSaveableObj($obj);
|
||||
|
||||
@@ -31,7 +31,7 @@ require_once(dirname(__FILE__)."/dao/lib.inclusion.php");
|
||||
|
||||
require_once(dirname(__FILE__)."/task/lib.inclusion.php");
|
||||
|
||||
// require_once(dirname(__FILE__)."/media/lib.inclusion.php");
|
||||
require_once(dirname(__FILE__)."/media/lib.inclusion.php");
|
||||
|
||||
// asdasdasd
|
||||
|
||||
|
||||
@@ -3,13 +3,19 @@
|
||||
interface HasMediaInterface{
|
||||
|
||||
/**
|
||||
* Ritorna un oggetto reference contenente id e collection name
|
||||
* Ritorna un oggetto reference contenente id e class
|
||||
* @return stdClass
|
||||
*/
|
||||
public function getReference();
|
||||
|
||||
/**
|
||||
* Setta la referenza ai media
|
||||
* Setta la referenza partendo da un array di oggetti media
|
||||
* @param array $references
|
||||
*/
|
||||
public function setMedias(array $medias);
|
||||
|
||||
/**
|
||||
* Setta la referenza partendo da un array di id di media
|
||||
* @param array $references
|
||||
*/
|
||||
public function setMediaReferences(array $references);
|
||||
@@ -20,8 +26,16 @@ interface HasMediaInterface{
|
||||
*/
|
||||
public function getMediaReferences();
|
||||
|
||||
public function setMainMedia();
|
||||
/**
|
||||
* Setta il media principale
|
||||
* @param MediaModel $media
|
||||
*/
|
||||
public function setMainMedia(MediaInterface $media);
|
||||
|
||||
public function getMainMedia();
|
||||
/**
|
||||
* Restituisce la reference (id) del main media
|
||||
* @return MongoId
|
||||
*/
|
||||
public function getMainMediaReference();
|
||||
}
|
||||
?>
|
||||
@@ -9,7 +9,7 @@ abstract class HasMediaModel extends Model implements HasMediaInterface{
|
||||
public function getReference(){
|
||||
$rval = new stdClass();
|
||||
|
||||
$rval->collection = static::getCollectionName();
|
||||
$rval->class = get_class($this);
|
||||
$rval->id = $this->id;
|
||||
return $rval;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ abstract class HasMediaModel extends Model implements HasMediaInterface{
|
||||
* (non-PHPdoc)
|
||||
* @see HasMediaInterface::setMediaReferences()
|
||||
*/
|
||||
public function setMediaReferences(array $medias){
|
||||
public function setMedias(array $medias){
|
||||
$this->mediaReferences = array();
|
||||
if(sizeof($medias)>0){
|
||||
foreach ($medias as $media){
|
||||
@@ -29,6 +29,15 @@ abstract class HasMediaModel extends Model implements HasMediaInterface{
|
||||
}
|
||||
}
|
||||
|
||||
public function setMediaReferences(array $references){
|
||||
$this->mediaReferences = array();
|
||||
if(sizeof($references)>0){
|
||||
foreach ($references as $reference){
|
||||
$this->mediaReferences[] = $reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see HasMediaInterface::getMediaReferences()
|
||||
@@ -40,5 +49,21 @@ abstract class HasMediaModel extends Model implements HasMediaInterface{
|
||||
return $this->mediaReferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see HasMediaInterface::setMainMedia()
|
||||
*/
|
||||
public function setMainMedia(MediaInterface $media){
|
||||
$this->mainMedia = $media->getReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see HasMediaInterface::getMainMediaReference()
|
||||
*/
|
||||
public function getMainMediaReference(){
|
||||
return $this->mainMedia;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -2,14 +2,15 @@
|
||||
|
||||
class MediaHandler{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param HasMediaModel $news
|
||||
* @param MediaModel $media
|
||||
* @param HasMediaInterface $news
|
||||
* @param MediaInterface $media
|
||||
*
|
||||
* Ritorna un array coi i media della news
|
||||
* Ritorna un array coi le reference dei media della news
|
||||
*/
|
||||
public static function getMedias(HasMediaModel $model,MediaModel $media){
|
||||
public static function getMedias(HasMediaInterface $model,MediaInterface $media){
|
||||
$newsReference = $model->getMediaReferences();
|
||||
$rval = array();
|
||||
|
||||
@@ -20,27 +21,133 @@ class MediaHandler{
|
||||
|
||||
|
||||
/**
|
||||
* Aggiunge il media al model e controlla se il model ha un main media e se non lo ha glielo assegna
|
||||
*
|
||||
* @param HasMediaModel $news
|
||||
* @param MediaModel $media
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
*/
|
||||
public function addMedia(HasMediaModel $news, MediaModel $media){
|
||||
$newsReference = $news->getReference();
|
||||
$media->newsReference = $newsReference;
|
||||
public static function addMedia(HasMediaInterface $model, MediaInterface $media){
|
||||
if(!$model->hasProperty("id")){
|
||||
throw new MediaException("Invalid HasMediaInterface passed to MediaHandler::addMedia (no property ID)");
|
||||
}
|
||||
if(!$media->hasProperty("id")){
|
||||
throw new MediaException("Invalid MediaInterface passed to MediaHandler::addMedia (no property ID)");
|
||||
}
|
||||
|
||||
$news->media = array($media->getType=>$media->id);
|
||||
$dao->save($media);
|
||||
$dao->save($news);
|
||||
try{
|
||||
$mediaArr = array();
|
||||
$mediaArr = $model->getMediaReferences();
|
||||
if(!in_array($media->getReference(), $mediaArr)){
|
||||
$mediaArr[] = $media->getReference();
|
||||
$model->setMediaReferences($mediaArr);
|
||||
|
||||
GlobalVariables::get("dao")->save($model);
|
||||
|
||||
$media->setOwner($model);
|
||||
GlobalVariables::get("dao")->save($media);
|
||||
}
|
||||
}catch(CoreException $ex){
|
||||
throw new MediaException("Error while saving in MediaHandler::addMedia (".$ex->getMessage().")");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteMedia(HasMediaModel $model, MediaModel $media){
|
||||
$newsReference = $model->getReference();
|
||||
$mediaId = $media->id;
|
||||
|
||||
$newsArr = $dao->query($model->getCollectionName(),array("media"=>$media->id));
|
||||
/**
|
||||
* Elimina l'id del media dal model e deleta il media
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
*/
|
||||
public static function deleteMedia(HasMediaInterface $model, MediaInterface $media){
|
||||
try{
|
||||
$mediaArr = array();
|
||||
$mediaArr = $model->getMediaReferences();
|
||||
$mediaId = $media->getReference();
|
||||
|
||||
if(sizeof($mediaArr)>0){
|
||||
$key = array_search($mediaId, $mediaArr);
|
||||
if($key !== false){
|
||||
unset($mediaArr[$key]);
|
||||
$model->setMediaReferences($mediaArr);
|
||||
|
||||
GlobalVariables::get("dao")->save($model);
|
||||
|
||||
GlobalVariables::get("dao")->delete($media);
|
||||
}
|
||||
else{
|
||||
throw new MediaException("Trying to delete invalid media from a model in MediaHandler::deleteMedia");
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new MediaException("This HasMediaInterface has no media in it '".$model->id."' sizeof on mediaReference failed in MediaHandler::deleteMedia");
|
||||
}
|
||||
|
||||
}catch(CoreException $ex){
|
||||
throw new MediaException("Error while deleting in MediaHandler::deleteMedia (".$ex->getMessage().")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setta l'owner al MediaModel
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaModel $media
|
||||
*/
|
||||
public static function setOwnerToMedia(HasMediaInterface $model, MediaModel $media){
|
||||
$media->setOwnerReference($model);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
* @return DaoSaveable
|
||||
*/
|
||||
public static function getMediaOwnerFromMedia(MediaInterface $media){
|
||||
$ownerRef = $media->getOwnerReference();
|
||||
try{
|
||||
$owner = GlobalVariables::get("dao")->getFirst($ownerRef->class,array("id"=>$ownerRef->id));
|
||||
return $owner;
|
||||
}catch(CoreException $ex){
|
||||
throw new MediaException("Invalid Media Reference trying get Media Owner in MediaHandler::getMEdiaOwner");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
*/
|
||||
public static function setMainMediaToModel(HasMediaInterface $model, MediaInterface $media){
|
||||
try{
|
||||
$model->setMainMedia($media);
|
||||
GlobalVariables::get("dao")->save($model);
|
||||
}catch(CoreException $ex){
|
||||
throw new MediaException("Error while trying to save an HasMediaInterface in ModelHandler::setMainMedia");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prende in ingresso un HasMediaInterface ritorna un array di un elemento array("mainMedia"=>"&value");
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @return array
|
||||
*/
|
||||
public static function getMainMediaFromModel(HasMediaInterface $model){
|
||||
$mainMedia = $model->getMainMediaReference();
|
||||
$modelRef = $model->getReference();
|
||||
|
||||
$rval = array();
|
||||
|
||||
$tmp = GlobalVariables::get("dao")->getFirst($modelRef->class,array("id"=>$modelRef->id));
|
||||
|
||||
if(!is_null($tmp)){
|
||||
$rval["mainMedia"] = $tmp->mainMedia;
|
||||
}
|
||||
|
||||
return $rval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
<?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();
|
||||
|
||||
@@ -24,7 +10,7 @@ interface MediaInterface{
|
||||
|
||||
public function getTitle();
|
||||
|
||||
public function setOwner(HasMediaInterface $model);
|
||||
public function setOwnerReference(HasMediaInterface $model);
|
||||
public function getOwnerReference();
|
||||
|
||||
public function getReference();
|
||||
|
||||
@@ -1,33 +1,49 @@
|
||||
<?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){
|
||||
if(property_exists($saveableObject, mediaType)){
|
||||
parent::__construct($saveableObject);
|
||||
if ($this->type == self::TYPE_HTML5){
|
||||
parent::__construct($saveableObject);
|
||||
if($this->hasProperty("mediaType")){
|
||||
if ($this->mediaType == self::TYPE_HTML5){
|
||||
$this->mediaRenderer = new MediaHtml5($this);
|
||||
}
|
||||
if ($this->type == self::TYPE_LOCALVIDEO){
|
||||
if ($this->mediaType == self::TYPE_LOCALVIDEO){
|
||||
$this->mediaRenderer = new MediaLocalVideo($this);
|
||||
}
|
||||
if ($this->type == self::TYPE_IMAGE){
|
||||
if ($this->mediaType == self::TYPE_IMAGE){
|
||||
$this->mediaRenderer = new MediaImage($this);
|
||||
}
|
||||
if ($this->type == self::TYPE_PDF){
|
||||
if ($this->mediaType == self::TYPE_PDF){
|
||||
$this->mediaRenderer = new MediaPdf($this);
|
||||
}
|
||||
if ($this->type == self::TYPE_YOUTUBE){
|
||||
if ($this->mediaType == self::TYPE_YOUTUBE){
|
||||
$this->mediaRenderer = new MediaYoutube($this);
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new MediaException("Invalid media type for Media; mediatype '".$mediaType."'");
|
||||
throw new MediaException("Missing mediatype for Media in MediaModel construct");
|
||||
}
|
||||
}
|
||||
|
||||
private function asText(){
|
||||
public function asText(){
|
||||
return $this->mediaRenderer->asText();
|
||||
}
|
||||
|
||||
@@ -36,7 +52,7 @@ class MediaModel extends Model implements MediaInterface{
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
return $this->type;
|
||||
return $this->mediaType;
|
||||
}
|
||||
|
||||
public function getTitle(){
|
||||
@@ -47,7 +63,7 @@ class MediaModel extends Model implements MediaInterface{
|
||||
return "media";
|
||||
}
|
||||
|
||||
public function setOwner(HasMediaInterface $model){
|
||||
public function setOwnerReference(HasMediaInterface $model){
|
||||
$this->owner = $model->getReference();
|
||||
}
|
||||
public function getOwnerReference(){
|
||||
@@ -57,5 +73,7 @@ class MediaModel extends Model implements MediaInterface{
|
||||
public function getReference(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class MediaLocalVideo implements MediaRendererInterface{
|
||||
private $modelRef;
|
||||
|
||||
public function __construct(MediaModel $model){
|
||||
$this->modelRef = $model;
|
||||
}
|
||||
|
||||
public function asText(){
|
||||
return $this->modelRef->path;
|
||||
}
|
||||
|
||||
public function render(){
|
||||
echo $this->asText();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -7,6 +7,7 @@ Creation Date: 22/dic/2015
|
||||
require_once(dirname(__FILE__)."/load.php");
|
||||
|
||||
try {
|
||||
$media = new MediaModel();
|
||||
|
||||
// TestTask::setActive(false);
|
||||
// echo "<br><br>";
|
||||
|
||||
Reference in New Issue
Block a user