444 lines
12 KiB
PHP
444 lines
12 KiB
PHP
<?php
|
||
class Review extends Zend_Controller_Plugin_Abstract
|
||
{
|
||
private $db; //传入PDO对象.
|
||
protected $events = NULL; //事件
|
||
|
||
//相关数据表
|
||
public $tbl_reviewexp = "mdexpertreview";
|
||
public $tbl_mdreview = "mdreview";
|
||
public $tbl_user = "users";
|
||
|
||
function __construct($db = NULL)
|
||
{
|
||
if(empty($db))
|
||
{
|
||
$this->db = Zend_Registry::get('db');
|
||
}else{
|
||
$this->db = $db;
|
||
}
|
||
}
|
||
|
||
/*
|
||
* events() 事件枚举
|
||
*
|
||
* @param $events Zend_EventManager_EventCollection default null
|
||
*
|
||
* return Zend_EventManager_EventManager
|
||
*
|
||
* 使用Zend_EventManager_EventManager枚举评审操作中的事件
|
||
*/
|
||
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;
|
||
}
|
||
|
||
/*
|
||
* invite() 接受或者拒绝评审
|
||
*
|
||
* @param $id int
|
||
* @param $uuid uuid
|
||
* @param $uid int
|
||
* @param $status string
|
||
*
|
||
* return bool/string
|
||
*
|
||
* 处理评审邀请,接受或者拒绝
|
||
*/
|
||
function invite($id,$uuid,$uid,$status)
|
||
{
|
||
if(empty($id) || empty($uuid) || !is_numeric($id) ||!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
||
{
|
||
return"参数错误";
|
||
}
|
||
|
||
if($id != $uid)
|
||
{
|
||
return "您无权使用此通知";
|
||
}//非本人操作
|
||
|
||
try{
|
||
$sql = "update ".$this->tbl_reviewexp." set status=$status where id='$id' and uuid='$uuid'";
|
||
if($this->db->exec($sql))
|
||
{
|
||
return true;
|
||
}else{
|
||
return "您无权限进行此操作";
|
||
}
|
||
}catch(Exception $e){
|
||
return "处理中出现错误";
|
||
}
|
||
}
|
||
|
||
/*
|
||
* getReviews() 根据UUID获得评审意见
|
||
*
|
||
* @param $uuid uuid
|
||
*
|
||
* return array
|
||
*
|
||
* 传入评审数据的UUID,返回评审意见记录
|
||
*/
|
||
function getReviews($uuid)
|
||
{
|
||
$sql = "SELECT mr.*,u.username,u.realname FROM ".$this->tbl_mdreview." mr
|
||
LEFT JOIN ".$this->tbl_user." u ON mr.userid = u.id
|
||
WHERE mr.uuid = '$uuid'";
|
||
|
||
$sth = $this->db->query($sql);
|
||
$reviews = $sth->fetchAll();
|
||
|
||
return $reviews;
|
||
}
|
||
|
||
/*
|
||
* needEditor() 需要分配责任编辑的元数据评审
|
||
*
|
||
* @param $filter array
|
||
*
|
||
* return array
|
||
*
|
||
* filter参数帮助生成sql语句中的where、order、sort条件
|
||
*/
|
||
function needEditor($filter = "")
|
||
{
|
||
$wheresql = array();
|
||
$ordersql = array();
|
||
|
||
$wheresql[] = " m.status in (1,2,3,4) ";
|
||
$wheresql[] = " (m.userid IS NULL OR u.usertype != 'administrator') ";
|
||
|
||
|
||
if(isset($filter['keyword']) && !empty($filter['keyword']))
|
||
{
|
||
$wheresql[] = " (md.title like '%".$filter['keyword']."%' OR u.username LIKE '%".$filter['keyword']."%' OR u.realname LIKE '%".$filter['keyword']."%') ";
|
||
}
|
||
|
||
if(count($wheresql)>0)
|
||
{
|
||
$wheresql = " WHERE ".join(" AND ",$wheresql);
|
||
}else{
|
||
$wheresql = "";
|
||
}
|
||
|
||
if(isset($filter['order']) && !empty($filter['order']))
|
||
{
|
||
$sort = "DESC";
|
||
if(isset($filter['sort']) && !empty($filter['sort']) && in_array( strtolower($filter['sort']),array('desc','asc')))
|
||
{
|
||
$sort = $filter['sort'];
|
||
}
|
||
$ordersql[] = " {$filter['order']} $sort ";
|
||
}
|
||
|
||
if(count($ordersql)>0)
|
||
{
|
||
$ordersql = " ORDER BY ".join(',',$ordersql);
|
||
}else{
|
||
$ordersql = " ORDER BY m.ts_created desc ";
|
||
}
|
||
|
||
$sql = "select m.*,md.title,u.username,u.realname from mdstatus m
|
||
right join metadata md on md.uuid=m.uuid
|
||
left join users u on u.id=m.userid
|
||
$wheresql
|
||
$ordersql";
|
||
$re = $this->db->query($sql);
|
||
$rows = $re->fetchAll();
|
||
|
||
return $rows;
|
||
}
|
||
|
||
/*
|
||
* adminReviews() 我负责的评审
|
||
*
|
||
* @param $filter array
|
||
*
|
||
* return array
|
||
*
|
||
* filter参数帮助生成sql语句中的where、order、sort条件
|
||
* 此函数返回当前登录的用户(管理员)负责的元数据评审
|
||
*/
|
||
function adminReviews($filter = "")
|
||
{
|
||
include_once('helper/view.php');
|
||
$uid = \view::User('id');
|
||
|
||
$wheresql = array();
|
||
$ordersql = array();
|
||
|
||
$wheresql[] = " m.status in (1,2,3,4) ";
|
||
$wheresql[] = " u.id=$uid ";
|
||
|
||
if(isset($filter['keyword']) && !empty($filter['keyword']))
|
||
{
|
||
$wheresql[] = " md.title like '%".$filter['keyword']."%' ";
|
||
}
|
||
if(isset($filter['code']) && !empty($filter['code']))
|
||
{
|
||
$wheresql[] = " s.sourceid=".$filter['code']." ";
|
||
}
|
||
if(isset($filter['order']) && !empty($filter['order']))
|
||
{
|
||
$sort = "DESC";
|
||
if(isset($filter['sort']) && !empty($filter['sort']) && in_array( strtolower($filter['sort']),array('desc','asc')))
|
||
{
|
||
$sort = $filter['sort'];
|
||
}
|
||
$ordersql[] = " {$filter['order']} $sort ";
|
||
}
|
||
|
||
if(count($wheresql)>0)
|
||
{
|
||
$wheresql = " WHERE ".join(" AND ",$wheresql);
|
||
}else{
|
||
$wheresql = "";
|
||
}
|
||
|
||
if(count($ordersql)>0)
|
||
{
|
||
$ordersql = " ORDER BY ".join(',',$ordersql);
|
||
}else{
|
||
$ordersql = " ORDER BY m.status desc,m.ts_accepted desc ";
|
||
}
|
||
|
||
$sql = "select m.id,g.id as gid, md.uuid,md.title,u.username,u.realname,m.status,md.id as mdid,md.author,m.ts_accepted,count(r.id) as reviews
|
||
FROM en.mdstatus m
|
||
right join en.metadata md on md.uuid=m.uuid
|
||
left join en.geonetworkmetadata g on m.uuid=g.uuid
|
||
left join users u on u.id=m.userid
|
||
left join datasource s on s.uuid=md.uuid
|
||
left join mdreview r ON r.uuid=md.uuid
|
||
$wheresql
|
||
GROUP BY m.id,g.id, md.uuid,md.title,u.username,u.realname,m.status,md.id,md.author,m.ts_accepted
|
||
$ordersql";
|
||
$re = $this->db->query($sql);
|
||
$rows = $re->fetchAll();
|
||
|
||
return $rows;
|
||
}
|
||
|
||
/*
|
||
* post() 通过评审
|
||
*
|
||
* @param $id int
|
||
* $param $emails array()
|
||
*
|
||
* return bool
|
||
*
|
||
* 元数据通过评审且发布
|
||
*/
|
||
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;
|
||
}
|
||
|
||
}//发布
|
||
|
||
/*
|
||
* post() 检查管理员
|
||
*
|
||
* @param $id int
|
||
* $param $emails array()
|
||
*
|
||
* return bool
|
||
*
|
||
* 元数据通过评审且发布
|
||
*/
|
||
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 en.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 en.mdstatus set status='$status',ts_accepted='now()' where id in ($id)"; }
|
||
else if($status==5)
|
||
{$sql = "update en.mdstatus set status='$status',ts_finished='now()' where id in ($id)";}
|
||
else
|
||
{$sql = "update en.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 = "select v.xml,m.uuid from en.mdversion v left join en.metadata m on m.uuid=v.uuid left join en.mdstatus ms on ms.uuid=m.uuid where ms.id=? order by v.ts_created desc limit 1";
|
||
$sth = $this->db->prepare($sql);
|
||
$sth->execute(array($id));
|
||
$row=$sth->fetch();
|
||
|
||
$iso=new ISO19115();
|
||
$iso->saveDB($this->db,$row['xml']);
|
||
|
||
//构建搜索
|
||
$sql="select * from xunsearch where uuid=?";
|
||
$sth = $this->db->prepare($sql);
|
||
$sth->execute(array($row['uuid']));
|
||
$data_search = $sth->fetch();
|
||
$search=new Search();
|
||
$search->update($data_search);
|
||
|
||
//发布正式版本
|
||
$sql = "UPDATE en.mdversion SET changelog=?,userid=? WHERE id in (select id from en.mdversion where uuid in (select uuid from en.mdstatus where id=?) order by ts_created desc limit 1)";
|
||
$this->db->query($sql,array('Version 1.0 Released.',$userid,$id));
|
||
//删除所有的中间版本
|
||
$sql="delete from en.mdversion where changelog is null and uuid in (select uuid from en.mdstatus where id=?)";
|
||
$this->db->query($sql,array($id));
|
||
//email message
|
||
if(isset($emails) &&is_array($emails) && count($emails)>0)
|
||
{
|
||
$config=Zend_Registry::get('config');
|
||
$mail=new WestdcMailer($config->smtp);
|
||
$sql="select m.uuid,m.title from en.metadata m left join en.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-en',array('uuid'=>$res['uuid'],'title'=>$res['title']));
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setFrom($config->service->email,'CARD support group');
|
||
foreach($emails as $email) $mail->addTo($email);
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->send();
|
||
}
|
||
}
|
||
|
||
if(is_array($id))
|
||
{
|
||
foreach($id as $v)
|
||
{
|
||
//同步元数据
|
||
$sql = "select v.xml,m.uuid from en.mdversion v left join en.metadata m on m.uuid=v.uuid left join en.mdstatus ms on ms.uuid=m.uuid where ms.id=? order by v.ts_created desc limit 1";
|
||
$sth = $this->db->prepare($sql);
|
||
$sth->execute(array($v));
|
||
$row=$sth->fetch();
|
||
|
||
$iso=new ISO19115();
|
||
$iso->saveDB($this->db,$row['xml']);
|
||
|
||
//构建搜索
|
||
$sql="select * from xunsearch where uuid=?";
|
||
$sth = $this->db->prepare($sql);
|
||
$sth->execute(array($row['uuid']));
|
||
$data_search = $sth->fetch();
|
||
$search=new Search();
|
||
$search->update($data_search);
|
||
|
||
//发布正式版本
|
||
$sql = "UPDATE en.mdversion SET changelog=?,userid=? WHERE id in (select id from en.mdversion where uuid in (select uuid from en.mdstatus where id=?) order by ts_created desc limit 1)";
|
||
$this->db->query($sql,array('Version 1.0 Released.',$userid,$v));
|
||
//删除所有的中间版本
|
||
$sql="delete from en.mdversion where changelog is null and uuid in (select uuid from en.mdstatus where id=?)";
|
||
$this->db->query($sql,array($v));
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
}
|