diff --git a/Westdc/Helpers/Captcha.php b/Westdc/Helpers/Captcha.php new file mode 100644 index 0000000..bee704d --- /dev/null +++ b/Westdc/Helpers/Captcha.php @@ -0,0 +1,65 @@ +loadCaptcha(); + } + + public function loadCaptcha() + { + $this->captcha = new \Zend\Captcha\Image(array( + 'captcha' => 'Image', + 'wordLen' => 4, + 'fontsize'=>16, + 'width' => 100, + 'height' => 38, + 'dotNoiseLevel'=>2, + 'lineNoiseLevel'=>1, + 'timeout' => 300, + 'font' => './data/fonts/ggbi.ttf', + 'imgDir' => $this->imgDir, + 'imgUrl' => '/images/captcha', + )); + } + + public function setCaptcha(){ + if(!is_dir($this->imgDir)) + { + mkdir($this->imgDir); + } + + $this->captcha->generate(); + $_SESSION[$this->sessionName] = $this->captcha->getWord(); + $url = $this->captcha->getImgUrl() + .$this->captcha->getId() + .$this->captcha->getSuffix(); + + return $url; + } + + public function isValid($captchaword) + { + if($captchaword == $_SESSION[$this->sessionName]) + { + return true; + }else{ + return false; + } + } + + //资源回收 + //删除目录中创建时间比超时时间久的 + public function recycle() + { + + } + +} \ No newline at end of file diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 8b2b21a..6cddeda 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -10,7 +10,7 @@ namespace Westdc\Review; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; use Westdc\EventModel\AbstractEventManager; -use Zend\Db\Sql\Select; +use Zend\Db\Sql; class Review extends AbstractEventManager implements ServiceManagerAwareInterface{ @@ -159,6 +159,126 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return $rs->fetchAll(\PDO::FETCH_ASSOC); } + /** + * 获取需要分配编辑的评审 + * @param string $filter + * @return mixed + * filter参数帮助生成sql语句中的where、order、sort条件 + */ + public function getEditor($filter = ""){ + $wheresql = array(); + $ordersql = array(); + + $wheresql[] = " m.status in (".self::REVIEW_STATUS_ACCEPT.",".self::REVIEW_STATUS_EXPERT_INVITED.",".self::REVIEW_STATUS_EXPERT_ACCEPT.",".self::REVIEW_STATUS_EXPERT_FEEDBACK.") "; + $wheresql[] = " (m.userid IS NULL OR u.usertype != 'administrator') "; + + + if(isset($filter['keyword']) && !empty($filter['keyword'])) + { + $wheresql[] = " (md.title like '%".$filter['keyword']."%' OR u.username LIKE '%".$filter['keyword']."%' OR u.realname LIKE '%".$filter['keyword']."%') "; + } + + if(count($wheresql)>0) + { + $wheresql = " WHERE ".join(" AND ",$wheresql); + }else{ + $wheresql = ""; + } + + if(isset($filter['order']) && !empty($filter['order'])) + { + $sort = "DESC"; + if(isset($filter['sort']) && !empty($filter['sort']) && in_array( strtolower($filter['sort']),array('desc','asc'))) + { + $sort = $filter['sort']; + } + $ordersql[] = " {$filter['order']} $sort "; + } + + if(count($ordersql)>0) + { + $ordersql = " ORDER BY ".join(',',$ordersql); + }else{ + $ordersql = " ORDER BY m.ts_created desc "; + } + + $sql = "select m.*,md.title,u.username,u.realname from mdstatus m + right join metadata md on md.uuid=m.uuid + left join users u on u.id=m.userid + $wheresql + $ordersql"; + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + + return $rows; + }//getEditor(); + + /** + * 待审核元数据 + * @return mixed + */ + public function getAccept(){ + + //调试sql时需要输入adapter环境 +// $dbService = $this->serviceManager->get('Db'); +// $adapter = $dbService->getZendDb(); +// $sql = new Sql\Sql($adapter); +// $select = $sql->select(); + + $select = new Sql\Select; + + $select->from(['m'=>'mdstatus']); + $select->columns(array('*')); + + $select->join( + ["md"=>"metadata"], + "md.uuid=m.uuid", + ["title"], + $select::JOIN_RIGHT); + + $select->join( + ["u"=>"users"], + "m.userid=u.id", + ["username","realname"], + $select::JOIN_LEFT); + + $select->where(function(Sql\Where $where){ + $where->AND->in("m.status",[ + self::REVIEW_STATUS_ACCEPT, + self::REVIEW_STATUS_EXPERT_INVITED, + self::REVIEW_STATUS_EXPERT_ACCEPT, + self::REVIEW_STATUS_EXPERT_FEEDBACK + ]); + },Sql\Predicate\PredicateSet::OP_AND); + + if(!empty($this->opt->keyword)) + { + $keyword = $this->opt->keyword; + + $tools = $this->serviceManager->get('Tools'); + + if($tools->isUUID($keyword)) { + $select->where("md.uuid = '$keyword'"); + }else{ + $whereSql = function(Sql\Where $where) use ($keyword){ + $where->OR->like('md.title',"%".$keyword."%"); + $where->OR->like('md.title_en',"%".$keyword."%"); + }; + $select->where($whereSql,Sql\Predicate\PredicateSet::OP_AND); + } + + } + + $select->order("md.id DESC"); + +// echo $sql->getSqlStringForSqlObject($select); //带环境的sql +// echo $select->getSqlString(); //普通级别的sql +// exit(); + + return $select; + + }//accept() + /** * 取消评审 * @param $id diff --git a/Westdc/User/Handle/PwdHandle.php b/Westdc/User/Handle/PwdHandle.php index 8e741d1..598efc2 100644 --- a/Westdc/User/Handle/PwdHandle.php +++ b/Westdc/User/Handle/PwdHandle.php @@ -19,7 +19,7 @@ class PwdHandle function __construct($db = NULL) { - $this->db = new Pdo; + $this->db = Pdo::getInstance(); $this->config = Config::get(); }