merge from heihedata branch from r3956 to r3959.

This commit is contained in:
wlx 2013-10-10 02:52:07 +00:00
parent a36fecad2a
commit f7eaf86999
10 changed files with 381 additions and 19 deletions

View File

@ -1101,14 +1101,14 @@ class Admin_DataController extends Zend_Controller_Action
}
} //搜索
else{
$sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference
from mdref mr right join metadata m on mr.uuid=m.uuid
left join reference r on mr.refid=r.id
order by m.ts_created desc,mr.place";
else{
$sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference
from mdref mr right join metadata m on mr.uuid=m.uuid
left join reference r on mr.refid=r.id
order by m.ts_created desc,mr.place";
$re=$this->db->query($sql);
$row=$re->fetchAll();
$paginator = Zend_Paginator::factory($row);
$paginator = Zend_Paginator::factory($row);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(30);
$paginator->setView($this->view);
@ -1147,11 +1147,13 @@ class Admin_DataController extends Zend_Controller_Action
//文献首页
if(empty($ac))
{
$this->view->referenceType = $reference->referenceType();
view::addPaginator($reference->fetchReferences(),$this,12);
return true;
}
else if ($ac == "water")
{
$this->view->referenceType = $reference->referenceType();
view::addPaginator($reference->fetchThemeReferences('water'),$this,10);
return true;
}
@ -1262,6 +1264,48 @@ class Admin_DataController extends Zend_Controller_Action
return true;
}
//相关数据
if($ac == "data")
{
$refid = $this->view->refid = $this->_getParam('id');
if(view::isXmlHttpRequest($this)){
$this->jsonexit($reference->getDataByReference($refid));
return true;
}else{
$this->_helper->viewRenderer('ref-metadatas');
$this->view->referenceType = $reference->referenceType();
view::addPaginator($reference->getDataByReference($refid),$this,10);
return true;
}
}
//添加数据文献
if($ac == "mdref" && view::isXmlHttpRequest($this))
{
$mdrefid = $this->_getParam('id');
$status = $reference->makeMdref($mdrefid);
if($status !== true)
{
$this->jsonexit(array('error'=>$status));
}else{
$this->jsonexit(array('success' => 1));
}
return true;
}
//移除数据文献
if($ac == "delmdref")
{
$mdrefid = $this->_getParam('id');
$status = $reference->delMdref($mdrefid);
if($status === true)
{
view::Post($this,"移除成功",-1);
}else{
view::Post($this,$status,-1);
}
return true;
}
}//文献管理 refAction()

View File

@ -0,0 +1,48 @@
<div class="modal hide fade" id="mdref-form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>添加数据文献</h3>
</div>
<div class="modal-body">
<form id="mdref" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputRefid">文献ID</label>
<div class="controls">
<input type="text" name="refid" id="inputRefid" placeholder="文献ID" value="<?= empty($this->refid) ? "":$this->refid ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUuid">元数据UUID</label>
<div class="controls">
<input type="text" name="uuid" id="inputUuid" placeholder="UUID">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPlace">排序数值(数字)</label>
<div class="controls">
<input type="text" name="place" id="inputPlace" placeholder="排序">
</div>
</div>
<div class="control-group">
<label class="control-label">文献类型</label>
<div class="controls">
<?php foreach($this->referenceType as $k=>$v) { ?>
<label class="radio">
<input type="radio" name="reftype" value="<?= $k ?>" /> <?= $v ?>
</label>
<?php } ?>
</div>
</div>
<input type="hidden" name="id" value="" />
</form>
</div>
<div id="alert-info"></div>
<div class="modal-footer">
<div class="progress progress-striped active" id="submit-loading" style="display:none;">
<div class="bar" style="width:100%;"></div>
</div>
<button onclick="$('#mdref')[0].reset();" class="btn">Reset</button>
<button onclick="$('#mdref-form').modal('hide');" class="btn">Close</button>
<button onclick="mdref.create()" class="btn btn-primary" id="submit_btn">Save changes</button>
</div>
</div>

View File

