#318 数据版本管理功能
This commit is contained in:
parent
564bd16bd6
commit
e1f261d61f
|
@ -746,7 +746,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
$this ->getResponse()
|
||||
->setHeader('Content-Type', 'application/json')
|
||||
->appendBody(Zend_Json::encode($data));
|
||||
exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1487,6 +1487,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
$u_id = $user->id;
|
||||
}
|
||||
|
||||
//查看单条数据的所有版本
|
||||
if (!empty($uuid) && empty($ac))
|
||||
{
|
||||
//view the versions of the data
|
||||
|
@ -1509,6 +1510,8 @@ class AuthorController extends Zend_Controller_Action
|
|||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||||
$this->view->paginator=$paginator;
|
||||
}
|
||||
|
||||
//查看所有版本列表
|
||||
else if((empty($ac) && empty($uuid))|| $ac=='list')
|
||||
{
|
||||
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
|
||||
|
@ -1530,6 +1533,8 @@ class AuthorController extends Zend_Controller_Action
|
|||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||||
$this->view->paginator=$paginator;
|
||||
}
|
||||
|
||||
//按数据浏览
|
||||
else if($ac=="bydata")
|
||||
{
|
||||
$keywords = $this->_request->getParam('q');
|
||||
|
@ -1560,6 +1565,186 @@ class AuthorController extends Zend_Controller_Action
|
|||
|
||||
$this->_helper->viewRenderer('version-bydata');
|
||||
}
|
||||
|
||||
|
||||
//删除某个版本
|
||||
else if($ac=="delete")
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$data = "";
|
||||
|
||||
try{
|
||||
$id = $this->_request->getParam('id');
|
||||
if(empty($id) || !is_numeric($id))
|
||||
{
|
||||
$data = array("error"=>"参数错误");
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM mdversion v
|
||||
USING mdauthor a
|
||||
WHERE v.id=? AND a.userid=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$ex = $sth -> execute(array($id,$u_id));
|
||||
|
||||
if($ex)
|
||||
{
|
||||
$data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}else{
|
||||
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
}catch(Exception $e) {
|
||||
$msg = "删除失败,请确认权限后重试";
|
||||
if($this->debug>0)
|
||||
{$msg .= $e->getMessage();}
|
||||
$data = array("error"=>$this->alertbox('error',$msg));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//恢复到geonetwork
|
||||
else if($ac == "restore")
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$data = "";
|
||||
try{
|
||||
$id = $this->_request->getParam('id');
|
||||
if(empty($id) || !is_numeric($id))
|
||||
{
|
||||
$data = array("error"=>"参数错误");
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
$db = Zend_Db::factory('Pdo_Pgsql', array(
|
||||
'host' => 'localhost',
|
||||
'username' => 'postgres',
|
||||
'password' => '************************************',
|
||||
'dbname' => 'geonetwork',
|
||||
'persistent' => true
|
||||
));
|
||||
|
||||
$sql = "SELECT v.xml,v.uuid FROM mdversion v
|
||||
LEFT JOIN mdauthor a ON a.uuid=v.uuid
|
||||
WHERE v.id=? AND a.userid=?";
|
||||
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth ->execute(array($id,$u_id));
|
||||
$row = $sth->fetch();
|
||||
|
||||
$sql = "SELECT data FROM metadata WHERE uuid=?";
|
||||
$sth = $db->prepare($sql);
|
||||
$sth ->execute(array($row['uuid']));
|
||||
$row_geo = $sth->fetch();
|
||||
|
||||
if($row['xml']==$row_geo['data'])
|
||||
{
|
||||
$data = array("error"=>$this->alertbox('warning','恢复失败,目前两个版本中的内容相同'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "UPDATE metadata SET data=? WHERE uuid=?";
|
||||
$sth = $db->prepare($sql);
|
||||
$ex = $sth ->execute(array($row['xml'],$row['uuid']));
|
||||
|
||||
if($ex)
|
||||
{
|
||||
$data = array("error"=>$this->alertbox('ok','恢复成功'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}else{
|
||||
$data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
}catch(Exception $e) {
|
||||
$msg = "恢复失败,请确认权限后重试";
|
||||
if($this->debug>0)
|
||||
{$msg .= $e->getMessage();}
|
||||
$data = array("error"=>$this->alertbox('error',$msg));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//发布到评审
|
||||
else if($ac == "commit")
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$data = "";
|
||||
try{
|
||||
$id = $this->_request->getParam('id');
|
||||
if(empty($id) || !is_numeric($id))
|
||||
{
|
||||
$data = array("error"=>"参数错误");
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM mdstatus s
|
||||
LEFT JOIN mdversion v ON v.uuid=s.uuid
|
||||
LEFT JOIN mdauthor a ON a.uuid=v.uuid
|
||||
WHERE v.id=? AND a.userid=?";
|
||||
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($id,$u_id));
|
||||
$row = $sth->fetch();
|
||||
|
||||
if(!empty($row['id']))
|
||||
{
|
||||
$data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "SELECT v.uuid FROM mdversion v
|
||||
LEFT JOIN mdauthor a ON a.uuid=v.uuid
|
||||
WHERE v.id=? AND a.userid=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($id,$u_id));
|
||||
$row = $sth->fetch();
|
||||
|
||||
$sql = "INSERT INTO mdstatus (uuid,status,userid) VALUES (?,?,?)";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$ex = $sth->execute(array($row['uuid'],1,$u_id));
|
||||
|
||||
if($ex)
|
||||
{
|
||||
$data = array("error"=>$this->alertbox('ok','提交成功!'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}else{
|
||||
$data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试'));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
}catch(Exception $e) {
|
||||
$msg = "提交失败,请确认权限后重试";
|
||||
if($this->debug>0)
|
||||
{$msg .= $e->getMessage();}
|
||||
$data = array("error"=>$this->alertbox('error',$msg));
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}// versionAction() 数据版本管理
|
||||
|
||||
//成为作者后的后继处理工作
|
||||
|
@ -1582,5 +1767,31 @@ class AuthorController extends Zend_Controller_Action
|
|||
$sth=$this->wdb->prepare($sql);
|
||||
$sth->execute(array($author,$uuid));
|
||||
}
|
||||
|
||||
public function alertbox($type='',$body){
|
||||
if($type == "error")
|
||||
{
|
||||
$img = '<img src="/images/alert_big_error.png" />';
|
||||
$text = '<h4>'.$body.'</h4>';
|
||||
return $img.$text;
|
||||
}
|
||||
if($type == "ok")
|
||||
{
|
||||
$img = '<img src="/images/alert_big_ok.png" />';
|
||||
$text = '<h4>'.$body.'</h4>';
|
||||
return $img.$text;
|
||||
}
|
||||
if($type == "warning")
|
||||
{
|
||||
$img = '<img src="/images/alert_big_warning.png" />';
|
||||
$text = '<h4>'.$body.'</h4>';
|
||||
return $img.$text;
|
||||
}
|
||||
if(empty($type))
|
||||
{
|
||||
$text = '<h4>'.$body.'</h4>';
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ $this->headTitle($this->config->title->site);
|
|||
$this->headTitle($this->config->title->author);
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
|
||||
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
|
||||
$this->headLink()->appendStylesheet('/css/author.css');
|
||||
$this->headLink()->appendStylesheet('/css/colorbox.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/author">数据作者</a>');
|
||||
$this->breadcrumb('数据版本管理');
|
||||
|
@ -21,7 +23,7 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
<div id="wapper">
|
||||
<div id="tabs-controller">
|
||||
<ul>
|
||||
<li class="box-shadow active"><a class="text-shadow" href="/author/version">所有版本概况</a></li>
|
||||
<li class="box-shadow <?php if(!$this->mdtitle) echo "active";?>"><a class="text-shadow" href="/author/version">所有版本概况</a></li>
|
||||
<li class="box-shadow"><a class="text-shadow" href="/author/version/ac/bydata">逐数据浏览</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -33,7 +35,7 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
$autoindex=0;
|
||||
foreach ($this->paginator as $item):
|
||||
$autoindex++;?>
|
||||
<li>
|
||||
<li id="list_<?php echo $item['id'];?>">
|
||||
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a>
|
||||
【<a href="/author/version/uuid/<?php echo $item['uuid']; ?>">查看此数据所有版本</a>】</p>
|
||||
<p>版本创建时间: <?php echo date("Y-m-d H:i",strtotime($item['ts_created']));?>
|
||||
|
@ -41,11 +43,11 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
echo "发布人: ".(empty($item['realname'])?$item['username']:$item['realname'])." 【";
|
||||
else :
|
||||
?>
|
||||
【<a href="/author/version/ac/delete/id/<?php echo $item['id'];?>" class="more">删除</a>
|
||||
【<a onclick="return confirm('是否确定删除该版本?');" href="javascript:action('delete','<?php echo $item['id'];?>');" class="more">删除</a>
|
||||
<?php endif; ?>
|
||||
<a href="/author/version/ac/restore/id/<?php echo $item['id'];?>" class="more">恢复到geonetwork</a>
|
||||
<a onclick="return confirm('是否确定将这个版本恢复到geonetwork?');" href="javascript:action('restore','<?php echo $item['id'];?>');" class="more">恢复到geonetwork</a>
|
||||
<a href="/author/version/ac/diff/id/<?php echo $item['id'];?>" class="more">与前一版对比</a>
|
||||
<a href="/author/version/ac/commit/id/<?php echo $item['id'];?>" class="more">提交评审发布</a>
|
||||
<a onclick="return confirm('是否确定将该版本提交至评审发布?');" href="javascript:action('commit','<?php echo $item['id'];?>');" class="more">提交评审发布</a>
|
||||
】</p>
|
||||
<?php if ($item['changelog']) : ?>
|
||||
<p><?php echo $item['changelog']; ?></p>
|
||||
|
@ -60,4 +62,33 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
<!-- //页面内容 -->
|
||||
<script>
|
||||
$('#wapper').width($('body').width()-300);
|
||||
function action(ac,id){
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':'/author/version/',
|
||||
'data':'ac='+ ac +'&id='+id,
|
||||
'success':function(data){
|
||||
if (typeof(data)=='object')
|
||||
{
|
||||
if(typeof(data.error)!='undefined')
|
||||
{$.colorbox({'innerWidth':'50%','html':data.error});}
|
||||
if(typeof(data.deleted)!='undefined')
|
||||
{$('#list_'+data.deleted).fadeOut("slow",function(){$(this).remove();});}
|
||||
}
|
||||
else{
|
||||
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_warning.png" /><h4>出现错误,请稍候再试</h4>'});
|
||||
}
|
||||
//$('#data_'+uuid).html('');
|
||||
},
|
||||
'timeout': 30000,
|
||||
'error': function(){
|
||||
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_error.png" /><h4>处理中出现错误,请刷新页面后重试</h4>'});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<div class="colorbox" style="display:none;">
|
||||
<div class="error"><img src="/images/alert_big_error.png" /><span></span></div>
|
||||
<div class="ok"><img src="/images/alert_big_ok.png" /><span></span></div>
|
||||
<div class="warning"><img src="/images/alert_big_warning.png" /><span></span></div>
|
||||
</div>
|
Loading…
Reference in New Issue