From 8c7acba4efb6a5faccd6e957af7e87c00aecbab5 Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Tue, 3 Feb 2015 22:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=85=E5=AE=A1=E5=85=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81=E7=A0=81=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9handle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Helpers/Captcha.php | 65 ++++++++++++++++ Westdc/Review/Review.php | 122 ++++++++++++++++++++++++++++++- Westdc/User/Handle/PwdHandle.php | 2 +- 3 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 Westdc/Helpers/Captcha.php 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 3675250..92609fb 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{ @@ -157,6 +157,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(); }