@ -0,0 +1,69 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$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->theme->AppendModel($this,'admin-data-ref');
?>
<style>
table thead tr th {background:#EBF2F6;}
</style>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<div>
<?= $this->partial('data/ref-nav.phtml',array('ac'=>$this->ac)); ?>
</div>
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<button type="button" class="btn btn-primary" onclick="$('#mdref')[0].reset();$('#mdref-form').modal('show');">添加一条</button>
<div id="datalist">
<?php if (count($this->paginator)): ?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>元数据</th>
<th>类型</th>
<th>排序</th>
<th width="140">操作</th>
</tr>
</thead>
<tbody>
<?php $autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<tr id="DataLine_<?= $item['id']?>">
<td><?= $item['title'] ?></td>
<td><?= isset($this->referenceType[$item['reftype']]) ? $this->referenceType[$item['reftype']]:"" ?></td>
<td><?= $item['place'] ?></td>
<td>
<a href="javascript:void(0);" onclick="mdref.edit(<?= $item['id'] ?>,<?= $item['refid']?>,'<?= $item['uuid'] ?>',<?= $item['reftype'] ?>,<?= $item['place'] ?>)">编辑</a>
<a href="/admin/data/ref/ac/delmdref/id/<?= $item['id']?>">移除</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<?php } ?>
</div>
</div>
<!-- //页面内容 -->
<?= $this->partial('data/ref-mdref-form.phtml',array('referenceType'=>$this->referenceType,'refid'=>$this->refid)); ?>
<script>
$(document).ready(function(e) {
});
</script>

View File

@ -8,6 +8,7 @@ $this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin');
$this->theme->AppendModel($this,'admin-data-ref');
?>
<style>
table thead tr th {background:#EBF2F6;}
@ -63,6 +64,7 @@ table thead tr th {background:#EBF2F6;}
<td><?= $item['year'] ?></td>
<td rowspan="2">
<a href="/admin/data/ref/ac/add/id/<?= $item['id']?>">编辑</a>
<a href="/admin/data/ref/ac/data/id/<?= $item['id'] ?>">数据</a>(<a href="javascript:void(0);" onclick="$('#mdref')[0].reset();mdref.edit(<?= $item['id'] ?>,<?= $item['id']?>,'',0,0)">+</a>)
<a href="/admin/data/ref/ac/deleteref/id/<?= $item['id']?>">删除</a>
</td>
</tr>
@ -74,6 +76,7 @@ table thead tr th {background:#EBF2F6;}
<td colspan="2"><?= $item['reference'] ?></td>
<td>
<a href="/admin/data/ref/ac/add/id/<?= $item['id']?>">编辑</a>
<a href="/admin/data/ref/ac/data/id/<?= $item['id'] ?>">数据</a>
<a href="/admin/data/ref/ac/deleteref/id/<?= $item['id']?>">删除</a>
</td>
</tr>
@ -88,5 +91,4 @@ table thead tr th {background:#EBF2F6;}
</div>
</div>
<!-- //页面内容 -->
<script>
</script>
<?= $this->partial('data/ref-mdref-form.phtml',array('referenceType'=>$this->referenceType,'refid'=>$this->refid)); ?>

View File

@ -52,6 +52,7 @@
$autoindex++;?>
<li id="list_<?php echo $item['id'];?>">
<p>
<?= $autoindex ?>.
<a href="mailto:<?= $item['email']; ?>?subject=答复数据申请问题"><?= $item['username']; ?></a> |
申请时间:<?= date('Y-m-d',strtotime($item['ts_created'])); ?>
<?php if(!empty($item['ts_received'])) echo " | 收到时间:".date('Y-m-d',strtotime($item['ts_received']));?>

View File

@ -8,4 +8,8 @@ interface ReferenceEvent
public function processReferenceData(\Zend_EventManager_Event $e);
public function insertToReferenceTable(\Zend_EventManager_Event $e);
public function checkMdrefParam(\Zend_EventManager_Event $e);
public function processMdrefData(\Zend_EventManager_Event $e);
}

View File

@ -86,4 +86,53 @@ class ReferenceHandler implements \Reference\Event\ReferenceEvent
return $cache_data;
}
public function checkMdrefParam(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(!is_array($data))
{
return "参数错误";
}
if(empty($data["refid"]))
{
return "请填写文献ID";
}
if(empty($data['uuid']))
{
return "请填写UUID";
}
if(!view::isUuid($data['uuid']))
{
return "UUID格式不正确";
}
if(empty($data['reftype']))
{
return "请选择文献类型";
}
return true;
}
public function processMdrefData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(empty($data['place']))
{
$data['place'] = 0;
}
if(!is_numeric($data['place']))
{
$data['place'] = 0;
}
return $data;
}
}

View File

@ -16,7 +16,11 @@ class ReferenceListener implements \Zend_EventManager_ListenerAggregate
$Handler = new ReferenceHandler();
$events->attach('submit.checkParam', array($Handler, 'checkReferenceParam'), 100);
$events->attach('submit.processData', array($Handler, 'processReferenceData'), 100);
$events->attach('upload.insertToReferenceTable', array($Handler, 'insertToReferenceTable'), 100);
$events->attach('mdref.checkParam', array($Handler, 'checkMdrefParam'), 100);
$events->attach('mdref.processData', array($Handler, 'processMdrefData'), 100);
}
public function detach(\Zend_EventManager_EventCollection $events)

View File

