在评审管理的我负责的元数据中添加了批量发布的功能
This commit is contained in:
parent
f30ac08f4f
commit
79fad444bb
|
@ -638,61 +638,35 @@ class Admin_ReviewController extends Zend_Controller_Action
|
|||
*/
|
||||
function postAction(){
|
||||
|
||||
include_once('helper/view.php');
|
||||
include_once('data/Review.php');
|
||||
|
||||
$id = $this->_request->getParam('id');
|
||||
$emails = $this->_request->getParam('emails');
|
||||
|
||||
include_once('helper/view.php');
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity())
|
||||
$review = new Review($this->db);
|
||||
$reviewListener = new reviewListener();
|
||||
@$review->events()->attachAggregate($reviewListener);
|
||||
|
||||
if(is_numeric($id))
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
$userid = $user->id;
|
||||
|
||||
$sql = "select id from mdstatus where id='$id' and userid='$userid'";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if(!empty($row['id']))
|
||||
$id = (int)$id;
|
||||
if($review->checkAdmin($id) !== true)
|
||||
{
|
||||
|
||||
if($this->changestatus($id,5))
|
||||
{
|
||||
//发布正式版本
|
||||
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid in (select uuid from mdstatus where id=?) order by ts_created desc limit 1)";
|
||||
$this->db->query($sql,array('发布第一个正式版本 version 1.0',$userid,$id));
|
||||
//删除所有的中间版本
|
||||
$sql="delete from mdversion where changelog is null and uuid in (select uuid from mdstatus where id=?)";
|
||||
$this->db->query($sql,array($id));
|
||||
//email message
|
||||
$mail=new WestdcMailer($this->view->config->smtp);
|
||||
$sql="select m.uuid,m.title from metadata m left join mdstatus s on m.uuid=s.uuid where s.id='$id'";
|
||||
$rs=$this->db->query($sql);
|
||||
$res=$rs->fetch();
|
||||
$mailtp=new EmailText($this->db,'metadata-publish',array('uuid'=>$res['uuid'],'title'=>$res['title']));
|
||||
$mail->setBodyText($mailtp->getBody());
|
||||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||||
$mail->addTo($emails);
|
||||
$mail->setSubject($mailtp->getSubject());
|
||||
$mail->send();
|
||||
|
||||
view::Post($this,array("content"=>'操作成功:该元数据成功发布','url'=>"/admin/review/myreview"));
|
||||
return true;
|
||||
}else{
|
||||
view::Post($this,array("content"=>'操作失败','url'=>"/admin/review/myreview"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}else{
|
||||
view::Post($this,array("content"=>'您没有权限操作其他管理员管理的元数据评审','url'=>"/admin/review/myreview"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
view::Post($this,array("content"=>'权限读取失败','url'=>"/admin/review/myreview"));
|
||||
return true;
|
||||
}
|
||||
|
||||
$s = $review->post($id,$emails);
|
||||
if($s)
|
||||
{
|
||||
view::Post($this,"发布成功",-1);
|
||||
return true;
|
||||
}else{
|
||||
view::Post($this,"发布失败",-1);
|
||||
return true;
|
||||
}
|
||||
}//发布元数据
|
||||
|
||||
/*
|
||||
|
|
|
@ -35,6 +35,7 @@ table thead tr th {background:#EBF2F6;color:#444;}
|
|||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:13px;"><input type="checkbox" class="select_rows" data-tbody="list" /></th>
|
||||
<th width='500'>元数据标题</th>
|
||||
<th width='80'>状态</th>
|
||||
<th>接收时间</th>
|
||||
|
@ -46,6 +47,7 @@ table thead tr th {background:#EBF2F6;color:#444;}
|
|||
<tbody id="list">
|
||||
<?php foreach ($this->paginator as $item): ?>
|
||||
<tr>
|
||||
<td><input type="checkbox" class="select_item" value="<?= $item['id']?>" /></td>
|
||||
<td><?= $item['title']?> [
|
||||
<a href="/service/geonetwork?url=metadata.edit?id=<?= $item['gid'] ?>" target="_blank">编辑</a> |
|
||||
<a href="javascript:void(0);" rel="<?= $item['uuid']?>" class="version">版本</a>
|
||||
|
@ -76,15 +78,81 @@ table thead tr th {background:#EBF2F6;color:#444;}
|
|||
</tbody>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<div><a class="btn btn-primary post">发布</a></div>
|
||||
<div class="pagenavi"><?= $this->paginator; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var sfadmin = {
|
||||
def_data_tag : 'tbody',
|
||||
def_select_input : '.select_item',
|
||||
init: function() {
|
||||
$('.select_rows').click(function () {
|
||||
var tableid = $(this).data(sfadmin.def_data_tag);
|
||||
$('#'+tableid).find(sfadmin.def_select_input).attr('checked', this.checked);
|
||||
});
|
||||
sfadmin.ajax.error();
|
||||
},
|
||||
getSelected : function(tableid){
|
||||
if(tableid == "")
|
||||
{
|
||||
dom = $(sfadmin.def_select_input + ':checked');
|
||||
}else{
|
||||
dom = $(sfadmin.def_select_input + ':checked', '#'+tableid);
|
||||
}
|
||||
datas = new Array();
|
||||
dom.each(function(index, element) {
|
||||
datas.push($(this).val());
|
||||
});
|
||||
return datas;
|
||||
},
|
||||
ajax : {
|
||||
error : function(){
|
||||
$(document).ajaxError(function(event, request, settings) {
|
||||
sfadmin.Alert("请求中发生错误");
|
||||
})
|
||||
}
|
||||
},
|
||||
Alert : function(content){
|
||||
$.colorbox({width:'50%',html:'<div class="ajax_error"><div class="text"><h2>'+content+'</h2></div></div>'});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(e) {
|
||||
$('.version').click(function(){
|
||||
$(this).getversion({'id':$(this).attr('rel')});
|
||||
});
|
||||
sfadmin.init();
|
||||
$('.post').click(function(e) {
|
||||
ids = getids();
|
||||
if(!ids)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
url = "/admin/review/post/" + '?' +ids;
|
||||
self.location=url
|
||||
});
|
||||
});
|
||||
function getids(){
|
||||
id = sfadmin.getSelected('list');
|
||||
if(id.length == '')
|
||||
{
|
||||
alert('请选择要操作的项目');
|
||||
return false;
|
||||
}
|
||||
|
||||
url_data = new Array();
|
||||
|
||||
for(i in id)
|
||||
{
|
||||
url_data.push('id[]='+id[i]);
|
||||
}
|
||||
|
||||
data = url_data.join("&");
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.fn.getversion = function( options ) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
class Review extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
private $db; //传入PDO对象.
|
||||
private $auth = NULL; //Zend_Auth 对象
|
||||
protected $events = NULL; //事件
|
||||
|
||||
//使用到的公共变量
|
||||
public $tbl_reviewexp = "mdexpertreview";
|
||||
|
@ -14,6 +14,16 @@ class Review extends Zend_Controller_Plugin_Abstract
|
|||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function events(Zend_EventManager_EventCollection $events = NULL)
|
||||
{
|
||||
if ($events !== NULL) {
|
||||
$this->events = $events;
|
||||
} elseif ($this->events === NULL) {
|
||||
$this->events = new Zend_EventManager_EventManager(__CLASS__);
|
||||
}
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
//接受或者拒绝评审
|
||||
function invite($id,$uuid,$uid,$status)
|
||||
{
|
||||
|
@ -89,4 +99,169 @@ class Review extends Zend_Controller_Plugin_Abstract
|
|||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
//发布
|
||||
function post($id,$emails)
|
||||
{
|
||||
if(is_numeric($id))
|
||||
{
|
||||
$cid = (int)$id;
|
||||
}
|
||||
|
||||
if(is_array($id))
|
||||
{
|
||||
$cid = join(",",$id);
|
||||
}
|
||||
|
||||
include_once("helper/view.php");
|
||||
$userid = (int)view::User('id');
|
||||
|
||||
if($this->changestatus($cid,5))
|
||||
{
|
||||
$results = $this->events()->trigger('post.post', $this, compact('emails','id','userid'));
|
||||
return $results->bottom();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}//发布
|
||||
|
||||
//检查管理员
|
||||
function checkAdmin($id,$userid = 0)
|
||||
{
|
||||
$id = (int)$id;
|
||||
if(empty($userid))
|
||||
{
|
||||
include_once("helper/view.php");
|
||||
$userid = (int)view::User('id');
|
||||
}
|
||||
$sql = "select id from mdstatus where id=$id and userid=$userid";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if(empty($row['id']))
|
||||
{
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* changestatus() 更改mdstatus中的status字段
|
||||
*
|
||||
* @param int $id //要更改状态的mdstatus记录的ID
|
||||
* @param int $status //状态
|
||||
*
|
||||
* return bool
|
||||
*/
|
||||
function changestatus($id,$status){
|
||||
$stvalues = array(
|
||||
-1, //取消评审
|
||||
0, //初始状态
|
||||
1, //接受元数据评审,进入评审阶段
|
||||
2, //开始邀请专家,送审阶段
|
||||
3, //专家接受邀请,在审阶段
|
||||
4, //专家反馈,在审
|
||||
5, //评审结束,发布
|
||||
6,7
|
||||
);
|
||||
if(empty($id) || !isset($status) || !in_array($status,$stvalues))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($status==1)
|
||||
{$sql = "update mdstatus set status='$status',ts_accepted='now()' where id in ($id)"; }
|
||||
else if($status==5)
|
||||
{$sql = "update mdstatus set status='$status',ts_finished='now()' where id in ($id)";}
|
||||
else
|
||||
{$sql = "update mdstatus set status='$status' where id in ($id)";}
|
||||
try{
|
||||
if($this->db->exec($sql)>0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}//changestatus 更改状态
|
||||
}
|
||||
|
||||
class ReviewListener implements Zend_EventManager_ListenerAggregate
|
||||
{
|
||||
private $db; //传入PDO对象.
|
||||
|
||||
function __construct($db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
$this->config = Zend_Registry::get('config');
|
||||
}
|
||||
|
||||
public function attach(Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
$events->attach('post.post', array($this, 'posted'), 100);
|
||||
}
|
||||
|
||||
public function detach(Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function posted($e)
|
||||
{
|
||||
$id = $e->getParam('id');
|
||||
$emails = $e->getParam('emails');
|
||||
$userid = $e->getParam('userid');
|
||||
|
||||
if(is_numeric($id))
|
||||
{
|
||||
//发布正式版本
|
||||
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid in (select uuid from mdstatus where id=?) order by ts_created desc limit 1)";
|
||||
$this->db->query($sql,array('发布第一个正式版本 version 1.0',$userid,$id));
|
||||
//删除所有的中间版本
|
||||
$sql="delete from mdversion where changelog is null and uuid in (select uuid from mdstatus where id=?)";
|
||||
$this->db->query($sql,array($id));
|
||||
//email message
|
||||
if(isset($emails) &&is_array($emails) && count($emails)>0)
|
||||
{
|
||||
$mail=new WestdcMailer($this->view->config->smtp);
|
||||
$sql="select m.uuid,m.title from metadata m left join mdstatus s on m.uuid=s.uuid where s.id='$id'";
|
||||
$rs=$this->db->query($sql);
|
||||
$res=$rs->fetch();
|
||||
$mailtp=new EmailText($this->db,'metadata-publish',array('uuid'=>$res['uuid'],'title'=>$res['title']));
|
||||
$mail->setBodyText($mailtp->getBody());
|
||||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||||
$mail->addTo($emails);
|
||||
$mail->setSubject($mailtp->getSubject());
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($id))
|
||||
{
|
||||
foreach($id as $v)
|
||||
{
|
||||
//发布正式版本
|
||||
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid in (select uuid from mdstatus where id=?) order by ts_created desc limit 1)";
|
||||
$this->db->query($sql,array('发布第一个正式版本 version 1.0',$userid,$v));
|
||||
//删除所有的中间版本
|
||||
$sql="delete from mdversion where changelog is null and uuid in (select uuid from mdstatus where id=?)";
|
||||
$this->db->query($sql,array($v));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue