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 [ '评审状态错误,有可能的错误是:', '此评审已被取消,请到已取消评审的元数据中将其重置', '此评审已经被接收', '此评审已经处于待分配责任编辑、邀请专家、等待专家评审、已通过评审的状态中' ]; $status = $this->changeStatus($id,self::REVIEW_STATUS_ACCEPT); if(false === $status){ return false; } $this->getEventManager()->trigger('review.accepted', $this, compact('id')); 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); } }