@ -268,16 +268,21 @@ class Reference
if($delete_att == false)
{
$sql = "DELETE FROM {$this->table->reference} WHERE id=$id";
return $this->db->exec($sql);
$this->db->exec($sql);
$sql = "DELETE FROM {$this->table->metadata_reference} WHERE refid=$id";
$this->db->exec($sql);
return true;
}else{
}
}
//建立文献与数据的关系
public function createRelationFromReferenceToData($refid,$uuid,$reftype,$place)
public function createRelationFromReferenceToData($refid,$uuid,$reftype,$place,$id = NULL)
{
if(empty($refid) || is_numeric($refid))
if(empty($refid) || !is_numeric($refid))
{
return "参数错误";
}
@ -296,14 +301,26 @@ class Reference
$dbh = new dbh();
$id = $dbh->insert($this->table->metadata_reference,$data,true);
if(is_numeric($id))
if(empty($id))
{
return $id;
$id = $dbh->insert($this->table->metadata_reference,$data,true);
if(is_numeric($id))
{
return $id;
}else{
return "关系写入失败,请检查是否已经存在";
}
}else{
return "关系写入失败,请检查是否已经存在";
}
$status = $dbh->update($this->table->metadata_reference,$data," id=$id ");
if($status === true)
{
return $id;
}else{
return "修改失败";
}
}
}
//获得某个文献关联的数据 (根据文献获得数据)
@ -314,9 +331,10 @@ class Reference
return "参数错误";
}
$sql = "SELECT mr.reftype,mr.place,md.title,md.uuid FROM {$this->table->metadata_reference} mr
$sql = "SELECT mr.id,mr.refid,mr.reftype,mr.place,md.title,md.uuid FROM {$this->table->metadata_reference} mr
LEFT JOIN {$this->table->metadata} md ON mr.uuid=md.uuid
WHERE mr.refid=$id";
WHERE mr.refid=$id
ORDER BY mr.place ASC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
@ -350,5 +368,62 @@ class Reference
4 => '多篇文献'
);
}
//数据文献参数
public function getMdrefParam(\Zend_Controller_Request_Abstract $request = NULL)
{
$request = new \Zend_Controller_Request_Http();
$data = array(
'uuid' => trim($request->getParam('uuid')),
'refid' => (int)$request->getParam('refid'),
'place' => (int)$request->getParam('place'),
'reftype' => (int)$request->getParam('reftype'),
);
return $data;
}
//写入数据文献
public function makeMdref($id = NULL)
{
$data = $this->getMdrefParam();
$results = $this->events()->trigger('mdref.checkParam', $this, compact('data'));
$cache_data = $results->bottom();
if($cache_data !== true)
{
return $cache_data;
}
$results = $this->events()->trigger('mdref.processData', $this, compact('data'));
$data = $results->bottom();
$id = $this->createRelationFromReferenceToData($data['refid'],$data['uuid'],$data['reftype'],$data['place'],$id);
if(is_numeric($id))
{
return true;
}else{
return $id;
}
}
//删除数据文献
public function delMdref($id)
{
if(empty($id) || !is_numeric($id))
{
return "参数错误";
}
$sql = "DELETE FROM {$this->table->metadata_reference} WHERE id=$id";
if($this->db->exec($sql))
{
return true;
}else{
return "删除失败";
}
}
}

View File

@ -0,0 +1,66 @@
var mdref = {
create : function(){
data = $('#mdref').serialize();
$.ajax({
'type':"POST",
'url':"/admin/data/ref/ac/mdref/",
'data':data,
'success':mdref.onsuccessed,
'timeout': 30000,
'error': function(){
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html("出现错误,请稍后重试");
$('#submit-loading').hide();
return false;
},
'beforeSend': function(){
$("#submit_btn").addClass('disabled');
$("#submit_btn").attr('disabled','disabled');
$('#submit-loading').show();
},
'complete': function(){
$("#submit_btn").removeClass('disabled');
$("#submit_btn").removeAttr('disabled');
$('#submit-loading').hide();
}
});
},
onsuccessed : function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html(data.error);
return false;
}
if(typeof(data.success)!='undefined')
{
$("#alert-info").attr('class','alert alert-success');
$("#alert-info").html("添加成功!");
setTimeout("$('#mdref-form').modal('hide');",1000);
setTimeout("window.location.href = window.location.href",2000);
return false;
}
}
else{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html('请求中发生错误,请重试');
return false;
}
},
edit : function(id,refid,uuid,reftype,place)
{
$('#mdref input[name=id]').val(id);
$('#mdref input[name=refid]').val(refid);
$('#mdref input[name=uuid]').val(uuid);
$('#mdref input[name=place]').val(place);
$('input[name=reftype]').each(function(index, element) {
if($(this).val() == reftype)
{
$(this).attr('checked','checked');
}
});
$('#mdref-form').modal('show');
}
}