后台实现元数据的时空范围编辑功能

This commit is contained in:
wlx 2015-01-14 05:59:20 +00:00
parent a0dfed5425
commit 6d65e945b2
6 changed files with 570 additions and 1 deletions

View File

@ -499,12 +499,13 @@ class Admin_DataController extends Zend_Controller_Action
}//search }//search
else{ else{
$sql = "SELECT md.*,s.viewed,g.id as gid,gen.id as genid,st.status as mdstatus,ds.id as datasetid FROM metadata md $sql = "SELECT md.*,s.viewed,g.id as gid,gen.id as genid,st.status as mdstatus,ds.id as datasetid,dataspatial.id as stid FROM metadata md
LEFT JOIN mdstat s ON md.uuid=s.uuid LEFT JOIN mdstat s ON md.uuid=s.uuid
LEFT JOIN geonetworkmetadata g ON g.uuid=md.uuid LEFT JOIN geonetworkmetadata g ON g.uuid=md.uuid
LEFT JOIN mdstatus st ON md.uuid=st.uuid LEFT JOIN mdstatus st ON md.uuid=st.uuid
LEFT JOIN dataset ds ON md.uuid=ds.uuid LEFT JOIN dataset ds ON md.uuid=ds.uuid
left join en.geonetworkmetadata gen on gen.uuid=md.uuid left join en.geonetworkmetadata gen on gen.uuid=md.uuid
left join dataspatial on dataspatial.uuid=md.uuid
ORDER BY md.id DESC"; ORDER BY md.id DESC";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$sth->execute(); $sth->execute();
@ -4198,6 +4199,102 @@ class Admin_DataController extends Zend_Controller_Action
} }
}//doi }//doi
public function spatialAction()
{
$ac = $this->_getParam('ac');
$submit = $this->_getParam('submit');
$uuid = $this->_getParam('uuid');
$q=$this->_getParam('q');
$this->view->q=$q;
include_once("data/DataSpatial.php");
$spatial = new DataSpatial($this->db);
include_once("helper/view.php");
if( empty($ac) || $ac == "index")
{
if(empty($uuid))
{
$rows = $spatial->fetch(0,$q);
view::addPaginator($rows,$this,10);
}else{
$this->_redirect('/admin/data/spatial/ac/edit/uuid/'.$uuid);
return true;
}
return true;
}//index
else if($ac == "edit")
{
$this->_helper->viewRenderer('spatial-add');
$id = $this->_getParam('id');
if(empty($uuid) && empty($id))
{
view::Msg('alert-error',"参数错误",-1);
return false;
}
if(empty($submit)){
if(!empty($uuid))
{
$this->view->uuid = $uuid;
$this->view->data = $spatial->view($uuid);
if(empty($this->view->data))
{
include('data/Metadata.php');
$md = new Metadata($this->db);
$metadata = $md->view($uuid);
$data['title']=$metadata['title'];
$data['temporal']=$spatial->mktemporal($metadata['timebegin'],$metadata['timeend']);
$data['spatial']=$spatial->mkspatial($metadata['east'],$metadata['south'],$metadata['west'],$metadata['north']);
$this->view->data[0]=$data;
}
}
}else{
$data = $spatial->_getParams($this->_request);
$this->view->data = $data;
$data['info'] = $spatial->checkinfo($data['info']);
if(!is_array($data['info'])){
$this->view->error = view::Error($data['info']);
return true;
}
$state = $spatial->update($data,$uuid);
if($state)
{
$this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/spatial/uuid/'.$uuid);
return false;
}else{
$this->view->error = view::Error("修改失败");
return false;
}
}
}//edit
else if($ac == "del")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$id = $this->_getParam('id');
if(empty($id))
{
$this->jsonexit(array('error'=>'参数错误'));
return true;
}
if($spatial->delete($id) == true)
{
$this->jsonexit(array('success'=>$id));
return true;
}else{
$this->jsonexit(array('error'=>'删除失败'));
return true;
}
}//del
}//spatial
//发送邀请专家的邮件 //发送邀请专家的邮件
public function sendMailToExpert($pid,$name,$email,$code,$test=0) public function sendMailToExpert($pid,$name,$email,$code,$test=0)
{ {

View File

@ -25,5 +25,6 @@
<li id="Nav-data-project"><a href="/admin/data/project">汇交计划</a></li> <li id="Nav-data-project"><a href="/admin/data/project">汇交计划</a></li>
<li id="Nav-data-fund"><a href="/admin/data/fund">支持项目</a></li> <li id="Nav-data-fund"><a href="/admin/data/fund">支持项目</a></li>
<li id="Nav-data-doi"><a href="/admin/data/doi">DOI</a></li> <li id="Nav-data-doi"><a href="/admin/data/doi">DOI</a></li>
<li id="Nav-data-spatial"><a href="/admin/data/spatial">数据时空范围</a></li>
</ul> </ul>
</div> </div>

View File

@ -76,6 +76,9 @@
<?php if (!isset($item['genid']) || !$item['genid']>0) : ?> <?php if (!isset($item['genid']) || !$item['genid']>0) : ?>
<a class="label label-primary iframe" href="/admin/data/gnenexport/uuid/<?php echo $item['uuid'];?>">导入英文版</a> <a class="label label-primary iframe" href="/admin/data/gnenexport/uuid/<?php echo $item['uuid'];?>">导入英文版</a>
<?php endif; ?> <?php endif; ?>
<?php if (!isset($item['stid']) || !$item['stid']>0) : ?>
<a class="label label-primary" href="/admin/data/spatial/ac/edit/uuid/<?php echo $item['uuid']; ?>">数据时空范围采集</a>
<?php endif; ?>
</p> </p>
<?php if($item['author']) :?> <?php if($item['author']) :?>
<p>数据贡献者:<?= $item['author']; ?></p> <p>数据贡献者:<?= $item['author']; ?></p>

View File

@ -0,0 +1,121 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('数据时空范围');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
?>
<div class="row">
<div class="hidden-sm hidden-xs col-md-2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="col-md-10 col-sm-12">
<div>
<ul class="nav nav-tabs">
<li><a href="/admin/data/spatial">浏览所有</a></li>
<?php if(!empty($this->uuid)) {?>
<li class="active"><a href="javascript:void(0);">编辑</a></li>
<?php }?>
</ul>
</div>
<div class="">
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<p></p>
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<h4>提示</h4>
1. 空间范围请使用经纬度dd格式进行添加。<br/>
2. 日期精确到天。中括号代表包含,小括号代表不包含。
</div>
<h2><?php echo $this->data[0]['title']; ?></h2>
<form class="form-horizontal" method="post">
<div id="datalist">
<?php if (count($this->data)): ?>
<table class="stylized table table-bordered table-striped table-hover">
<thead>
<tr>
<th width="60%">空间范围</th>
<th>时间范围</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
<?php $autoindex=0;
foreach ($this->data as $item):
if (isset($item['id']) && $item['id']>0) :
$autoindex++; ?>
<tr class="infocontrol">
<td><textarea class="col-md-12" rows="3" name="info[<?= $autoindex ?>][spatial]" ><?= $item['spatial'] ?></textarea></td>
<td><input type="text" name="info[<?= $autoindex ?>][temporal]" class="form-control" value="<?= $item['temporal'] ?>" /></td>
<td>
编辑:点 线 矩形 多边形
<a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a>
</td>
<input type="hidden" name="info[<?= $autoindex ?>][id]" value=" <?=$item->id?> " />
</tr>
<?php endif; endforeach; if ((count($this->data)==1) && !isset($this->data[0]['id'])) :
$item=$this->data[0]; ?>
<tr class="infocontrol">
<td><textarea class="col-md-12" rows="3" name="info[1][spatial]" ><?= $item['spatial'] ?></textarea></td>
<td><input type="text" name="info[1][temporal]" class="form-control"
value="<?= $item['temporal'] ?>" /></td>
<td>
点 线 矩形 多边形
<a href="/admin/data/spatial/ac/edit/uuid/<?= $item['uuid']?>">编辑</a>
</td>
<input type="hidden" name="info[1][id]" value="0" />
</tr>
<?php endif; endif;?>
</tbody>
</table>
</div>
<div class="form-group">
<div class="col-sm-12">
<a class="pull-right" href="javascript:void(0);" onclick="addinput()" >+为该数据添加一行新时空范围</a>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="hidden" name="submit" value="1" />
<?php if(!empty($this->uuid)) { ?>
<input type="hidden" name="uuid" value=" <?=$this->uuid?>" />
<?php } ?>
<button type="submit" class="btn btn-primary pull-right">提交</button>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
<script>
function addinput(){
var now_index = $('.infocontrol').length;
var index = now_index + 1;
html = '<tr class="infocontrol">'
+'<td><textarea class="col-md-12" rows="3" name="info['+index+'][spatial]" placeholder="WKT Geometry"></textarea></td>'
+'<td><input type="text" name="info['+index+'][temporal]" class="form-control" value="" placeholder="Date range"/></td>'
+'<td><a href="">点 线 矩形 多边形</a>'
+' <label class="control-label"><a href="javascript:void(0);" onclick="RmInput(this)"> -删除</a></label>'
+'</td><input type="hidden" name="info['+index+'][id]" value="0" />'
+'</tr>';
now_index = null;
index = null;
$('.infocontrol').last().after(html);
}
function RmInput(e){
$e = $(e);
$e.parent().parent().parent('tr.infocontrol').remove();
}
</script>
<!-- //页面内容 -->

View File

@ -0,0 +1,167 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('数据时空范围');
$this->breadcrumb()->setSeparator(' > ');
// $this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin');
$this->headScript()->appendFile('/js/lib/colorbox/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/js/lib/colorbox/colorbox.css');
?>
<div class="row">
<div class="hidden-sm hidden-xs col-md-2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="col-md-10 col-sm-12 span10">
<div class="form-group">
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="/admin/data/spatial">浏览所有</a></li>
</ul>
</div>
<div class="input-group form-group">
<form id="datasearch" class="search_form input-group" action="">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" class="form-control" placeholder="搜索关键字" />
<span class="input-group-btn"><button class="btn btn-default" type="submit" id="search_btn">搜索</button></span>
</form>
</div>
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<div id="datalist">
<?php if (count($this->paginator)): ?>
<table class="stylized table table-bordered table-striped table-hover">
<thead>
<tr>
<th>元数据</th>
<th>空间范围</th>
<th>时间范围</th>
<th>修改时间</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
<?php $autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<tr id="DataLine_<?= $item['id']?>">
<td><a href="/data/<?= $item['uuid'] ?>"><?= $item['title'] ?></a></td>
<td><?= $item['spatial'] ?></td>
<td><?= $item['temporal'] ?></td>
<td><?= date("Y-m-d H:i",strtotime($item['ts_changed'])) ?></td>
<td>
<a href="/admin/data/spatial/ac/edit/uuid/<?= $item['uuid']?>">编辑</a>
<a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<?php } ?>
</div>
</div>
<!-- //页面内容 -->
<script>
var info = {
btn_prefix : "delbtn_",
item_prefix : "DataLine_",
url : "/admin/data/spatial/ac/del"
}
$(document).ready(function(e) {
$('.verified_btn').click(function(e) {
$(this).ajaxmsg({
callback:function(){window.location.reload();}
});
});
});
(function( $ ){
$.fn.ajaxmsg = function( options ) {
var settings = $.extend( {
url:'',
callback : '',
}, options);
var methods = {
msg : function(id)
{
methods.submited();
},
creatWindow : function(content){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
html: methods.dialog(content),
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
if(typeof(settings.callback)=='function')
{
settings.callback();
}
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
},
submited : function(){
$.ajax({
'type':"POST",
'url':settings.url,
'data':'',
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
if(typeof(data.success)!='undefined')
{
methods.creatWindow(data.success);
}
}
else{
alert('出现错误,请稍候再试');
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : function(content){
HTML = '<div class=""><div class="modal-header"><h3>提示信息</h3></div>'
+ '<div class="modal-body"><div class=" span5">'+content+'</div></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">确定</a></div></div>';
return HTML;
}
}
this.each(function() {
settings.url = $(this).attr('rel');
if(settings.url == '')
{
alert('参数错误');
}
methods.msg();
});
};
})( jQuery );
</script>

View File

@ -0,0 +1,180 @@
<?php
class DataSpatial extends Zend_Controller_Plugin_Abstract
{
private $db; //传入PDO对象.
private $auth = NULL; //Zend_Auth 对象
//使用到的公共变量
public $tbl = "dataspatial";
function __construct($db)
{
$this->db = $db;
}
function fetch($uid=0,$keyword='')
{
$wheresql=' 1=1 ';
if(!empty($keyword))
{
if(preg_match("/\'/",$keyword))
{
$keyword = preg_replace("/\'/","''",$keyword);
}
$wheresql.=" and m.title like '%$keyword%'";
}
if(empty($uid))
{
$sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid where ".$wheresql."ORDER BY d.ts_changed desc";
}else{
$sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d
left join metadata m on d.uuid=m.uuid
LEFT JOIN mdauthor a ON d.uuid=a.uuid
WHERE a.userid=".$uid." AND a.status>0 and ".$wheresql."
ORDER BY d.ts_published desc,d.ts_submitted desc,d.ts_created DESC
";
}
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
function update($data,$uuid,$uid=0){
if(!empty($uid))
{
include_once("data/Author.php");
$author = new Author($this->db);
if($author->checkAuthor($uuid,$uid)==false)
{
return "您没有权限";
}
}
$this->db->beginTransaction();
try
{
foreach($data['info'] as $item)
{
if ($item['id']>0)
{
//update
if (isset($item['temporal']))
$sql="update $this->tbl set the_geom=ST_GeometryFromText('SRID=4326;".$item['spatial']."'),temporal='".$item['temporal']."',ts_changed=now() where id=".$item['id']." and uuid='".$data['uuid']."'";
else
$sql="update $this->tbl set the_geom=ST_GeometryFromText('SRID=4326;".$item['spatial']."'),ts_changed=now() where id=".$item['id']." and uuid='".$data['uuid']."'";
} else {
//insert
if (isset($item['temporal']))
$sql="insert into $this->tbl (uuid,the_geom,temporal) values('".$data['uuid']."',ST_GeometryFromText('SRID=4326;".$item['spatial']."'),'".$item['temporal']."')";
else
$sql="insert into $this->tbl (uuid,the_geom) values('".$data['uuid']."',ST_GeometryFromText('SRID=4326;".$item['spatial']."'))";
}
$this->db->exec($sql);
}
$this->db->commit();
return true;
} catch (Exception $e) {
$this->db->rollBack();
return $e->getMessage();
}
}
function view($id)
{
if(is_numeric($id))
{
$sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid WHERE d.id=$id";
}else{
$sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid WHERE d.uuid='$id'";
}
$rs = $this->db->query($sql);
$row = $rs->fetchAll();
return $row;
}
function delete($id,$uid=0){
if(!is_numeric($id))
{
return "参数错误";
}
if($uid != 0){
$sql = "SELECT uuid FROM ".$this->tbl." WHERE id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(isset($row['uuid']) && !empty($row['uuid'])){
include_once("data/Author.php");
$author = new Author($this->db);
if($author->checkAuthor($row['uuid'],$uid)==false)
{
return "您没有权限";
}
$condition = " id=$id ";
$sql = "DELETE FROM ".$this->tbl." WHERE $condition";
return $this->db->exec($sql);
}else{
return "该记录不存在";
}
}else{
$condition = " id=$id ";
$sql = "DELETE FROM ".$this->tbl." WHERE $condition";
return $this->db->exec($sql);
}
}
function _getParams(Zend_Controller_Request_Abstract $request)
{
$data = array(
'uuid' => trim($request->getParam('uuid')),
'info'=>$_POST['info']
);
return $data;
}
function checkinfo($info){
if(!is_array($info)){
return NULL;
}
foreach($info as $k=>$v)
{
if(empty($v['spatial']) && empty($v['temporal']))
{
unset($info[$k]);
}else{
if(empty($v['spatial']))
{
return "请输入 $k 中的空间范围";
}
}
}
return $info;
}
function mkspatial($e,$s,$w,$n)
{
$str='GeometryCollection(';
if (($e==$w) && ($s==$n))
{
$str.="Point($e $s)";
} else {
$str.="Polygon(($e $s,$e $n,$w $n,$w $s,$e $s))";
}
$str.=')';
return $str;
}
function mktemporal($begin,$end=null)
{
if (!$begin) return '';
$str='[';
$begin=date('Y-m-d',strtotime($begin));
if (isset($end)) $end=date('Y-m-d',strtotime($end));
if (isset($end) && ($end!=$begin))
{
$str.="$begin,$end";
} else {
$str.="$begin,$begin";
}
$str.=']';
return $str;
}
}