2013-05-03 06:41:06 +00:00
< ? php
class Review extends Zend_Controller_Plugin_Abstract
{
private $db ; //传入PDO对象.
2013-06-09 09:39:16 +00:00
protected $events = NULL ; //事件
2013-05-03 06:41:06 +00:00
2013-10-28 14:54:21 +00:00
//相关数据表
2013-05-10 08:53:24 +00:00
public $tbl_reviewexp = " mdexpertreview " ;
public $tbl_mdreview = " mdreview " ;
public $tbl_user = " users " ;
2013-05-03 06:41:06 +00:00
2013-10-28 14:54:21 +00:00
function __construct ( $db = NULL )
2013-05-03 06:41:06 +00:00
{
2013-10-28 14:54:21 +00:00
if ( empty ( $db ))
{
$this -> db = Zend_Registry :: get ( 'db' );
} else {
$this -> db = $db ;
}
2013-05-03 06:41:06 +00:00
}
2013-10-28 14:54:21 +00:00
/*
* events () 事件枚举
*
* @ param $events Zend_EventManager_EventCollection default null
*
* return Zend_EventManager_EventManager
*
* 使用Zend_EventManager_EventManager枚举评审操作中的事件
*/
2013-06-09 09:39:16 +00:00
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 ;
}
2013-10-28 14:54:21 +00:00
/*
* invite () 接受或者拒绝评审
*
* @ param $id int
* @ param $uuid uuid
* @ param $uid int
* @ param $status string
*
* return bool / string
*
* 处理评审邀请,接受或者拒绝
*/
2013-05-03 06:41:06 +00:00
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 {
2013-05-10 08:53:24 +00:00
$sql = " update " . $this -> tbl_reviewexp . " set status= $status where id=' $id ' and uuid=' $uuid ' " ;
2013-05-03 06:41:06 +00:00
if ( $this -> db -> exec ( $sql ))
{
return true ;
} else {
return " 您无权限进行此操作 " ;
}
} catch ( Exception $e ){
return " 处理中出现错误 " ;
}
2013-05-10 08:53:24 +00:00
}
2013-10-28 14:54:21 +00:00
/*
* getReviews () 根据UUID获得评审意见
*
* @ param $uuid uuid
*
* return array
*
* 传入评审数据的UUID, 返回评审意见记录
*/
2013-05-10 08:53:24 +00:00
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 ();
2013-05-03 06:41:06 +00:00
2013-05-10 08:53:24 +00:00
return $reviews ;
2013-05-03 06:41:06 +00:00
}
2013-05-14 08:57:30 +00:00
2013-10-28 14:54:21 +00:00
/*
* 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 = " " )
2013-05-14 08:57:30 +00:00
{
include_once ( 'helper/view.php' );
2013-10-28 14:54:21 +00:00
$uid = \view :: User ( 'id' );
2013-05-14 08:57:30 +00:00
$wheresql = array ();
2013-10-28 14:54:21 +00:00
$ordersql = array ();
2013-05-14 08:57:30 +00:00
2013-05-29 07:36:44 +00:00
$wheresql [] = " m.status in (1,2,3,4) " ;
2013-05-14 08:57:30 +00:00
$wheresql [] = " u.id= $uid " ;
2013-06-13 08:06:11 +00:00
if ( isset ( $filter [ 'keyword' ]) && ! empty ( $filter [ 'keyword' ]))
2013-05-14 08:57:30 +00:00
{
2013-06-13 08:06:11 +00:00
$wheresql [] = " md.title like '% " . $filter [ 'keyword' ] . " %' " ;
}
if ( isset ( $filter [ 'code' ]) && ! empty ( $filter [ 'code' ]))
{
2013-06-16 15:28:28 +00:00
$wheresql [] = " s.sourceid= " . $filter [ 'code' ] . " " ;
2013-05-14 08:57:30 +00:00
}
2013-10-28 14:54:21 +00:00
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 " ;
}
2013-05-14 08:57:30 +00:00
if ( count ( $wheresql ) > 0 )
{
$wheresql = " WHERE " . join ( " AND " , $wheresql );
} else {
$wheresql = " " ;
}
2013-10-28 14:54:21 +00:00
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
2014-06-23 06:42:49 +00:00
FROM en . mdstatus m
right join en . metadata md on md . uuid = m . uuid
left join en . geonetworkmetadata g on m . uuid = g . uuid
2013-05-14 08:57:30 +00:00
left join users u on u . id = m . userid
2013-06-13 08:06:11 +00:00
left join datasource s on s . uuid = md . uuid
2013-10-28 14:54:21 +00:00
left join mdreview r ON r . uuid = md . uuid
2013-05-14 08:57:30 +00:00
$wheresql
2013-10-28 14:54:21 +00:00
GROUP BY m . id , g . id , md . uuid , md . title , u . username , u . realname , m . status , md . id , md . author , m . ts_accepted
$ordersql " ;
2013-05-14 08:57:30 +00:00
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
return $rows ;
}
2013-06-09 09:39:16 +00:00
2013-10-28 14:54:21 +00:00
/*
* post () 通过评审
*
* @ param $id int
* $param $emails array ()
*
* return bool
*
* 元数据通过评审且发布
*/
2013-06-09 09:39:16 +00:00
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 ;
}
} //发布
2013-10-28 14:54:21 +00:00
/*
* post () 检查管理员
*
* @ param $id int
* $param $emails array ()
*
* return bool
*
* 元数据通过评审且发布
*/
2013-06-09 09:39:16 +00:00
function checkAdmin ( $id , $userid = 0 )
{
$id = ( int ) $id ;
if ( empty ( $userid ))
{
include_once ( " helper/view.php " );
$userid = ( int ) view :: User ( 'id' );
}
2014-06-23 06:56:40 +00:00
$sql = " select id from en.mdstatus where id= $id and userid= $userid " ;
2013-06-09 09:39:16 +00:00
$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 )
2014-06-23 06:45:27 +00:00
{ $sql = " update en.mdstatus set status=' $status ',ts_accepted='now()' where id in ( $id ) " ; }
2013-06-09 09:39:16 +00:00
else if ( $status == 5 )
2014-06-23 06:45:27 +00:00
{ $sql = " update en.mdstatus set status=' $status ',ts_finished='now()' where id in ( $id ) " ;}
2013-06-09 09:39:16 +00:00
else
2014-06-23 06:45:27 +00:00
{ $sql = " update en.mdstatus set status=' $status ' where id in ( $id ) " ;}
2013-06-09 09:39:16 +00:00
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 ))
{
2015-12-21 15:38:39 +00:00
//同步元数据
2015-12-21 15:43:04 +00:00
$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 " ;
2015-12-21 15:38:39 +00:00
$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 );
2013-06-09 09:39:16 +00:00
//发布正式版本
2014-06-23 06:56:40 +00:00
$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 ));
2013-06-09 09:39:16 +00:00
//删除所有的中间版本
2014-06-23 06:56:40 +00:00
$sql = " delete from en.mdversion where changelog is null and uuid in (select uuid from en.mdstatus where id=?) " ;
2013-06-09 09:39:16 +00:00
$this -> db -> query ( $sql , array ( $id ));
//email message
if ( isset ( $emails ) && is_array ( $emails ) && count ( $emails ) > 0 )
2013-10-28 14:54:21 +00:00
{
2013-06-21 13:58:44 +00:00
$config = Zend_Registry :: get ( 'config' );
$mail = new WestdcMailer ( $config -> smtp );
2014-06-23 06:56:40 +00:00
$sql = " select m.uuid,m.title from en.metadata m left join en.mdstatus s on m.uuid=s.uuid where s.id=' $id ' " ;
2013-06-09 09:39:16 +00:00
$rs = $this -> db -> query ( $sql );
$res = $rs -> fetch ();
2014-06-23 06:56:40 +00:00
$mailtp = new EmailText ( $this -> db , 'metadata-publish-en' , array ( 'uuid' => $res [ 'uuid' ], 'title' => $res [ 'title' ]));
2013-10-28 14:54:21 +00:00
$mail -> setBodyText ( $mailtp -> getBody ());
2014-06-23 06:56:40 +00:00
$mail -> setFrom ( $config -> service -> email , 'CARD support group' );
2013-06-21 13:58:44 +00:00
foreach ( $emails as $email ) $mail -> addTo ( $email );
2013-06-09 09:39:16 +00:00
$mail -> setSubject ( $mailtp -> getSubject ());
$mail -> send ();
}
}
if ( is_array ( $id ))
{
foreach ( $id as $v )
{
2015-12-21 15:38:39 +00:00
//同步元数据
2015-12-21 15:43:04 +00:00
$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 " ;
2015-12-21 15:38:39 +00:00
$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 );
2013-06-09 09:39:16 +00:00
//发布正式版本
2014-06-23 06:56:40 +00:00
$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 ));
2013-06-09 09:39:16 +00:00
//删除所有的中间版本
2014-06-23 06:56:40 +00:00
$sql = " delete from en.mdversion where changelog is null and uuid in (select uuid from en.mdstatus where id=?) " ;
2013-06-09 09:39:16 +00:00
$this -> db -> query ( $sql , array ( $v ));
}
}
return true ;
}
2013-05-03 06:41:06 +00:00
}