2011-10-13 07:56:18 +00:00
< ? php
class ReviewController extends Zend_Controller_Action
2011-10-28 10:00:13 +00:00
{
2011-10-27 14:30:52 +00:00
private $limit = 10 ;
2011-10-13 07:56:18 +00:00
function preDispatch ()
{
$this -> view -> config = Zend_Registry :: get ( 'config' );
$this -> db = Zend_Registry :: get ( 'db' );
$this -> messenger = $this -> _helper -> getHelper ( 'FlashMessenger' );
$this -> view -> messages = $this -> messenger -> getMessages ();
}
function indexAction ()
{
//最新10个收稿
2011-10-14 07:34:01 +00:00
$sql = " select m.uuid,m.title,date(s.ts_created) as ts_created from mdstatus s left join metadata m on m.uuid=s.uuid where s.status=0 order by s.ts_created desc limit 10 " ;
2011-10-13 07:56:18 +00:00
$this -> view -> mdreceived = $this -> db -> fetchAll ( $sql );
//最新10个接收
$sql = " select m.uuid,m.title,s.ts_accepted from mdstatus s left join metadata m on m.uuid=s.uuid where s.status=1 order by s.ts_created desc limit 10 " ;
$this -> view -> mdaccepted = $this -> db -> fetchAll ( $sql );
//最新10个送审
$sql = " select m.uuid,m.title,s.ts_accepted from mdstatus s left join metadata m on m.uuid=s.uuid where s.status in (2,3,4) order by s.ts_created desc limit 10 " ;
$this -> view -> mdinreview = $this -> db -> fetchAll ( $sql );
//最新10个已审
$sql = " select m.uuid,m.title,s.ts_accepted from mdstatus s left join metadata m on m.uuid=s.uuid where s.status=5 order by s.ts_created desc limit 10 " ;
$this -> view -> mdreviewed = $this -> db -> fetchAll ( $sql );
//统计数字
$sql = " select (select count(*) from mdexperts) as experts,(select count(*) from mdstatus where status=0) as draft,(select count(*) from mdstatus where status=1) as accept,(select count(*) from mdstatus where status in (2,3,4)) as inreview,(select count(*) from mdstatus where status=5) as reviewed,(select count(*) from mdreview) as openreview,(select count(distinct(userid)) from mdreview) as openreviewuser " ;
$this -> view -> stat = $this -> db -> fetchRow ( $sql );
}
function myreviewAction (){
2011-10-28 02:32:39 +00:00
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
} else {
$this -> _redirect ( '/account/login/?href=/review/myreview' );
2011-10-31 03:10:26 +00:00
}
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join normalmetadata m on s.uuid=m.uuid where m.uuid in (select uuid from mdexpertreview er where er.id= $uid union select uuid from mdreview r where r.userid= $uid ) " );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,s.ts_accepted,s.ts_finished,g.id as gid,t.filename from mdstatus s left join normalmetadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where m.uuid in (select uuid from mdexpertreview er where er.id= $uid union select uuid from mdreview r where r.userid= $uid ) order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
2011-10-28 02:32:39 +00:00
foreach ( $this -> view -> metadata as $k => $v )
{
$this -> view -> metadata [ $k ][ 'statustext' ] = $this -> rewritestatus ( $v [ 'status' ]);
}
2011-10-13 07:56:18 +00:00
} //我参审的
function draftAction (){
2011-10-31 03:10:26 +00:00
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join metadata m on s.uuid=m.uuid where s.status in (0) " );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,s.ts_created,g.id as gid,t.filename from mdstatus s left join metadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where s.status in (0) order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
2011-10-28 02:32:39 +00:00
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
2011-10-17 09:23:30 +00:00
} //最新收稿
function acceptAction (){
2011-10-31 03:10:26 +00:00
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join normalmetadata m on s.uuid=m.uuid where s.status in (1) " );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,s.ts_accepted,g.id as gid,t.filename from mdstatus s left join normalmetadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where s.status in (1) order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
2011-10-28 02:32:39 +00:00
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
2011-10-13 07:56:18 +00:00
} //最新收稿
2011-10-13 09:30:53 +00:00
function inreviewAction (){
2011-10-31 03:10:26 +00:00
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join normalmetadata m on s.uuid=m.uuid where s.status in (2,3,4) " );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,s.ts_accepted,g.id as gid,t.filename from mdstatus s left join normalmetadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where s.status in (2,3,4) order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
2011-10-13 09:30:53 +00:00
} //在审阶段的元数据
2011-10-13 09:42:04 +00:00
function reviewedAction (){
2011-10-31 03:10:26 +00:00
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join normalmetadata m on s.uuid=m.uuid where s.status in (5) " );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,s.ts_finished,g.id as gid,t.filename from mdstatus s left join normalmetadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where s.status in (5) order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
2011-10-28 02:32:39 +00:00
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
2011-10-13 09:42:04 +00:00
} //已完成评审的元数据
2011-10-27 14:49:00 +00:00
function rewritestatus ( $status ){
2011-10-13 09:30:53 +00:00
if ( $status ==- 1 )
{ return " 取消评审 " ;}
else if ( $status == 0 )
2011-10-27 14:49:00 +00:00
{ return " 投稿元数据 " ;}
2011-10-13 09:30:53 +00:00
else if ( $status == 1 )
2011-10-27 14:49:00 +00:00
{ return " 接收元数据 " ;}
2011-10-13 09:30:53 +00:00
else if ( $status == 2 )
{ return " 专家评审中 " ;}
else if ( $status == 3 )
{ return " 专家评审中 " ;}
else if ( $status == 4 )
{ return " 专家反馈 " ;}
else if ( $status == 5 )
{ return " 已发布 " ;}
else
{ return " " ;}
} //function rewriterstatus
2011-10-14 10:29:26 +00:00
function replace ( $string ){
$patterns = array ( " / \" /i " , " / \ '/i " );
$replacements = array ( " “ " , " ‘ " );
ksort ( $patterns );
ksort ( $replacements );
return preg_replace ( $patterns , $replacements , $string );
}
function reviewAction () {
$uuid = $this -> _request -> getParam ( 'uuid' );
2011-10-18 08:15:32 +00:00
$sql = $this -> db -> quoteInto ( " select m.id,m.uuid,m.title,m.description,m.title_en,r.status from metadata m
left join mdstatus r on r . uuid = m . uuid
where m . uuid = ? " , $uuid );
2011-10-28 10:00:13 +00:00
$md = $this -> db -> fetchRow ( $sql );
$this -> view -> metadata = $md ;
2011-10-17 08:10:25 +00:00
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
2011-10-31 03:10:26 +00:00
$sql = " select * from mdreview where userid=' $userid ' and uuid=' $uuid ' " ;
2011-10-17 08:10:25 +00:00
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
2011-10-31 03:10:26 +00:00
$this -> view -> review = $row ;
2011-10-14 10:29:26 +00:00
}
} //reviewAction()
2011-10-17 08:10:25 +00:00
function allreviewAction (){
2011-10-18 01:41:20 +00:00
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2011-10-17 08:10:25 +00:00
$uuid = $this -> _request -> getParam ( 'uuid' );
2011-11-08 04:02:04 +00:00
$sql = " select r.id,r.uuid,r.userid,r.ts_created,u.realname,r.mdcomment,r.conclusion,ratt.reviewid from mdreview r
2011-10-17 08:10:25 +00:00
left join users u on u . id = r . userid
2011-11-08 04:02:04 +00:00
right join mdreviewattach ratt on r . id = ratt . reviewid
where r . uuid = '$uuid' and r . status >- 1
group by r . id , r . uuid , r . userid , r . ts_created , u . realname , r . mdcomment , r . conclusion , ratt . reviewid
" ;
2011-10-17 08:10:25 +00:00
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
2011-10-18 01:41:20 +00:00
$paginator -> setItemCountPerPage ( 5 );
$paginator -> setView ( $this -> view );
2011-10-17 10:20:19 +00:00
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'review/pagination_ajax.phtml' );
2011-10-17 08:10:25 +00:00
$list = " " ;
2011-10-18 01:41:20 +00:00
foreach ( $paginator as $k => $v )
2011-10-17 08:10:25 +00:00
{
$list .= '
< li >
< div class = " reviewitem " >
2011-11-08 04:02:04 +00:00
< div class = " itemtitle " > 评审人: '.$v[' realname '].' </ div >< div class = " itemtime " > ' ;
if ( $v [ 'reviewid' ] != " " )
{
$list .= '[<a href="javascript:;" onclick="checkfiles(\'' . $v [ 'id' ] . '\')">查看评审附件</a>] ' ;
}
$list .= '
评审时间: '.date("Y-m-d H:i",strtotime($v[' ts_created '])).' </ div >
2011-10-17 09:05:46 +00:00
< div class = " itemcontent " >< p > '.str_replace(array("\r\n", "\n", "\r"),' </ p >< p > ',$v[' mdcomment ']).' </ p ></ div >
2011-11-08 04:02:04 +00:00
< div id = " filelist_'. $v['id'] .' " class = " filelist " ></ div >
2011-10-17 08:10:25 +00:00
</ div >
</ li >
' ;
}
2011-10-28 10:00:13 +00:00
if ( empty ( $list ))
{
$list = " <p style='text-align:center'>暂无评审数据</p> " ;
}
2011-10-17 08:10:25 +00:00
$stringbuffer = " <ul class='reviewlist'> $list </ul> " ;
2011-10-18 01:41:20 +00:00
2011-10-17 08:10:25 +00:00
echo $stringbuffer . '<div class="paginator">' . $paginator . '</div>' ;
2011-10-28 10:00:13 +00:00
} //allreviewAction() 所有评论 ajax
function saveAction (){
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2011-11-04 08:01:27 +00:00
$do = $this -> _request -> getParam ( 'do' );
2011-10-31 03:10:26 +00:00
$conclusion = $this -> _request -> getParam ( 'conclusion' );
$mdcomment = $this -> replace ( trim ( $this -> _request -> getParam ( 'mdcomment' )));
$datacomment = $this -> replace ( trim ( $this -> _request -> getParam ( 'datacomment' )));
$editorcomment = $this -> replace ( trim ( $this -> _request -> getParam ( 'editorcomment' )));
$uuid = $this -> _request -> getParam ( 'uuid' );
$sql = $this -> db -> quoteInto ( " select m.id,m.uuid,m.title,m.description,m.title_en,r.status from metadata m
left join mdstatus r on r . uuid = m . uuid
where m . uuid = ? " , $uuid );
$md = $this -> db -> fetchRow ( $sql );
if ( $md [ 'status' ] > 4 )
{
echo '<div class="box box-info">该数据已经通过评审,不能再发表评审意见,如需提交问题,请联系数据管理员</div>' ;
exit ();
}
if ( $md [ 'status' ] < 1 )
{
echo '<div class="box box-info">已被数据中心接收的数据才可以进行评审</div>' ;
exit ();
}
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql = " select id,userid,status from mdreview where userid=' $userid ' and uuid=' $uuid ' " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
if ( $row [ 'id' ] != '' && $row [ 'status' ] >- 1 )
{
echo '<div class="box box-info">您已经对该元数据发表过评审了</div>' ;
exit ();
}
} else {
echo '<div class="box box-info">读取用户信息失败,请刷新页面后重试 :(</div>' ;
exit ();
}
if ( empty ( $conclusion ))
{
echo '<div class="box box-info">请选择评审意见</div>' ;
exit ();
}
if ( ! is_numeric ( $conclusion ) || ! in_array ( $conclusion , array ( - 1 , 1 , 2 , 3 )))
{
echo '<div class="box box-info">参数有误,请刷新页面 :(</div>' ;
exit ();
}
if ( empty ( $mdcomment ) )
{
2011-11-04 08:01:27 +00:00
echo '<div class="box box-info">请填写元数据意见 :(</div>' ;
2011-10-31 03:10:26 +00:00
exit ();
}
try {
if ( $row [ 'status' ] < 0 )
{
$sql = " delete from mdreview where id=' { $row [ 'id' ] } ' " ;
if ( $this -> db -> exec ( $sql ) < 1 )
{
echo '<div class="box box-error">处理出错,请重试</div>' ;
exit ();
}
}
$data = array (
'userid' => $userid ,
'uuid' => $uuid ,
'mdcomment' => $mdcomment ,
'ts_created' => 'now()' ,
'datacomment' => $datacomment ,
'editorcomment' => $editorcomment ,
'conclusion' => $conclusion ,
'status' => - 1
);
2011-11-04 08:01:27 +00:00
if ( $do == 'submit' )
{
$data [ 'status' ] = 0 ;
}
2011-10-31 03:10:26 +00:00
$sql = " select id from mdexpertreview where id=' $userid ' and uuid=' $uuid ' " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
if ( $row [ 'id' ] != '' )
{
$data [ 'is_expert' ] = 'true' ;
}
$keys = array ();
$values = array ();
foreach ( $data as $k => $v )
{
$keys [] = $k ;
$values [] = $v ;
}
$keys = join ( " , " , $keys );
$values = " ' " . join ( " ',' " , $values ) . " ' " ;
$sql = " insert into mdreview ( $keys ) values ( $values ) RETURNING id " ;
$sth = $this -> db -> prepare ( $sql );
2011-11-01 02:01:22 +00:00
if ( $sth -> execute ())
{
2011-11-04 08:01:27 +00:00
if ( $_POST [ 'atts' ])
{
$review = $sth -> fetch ( PDO :: FETCH_ASSOC );
$reviewid = $review [ 'id' ];
try {
foreach ( $_POST [ 'atts' ] as $v )
{
$sql = " insert into mdreviewattach (attachid,reviewid) values (' $v ',' $reviewid ') " ;
$this -> db -> exec ( $sql );
}
echo '<div class="box box-success">保存成功!' ;
if ( $data [ 'status' ] >= 0 )
{
echo '<script>$("#postcomment").remove();</script>' ;
}
echo " </div> " ;
exit ();
} catch ( Exception $e ){
echo '<div class="box box-error">保存草稿出错,请稍后再试!</div>' ;
exit ();
}
}
2011-11-01 02:01:22 +00:00
} else {
echo '<div class="box box-error">保存草稿出错,请稍后再试!</div>' ;
exit ();
}
2011-10-31 03:10:26 +00:00
} catch ( Exception $e ){
echo '<div class="box box-error">保存失败,请重试!</div>' ;
exit ();
}
2011-10-28 10:00:13 +00:00
} // saveAction 存草稿 ajax
2011-10-27 14:30:52 +00:00
2011-10-28 10:00:13 +00:00
function searchAction ()
{
$key = $this -> _request -> getParam ( 'q' );
if ( ! empty ( $key )) {
$search = new Search ( $key );
$where = $search -> sql_expr ( array ( " m.title " , " m.description " ));
$page =@ ( int ) $this -> _request -> getParam ( 'page' );
if ( empty ( $page )) $page = 1 ;
$offset = $this -> limit * ( $page - 1 );
$row = $this -> db -> fetchAll ( " select count(s.*) from mdstatus s left join normalmetadata m on s.uuid=m.uuid where s.status>0 and " . $where );
$sum = $row [ 0 ][ 'count' ];
$sql = " select m.uuid,m.title,m.id,m.description,s.status,g.id as gid,t.filename from mdstatus s left join normalmetadata m on s.uuid=m.uuid left join geonetworkmetadata g on g.uuid=m.uuid left join thumbnail t on t.id=m.id where s.status>0 and " . $where . " order by s.ts_created desc,m.title limit ? offset ? " ;
$this -> view -> metadata = $this -> db -> fetchAll ( $sql , array ( $this -> limit , $offset ));
$this -> view -> page = new Pagination ( $sum , $page , $this -> limit );
$this -> view -> key = $key ;
2011-10-27 14:49:00 +00:00
foreach ( $this -> view -> metadata as $k => $v )
{
$this -> view -> metadata [ $k ][ 'statustext' ] = $this -> rewritestatus ( $v [ 'status' ]);
2011-10-28 10:00:13 +00:00
}
}
2011-11-08 04:02:04 +00:00
}
function helpAction ()
{
}
function attlistAction ()
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$rid = $this -> _request -> getParam ( 'id' );
$list = array ();
$list [] = '
< li style = " border:none " >
附件列表:
< span >< a href = " javascript:void(0); " onclick = " $ ( \ '#filelist_'. $rid .' ul \ ').remove(); " > [ 关闭 ] </ a ></ span >
</ li >
' ;
$sql = " select att.realname,att.id from attachments att
left join mdreviewattach ratt on ratt . attachid = att . id
where ratt . reviewid = $rid " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
foreach ( $rows as $k => $v )
{
$list [] = '
< li > '.$v[' realname '].'
< span >< a href = " /review/downatt/id/'. $v['id'] .' " > 下载 </ a ></ span >
</ li >
' ;
}
if ( count ( $rows ) > 0 )
{
echo " <ul> " . join ( '' , $list ) . " </ul> " ;
} else {
echo " 无附件 " ;
}
exit ();
} // ajax 评审附件列表
2011-10-13 07:56:18 +00:00
}