Fixato DaoMediaHandler::getMedias commento errato e ora trasforma gli id
delle refenrece in mongoId editBanner crea correttamente i banner nuovi ma non li edita, da finire deleteBanner cancella correttamente banner e media associato
This commit is contained in:
@@ -33,6 +33,9 @@ require_once(dirname(__FILE__)."/models/AccessModel.php");
|
||||
require_once(dirname(__FILE__)."/models/LogModel.php");
|
||||
require_once(dirname(__FILE__)."/models/StatisticModel.php");
|
||||
|
||||
|
||||
require_once(dirname(__FILE__)."/models/BannerModel.php");
|
||||
|
||||
$dao = new GenericDao($database->dbName,$database->connectionString);
|
||||
GlobalVariables::set("dao", $dao);
|
||||
?>
|
||||
|
||||
@@ -5,22 +5,27 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
/**
|
||||
*
|
||||
* @param HasMediaInterface $news
|
||||
* @param MediaInterface $media
|
||||
*
|
||||
* Ritorna un array coi le reference dei media della news
|
||||
* @return MediaInterface[] $media
|
||||
* Ritorna un array con i media model della news
|
||||
*/
|
||||
public static function getMedias(HasMediaInterface $model){
|
||||
$newsReference = $model->getMediaReferences();
|
||||
$referenceIds = array();
|
||||
if (sizeof($newsReference)>0){
|
||||
foreach ($newsReference as $ref){
|
||||
$referenceIds[] = new MongoId($ref);
|
||||
}
|
||||
}
|
||||
$rval = array();
|
||||
// var_dump($newsReference);
|
||||
$rval = GlobalVariables::get("dao")->query("MediaModel",array('id'=>array('$in'=>$newsReference)),array());
|
||||
$rval = GlobalVariables::get("dao")->query("MediaModel",array('id'=>array('$in'=>$referenceIds)));
|
||||
// var_dump($rval);
|
||||
return $rval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aggiunge il media al model e controlla se il model ha un main media e se non lo ha glielo assegna
|
||||
* Aggiunge il media al model e controlla se il model ha un main media e se non lo ha glielo assegna (salva sia il media che la news)
|
||||
*
|
||||
* @param HasMediaInterface $model
|
||||
* @param MediaInterface $media
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class BannerModel extends HasMediaModel{
|
||||
|
||||
const TYPE_IMAGE = 1;
|
||||
const TYPE_HTML = 2;
|
||||
|
||||
public static $BANNER_TYPES = array(
|
||||
self::TYPE_IMAGE=>array("label"=>"Image"),
|
||||
self::TYPE_HTML=>array("label"=>"Html")
|
||||
);
|
||||
|
||||
public static function getCollectionName(){
|
||||
return "banner";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/../load.php");
|
||||
|
||||
GUIHandler::generateHtmlHeaders(array(),true);
|
||||
|
||||
if (!AdminLoginManager::isLogged()){
|
||||
GUIHandler::redirect("admin/login.php");
|
||||
}
|
||||
else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_BANNER_SUPERVISOR)){
|
||||
GUIHandler::redirect("admin/index.php");
|
||||
}
|
||||
|
||||
MenuGenerator::generateMenu();
|
||||
|
||||
HTMLHelper::generateAdminHead();
|
||||
|
||||
$id = PostHandler::get("id");
|
||||
if (is_null($id) || strcmp("", $id)==0){
|
||||
GUIHandler::redirect("admin/listBanner.php");
|
||||
}
|
||||
|
||||
$banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$id));
|
||||
if (is_null($banner)){
|
||||
GUIHandler::redirect("admin/listBanner.php");
|
||||
}
|
||||
|
||||
$confirm = PostHandler::get("confirm");
|
||||
if (!is_null($confirm) && strcmp("", $confirm)!=0){
|
||||
if (strcmp("true", $confirm)==0){
|
||||
$medias = DaoMediaHandler::getMedias($banner);
|
||||
$media = reset($medias);
|
||||
|
||||
// $media = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$mediaId));
|
||||
|
||||
DaoMediaHandler::deleteMedia($banner, $media);
|
||||
|
||||
GlobalVariables::get("dao")->delete($banner);
|
||||
}
|
||||
GUIHandler::redirect("admin/listBanner.php");
|
||||
}
|
||||
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
echo "Sei sicuro di voler eliminare questo banner <span style='color:blue;'>".$banner->customer."</span> ?";
|
||||
?>
|
||||
<form id="notiziaDeletionForm" method="POST" action="">
|
||||
<input type="hidden" name="confirm" value="" />
|
||||
<input type="hidden" name="id" value="<?php echo $id;?>" />
|
||||
</form>
|
||||
<a href="#" id="notiziaDeletionForm_confirm" >Conferma</a>
|
||||
<a href="#" id="notiziaDeletionForm_cancel" >Annulla</a>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(event){
|
||||
$("#notiziaDeletionForm_confirm").click(function(event){
|
||||
$("form#notiziaDeletionForm input[type=hidden][name=confirm]").val("true");
|
||||
$("form#notiziaDeletionForm").submit();
|
||||
});
|
||||
$("#notiziaDeletionForm_cancel").click(function(event){
|
||||
$("form#notiziaDeletionForm input[type=hidden][name=confirm]").val("false");
|
||||
$("form#notiziaDeletionForm").submit();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/../load.php");
|
||||
|
||||
GUIHandler::generateHtmlHeaders(array(),true);
|
||||
|
||||
if (!AdminLoginManager::isLogged()){
|
||||
GUIHandler::redirect("admin/login.php");
|
||||
}
|
||||
else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_BANNER_SUPERVISOR)){
|
||||
GUIHandler::redirect("admin/index.php");
|
||||
}
|
||||
|
||||
MenuGenerator::generateMenu();
|
||||
|
||||
HTMLHelper::generateAdminHead();
|
||||
|
||||
$bannerId = PostHandler::get("id");
|
||||
|
||||
try{
|
||||
$error="";
|
||||
$edit=false;
|
||||
$banner = new BannerModel();
|
||||
|
||||
Finire Edit !!!!!!!!!!
|
||||
$mediaTypeSaved = PostHandler::get("mediaType");
|
||||
$banner->customer = PostHandler::get("customer");
|
||||
|
||||
if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "save")==0){
|
||||
if(is_null($bannerId) || strcmp($bannerId, "")==0){
|
||||
$banner->customer = PostHandler::get("customer");
|
||||
$banner->type = PostHandler::get("mediaType");
|
||||
$banner->start = new Mongodate(strtotime(PostHandler::get("dateStart")));
|
||||
$banner->end = new Mongodate(strtotime(PostHandler::get("dateEnd")));
|
||||
GlobalVariables::get("dao")->save($banner);
|
||||
$bannerId = $banner->id;
|
||||
}
|
||||
|
||||
if(!is_null($bannerId) && strcmp($bannerId, "")!=0){
|
||||
$edit=true;
|
||||
// $banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
||||
$file = "";
|
||||
|
||||
$mediaType = PostHandler::get("mediaType");
|
||||
$banner->type=$mediaType;
|
||||
if(strcmp($mediaType, "")!=0){
|
||||
$tmp = array();
|
||||
$saveable = new stdClass();
|
||||
$saveable->mediaType = $mediaType;
|
||||
if(strcmp($mediaType,MediaModel::TYPE_HTML5)==0){
|
||||
$saveable->code = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewTextBasedMedia($saveable);
|
||||
}
|
||||
else if(strcmp($mediaType,MediaModel::TYPE_IMAGE)==0){
|
||||
$saveable->path = PostHandler::get("data");
|
||||
$file = $_FILES['data']['tmp_name'];
|
||||
$info = pathinfo($_FILES['data']['name']);
|
||||
// $file = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file,$info["extension"]);
|
||||
}
|
||||
|
||||
if(!is_null($media)){
|
||||
GlobalVariables::get("dao")->save($media);
|
||||
DaoMediaHandler::addMedia($banner, $media);
|
||||
GlobalVariables::get("dao")->save($banner);
|
||||
}
|
||||
else{
|
||||
throw new Exception("Cannot save a null media in the news with id '".$bannerId."'");
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new Exception("Invalid mediaType '".$mediaType."' while trying to add the media in editBanner");
|
||||
}
|
||||
|
||||
GUIHandler::redirect("admin/listBanner.php");
|
||||
}
|
||||
else if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "delete")==0){
|
||||
$medias = DaoMediaHandler::getMedias($banner);
|
||||
// $media = reset($medias);
|
||||
// $media = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$mediaId));
|
||||
foreach ($medias as $media){
|
||||
DaoMediaHandler::deleteMedia($banner, $media);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formFile = '<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
||||
<input type="file" name="data"/>';
|
||||
|
||||
$formHtml = 'Inserire html: <textarea type="text" name ="data"/ rows="5" cols="30">'.$banner->code.'</textarea>';
|
||||
|
||||
|
||||
}catch(GUIException $ex){
|
||||
$error = $ex->getMessage();
|
||||
}catch (Exception $exec){
|
||||
LoggingFacilityManager::getLogger("gui")->log(LoggingFacility::$LEVEL_ERROR, $exec->getMessage());
|
||||
$error = "Si è verificato un errore inaspettato durante l'esecuzione della pagina. Se l'errore persiste contattare il supporto tecnico.";
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
if(strcmp($error, "")!=0){
|
||||
?>
|
||||
<div style="font-size: 16px; color:red;">
|
||||
<?php echo $error;?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<form enctype="multipart/form-data" id="loadFile" method="POST">
|
||||
<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($mediaType, MediaModel::TYPE_HTML5)==0 || strcmp($mediaType, MediaModel::TYPE_IMAGE)==0)
|
||||
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_HTML5)==0){
|
||||
echo $formHtml;
|
||||
}
|
||||
else if (strcmp($mediaTypeSaved, MediaModel::TYPE_IMAGE)==0){
|
||||
echo $formFile;
|
||||
}
|
||||
?> <input type="hidden" name="id" value="<?php echo $bannerId;?>" />
|
||||
<input type="hidden" name="action" value=""/>
|
||||
<div style="margin:10px 0px;">Cliente: <input type="text" name="customer" value="<?php echo $banner->customer;?>" /></div>
|
||||
<div style="display:inline-block;">Data inizio: <input type="text" id="datepickerStart" name="dateStart" value="<?php echo ($edit)? date("d-m-Y",$banner->start->sec):date("d-m-Y");?>"></div>
|
||||
<div style="display:inline-block;">Data fine: <input type="text" id="datepickerEnd" name="dateEnd" value="<?php echo ($edit)? date("d-m-Y",$banner->end->sec):date("d-m-Y");?>"></div>
|
||||
</div>
|
||||
</form>
|
||||
<div style="margin:15px 5px;">
|
||||
<a href="#" id="submit" >Invia</a>
|
||||
<a href="#" id="back" >Back</a>
|
||||
<a href="#" id="delete">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(event){
|
||||
$("#submit").click(function(event){
|
||||
$("form#loadFile input[type=hidden][name=action]").val("save");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#mediaType").change(function (event){
|
||||
$("form#loadFile input[type=hidden][name=action]").val("change");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#back").click(function(event){
|
||||
$("form#loadFile").attr("action","listBanner.php");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#delete").click(function(event){
|
||||
$("form#loadFile input[type=hidden][name=action]").val("delete");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#datepickerStart").datepicker({dateFormat:"dd-mm-yy"});
|
||||
$("#datepickerEnd").datepicker({dateFormat:"dd-mm-yy"});
|
||||
});
|
||||
</script>
|
||||
@@ -90,7 +90,7 @@ try{
|
||||
<input type="hidden" name="id" value="<?php echo $notiziaId;?>" />
|
||||
</form>
|
||||
<?php if($notizia->hasProperty("sondaggio") && !is_null($notizia->sondaggio)){?>
|
||||
<div id="sondaggioGraph" style="height:300px;"></div>
|
||||
<div id="sondaggioGraph" style="height:300px;margin-right:280px;margin-top:10px;"></div>
|
||||
<div class="votanti">Votanti: <?php $i=0; foreach ($notizia->sondaggio->votanti as $votante){ echo ($i++==0?"":", ").$votante;}?></div>
|
||||
<?php }?>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__)."/../load.php");
|
||||
|
||||
GUIHandler::generateHtmlHeaders(array(),true);
|
||||
|
||||
if (!AdminLoginManager::isLogged()){
|
||||
GUIHandler::redirect("admin/login.php");
|
||||
}
|
||||
else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_BANNER_SUPERVISOR)){
|
||||
GUIHandler::redirect("admin/index.php");
|
||||
}
|
||||
|
||||
MenuGenerator::generateMenu();
|
||||
|
||||
HTMLHelper::generateAdminHead();
|
||||
$columns = array(
|
||||
array("label"=>"Cliente","data"=>"customer"),
|
||||
array("label"=>"Inzio","data"=>"start"),
|
||||
array("label"=>"Fine","data"=>"end")
|
||||
);
|
||||
|
||||
$buttons = array(
|
||||
array("icon"=>"icon-medium-blue icon-editmed","page"=>"editBanner.php"),
|
||||
array("icon"=>"icon-medium-blue icon-remove","page"=>"deleteBanner.php")
|
||||
);
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
$details = DatatablesHelper::generateTable("bannerTableBackend.php",$columns,array("buttons"=>$buttons));
|
||||
?>
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__)."/../../load.php");
|
||||
|
||||
$useModel = "BannerModel";
|
||||
$permissionFlagRequired = AdminModel::ADMIN_TYPE_BANNER_SUPERVISOR;
|
||||
$exposedFields = array(
|
||||
"customer"=>null,
|
||||
"start"=>null,
|
||||
"end"=>null,
|
||||
"id"=>null
|
||||
);
|
||||
|
||||
$ret = DatatablesHelper::getResult($useModel, $permissionFlagRequired, $exposedFields);
|
||||
echo json_encode($ret);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user