Aggiunta funzione a DaoMediaHandler che riporta true se un hasmediamodel
ha un meinmedia false altrimenti; admin.css force di ricaricamento; Aggiustati i mediarender che non mostravano correttamente i correspettiivi esText e uniformata la firma della funzione; addMultimedia aggiunge correttamente i meultimedia; homeMultimedia in testing;
This commit is contained in:
@@ -53,7 +53,7 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina l'id del media dal model e deleta il media
|
||||
* Elimina l'id del media dal model e deleta il media.
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaInterface $media
|
||||
@@ -126,7 +126,7 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
*/
|
||||
public static function setMainMediaToModel(HasMediaInterface $model, MediaInterface $media){
|
||||
public static function setMainMediaToModel(HasMediaInterface $model, MediaInterface $media=null){
|
||||
try{
|
||||
$model->setMainMedia($media);
|
||||
GlobalVariables::get("dao")->save($model);
|
||||
@@ -158,11 +158,10 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
* @param string $filePath
|
||||
* @return MediaModel
|
||||
*/
|
||||
public static function createNewFileBasedMedia($saveableObj, $filePath){
|
||||
public static function createNewFileBasedMedia($saveableObj, $filePath,$extension){
|
||||
$basepath = GlobalVariables::get("config")->paths->media;
|
||||
$info = pathinfo($filePath);
|
||||
$media = new MediaModel($saveableObj);
|
||||
$media->extension = $info["extension"];
|
||||
$media->extension = $extension;
|
||||
GlobalVariables::get("dao")->save($media);
|
||||
SFSManager::copyFile($filePath, $basepath."/".$media->id.".".$media->extension);
|
||||
return $media;
|
||||
@@ -179,6 +178,14 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
return $media;
|
||||
}
|
||||
|
||||
public static function hasMainMedia(HasMediaInterface $model){
|
||||
$hasMainMedia = false;
|
||||
if(!is_null($model->getMainMediaReference())){
|
||||
$hasMainMedia = true;
|
||||
}
|
||||
return $hasMainMedia;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -10,7 +10,7 @@ GUIHandler::addStylesheet(GUIHandler::STYLESHEET_ADMIN, "jquery-ui.css");
|
||||
|
||||
GUIHandler::addStylesheet(GUIHandler::STYLESHEET_ADMIN, "chosen.css");
|
||||
|
||||
GUIHandler::addStylesheet(GUIHandler::STYLESHEET_ADMIN, "admin.css");
|
||||
GUIHandler::addStylesheet(GUIHandler::STYLESHEET_ADMIN, "admin.css?rev=".time());
|
||||
|
||||
GUIHandler::addStylesheet(GUIHandler::STYLESHEET_ADMIN, "datatables.css");
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ interface MediaHandlerInterface{
|
||||
* @param MediaInterface $media
|
||||
* @throws MediaException
|
||||
*/
|
||||
public static function setMainMediaToModel(HasMediaInterface $model, MediaInterface $media);
|
||||
public static function setMainMediaToModel(HasMediaInterface $model, MediaInterface $media=null);
|
||||
|
||||
/**
|
||||
* Prende in ingresso un HasMediaInterface ritorna un array di un elemento array("mainMedia"=>"&value");
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
class MediaLocalVideo implements MediaRendererInterface{
|
||||
private $id;
|
||||
|
||||
public function __construct($id){
|
||||
$this->id = $id;
|
||||
public function __construct($model){
|
||||
$this->id = $model->id;
|
||||
}
|
||||
|
||||
public function asText(array $opt = array()){
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
class MediaPdf implements MediaRendererInterface{
|
||||
private $id;
|
||||
|
||||
public function __construct($id){
|
||||
$this->id = $model;
|
||||
public function __construct($model){
|
||||
$this->id = $model->id;
|
||||
}
|
||||
|
||||
public function asText(array $opt = array()){
|
||||
return $this->id;
|
||||
return GlobalVariables::get("config")->paths->media."/".$this->id.".pdf";
|
||||
}
|
||||
|
||||
public function render(array $opt = array()){
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
class MediaYoutube implements MediaRendererInterface{
|
||||
private $link;
|
||||
|
||||
public function __construct($link){
|
||||
$this->link = $link;
|
||||
public function __construct($model){
|
||||
$this->link = $model->link;
|
||||
}
|
||||
|
||||
public function asText(array $opt = array()){
|
||||
return '<iframe width="420" height="315"
|
||||
src=\"'.$this->link.'?autoplay=0\">
|
||||
</iframe>';
|
||||
return $this->link;
|
||||
// return '<iframe width="420" height="315"
|
||||
// src="'.$this->link.'?autoplay=0" frameborder="0" />';
|
||||
}
|
||||
|
||||
public function render(array $opt = array()){
|
||||
|
||||
@@ -43,8 +43,9 @@ try{
|
||||
else {
|
||||
$saveable->path = PostHandler::get("data");
|
||||
$file = $_FILES['data']['tmp_name'];
|
||||
$info = pathinfo($_FILES['data']['name']);
|
||||
// $file = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file);
|
||||
$media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file,$info["extension"]);
|
||||
}
|
||||
|
||||
if(!is_null($media)){
|
||||
@@ -85,22 +86,23 @@ HTMLHelper::generateAdminHead();
|
||||
<?php echo $error;?>
|
||||
<div>
|
||||
<form enctype="multipart/form-data" id="loadFile" method="POST">
|
||||
<div style="margin:15px 5px;">Selezionare tipo multimedia:
|
||||
<select id="mediaType" name="mediaType">
|
||||
<?php foreach (MediaModel::$MEDIA_TYPES as $mediaType=>$data){
|
||||
if(strcmp($mediaTypeSaved,$mediaType)==0){?>
|
||||
<option value="<?php echo $mediaType;?>" selected="selected">
|
||||
<?php
|
||||
}
|
||||
else{?>
|
||||
<option value="<?php echo $mediaType;?>">
|
||||
<?php
|
||||
}?>
|
||||
<?php echo $data["label"];?></option>
|
||||
<?php }?>
|
||||
</select>
|
||||
</div>
|
||||
<div style="margin:15px 5px;"><?php
|
||||
<div style="margin:15px 5px;">Selezionare tipo multimedia:
|
||||
<select id="mediaType" name="mediaType">
|
||||
<option disabled selected style="display:none;">Seleziona Tipo</option>
|
||||
<?php foreach (MediaModel::$MEDIA_TYPES as $mediaType=>$data){
|
||||
if(strcmp($mediaTypeSaved,$mediaType)==0){?>
|
||||
<option value="<?php echo $mediaType;?>" selected="selected">
|
||||
<?php
|
||||
}
|
||||
else{?>
|
||||
<option value="<?php echo $mediaType;?>">
|
||||
<?php
|
||||
}?>
|
||||
<?php echo $data["label"];?></option>
|
||||
<?php }?>
|
||||
</select>
|
||||
</div>
|
||||
<div style="margin:15px 5px;"><?php
|
||||
// <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
||||
// <input type="file" name="userFile"/>
|
||||
if(strcmp($mediaTypeSaved, MediaModel::TYPE_YOUTUBE)==0){
|
||||
@@ -114,11 +116,11 @@ HTMLHelper::generateAdminHead();
|
||||
}
|
||||
?> <input type="hidden" name="id" value="<?php echo $notiziaId;?>" />
|
||||
<input type="hidden" name="action" value=""/>
|
||||
</form>
|
||||
<div style="margin:15px 5px;">
|
||||
<a href="#" id="submit" >Invia</a>
|
||||
<a href="#" id="back" >Back</a>
|
||||
</div>
|
||||
</form>
|
||||
<div style="margin:15px 5px;">
|
||||
<a href="#" id="submit" >Invia</a>
|
||||
<a href="#" id="back" >Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,24 +16,55 @@ try{
|
||||
$error = "";
|
||||
$notiziaId = PostHandler::get("id");
|
||||
|
||||
$notizia = "";
|
||||
$notizia = new NotiziaModel();
|
||||
$medias = array();
|
||||
// var_dump($notizia);
|
||||
if(!is_null($notiziaId) && strcmp($notiziaId, "")!=0){
|
||||
// $notizia = "Pene";
|
||||
// $notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$notiziaId));
|
||||
$notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array('id'=>$notiziaId));
|
||||
$medias = GlobalVariables::get("dao")->query("MediaModel",array('owner.id'=>$notiziaId));
|
||||
// // echo "pene";
|
||||
// if(is_null($notizia)){
|
||||
// GUIHandler::redirect("admin/myNotizie.php");
|
||||
// }
|
||||
|
||||
// if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR) &&
|
||||
// AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE)){
|
||||
// if(strcmp($notizia->about->owner, AdminLoginManager::getLogged()->id) != 0){
|
||||
// GUIHandler::redirect("admin/myNotizie.php");
|
||||
// }
|
||||
// }
|
||||
|
||||
if(array_key_exists("remove", $_POST)){
|
||||
$idsString = PostHandler::get("remove");
|
||||
$idsArr = explode("\n", $idsString);
|
||||
|
||||
$ids = array();
|
||||
if(sizeof($idsArr)>0){
|
||||
foreach ($idsArr as $id){
|
||||
$id = trim($id);
|
||||
if(strcmp($id, "")!=0){
|
||||
$ids[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(sizeof($ids)>0){
|
||||
|
||||
// $notiziaModel = GlobalVariables::get("dao")->getFirst("NotiziaModel", array("id"=>$notiziaId));
|
||||
foreach ($ids as $id){
|
||||
$media = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$id));
|
||||
DaoMediaHandler::deleteMedia($notizia, $media);
|
||||
}
|
||||
}
|
||||
GUIHandler::redirectPost("admin/homeMultimedia.php",array("id"=>$notiziaId));
|
||||
}
|
||||
|
||||
if(array_key_exists("setMain", $_POST)){
|
||||
$id = PostHandler::get("setMain");
|
||||
$id = trim($id);
|
||||
$mediaMain = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$id));
|
||||
|
||||
DaoMediaHandler::setMainMediaToModel($notizia, $mediaMain);
|
||||
GUIHandler::redirectPost("admin/homeMultimedia.php",array("id"=>$notiziaId));
|
||||
}
|
||||
|
||||
if(array_key_exists("rmMain", $_POST) && strcmp(PostHandler::get("rmMain"), "true")==0){
|
||||
|
||||
DaoMediaHandler::setMainMediaToModel($notizia,null);
|
||||
GUIHandler::redirectPost("admin/homeMultimedia.php",array("id"=>$notiziaId));
|
||||
}
|
||||
}
|
||||
else{
|
||||
GUIHandler::redirect("admin/listNotizie.php");
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +84,15 @@ HTMLHelper::generateAdminHead();
|
||||
<?php echo $error;?>
|
||||
<div class="notiziaContainer">
|
||||
<?php if(sizeof($medias)>0){
|
||||
foreach ($medias as $media){?>
|
||||
<div style="display:inline-block; margin:5px 15px" class="mediaElement">
|
||||
<?php $media->renderMedia();?>
|
||||
</div>
|
||||
foreach ($medias as $media){
|
||||
if($media->id == $notizia->getMainMediaReference()){?>
|
||||
<div style="display:inline-block; margin:5px 15px; background-color:yellow;padding:5px;" class="mediaElement" idref="<?php echo $media->id;?>">
|
||||
<?php }
|
||||
else{?>
|
||||
<div style="display:inline-block; margin:5px 15px" class="mediaElement" idref="<?php echo $media->id;?>">
|
||||
<?php }
|
||||
$media->renderMedia();?>
|
||||
</div>
|
||||
<?php }
|
||||
}?>
|
||||
</div>
|
||||
@@ -64,8 +100,11 @@ HTMLHelper::generateAdminHead();
|
||||
<ul>
|
||||
<li><a href="#" id="mediaMenu_addMedia">Aggiungi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_rmMedia">Rimuovi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_setMain">Setta Media Principale</a></li>
|
||||
<li><a href="#" id="mediaMenu_unsetMain">Rimuovi Media Principale</a></li>
|
||||
<?php if(!DaoMediaHandler::hasMainMedia($notizia)){?>
|
||||
<li><a href="#" id="mediaMenu_setMain">Imposta Media Principale</a></li>
|
||||
<?php }else{ ?>
|
||||
<li><a href="#" id="mediaMenu_unsetMain">Rimuovi Media Principale</a></li>
|
||||
<?php }?>
|
||||
<li><a href="#" id="mediaMenu_back">Back</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -89,5 +128,27 @@ HTMLHelper::generateAdminHead();
|
||||
$("form#mediaForm input[type=hidden][name=id]").val("<?php echo $notiziaId;?>");
|
||||
$("form#mediaForm").submit();
|
||||
});
|
||||
|
||||
$(".mediaElement").click(function (){
|
||||
$(this).toggleClass("selected");
|
||||
});
|
||||
|
||||
$("#mediaMenu_rmMedia").click(function (){
|
||||
var paramStr = "";
|
||||
$(".mediaElement.selected").each(function(){
|
||||
paramStr+="\n"+$(this).attr("idref");
|
||||
});
|
||||
openPagePost("homeMultimedia.php", [{name:"id",value:"<?php echo $notiziaId;?>"},{name:"remove",value:paramStr}]);
|
||||
});
|
||||
|
||||
$("#mediaMenu_setMain").click(function (){
|
||||
var paramStr = "";
|
||||
paramStr = $(".mediaElement.selected").attr("idref");
|
||||
openPagePost("homeMultimedia.php", [{name:"id",value:"<?php echo $notiziaId;?>"},{name:"setMain",value:paramStr}]);
|
||||
});
|
||||
|
||||
$("#mediaMenu_unsetMain").click(function (){
|
||||
openPagePost("homeMultimedia.php", [{name:"id",value:"<?php echo $notiziaId;?>"},{name:"rmMain",value:"true"}]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
+11
-1
@@ -37,4 +37,14 @@ table.dataTable tr.even td{background-color:rgba(126, 151, 214, 0.4); }
|
||||
.notiziaContainer h1,.notiziaContainer h2,.notiziaContainer h3{padding:10px;}
|
||||
.notiziaMenu{display:inline-block;background-color:#33ccff;position:absolute; width:250px;right:20px;top:20px;}
|
||||
.notiziaMenu a{text-decoration:none;color:black;cursor:pointer;}
|
||||
.notiziaMenu a:hover{text-decoration:underline;}
|
||||
.notiziaMenu a:hover{text-decoration:underline;}
|
||||
|
||||
/*
|
||||
__ __ _ _
|
||||
| \/ | ___ __| (_) __ _
|
||||
| |\/| |/ _ \/ _` | |/ _` |
|
||||
| | | | __/ (_| | | (_| |
|
||||
|_| |_|\___|\__,_|_|\__,_|
|
||||
|
||||
*/
|
||||
.mediaElement.selected > img{opacity:0.4;}
|
||||
Reference in New Issue
Block a user