260 lines
7.5 KiB
PHP
260 lines
7.5 KiB
PHP
<?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;
|
||
|
||
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
|
||
WHERE m.status=0 $searchJoin
|
||
{$this->orderSql} {$this->sortSql}
|
||
{$this->limitSql}";
|
||
|
||
$rs = $this->db->query($sql);
|
||
return $rs->fetchAll();
|
||
}//getDraft()
|
||
|
||
/**
|
||
* 取消评审
|
||
* @param $id
|
||
* @return bool
|
||
*/
|
||
public function cancel($id){
|
||
if(!is_numeric($id) || $id<1)
|
||
return false;
|
||
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;
|
||
}
|
||
|
||
$authorEmail = $this->getAuthor($id);
|
||
|
||
foreach($authorEmail as $v)
|
||
{
|
||
$mailSender = $this->serviceManager->get('Mail/Sender');
|
||
$mailSender->backend([
|
||
'email' => $v['email'],
|
||
'name' => !empty($v['realname']) ? $v['realname']:$v['username'],
|
||
'template' => 'review-new-accept',
|
||
'data' => [
|
||
'uuid' => $v['uuid'],
|
||
'title' => $v['title'],
|
||
]
|
||
]);
|
||
}
|
||
|
||
return true;
|
||
|
||
}//accept($id)
|
||
|
||
/**
|
||
* 获得某条评审涉及的元数据相关作者信息(email,元数据标题,uuid)
|
||
* @param $id
|
||
* @return mixed
|
||
*/
|
||
public function getAuthor($id){
|
||
$sql = "SELECT DISTINCT u.email,u.realname,u.username,m.title,m.uuid FROM mdstatus s
|
||
LEFT JOIN metadata m ON s.uuid=m.uuid
|
||
RIGHT JOIN mdauthor a ON s.uuid=a.uuid
|
||
LEFT JOIN users u ON a.userid=u.id
|
||
WHERE s.id=$id
|
||
ORDER BY u.email";
|
||
|
||
$rs = $this->db->query($sql);
|
||
return $rs->fetchAll(\PDO::FETCH_ASSOC);
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
|
||
}
|