db = $db; } 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; } //接受或者拒绝评审 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{ $sql = "update ".$this->tbl_reviewexp." set status=$status where id='$id' and uuid='$uuid'"; if($this->db->exec($sql)) { return true; }else{ return "您无权限进行此操作"; } }catch(Exception $e){ return "处理中出现错误"; } } //根据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(); return $reviews; } //后台我负责的评审 function adminReviews($keyword = "",$order="") { include_once('helper/view.php'); $uid = view::User('id'); $wheresql = array(); $wheresql[] = " m.status in (1,2,3,4) "; $wheresql[] = " u.id=$uid "; if(!empty($keyword)) { $wheresql[] = " md.title like '%$keyword%' "; } if(count($wheresql)>0) { $wheresql = " WHERE ".join(" AND ",$wheresql); }else{ $wheresql = ""; } $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 FROM mdstatus m right join metadata md on md.uuid=m.uuid left join geonetworkmetadata g on m.uuid=g.uuid left join users u on u.id=m.userid $wheresql order by m.status desc,m.ts_accepted desc"; $re = $this->db->query($sql); $rows = $re->fetchAll(); return $rows; } //发布 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; } }