2015-01-02 15:11:09 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created by PhpStorm.
|
|
|
|
|
* User: liujin834
|
|
|
|
|
* Date: 15/1/1
|
|
|
|
|
* Time: 下午8:04
|
|
|
|
|
*/
|
|
|
|
|
namespace Westdc\Review;
|
|
|
|
|
|
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
|
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
|
|
|
|
use Westdc\EventModel\AbstractEventManager;
|
2015-01-13 16:25:56 +00:00
|
|
|
|
use Zend\Db\Sql\Select;
|
2015-01-02 15:11:09 +00:00
|
|
|
|
|
|
|
|
|
class Review extends AbstractEventManager implements ServiceManagerAwareInterface{
|
|
|
|
|
|
|
|
|
|
protected $serviceManager;
|
|
|
|
|
|
|
|
|
|
public $opt,$orderSql = "",$limitSql = "",$sortSql = "";
|
|
|
|
|
|
|
|
|
|
const REVIEW_STATUS_CANCELED = -1; //取消评审
|
|
|
|
|
const REVIEW_STATUS_DEFAULT = 0; //初始状态
|
|
|
|
|
const REVIEW_STATUS_ACCEPT = 1; //接收元数据,进入评审状态
|
|
|
|
|
const REVIEW_STATUS_EXPERT_INVITED = 2; //开始邀请专家
|
|
|
|
|
const REVIEW_STATUS_EXPERT_ACCEPT = 3; //专家接受邀请
|
|
|
|
|
const REVIEW_STATUS_EXPERT_FEEDBACK = 4; //专家有反馈
|
|
|
|
|
const REVIEW_STATUS_PUBLISH = 5; //已发布
|
|
|
|
|
|
|
|
|
|
public function setServiceManager(ServiceManager $serviceManager)
|
|
|
|
|
{
|
|
|
|
|
$this->serviceManager = $serviceManager;
|
|
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function init(){
|
|
|
|
|
$dbService = $this->serviceManager->get('Db');
|
|
|
|
|
$this->db = $dbService->getPdo();
|
|
|
|
|
unset($dbService);
|
|
|
|
|
|
|
|
|
|
$this->opt = new \stdClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理sql中用到的排序,limit等语句
|
|
|
|
|
*/
|
|
|
|
|
private function processOptions()
|
|
|
|
|
{
|
|
|
|
|
if(isset($this->opt->limit) && $this->opt->limit > 0)
|
|
|
|
|
$this->limitSql = "LIMIT {$this->opt->limit}";
|
|
|
|
|
|
|
|
|
|
if(isset($this->opt->order) && !empty($this->opt->order)) {
|
|
|
|
|
$this->orderSql = "ORDER BY {$this->opt->order}";
|
|
|
|
|
|
|
|
|
|
if (isset($this->opt->sortSql) && !empty($this->opt->sortSql))
|
|
|
|
|
$this->sortSql = "{$this->opt->sort}";
|
|
|
|
|
else
|
|
|
|
|
$this->sortSql = "DESC";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得最新的数据
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getLatest()
|
|
|
|
|
{
|
|
|
|
|
$this->processOptions();
|
|
|
|
|
|
|
|
|
|
$sql = "select m.id,md.title,u.username,u.realname,m.status from mdstatus m
|
|
|
|
|
right join metadata md on md.uuid=m.uuid
|
|
|
|
|
left join users u on u.id=m.userid
|
|
|
|
|
order by m.id desc
|
|
|
|
|
{$this->limitSql}";
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
return $rs->fetchAll();
|
|
|
|
|
}//getLatest()
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得管理员负责的评审
|
|
|
|
|
* @param $userId
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getAdminReview($userId)
|
|
|
|
|
{
|
|
|
|
|
$this->processOptions();
|
|
|
|
|
|
|
|
|
|
$sql = "select m.id,md.title,u.username,u.realname,m.status from mdstatus m
|
|
|
|
|
right join metadata md on md.uuid=m.uuid
|
|
|
|
|
left join users u on u.id=m.userid
|
|
|
|
|
where u.id='$userId'
|
|
|
|
|
{$this->limitSql}";
|
|
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
return $rs->fetchAll();
|
|
|
|
|
} //getAdminReview
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 投稿元数据
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getDraft(){
|
|
|
|
|
|
|
|
|
|
$this->processOptions();
|
|
|
|
|
|
|
|
|
|
$searchJoin = "";
|
|
|
|
|
if(isset($this->opt->keyword) && !empty($this->opt->keyword))
|
|
|
|
|
{
|
|
|
|
|
$searchJoin = " AND md.title LIKE '%{$this->opt->keyword}%'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(empty($this->orderSql))
|
|
|
|
|
{
|
|
|
|
|
$this->orderSql = "ORDER BY m.ts_created DESC";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT m.id,md.title,md.uuid,u.username,u.realname,m.status,m.ts_created,gn.id as gnid FROM mdstatus m
|
|
|
|
|
RIGHT JOIN metadata md ON md.uuid=m.uuid
|
|
|
|
|
LEFT JOIN users u ON u.id=m.userid
|
|
|
|
|
LEFT JOIN geonetworkmetadata gn ON m.uuid=gn.uuid
|
2015-01-12 15:43:37 +00:00
|
|
|
|
WHERE m.status=".self::REVIEW_STATUS_DEFAULT." $searchJoin
|
2015-01-02 15:11:09 +00:00
|
|
|
|
{$this->orderSql} {$this->sortSql}
|
|
|
|
|
{$this->limitSql}";
|
|
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
2015-01-13 16:25:56 +00:00
|
|
|
|
return $rs->fetchAll(\PDO::FETCH_ASSOC);
|
2015-01-02 15:11:09 +00:00
|
|
|
|
}//getDraft()
|
|
|
|
|
|
2015-01-13 16:25:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取被取消评审的元数据
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getCanceled()
|
|
|
|
|
{
|
|
|
|
|
$this->processOptions();
|
|
|
|
|
|
|
|
|
|
$searchJoin = "";
|
|
|
|
|
if(isset($this->opt->keyword) && !empty($this->opt->keyword))
|
|
|
|
|
{
|
|
|
|
|
$searchJoin = " AND md.title LIKE '%{$this->opt->keyword}%'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(empty($this->orderSql))
|
|
|
|
|
{
|
|
|
|
|
$this->orderSql = "ORDER BY m.ts_created DESC";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT m.id,md.title,md.uuid,m.status,m.ts_created FROM mdstatus m
|
|
|
|
|
RIGHT JOIN metadata md ON md.uuid=m.uuid
|
|
|
|
|
WHERE m.status=".self::REVIEW_STATUS_CANCELED." $searchJoin
|
|
|
|
|
{$this->orderSql} {$this->sortSql}
|
|
|
|
|
{$this->limitSql}";
|
|
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
return $rs->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
}
|
2015-01-12 15:43:37 +00:00
|
|
|
|
|
2015-01-02 15:11:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* 取消评审
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function cancel($id){
|
|
|
|
|
if(!is_numeric($id) || $id<1)
|
|
|
|
|
return false;
|
2015-01-12 15:43:37 +00:00
|
|
|
|
|
|
|
|
|
$this->getEventManager()->trigger('review.canceled', $this, compact('id'));
|
|
|
|
|
|
2015-01-02 15:11:09 +00:00
|
|
|
|
return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 接收投稿的元数据
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function accept($id){
|
|
|
|
|
|
|
|
|
|
if($this->getStatus($id) != self::REVIEW_STATUS_DEFAULT)
|
|
|
|
|
return [
|
|
|
|
|
'评审状态错误,有可能的错误是:',
|
|
|
|
|
'此评审已被取消,请到<b>已取消评审的元数据</b>中将其重置',
|
|
|
|
|
'此评审已经被接收',
|
|
|
|
|
'此评审已经处于待分配责任编辑、邀请专家、等待专家评审、已通过评审的状态中'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$status = $this->changeStatus($id,self::REVIEW_STATUS_ACCEPT);
|
|
|
|
|
|
|
|
|
|
if(false === $status){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-04 05:57:48 +00:00
|
|
|
|
$this->getEventManager()->trigger('review.accepted', $this, compact('id'));
|
2015-01-02 15:11:09 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}//accept($id)
|
|
|
|
|
|
|
|
|
|
public function reset($id){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更改mdstatus中的status字段
|
|
|
|
|
* @param $id
|
|
|
|
|
* @param $status
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function changeStatus($id,$status){
|
|
|
|
|
$statusValues = array(
|
|
|
|
|
self::REVIEW_STATUS_CANCELED, //取消评审
|
|
|
|
|
self::REVIEW_STATUS_DEFAULT, //初始状态
|
|
|
|
|
self::REVIEW_STATUS_ACCEPT, //接受元数据评审,进入评审阶段
|
|
|
|
|
self::REVIEW_STATUS_EXPERT_INVITED, //开始邀请专家,送审阶段
|
|
|
|
|
self::REVIEW_STATUS_EXPERT_ACCEPT, //专家接受邀请,在审阶段
|
|
|
|
|
self::REVIEW_STATUS_EXPERT_FEEDBACK,//专家反馈,在审
|
|
|
|
|
self::REVIEW_STATUS_PUBLISH, //评审结束,发布
|
|
|
|
|
6,7
|
|
|
|
|
);
|
|
|
|
|
if(empty($id) || !isset($status) || !in_array($status,$statusValues))
|
|
|
|
|
{
|
|
|
|
|
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 更改状态
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取mdstatus表中的status字段
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getStatus($id)
|
|
|
|
|
{
|
|
|
|
|
$sql = "SELECT status FROM mdstatus WHERE id=$id";
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
return $rs->fetchColumn(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|