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-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
function __construct ( $db )
{
$this -> db = $db ;
}
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-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
}
//根据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 ();
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-06-13 08:06:11 +00:00
function adminReviews ( $filter = " " , $order = " " )
2013-05-14 08:57:30 +00:00
{
include_once ( 'helper/view.php' );
$uid = view :: User ( 'id' );
$wheresql = array ();
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' ]))
{
$wheresql [] = " s.id= " . $filter [ 'code' ] . " " ;
2013-05-14 08:57:30 +00:00
}
if ( count ( $wheresql ) > 0 )
{
$wheresql = " WHERE " . join ( " AND " , $wheresql );
} else {
$wheresql = " " ;
}
2013-05-24 00:35:07 +00:00
$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
2013-05-14 08:57:30 +00:00
FROM mdstatus m
2013-05-29 07:36:44 +00:00
right join metadata md on md . uuid = m . uuid
2013-05-24 00:35:07 +00:00
left join 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-05-14 08:57:30 +00:00
$wheresql
order by m . status desc , m . ts_accepted desc " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
return $rows ;
}
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 ;
}
} //发布
//检查管理员
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 ;
}
2013-05-03 06:41:06 +00:00
}