MediaHandler, MediaModel e HasMediaModel da testare

This commit is contained in:
Lorenzo Giacomelli
2016-01-13 18:20:44 +01:00
parent d0ec7b3aa4
commit 8d351faa5e
7 changed files with 68 additions and 56 deletions
-1
View File
@@ -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);
+1 -1
View File
@@ -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
+1 -1
View File
@@ -30,7 +30,7 @@ interface HasMediaInterface{
* Setta il media principale
* @param MediaModel $media
*/
public function setMainMedia(MediaModel $media);
public function setMainMedia(MediaInterface $media);
/**
* Restituisce la reference (id) del main media
+14 -9
View File
@@ -66,7 +66,8 @@ class MediaHandler{
$mediaId = $media->getReference();
if(sizeof($mediaArr)>0){
if($key = array_search($mediaId, $mediaArr) !== false){ /*:TODO check con riky*/
$key = array_search($mediaId, $mediaArr);
if($key !== false){
unset($mediaArr[$key]);
$model->setMediaReferences($mediaArr);
@@ -88,10 +89,19 @@ class MediaHandler{
}
/**
*
* 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 unknown
* @return DaoSaveable
*/
public static function getMediaOwnerFromMedia(MediaInterface $media){
$ownerRef = $media->getOwnerReference();
@@ -103,11 +113,6 @@ class MediaHandler{
}
}
public static function setMediaOwner(){
}
/**
*
* @param HasMediaInterface $model
@@ -127,7 +132,7 @@ class MediaHandler{
* Prende in ingresso un HasMediaInterface ritorna un array di un elemento array("mainMedia"=>"&value");
*
* @param HasMediaInterface $model
* @return multitype:NULL
* @return array
*/
public static function getMainMediaFromModel(HasMediaInterface $model){
$mainMedia = $model->getMainMediaReference();
-14
View File
@@ -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();
+28 -10
View File
@@ -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(){
@@ -57,5 +73,7 @@ class MediaModel extends Model implements MediaInterface{
public function getReference(){
return $this->id;
}
}
?>
+24 -20
View File
@@ -7,33 +7,37 @@ Creation Date: 22/dic/2015
require_once(dirname(__FILE__)."/load.php");
try {
// var_dump($dao->query("notizia"));
TestTask::setActive(false);
echo "<br><br>";
$models = $dao->query("NotiziaModel");
$model = reset($models);
$media = new MediaModel();
var_dump($model);
echo "<br><br>";
$model->immagini = array();
// // var_dump($dao->query("notizia"));
// TestTask::setActive(false);
// echo "<br><br>";
$model->immagini[] = "1.jpg";
$model->immagini[] = "2.jpg";
$model->about->giorno = "boh";
// $models = $dao->query("NotiziaModel");
// $model = reset($models);
if ($model->hasProperty("about")){
echo "esiste";
}
else {
echo "non esiste";
}
// var_dump($model);
// echo "<br><br>";
var_dump($model);
echo "<br><br>";
// $model->immagini = array();
$dao->save($model);
// $model->immagini[] = "1.jpg";
// $model->immagini[] = "2.jpg";
// $model->about->giorno = "boh";
// // if ($model->hasProperty("about")){
// // echo "esiste";
// // }
// // else {
// // echo "non esiste";
// // }
// var_dump($model);
// echo "<br><br>";
// $dao->save($model);
}
catch (Exception $ex){