From ab512665b06a0831b47f937e01619f5b1bfde426 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 4 Jan 2015 13:57:48 +0800 Subject: [PATCH 01/36] add non-MVC framework calling to MailSender,add event review.accepted in Review module --- Westdc/Mail/Sender.php | 10 ++++++++++ Westdc/Review/Review.php | 33 +-------------------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/Westdc/Mail/Sender.php b/Westdc/Mail/Sender.php index b7c860c..51dbc9b 100644 --- a/Westdc/Mail/Sender.php +++ b/Westdc/Mail/Sender.php @@ -10,6 +10,7 @@ namespace Westdc\Mail; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; +use Westdc\Service\ServiceManager as WestdcServiceManager; class Sender implements ServiceManagerAwareInterface{ @@ -24,6 +25,15 @@ class Sender implements ServiceManagerAwareInterface{ return $this; } + public function __construct() + { + if(!$this->serviceManager instanceof ServiceManager) + { + $serviceManager = new WestdcServiceManager(); + $this->serviceManager = $serviceManager->getServiceManager(); + } + } + /** * 发送即时邮件 * @param $options diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 010988e..77c0a83 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -159,43 +159,12 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac 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'], - ] - ]); - } + $this->getEventManager()->trigger('review.accepted', $this, compact('id')); 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){ } From 1864044f8e7f24d688baee099b85b16b2d8c4586 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Fri, 9 Jan 2015 23:33:25 +0800 Subject: [PATCH 02/36] profection the base classes --- Westdc/Helpers/Auth.php | 5 ++--- Westdc/Helpers/Config.php | 39 ++++++++++++++++++++++++++++----------- Westdc/Helpers/Layout.php | 20 +++++--------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Westdc/Helpers/Auth.php b/Westdc/Helpers/Auth.php index 5334bc1..ecd87f0 100644 --- a/Westdc/Helpers/Auth.php +++ b/Westdc/Helpers/Auth.php @@ -1,9 +1,8 @@ "config/autoload/local.php", - 'global' => "config/autoload/global.php" - ); - + function __construct() { //$reader = new \Zend\Config\Reader\Ini(); //$data = $reader->fromFile('config/config.ini'); } - static function get($type = 'global') + static function get($configName = 'global') { - $config_path = array( - 'local' => "config/autoload/local.php", - 'global' => "config/autoload/global.php", - 'file' => "config/autoload/file.php" + if(defined(CONFIG_PATH)) + { + throw new \RuntimeException('Not found the config files path'); + } + + $config_path = CONFIG_PATH; + + if(empty($configName)) + $configName = "global.php"; + + if(!preg_match("/(\\/|\\\)$/",$config_path)) + { + $config_path .= "/"; + } + + $config_names = array( + 'local' => "local.php", + 'global' => "global.php", + 'file' => "file.php" ); + + $configFile = $config_path .'autoload/' . $config_names[$configName]; + + unset($config_path); + unset($configName); - $config = new \Zend\Config\Config(include $config_path[$type]); + $config = new \Zend\Config\Config(include $configFile); + return $config; } diff --git a/Westdc/Helpers/Layout.php b/Westdc/Helpers/Layout.php index 136c77a..44ce42a 100644 --- a/Westdc/Helpers/Layout.php +++ b/Westdc/Helpers/Layout.php @@ -3,17 +3,15 @@ namespace Westdc\Helpers; use \Zend\Authentication\AuthenticationService; use \Zend\Authentication\Storage\Session as SessionStorage; -use \Westdc\Helpers\Config; -use Westdc\Helpers\MobileDetect; use View as view; class Layout { - public $config; + function __construct() { - $this->config = Config::get(); + } //设置网页标题 @@ -26,8 +24,8 @@ class Layout return; } - $action = $matches->getParam('action'); - $controller = $matches->getParam('controller'); +// $action = $matches->getParam('action'); +// $controller = $matches->getParam('controller'); $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager'); @@ -36,15 +34,7 @@ class Layout // Setting a separator string for segments $headTitleHelper->setSeparator(' - '); - if(isset($this->config->title_map->$controller->action->$action)) - { - $headTitleHelper->append($this->config->title_map->$controller->action->$action->title); - } - - if(isset($this->config->title_map->$controller)) - { - $headTitleHelper->append($this->config->title_map->$controller->title); - } + return; } //导航条按钮激活 From 3b0b9a12c88167decb98de265fa01e01bef64ca3 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 11 Jan 2015 11:24:31 +0800 Subject: [PATCH 03/36] profection the base classes --- Westdc/Db/Pdo.php | 7 ++----- Westdc/Helpers/Tools.php | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Westdc/Db/Pdo.php b/Westdc/Db/Pdo.php index ce6f3f5..83ea8c5 100644 --- a/Westdc/Db/Pdo.php +++ b/Westdc/Db/Pdo.php @@ -1,20 +1,17 @@ config_local_path); + $config_local = Config::get('local'); $dsn = "pgsql:host={$config_local->db->hostname};" . "port={$config_local->db->port};" diff --git a/Westdc/Helpers/Tools.php b/Westdc/Helpers/Tools.php index ee0658f..d8e4d3d 100644 --- a/Westdc/Helpers/Tools.php +++ b/Westdc/Helpers/Tools.php @@ -45,8 +45,12 @@ class Tools { { $response = array(); $handle = popen("$cmd 2>&1", 'r'); - $read = ''; + while ($read = fread($handle, 20096)) { + + if(!mb_detect_encoding($read, 'UTF-8', true)) + iconv("GB2312","UTF-8",$read); + $response[] = trim($read); } pclose($handle); From 23ac2439f893b9e1f1621eee37b3fbeb51a96784 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 12 Jan 2015 16:58:26 +0800 Subject: [PATCH 04/36] change the using class name in Cookie --- Westdc/Member/Cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Westdc/Member/Cookie.php b/Westdc/Member/Cookie.php index 5d3f557..406d6c1 100644 --- a/Westdc/Member/Cookie.php +++ b/Westdc/Member/Cookie.php @@ -2,7 +2,7 @@ namespace Westdc\Member; use Westdc\Helpers\Config; -use Westdc\Db\PDO as Db; +use Westdc\Db\Pdo as Db; class Cookie { From 053c2f2f4b3b416956b7ffc691ceb256d9ac27d4 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 12 Jan 2015 17:13:14 +0800 Subject: [PATCH 05/36] fixed bug in Auth Servic classes --- .../Authentication/AuthenticationService.php | 6 ++-- Westdc/User/Account.php | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Westdc/Authentication/AuthenticationService.php b/Westdc/Authentication/AuthenticationService.php index 9bf780e..80216aa 100644 --- a/Westdc/Authentication/AuthenticationService.php +++ b/Westdc/Authentication/AuthenticationService.php @@ -2,11 +2,9 @@ namespace Westdc\Authentication; use Zend\Permissions\Acl\Acl; -use Zend\Permissions\Acl\Role\GenericRole as Role; -use Zend\Permissions\Acl\Resource\GenericResource as Resource; use Westdc\Helpers\Assist as view; use Westdc\Member\Cookie; -use Zend\Mvc\MvcEvent; +use Westdc\User\Account; class AuthenticationService { @@ -86,7 +84,7 @@ class AuthenticationService if($mb->checkcookie()) { $account = new Account(); - $account->cookieLogin(array($mb->FieldUsername=>$mb->user,$mb->FieldPasword=>$mb->srpwd)); + $account->cookieLogin(array('username'=>$mb->user)); } } } diff --git a/Westdc/User/Account.php b/Westdc/User/Account.php index 9c526ff..d3525d6 100644 --- a/Westdc/User/Account.php +++ b/Westdc/User/Account.php @@ -60,16 +60,21 @@ class Account implements EventManagerAwareInterface } //获取账号信息,数组 - public function getAccountInfo($id = 0) - { - if($id == 0) - { - $id = view::User('id'); - } - $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } + public function getAccountInfo($id = 0) + { + + if(is_string($id)) + $sql = "SELECT * FROM {$this->conf->table->member} WHERE username='$id'"; + elseif(is_numeric($id)) + { + if($id == 0) + $id == view::User('id'); + $sql = "SELECT * FROM {$this->conf->table->member} WHERE id=$id"; + } + + $rs = $this->db->query($sql); + return $rs->fetch(\PDO::FETCH_ASSOC); + } //注册 public function register($data) @@ -212,7 +217,14 @@ class Account implements EventManagerAwareInterface public function cookieLogin($data) { - return $this->storeLogin($data,false); + $data = $this->getAccountInfo($data['username']); + + if(!$data) + { + return false; + } + + return $this->storeLogin($data,false); } //注册信息参数 From b113f19dce1eddd488d54eb91fd1283af7c3c15a Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 12 Jan 2015 17:32:18 +0800 Subject: [PATCH 06/36] fixed bug in User Account class --- Westdc/User/Account.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Westdc/User/Account.php b/Westdc/User/Account.php index d3525d6..a9eca50 100644 --- a/Westdc/User/Account.php +++ b/Westdc/User/Account.php @@ -8,9 +8,9 @@ use Zend\Authentication\AuthenticationService; use Zend\Authentication\Storage\Session as SessionStorage; use Westdc\Helpers\View as view; use Westdc\Helpers\Config; -use Westdc\Helpers\Dbh as dbh; -use Westdc\Helpers\PDO as Db; -use Westdc\Helpers\Db as Zend_Db; +use Westdc\Db\Dbh as dbh; +use Westdc\Db\Pdo as Db; +use Westdc\Db\Db as Zend_Db; use Westdc\Mail\Mail; use Westdc\User\Listener\AccountListener as Listener; use Westdc\User\Listener\PwdListener; From 23f3a7828ce7584f541a4623602b38e45742a81d Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 12 Jan 2015 20:59:23 +0800 Subject: [PATCH 07/36] add new function attachDefaultListener() in FileUpload Service and change import function in Reference Service --- Westdc/File/Upload.php | 12 +++++++++--- Westdc/Reference/Reference.php | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Westdc/File/Upload.php b/Westdc/File/Upload.php index 81064f7..281b7fd 100644 --- a/Westdc/File/Upload.php +++ b/Westdc/File/Upload.php @@ -39,9 +39,6 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac public function init() { - $Listener = new DefaultFileUploadListener; - $this->getEventManager()->attachAggregate($Listener); - $configService = $this->serviceManager->get('ConfigService'); $this->config = $configService->get('file.php'); } @@ -51,6 +48,15 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac return $this->upload($files,$rootDir,$childDir,$fileName,$dateDirModel); } + /** + * 添加默认侦听器,会将信息保存到Attachments数据表 + */ + public function attachDefaultListener() + { + $Listener = new DefaultFileUploadListener; + $this->getEventManager()->attachAggregate($Listener); + } + /** * 上传文件 * @param $files 上传文件的信息 e.g.$_FILE['fileData'] diff --git a/Westdc/Reference/Reference.php b/Westdc/Reference/Reference.php index e126cd0..699739b 100644 --- a/Westdc/Reference/Reference.php +++ b/Westdc/Reference/Reference.php @@ -97,6 +97,7 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter $appConfig = $configService->get('application.ini'); $fileUploadService = $this->serviceManager->get('File/Upload'); + $fileUploadService->attachDefaultListener(); $fileUploadService->setParams(['file_type' => 'literature']); $file_info = $fileUploadService($file,$appConfig['reference_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y); From cc2406aee56aa254ff1ef4aae6b2d8c925e66a8b Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 12 Jan 2015 23:43:37 +0800 Subject: [PATCH 08/36] change details in Review Service --- Westdc/Review/Review.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 77c0a83..6eec2c0 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -119,7 +119,7 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac 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 + WHERE m.status=".self::REVIEW_STATUS_DEFAULT." $searchJoin {$this->orderSql} {$this->sortSql} {$this->limitSql}"; @@ -127,6 +127,8 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return $rs->fetchAll(); }//getDraft() + + /** * 取消评审 * @param $id @@ -135,6 +137,9 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac public function cancel($id){ if(!is_numeric($id) || $id<1) return false; + + $this->getEventManager()->trigger('review.canceled', $this, compact('id')); + return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED); } From fed47b03ca9b191fd1ec99e85748d1ae49f17a1f Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Tue, 13 Jan 2015 11:06:14 +0800 Subject: [PATCH 09/36] change the namespaces in User module --- Westdc/User/Event/LoginEvent.php | 2 +- Westdc/User/Gravatar.php | 2 +- Westdc/User/Handle/EditHandle.php | 12 ++++++------ Westdc/User/Handle/LoginHandle.php | 15 ++++++--------- Westdc/User/Listener/AccountListener.php | 6 +++--- Westdc/User/Listener/EditListener.php | 4 ++-- Westdc/User/Listener/PwdListener.php | 4 ++-- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Westdc/User/Event/LoginEvent.php b/Westdc/User/Event/LoginEvent.php index a6ad49b..d1ce34a 100644 --- a/Westdc/User/Event/LoginEvent.php +++ b/Westdc/User/Event/LoginEvent.php @@ -1,5 +1,5 @@ FieldPasword},status FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?"; $sth = $this->db->prepare($sql); $rs = $sth->execute(array($data[$this->FieldUsername])); - $row = $sth->fetch(); + $row = $sth->fetch(\PDO::FETCH_ASSOC); if(isset($row['id']) && !empty($row['id'])) { diff --git a/Westdc/User/Listener/AccountListener.php b/Westdc/User/Listener/AccountListener.php index 84e2638..4947367 100644 --- a/Westdc/User/Listener/AccountListener.php +++ b/Westdc/User/Listener/AccountListener.php @@ -1,8 +1,8 @@ Date: Tue, 13 Jan 2015 11:13:32 +0800 Subject: [PATCH 10/36] remove useless files ,change namespace in User module --- Westdc/User/Event/EditEvent.php | 13 ------------- Westdc/User/Event/LoginEvent.php | 14 -------------- Westdc/User/Event/PwdEvent.php | 15 --------------- Westdc/User/Event/RegisterEvent.php | 15 --------------- Westdc/User/Handle/EditHandle.php | 1 - Westdc/User/Handle/PwdHandle.php | 10 ++++------ Westdc/User/Handle/RegisterHandle.php | 12 +++++------- 7 files changed, 9 insertions(+), 71 deletions(-) delete mode 100644 Westdc/User/Event/EditEvent.php delete mode 100644 Westdc/User/Event/LoginEvent.php delete mode 100644 Westdc/User/Event/PwdEvent.php delete mode 100644 Westdc/User/Event/RegisterEvent.php diff --git a/Westdc/User/Event/EditEvent.php b/Westdc/User/Event/EditEvent.php deleted file mode 100644 index 2bdcdc1..0000000 --- a/Westdc/User/Event/EditEvent.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Tue, 13 Jan 2015 11:21:11 +0800 Subject: [PATCH 11/36] fixed bug in Westdc/User/Account --- Westdc/User/Account.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Westdc/User/Account.php b/Westdc/User/Account.php index a9eca50..a8143f0 100644 --- a/Westdc/User/Account.php +++ b/Westdc/User/Account.php @@ -18,7 +18,7 @@ use Westdc\User\Member; class Account implements EventManagerAwareInterface { - public $memberTable = "tbl_member"; + public $memberTable = "users"; public $FieldUsername = "username"; public $FieldPasword = "password"; public $FieldLastlogin = "ts_last_login"; @@ -64,12 +64,12 @@ class Account implements EventManagerAwareInterface { if(is_string($id)) - $sql = "SELECT * FROM {$this->conf->table->member} WHERE username='$id'"; + $sql = "SELECT * FROM ".$this->memberTable." WHERE username='$id'"; elseif(is_numeric($id)) { if($id == 0) $id == view::User('id'); - $sql = "SELECT * FROM {$this->conf->table->member} WHERE id=$id"; + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; } $rs = $this->db->query($sql); From 9a7e8c9b1e91fa85a0503a34fe3f2d0734c893b2 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Tue, 13 Jan 2015 17:24:11 +0800 Subject: [PATCH 12/36] prefection the FileUpload Service --- Westdc/File/Upload.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/Westdc/File/Upload.php b/Westdc/File/Upload.php index 281b7fd..3045758 100644 --- a/Westdc/File/Upload.php +++ b/Westdc/File/Upload.php @@ -16,6 +16,7 @@ use Westdc\File\Listener\DefaultFileUploadListener; class Upload extends AbstractEventManager implements ServiceManagerAwareInterface{ protected $serviceManager; + protected $defaultListener = false; private $uploadPath = ""; private $relativePath = ""; @@ -55,6 +56,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac { $Listener = new DefaultFileUploadListener; $this->getEventManager()->attachAggregate($Listener); + $this->defaultListener = true; } /** @@ -79,11 +81,15 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $file = $files; $results = $this->getEventManager()->trigger('upload.pre', $this, compact('file')); - $cache_data = $results->last(); - if($cache_data !== true) + if($this->defaultListener === true) { - return $cache_data; + $cache_data = $results->last(); + + if($cache_data !== true) + { + return $cache_data; + } } $fileService = $this->serviceManager->get('File'); @@ -94,7 +100,11 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac if($dateDirModel !== false) $this->makeDateDir($dateDirModel); - $this->setFileName($fileName , $fileService->getFileTextExt($files['name'])); + if(empty($this->fileName) || empty($fileName)) + $this->setFileName(NULL , $fileService->getFileTextExt($files['name'])); + + if(!empty($fileName)) + $this->setFileName($fileName , $fileService->getFileTextExt($files['name'])); //移动文件 $file_path = $this->getUploadPath() . $this->getFileName(); @@ -112,7 +122,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $file_data['file_ext'] = $fileService->getFileTextExt($files['name']); $file_data['file_mime'] = $fileService->getFileMime($file_path); - if(!empty($file_data) && is_array($file_data)) + if(!empty($this->params) && is_array($this->params)) { $file_data = array_merge($file_data,$this->params); } @@ -209,18 +219,32 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac * @param $fileName * @param $fileExt */ - public function setFileName($fileName,$fileExt) + public function setFileName($fileName,$fileExt = "") { if(!empty($fileName)){ - $this->fileName = $fileName . "." .$fileExt; + + if(empty($fileExt)) + { + $fileExt = pathinfo($fileName,PATHINFO_EXTENSION); + } + + if(empty($fileExt)) + $this->fileName = $fileName; + else + $this->fileName = $fileName . "." .$fileExt; + return; } $tools = $this->serviceManager->get('Tools'); $uuid = $tools->uuid(); - $this->fileName = $uuid . "." . $fileExt; + if(empty($fileExt)) + $this->fileName = $uuid; + else + $this->fileName = $uuid . "." . $fileExt; + return; } From 32806de819ec097fd1bbeab63d2632af5e4fa449 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Wed, 14 Jan 2015 00:25:56 +0800 Subject: [PATCH 13/36] perfect the paginator service and zend db service,add new functions in review service --- Westdc/Helpers/Paginator.php | 14 +++++++++---- Westdc/Review/Review.php | 32 ++++++++++++++++++++++++++++-- Westdc/Service/ServiceAgent/Db.php | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Westdc/Helpers/Paginator.php b/Westdc/Helpers/Paginator.php index 2519f00..4aadcdf 100644 --- a/Westdc/Helpers/Paginator.php +++ b/Westdc/Helpers/Paginator.php @@ -30,10 +30,6 @@ class Paginator implements ServiceManagerAwareInterface{ { $this->serviceManager = $serviceManager; - $this->setPageLimit(); - $this->setPageRange(); - $this->setRoute(); - return $this; } @@ -97,6 +93,16 @@ class Paginator implements ServiceManagerAwareInterface{ { $page = $ctl->params()->fromRoute('page'); + if(empty($this->pageLimit)) + $this->setPageLimit(); + + if(empty($this->pageRange)) + $this->setPageRange(); + + if(empty($this->route)) + $this->setRoute(); + + if(is_array($data)) $data = new ArrayAdapter($data); diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 6eec2c0..99362ea 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -10,6 +10,7 @@ namespace Westdc\Review; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; use Westdc\EventModel\AbstractEventManager; +use Zend\Db\Sql\Select; class Review extends AbstractEventManager implements ServiceManagerAwareInterface{ @@ -124,10 +125,37 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac {$this->limitSql}"; $rs = $this->db->query($sql); - return $rs->fetchAll(); + return $rs->fetchAll(\PDO::FETCH_ASSOC); }//getDraft() - + /** + * 获取被取消评审的元数据 + * @return mixed + */ + public function getCanceled() + { + $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,m.status,m.ts_created FROM mdstatus m + RIGHT JOIN metadata md ON md.uuid=m.uuid + WHERE m.status=".self::REVIEW_STATUS_CANCELED." $searchJoin + {$this->orderSql} {$this->sortSql} + {$this->limitSql}"; + + $rs = $this->db->query($sql); + return $rs->fetchAll(\PDO::FETCH_ASSOC); + } /** * 取消评审 diff --git a/Westdc/Service/ServiceAgent/Db.php b/Westdc/Service/ServiceAgent/Db.php index 0792cfe..74fc418 100644 --- a/Westdc/Service/ServiceAgent/Db.php +++ b/Westdc/Service/ServiceAgent/Db.php @@ -14,7 +14,7 @@ class Db { public function getZendDb(){ - $dbObject = new WestdcDb\Db($adapter); + $dbObject = new WestdcDb\Db(); return $dbObject->getAdapter(); } From a5e8eb8c0626acd8068dd4eecaf40eb1a6ba75df Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Wed, 14 Jan 2015 16:49:10 +0800 Subject: [PATCH 14/36] add function for detach trigger in upload function --- Westdc/File/Upload.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Westdc/File/Upload.php b/Westdc/File/Upload.php index 3045758..a7f3c23 100644 --- a/Westdc/File/Upload.php +++ b/Westdc/File/Upload.php @@ -17,6 +17,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac protected $serviceManager; protected $defaultListener = false; + protected $returnInPreCheckTrigger = true; private $uploadPath = ""; private $relativePath = ""; @@ -82,7 +83,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $results = $this->getEventManager()->trigger('upload.pre', $this, compact('file')); - if($this->defaultListener === true) + if($this->returnInPreCheckTrigger === true) { $cache_data = $results->last(); @@ -248,11 +249,23 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac } + /** + * @param $params + */ public function setParams($params) { $this->params = $params; } + /** + * 强制关闭文件上传前的钩子,默认是所有上传必须执行此钩子已避免上传文件不符合规格 + * 除了后台中特殊的文件操作之外不建议关闭 + */ + public function forceDetachPreCheckTrigger() + { + $this->returnInPreCheckTrigger = false; + } + /** * @return string */ From cb9e731792340560a5924b738a90c9f2a8c07e79 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Fri, 16 Jan 2015 23:37:40 +0800 Subject: [PATCH 15/36] change user login function --- Westdc/Member/Account.php | 30 +++++++++++-------------- Westdc/Service/ServiceAgent/Account.php | 17 -------------- 2 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 Westdc/Service/ServiceAgent/Account.php diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index 43da9fe..b4b2335 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -10,12 +10,10 @@ use Zend\Authentication\Adapter\DbTable; use Westdc\Helpers\Assist as view; use Westdc\Helpers\Config; use Westdc\Helpers\Dbh as dbh; -use Westdc\Db\Pdo as Db; use Westdc\Db\Db as Zend_Db; use Westdc\Mail\Mail; use Westdc\User\Member; - class Account extends AbstractEventManager implements ServiceManagerAwareInterface { public $memberTable = "tbl_member"; @@ -149,9 +147,11 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa if(isset($state['success'])) { - //$mb = new Member(); - //$mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); - } + $user = (array)$state['user']; + $this->getEventManager()->trigger('login.success', $this, compact('user')); + }else{ + $this->getEventManager()->trigger('login.failed', $this, compact('data')); + } return $state; }//login @@ -184,23 +184,19 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa ; $result = $authAdapter->authenticate(); - - $user = $authAdapter->getResultRowObject(null,array('password')); - + if(!$result->isValid()) { return array("error"=>"用户信息验证失败"); } - - $email = $user->email; - $results = $this->getEventManager()->trigger('login.success.createAvatar', $this, compact('email')); - $user->avatar = $results->last(); - $auth->getStorage()->write($user); - - $id = $user->id; - $results = $this->getEventManager()->trigger('login.success.updateStatus', $this, compact('id')); + + $user = $authAdapter->getResultRowObject(null,array('password')); + $auth->getStorage()->write($user); - return array('success'=>1); + return array( + 'success'=>1, + 'user' => $user + ); } public function cookieLogin($data) diff --git a/Westdc/Service/ServiceAgent/Account.php b/Westdc/Service/ServiceAgent/Account.php deleted file mode 100644 index b35cee4..0000000 --- a/Westdc/Service/ServiceAgent/Account.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Sun, 18 Jan 2015 23:24:31 +0800 Subject: [PATCH 16/36] change login triggers in login function,add session write function in Auth service --- Westdc/Helpers/Auth.php | 15 ++++++++++++++- Westdc/Member/Account.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Westdc/Helpers/Auth.php b/Westdc/Helpers/Auth.php index ecd87f0..11c132c 100644 --- a/Westdc/Helpers/Auth.php +++ b/Westdc/Helpers/Auth.php @@ -7,6 +7,7 @@ use Zend\Authentication\Storage\Session as SessionStorage; class Auth { public $auth; + function __construct($getAuthService = false) { $config = Config::get(); @@ -25,11 +26,23 @@ class Auth return $this->auth->clearIdentity(); } - public function getIdentity($field) + public function getIdentity($field = "") { + if(empty($field)) + return $this->auth->getIdentity(); + if(isset($this->auth->getIdentity()->$field)) return $this->auth->getIdentity()->$field; else return null; } + + public function write($user) + { + + if(is_array($user)) + $user = (object)$user; + + $this->auth->getStorage()->write($user); + } } \ No newline at end of file diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index b4b2335..d9856ae 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -130,7 +130,7 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa //登陆 public function login($data) { - $results = $this->getEventManager()->trigger('login.checkParam', $this, compact('data')); + $results = $this->getEventManager()->trigger('login.pre', $this, compact('data')); $cache_data = $results->last(); if($cache_data !== true) From fbe7ef3bfeeb7a6e29b859abf02c83a463fd29c6 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 19 Jan 2015 00:00:34 +0800 Subject: [PATCH 17/36] change register function --- Westdc/Member/Account.php | 79 +++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index d9856ae..7150fa1 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -62,11 +62,15 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa return $rs->fetch(); } - //注册 + /** + * 用户注册 + * @param $data + * @return array + */ public function register($data) { $params = compact('data'); - $results = $this->getEventManager()->trigger('register.checkParam', $this, $params); + $results = $this->getEventManager()->trigger('register.pre', $this, $params); $cache_data = $results->last(); if($cache_data !== true) @@ -78,43 +82,49 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa return $cache_data; } } - - $results = $this->getEventManager()->trigger('register.checkUser', $this, $params); - $cache_data = $results->last(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - + + /** + * 将数据分为两组,一组用于做注册成功后的登陆,一组用于写入数据库 + * 写入数据库的数据需要完全重建一个新的,防止因为前端传入时有人恶意增加字段造成破坏 + */ $loginData = array( 'username'=>$data['username'], 'password'=>$data['password'] ); - - $data['password'] = md5($data['password']); - $data['usertype'] = "guest"; - unset($data['confirm_password']); + + $registerData = [ + 'username' => $data['username'], + 'password' => md5($data['password']), + 'usertype' => 'guest', + 'email' => $data['email'], + 'realname' => $data['realname'], + 'unit' => $data['unit'], + 'address' => $data['address'], + 'project' => $data['project'], + 'phone' => $data['phone'], + 'project_id' => $data['project_id'], + 'project_type' => $data['project_type'], + 'project_title' => $data['project_title'], + 'project_leader' => $data['project_leader'], + ]; $dbh = new dbh(); - $id = $dbh->insert($this->memberTable,$data,true); + $id = $dbh->insert($this->memberTable,$registerData,true); if(!empty($id) && is_numeric($id)) { $this->storeLogin($loginData); + if(isset($state['success'])) { //$mb = new Member(); //$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); } + + $data = $registerData; $params = compact('data','id'); - $results = $this->getEventManager()->trigger('register.success', $this, $params); + $this->getEventManager()->trigger('register.success', $this, $params); return array("success" => 1); }else{ if($id === false) @@ -126,8 +136,12 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa } }//register - - //登陆 + + /** + * 用户登陆 + * @param $data + * @return array + */ public function login($data) { $results = $this->getEventManager()->trigger('login.pre', $this, compact('data')); @@ -147,16 +161,25 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa if(isset($state['success'])) { + //$mb = new Member(); + //$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); + $user = (array)$state['user']; $this->getEventManager()->trigger('login.success', $this, compact('user')); }else{ $this->getEventManager()->trigger('login.failed', $this, compact('data')); } - return $state; + return $state; }//login - - //storeLogin + + /** + * 存储用户登陆信息 + * 为了防止login中的用户信息检查不规范,再加入一层内置的数据库权限检查,以防通过漏洞登入系统 + * @param $data + * @param bool $md5 是否对密码进行md5加密再校验 + * @return array + */ private function storeLogin($data,$md5 = true) { $auth = new AuthenticationService(); @@ -197,7 +220,7 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa 'success'=>1, 'user' => $user ); - } + }//storeLogin public function cookieLogin($data) { From bd7e404a5f4593c69e0a6ef77e7e747834147767 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 19 Jan 2015 20:18:46 +0800 Subject: [PATCH 18/36] =?UTF-8?q?=E8=A7=A3=E5=86=B3cookie=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=99=BB=E5=BD=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Authentication/AuthenticationService.php | 39 ++++++++++++++-- Westdc/Member/Account.php | 21 +++------ Westdc/Member/Cookie.php | 45 +++++++++++-------- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/Westdc/Authentication/AuthenticationService.php b/Westdc/Authentication/AuthenticationService.php index 80216aa..00a80b8 100644 --- a/Westdc/Authentication/AuthenticationService.php +++ b/Westdc/Authentication/AuthenticationService.php @@ -15,6 +15,7 @@ class AuthenticationService protected $role; public $loginRouterName = "login"; + public $logoutRouterName = "logout"; function __construct() { @@ -47,7 +48,8 @@ class AuthenticationService // view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); - $this->preCookieCheck(); + if($rsp = $this->preCookieCheck($e) !== false) + return $rsp; try{ if(!$this->acl->hasResource($controller)) @@ -68,14 +70,13 @@ class AuthenticationService } } }catch (Exception $e) { - //echo 'Caught exception: ', $e->getMessage(), "\n"; $this->badRequest($e); return; } } - public function preCookieCheck() + public function preCookieCheck($e) { if(!view::User()) { @@ -85,8 +86,40 @@ class AuthenticationService { $account = new Account(); $account->cookieLogin(array('username'=>$mb->user)); + + $response = $e->getResponse(); + $response->setStatusCode(200); + $response->sendHeaders(); + + $layout = $e->getViewModel(); + + $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager'); + $partial = $viewHelperManager->get('partial'); + + $page_content = $partial( + 'layout/layout/message', + array( + 'message' => '您的账号已自动登陆', + 'url'=> [ + ['title' => '立即跳转', 'url' => $_SERVER['REQUEST_URI']], + ['title'=>'退出登陆','url'=>$e->getRouter()->assemble(array(), array('name' => $this->logoutRouterName))] + ], + ) + ); + + $layout->setVariable('content',$page_content); + $layout->setTemplate('layout/layout'); + + $e->stopPropagation(); + + return $response; + } } + else + { + return false; + } } public function response($e) diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index 7150fa1..ce6c771 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -11,8 +11,6 @@ use Westdc\Helpers\Assist as view; use Westdc\Helpers\Config; use Westdc\Helpers\Dbh as dbh; use Westdc\Db\Db as Zend_Db; -use Westdc\Mail\Mail; -use Westdc\User\Member; class Account extends AbstractEventManager implements ServiceManagerAwareInterface { @@ -95,17 +93,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa $registerData = [ 'username' => $data['username'], 'password' => md5($data['password']), - 'usertype' => 'guest', + 'usertype' => $this->RoleMember, 'email' => $data['email'], - 'realname' => $data['realname'], - 'unit' => $data['unit'], - 'address' => $data['address'], - 'project' => $data['project'], - 'phone' => $data['phone'], - 'project_id' => $data['project_id'], - 'project_type' => $data['project_type'], - 'project_title' => $data['project_title'], - 'project_leader' => $data['project_leader'], ]; $dbh = new dbh(); @@ -118,8 +107,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa if(isset($state['success'])) { - //$mb = new Member(); - //$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); } $data = $registerData; @@ -161,8 +150,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa if(isset($state['success'])) { - //$mb = new Member(); - //$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); + $mb = new Cookie(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); $user = (array)$state['user']; $this->getEventManager()->trigger('login.success', $this, compact('user')); diff --git a/Westdc/Member/Cookie.php b/Westdc/Member/Cookie.php index 406d6c1..b859efc 100644 --- a/Westdc/Member/Cookie.php +++ b/Westdc/Member/Cookie.php @@ -3,10 +3,11 @@ namespace Westdc\Member; use Westdc\Helpers\Config; use Westdc\Db\Pdo as Db; +use Zend\Http\Cookies as ZendCookie; class Cookie { - var $ck='Dxe8SqIcmyUf'; + var $ck='ff08XearZpUkjl3H'; var $db; //传入PDO对象 var $mid; //会员ID @@ -29,12 +30,12 @@ class Cookie { $this->db = new Db(); $this->config = Config::get(); - - if(!empty($_COOKIE['scr'])) + + if(isset($_COOKIE['scr']) && !empty($_COOKIE['scr'])) { $this->scr = $_COOKIE['scr']; } - if(!empty($_COOKIE['user'])) + if(isset($_COOKIE['user']) && !empty($_COOKIE['user'])) { $this->user= $_COOKIE['user']; } @@ -48,7 +49,7 @@ class Cookie { $uname = $this->user; $hash = $this->scr; - + if(!empty($uname) && !empty($hash)) { if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash)) @@ -61,7 +62,7 @@ class Cookie $rs = $this->db->query($sql); $row = $rs->fetch(); $scr = $this->makescr($row['userid'],$row['pwd']); - + if($hash == $scr) { $this->srpwd=$row['pwd']; @@ -75,26 +76,31 @@ class Cookie return false; }//exit }//function checkcookie - - /** - * putcookie - * - * 登陆成功后放置cookie,包含安全码 - * - * @param String $uname - * @param String $pwd - * @param Int $time - */ + + /** + * putcookie + * + * 登陆成功后放置cookie,包含安全码 + * + * @param $uname + * @param $pwd + * @param int $time + * @return bool + */ public function putcookie($uname,$pwd,$time = 604800) { try { - $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。 - + $scrString = $this->makescr($uname,md5($pwd));//加密验证串:防止用户密码被盗;防止伪造cookie。 + if(!is_numeric($time)) { $time = 604800; } - + + //$client = new Client(); + //$client->addCookie('user',$uname,time()+$time,"/"); + //$client->addCookie('scr',$scrString,time()+$time,"/"); + setcookie('user',$uname,time()+$time,'/'); setcookie('scr',$scrString,time()+$time,'/'); @@ -110,6 +116,7 @@ class Cookie * * @param String $u * @param String $p + * @return string */ public function makescr($u,$p) { From 911e7d4043f34d28ee34622b06d4d1a8e2637ccc Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 19 Jan 2015 21:12:40 +0800 Subject: [PATCH 19/36] fixed bug in authenticationService --- Westdc/Authentication/AuthenticationService.php | 10 +++++----- Westdc/Helpers/Auth.php | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Westdc/Authentication/AuthenticationService.php b/Westdc/Authentication/AuthenticationService.php index 00a80b8..5058470 100644 --- a/Westdc/Authentication/AuthenticationService.php +++ b/Westdc/Authentication/AuthenticationService.php @@ -46,10 +46,12 @@ class AuthenticationService return true; } -// view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); + //view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); if($rsp = $this->preCookieCheck($e) !== false) + { return $rsp; + } try{ if(!$this->acl->hasResource($controller)) @@ -116,10 +118,8 @@ class AuthenticationService } } - else - { - return false; - } + + return false; } public function response($e) diff --git a/Westdc/Helpers/Auth.php b/Westdc/Helpers/Auth.php index 11c132c..c12b762 100644 --- a/Westdc/Helpers/Auth.php +++ b/Westdc/Helpers/Auth.php @@ -23,7 +23,8 @@ class Auth public function clearIndentity() { - return $this->auth->clearIdentity(); + $this->auth->clearIdentity(); + return true; } public function getIdentity($field = "") From cbe18f569902eab9b827e4ab7411fa76d0f967b0 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 19 Jan 2015 22:03:34 +0800 Subject: [PATCH 20/36] fixed bug Account Service --- Westdc/Member/Account.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index ce6c771..5dfedd5 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -111,7 +111,6 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); } - $data = $registerData; $params = compact('data','id'); $this->getEventManager()->trigger('register.success', $this, $params); return array("success" => 1); From 84611b854794b56a8c0b4b879f033479de52646a Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 23 Jan 2015 16:19:03 +0800 Subject: [PATCH 21/36] add singleton pattern in Db service of getPdo() function --- Westdc/Db/Dbh.php | 2 +- Westdc/Db/Pdo.php | 25 +++++++++++++++---------- Westdc/Member/Cookie.php | 4 ++-- Westdc/Service/ServiceAgent/Db.php | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Westdc/Db/Dbh.php b/Westdc/Db/Dbh.php index 9fe07b5..f12f429 100644 --- a/Westdc/Db/Dbh.php +++ b/Westdc/Db/Dbh.php @@ -11,7 +11,7 @@ class Dbh function __construct($db = NULL) { if($db == NULL) - $this->db = new PDO(); + $this->db = PDO::getInstance(); else $this->db = $db; } diff --git a/Westdc/Db/Pdo.php b/Westdc/Db/Pdo.php index ce6f3f5..4146ecc 100644 --- a/Westdc/Db/Pdo.php +++ b/Westdc/Db/Pdo.php @@ -3,26 +3,31 @@ namespace Westdc\Db; use Zend\Config\Config as Zend_Config; -class Pdo extends \PDO +class Pdo { - private $debug = 0; //调试模式 + + private static $_instance = NULL; - private $config_local_path = "config/autoload/local.php"; - - function __construct($DSN = NULL) + private function __construct($DSN = NULL) { - if (!empty($DSN)) { - parent::__construct($DSN); - } else { - $config_local = new Zend_Config(include $this->config_local_path); + + } + + public static function getInstance() + { + if (self::$_instance === null) { + $config_local = new Zend_Config(include "config/autoload/local.php"); $dsn = "pgsql:host={$config_local->db->hostname};" . "port={$config_local->db->port};" . "dbname={$config_local->db->database};" . "user={$config_local->db->username};" . "password={$config_local->db->password}"; - parent::__construct($dsn); + self::$_instance = new \PDO($dsn); } + + return self::$_instance; } + } \ No newline at end of file diff --git a/Westdc/Member/Cookie.php b/Westdc/Member/Cookie.php index 5d3f557..4d56afd 100644 --- a/Westdc/Member/Cookie.php +++ b/Westdc/Member/Cookie.php @@ -2,7 +2,7 @@ namespace Westdc\Member; use Westdc\Helpers\Config; -use Westdc\Db\PDO as Db; +use Westdc\Db\Pdo as Db; class Cookie { @@ -27,7 +27,7 @@ class Cookie function __construct() { - $this->db = new Db(); + $this->db = Db::getInstance(); $this->config = Config::get(); if(!empty($_COOKIE['scr'])) diff --git a/Westdc/Service/ServiceAgent/Db.php b/Westdc/Service/ServiceAgent/Db.php index 0792cfe..7faf5e8 100644 --- a/Westdc/Service/ServiceAgent/Db.php +++ b/Westdc/Service/ServiceAgent/Db.php @@ -21,7 +21,7 @@ class Db { public function getPdo() { - return new WestdcDb\Pdo; + return WestdcDb\Pdo::getInstance(); } public function getDbh() From 03cb772bfc01e3295111a1316a501283afd43e05 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 23 Jan 2015 16:27:48 +0800 Subject: [PATCH 22/36] fixed using error in Pdo class --- Westdc/Db/Pdo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Westdc/Db/Pdo.php b/Westdc/Db/Pdo.php index 8691867..0836108 100644 --- a/Westdc/Db/Pdo.php +++ b/Westdc/Db/Pdo.php @@ -1,7 +1,7 @@ Date: Sat, 24 Jan 2015 16:37:09 +0800 Subject: [PATCH 23/36] add singleton pattern in db service --- Westdc/Db/Db.php | 44 +++++++++++++----------------- Westdc/Service/ServiceAgent/Db.php | 5 +--- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Westdc/Db/Db.php b/Westdc/Db/Db.php index f1097ec..46f316d 100644 --- a/Westdc/Db/Db.php +++ b/Westdc/Db/Db.php @@ -1,43 +1,37 @@ getServiceManager()->get('Config'); - $config_local = $configService->get("local.php"); - - if(is_array($param) && count($param)>0) - { - $this->db = new Adapter($param); - }else{ - $this->db = new Adapter(array( + private static $_instance = NULL; + + private function __construct(){ + + } + + public static function getInstance(){ + + if (self::$_instance === NULL) { + + $config_local = new Zend_Config(include "config/autoload/local.php"); + + self::$_instance = new Adapter(array( 'driver' => $config_local->db->driver, 'hostname' => $config_local->db->hostname, - 'port' => $config_local->db->port, + 'port' => $config_local->db->port, 'database' => $config_local->db->database, 'username' => $config_local->db->username, 'password' => $config_local->db->password )); + } - $db = $this->db; + return self::$_instance; + } - - public function getAdapter() - { - return $this->db; - } - - public function setConfig() - { - - } } \ No newline at end of file diff --git a/Westdc/Service/ServiceAgent/Db.php b/Westdc/Service/ServiceAgent/Db.php index f415995..e480381 100644 --- a/Westdc/Service/ServiceAgent/Db.php +++ b/Westdc/Service/ServiceAgent/Db.php @@ -13,10 +13,7 @@ use Westdc\Db as WestdcDb; class Db { public function getZendDb(){ - - $dbObject = new WestdcDb\Db(); - - return $dbObject->getAdapter(); + return WestdcDb\Db::getInstance(); } public function getPdo() From 9361b1ba9b121b198d3e0ab8477e6cacd285bb3b Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 25 Jan 2015 17:19:22 +0800 Subject: [PATCH 24/36] change Db object import function in Account module --- Westdc/User/Account.php | 6 +++--- Westdc/User/Handle/LoginHandle.php | 2 +- Westdc/User/Handle/RegisterHandle.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Westdc/User/Account.php b/Westdc/User/Account.php index a8143f0..c5b85ec 100644 --- a/Westdc/User/Account.php +++ b/Westdc/User/Account.php @@ -34,7 +34,7 @@ class Account implements EventManagerAwareInterface function __construct() { - $this->db = new Db(); + $this->db = Db::getInstance(); $this->config = Config::get(); $Listener = new Listener(); @@ -173,8 +173,8 @@ class Account implements EventManagerAwareInterface { $auth = new AuthenticationService(); $auth->setStorage(new SessionStorage($this->config->session_namespace)); - - new Zend_Db($dbAdapter); + + $dbAdapter = Zend_Db::getInstance(); $authAdapter = new \Zend\Authentication\Adapter\DbTable( $dbAdapter, diff --git a/Westdc/User/Handle/LoginHandle.php b/Westdc/User/Handle/LoginHandle.php index 48d1f8d..7630bed 100644 --- a/Westdc/User/Handle/LoginHandle.php +++ b/Westdc/User/Handle/LoginHandle.php @@ -19,7 +19,7 @@ class LoginHandle function __construct() { - $this->db = new Db(); + $this->db = Db::getInstance(); } public function checkParam(EventInterface $e){ diff --git a/Westdc/User/Handle/RegisterHandle.php b/Westdc/User/Handle/RegisterHandle.php index 4b543cc..0ddc32d 100644 --- a/Westdc/User/Handle/RegisterHandle.php +++ b/Westdc/User/Handle/RegisterHandle.php @@ -21,7 +21,7 @@ class RegisterHandle function __construct($db = NULL) { - $this->db = new Db(); + $this->db = Db::getInstance(); $this->config = Config::get(); } From 79b7ab0030e402801dec0e44ec78fb0d69891875 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 25 Jan 2015 19:53:13 +0800 Subject: [PATCH 25/36] add reset function of reviews in Review Service --- Westdc/Review/Review.php | 60 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 99362ea..3675250 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -163,12 +163,23 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac * @return bool */ public function cancel($id){ - if(!is_numeric($id) || $id<1) - return false; - $this->getEventManager()->trigger('review.canceled', $this, compact('id')); + if(is_numeric($id)) + { + $this->getEventManager()->trigger('review.canceled', $this, compact('id')); - return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED); + return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED); + }elseif(is_array($id)){ + foreach($id as $item){ + $item = (int)$item; + if($this->changeStatus($item,self::REVIEW_STATUS_CANCELED) === false) + return "ID:$item:取消失败"; + } + $this->getEventManager()->trigger('review.canceled', $this, compact('id')); + return true; + } + + return false; } /** @@ -198,8 +209,49 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac }//accept($id) + /** + * 重置评审,将评审的状态设置为投稿元数据状态 + * @param $id + * @return array|bool + */ public function reset($id){ + if(!is_array($id)) + { + if($this->getStatus($id) != self::REVIEW_STATUS_CANCELED) + return [ + '此条评审的当前状态已经不属于被取消的评审,可能已经由其他管理人员重置', + ]; + + $status = $this->changeStatus($id,self::REVIEW_STATUS_DEFAULT); + + if(false === $status) + return false; + + }else{ + $message = []; + foreach($id as $item) + { + $item = (int)$item; + if($this->getStatus($item) != self::REVIEW_STATUS_CANCELED){ + $message[] = "ID:$item:此条评审的当前状态已经不属于被取消的评审,可能已经由其他管理人员重置"; + continue; + } + + $status = $this->changeStatus($item,self::REVIEW_STATUS_DEFAULT); + + if(false === $status) + $message[] = "ID:$item:重置失败"; + } + + if(count($message) > 0) + return $message; + } + + + $this->getEventManager()->trigger('review.reset', $this, compact('id')); + + return true; } /** From dd402a698bf1bf321e23e445d2457ec1a6c75ba0 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 26 Jan 2015 09:54:47 +0800 Subject: [PATCH 26/36] fixed bug in Westdc/Member/Account.php --- Westdc/Member/Account.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index 5dfedd5..3655466 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -172,8 +172,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa { $auth = new AuthenticationService(); $auth->setStorage(new SessionStorage($this->config->session_namespace)); - - new Zend_Db($dbAdapter); + + $dbAdapter = Zend_Db::getInstance(); $authAdapter = new DbTable( $dbAdapter, From 8214e0ce8d5c247b8e187b3b57c19c9504f4aa96 Mon Sep 17 00:00:00 2001 From: cuixin Date: Tue, 27 Jan 2015 02:28:03 +0800 Subject: [PATCH 27/36] user ser modify --- Westdc/User/User.php | 75 ++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/Westdc/User/User.php b/Westdc/User/User.php index 9fe7d49..169a010 100644 --- a/Westdc/User/User.php +++ b/Westdc/User/User.php @@ -12,35 +12,64 @@ use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; use Westdc\EventModel\AbstractEventManager; -class User extends AbstractEventManager implements ServiceManagerAwareInterface{ +class User extends AbstractEventManager implements ServiceManagerAwareInterface { - protected $serviceManager; + protected $serviceManager; - private $db; + private $db; - public function setServiceManager(ServiceManager $serviceManager) - { - $this->serviceManager = $serviceManager; - - $this->init(); - - return $this; - } - - private function init() - { - $dbService = $this->serviceManager->get('Db'); - $this->db = $dbService->getPdo(); - } - - public function fetchAll(){ - $sql = "select * from users where usertype = 'member'"; - $rs = $this->db->query($sql); - return $rs->fetchAll(\PDO::FETCH_ASSOC); + public function setServiceManager (ServiceManager $serviceManager) { + $this->serviceManager = $serviceManager; + $this->init(); + return $this; + } + + private function init () { + $dbService = $this->serviceManager->get('Db'); + $this->db = $dbService->getPdo(); + } + + + /** + * @param $usertype + * @return mixed + */ + public function fetchAll ($usertype) { + + $sql = "SELECT * FROM users WHERE usertype = '$usertype'"; + $rs = $this->db->query($sql); + + return $rs->fetchAll(\PDO::FETCH_ASSOC); + } + + + /** + * @return bool + */ + public function fetchAllHeiHe () { + + $sql = "SELECT * FROM heiheuser ORDER BY id DESC"; + $rs = $this->db->query($sql); + + return $rs->fetchAll(\PDO::FETCH_ASSOC); + + return true; + } + + + public function fetchAllSendmail () { + + $time = date("Y-m-d H:i:s", time() - 3 * 365 * 24 * 3600); + + $sql = "SELECT * FROM users + WHERE ts_last_login<'$time' + ORDER BY ts_last_login DESC"; + $rs = $this->db->query($sql); + + return $rs->fetchAll(\PDO::FETCH_ASSOC); } - } \ No newline at end of file From 9bc2e4e065bd64f1664055419138e77bd6c09b30 Mon Sep 17 00:00:00 2001 From: cuixin Date: Tue, 27 Jan 2015 02:28:39 +0800 Subject: [PATCH 28/36] add user/group ser --- Westdc/User/Group.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Westdc/User/Group.php diff --git a/Westdc/User/Group.php b/Westdc/User/Group.php new file mode 100644 index 0000000..3566d8c --- /dev/null +++ b/Westdc/User/Group.php @@ -0,0 +1,47 @@ +serviceManager = $serviceManager; + + $this->init(); + + return $this; + } + + private function init() + { + $dbService = $this->serviceManager->get('Db'); + $this->db = $dbService->getPdo(); + } + + + /** + * @return mixed + */ + public function fetchAll () { + + $sql = "SELECT * FROM groups"; + $rs = $this->db->query($sql); + + return $rs->fetchAll(\PDO::FETCH_ASSOC); + } + +} \ No newline at end of file From 60e3d2e97af69d2c94f1cbaa81a087488e9d216a Mon Sep 17 00:00:00 2001 From: cuixin Date: Tue, 27 Jan 2015 02:42:06 +0800 Subject: [PATCH 29/36] user ser modify --- Westdc/User/Group.php | 42 ++++++++++++++++++++---------------------- Westdc/User/User.php | 1 - 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Westdc/User/Group.php b/Westdc/User/Group.php index 3566d8c..8d83d6e 100644 --- a/Westdc/User/Group.php +++ b/Westdc/User/Group.php @@ -11,37 +11,35 @@ namespace Westdc\User; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; -class Group implements ServiceManagerAwareInterface{ +class Group implements ServiceManagerAwareInterface { - protected $serviceManager; + protected $serviceManager; - private $db; + private $db; - public function setServiceManager(ServiceManager $serviceManager) - { - $this->serviceManager = $serviceManager; + public function setServiceManager (ServiceManager $serviceManager) { + $this->serviceManager = $serviceManager; - $this->init(); + $this->init(); - return $this; - } + return $this; + } - private function init() - { - $dbService = $this->serviceManager->get('Db'); - $this->db = $dbService->getPdo(); - } + private function init () { + $dbService = $this->serviceManager->get('Db'); + $this->db = $dbService->getPdo(); + } - /** - * @return mixed - */ - public function fetchAll () { + /** + * @return mixed + */ + public function fetchAll () { - $sql = "SELECT * FROM groups"; - $rs = $this->db->query($sql); + $sql = "SELECT * FROM groups"; + $rs = $this->db->query($sql); - return $rs->fetchAll(\PDO::FETCH_ASSOC); - } + return $rs->fetchAll(\PDO::FETCH_ASSOC); + } } \ No newline at end of file diff --git a/Westdc/User/User.php b/Westdc/User/User.php index 169a010..62863fe 100644 --- a/Westdc/User/User.php +++ b/Westdc/User/User.php @@ -71,5 +71,4 @@ class User extends AbstractEventManager implements ServiceManagerAwareInterface return $rs->fetchAll(\PDO::FETCH_ASSOC); } - } \ No newline at end of file From 42cdb3e7266c58ebd26232a397f9d2aaa14cc7aa Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 3 Feb 2015 19:02:23 +0800 Subject: [PATCH 30/36] =?UTF-8?q?ReviewService=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BF=AE=E6=94=B9=E7=AE=A1=E7=90=86=E5=91=98=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Review/Review.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 3675250..8b2b21a 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -37,6 +37,8 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac private function init(){ $dbService = $this->serviceManager->get('Db'); + + /** @var \PDO $this->db */ $this->db = $dbService->getPdo(); unset($dbService); @@ -254,13 +256,49 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return true; } + /** + * 更改管理员 + * @param $id array|int 可以输入数组 + * @param $user_id int : 不能输入数组 + * @return bool|string + */ + public function changeAdmin($id,$user_id) + { + if((!is_numeric($id) && !is_array($id)) || !is_numeric($user_id)) + return false; + + if(is_numeric($id)){ + return $this->db->exec("UPDATE mdstatus SET userid=$user_id WHERE id=$id"); + } + + if(is_array($id)) + { + try{ + $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $this->db->beginTransaction(); + foreach($id as $item_id){ + $item_id = $item_id+0; + $this->db->exec("UPDATE mdstatus SET userid=$user_id WHERE id=$item_id"); + } + $this->db->commit(); + return true; + + }catch (\Exception $e){ + $this->db->rollBack(); + return $e->getMessage(); + } + + } + return false; + }//changeAdmin(); + /** * 更改mdstatus中的status字段 * @param $id * @param $status * @return bool */ - function changeStatus($id,$status){ + protected function changeStatus($id,$status){ $statusValues = array( self::REVIEW_STATUS_CANCELED, //取消评审 self::REVIEW_STATUS_DEFAULT, //初始状态 From 8c7acba4efb6a5faccd6e957af7e87c00aecbab5 Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Tue, 3 Feb 2015 22:44:52 +0800 Subject: [PATCH 31/36] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=85=E5=AE=A1?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81=E7=A0=81=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=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(); } From 2e3fec30cdcc284d1bdeb792352de27d7b80515e Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Thu, 5 Feb 2015 15:11:15 +0800 Subject: [PATCH 32/36] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=AD=E9=92=88=E5=AF=B9TableGateway?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Helpers/Paginator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Westdc/Helpers/Paginator.php b/Westdc/Helpers/Paginator.php index 4aadcdf..fe3460d 100644 --- a/Westdc/Helpers/Paginator.php +++ b/Westdc/Helpers/Paginator.php @@ -16,7 +16,7 @@ use Zend\Paginator\Adapter\DbSelect; use Zend\Paginator\Adapter\DbTableGateway; use Zend\Paginator\Paginator as Zend_Paginator; use Zend\Db\Sql\Select; -use Zend\Db\TableGateway\TableGateway; +use Zend\Db\TableGateway; class Paginator implements ServiceManagerAwareInterface{ @@ -113,7 +113,7 @@ class Paginator implements ServiceManagerAwareInterface{ $data = new DbSelect($data,$zendDb); } - if($data instanceof TableGateway) + if($data instanceof TableGateway\TableGatewayInterface || $data instanceof TableGateway\AbstractTableGateway) $data = new DbTableGateway($data,$this->sqlQuery,$this->sqlOrder,$this->sqlGroup,$this->sqlHaving); $paginator = new Zend_Paginator($data); From d209a34b80be5780114e6212e19f059c0c433cb5 Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Fri, 6 Feb 2015 22:15:28 +0800 Subject: [PATCH 33/36] change nav-helper --- Westdc/Helpers/Layout.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Westdc/Helpers/Layout.php b/Westdc/Helpers/Layout.php index 44ce42a..7b63720 100644 --- a/Westdc/Helpers/Layout.php +++ b/Westdc/Helpers/Layout.php @@ -49,17 +49,14 @@ class Layout $inlineScriptHelper = $viewHelperManager->get('inlineScript'); $inlineScriptHelper ->captureStart(); - echo "$('#page-nav-".$this->getControllerNavName($controller)."-".$action."').addClass('active');"; + echo "$('#Nav-".$this->getControllerNavName($controller)."-".$action."').addClass('active');"; $inlineScriptHelper ->captureEnd(); } public function getControllerNavName($invokename) { - $ctl = array( - 'Application\Controller\Index' => 'index', - 'Application\Controller\Account' => 'account' - ); - return isset($ctl[$invokename]) ? $ctl[$invokename]:""; + $controller_spell = explode("\\",$invokename); + return strtolower(end($controller_spell)); } //添加用户Ajax脚本 From c6e6b2bcec037ef4aea368871dadf6e4a9e8740c Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Sat, 7 Feb 2015 10:31:39 +0800 Subject: [PATCH 34/36] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=88=91=E8=B4=9F?= =?UTF-8?q?=E8=B4=A3=E7=9A=84=E5=85=83=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Review/Review.php | 72 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 92609fb..7ebfc42 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -275,7 +275,75 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return $select; - }//accept() + }//getAccept() + + /** + * 获得我负责的元数据 + * @param string $filter + * @return null + */ + public function getAdminReviews($filter = "") + { + $authService = $this->serviceManager->get('Auth'); + $user_id = $authService->getIdentity('id'); + + if(empty($user_id)) + return false; + + $wheresql = array(); + $ordersql = array(); + + $wheresql[] = " m.status in (1,2,3,4) "; + $wheresql[] = " u.id=$user_id "; + + if(isset($filter['keyword']) && !empty($filter['keyword'])) + { + $wheresql[] = " md.title like '%".$filter['keyword']."%' "; + } + if(isset($filter['code']) && !empty($filter['code'])) + { + $wheresql[] = " s.sourceid=".$filter['code']." "; + } + 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($wheresql)>0) + { + $wheresql = " WHERE ".join(" AND ",$wheresql); + }else{ + $wheresql = ""; + } + + if(count($ordersql)>0) + { + $ordersql = " ORDER BY ".join(',',$ordersql); + }else{ + $ordersql = " ORDER BY m.status desc,m.ts_accepted desc "; + } + + $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,count(r.id) as reviews + 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 + left join datasource s on s.uuid=md.uuid + left join mdreview r ON r.uuid=md.uuid + $wheresql + GROUP BY m.id,g.id, md.uuid,md.title,u.username,u.realname,m.status,md.id,md.author,m.ts_accepted + $ordersql"; + $re = $this->db->query($sql); + $rows = $re->fetchAll(); + + return $rows; + + }//getAdminReviews /** * 取消评审 @@ -372,7 +440,7 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac $this->getEventManager()->trigger('review.reset', $this, compact('id')); return true; - } + }//reset() /** * 更改mdstatus中的status字段 From ddb410117312860a5de424295d22273986274af5 Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Sat, 7 Feb 2015 20:37:47 +0800 Subject: [PATCH 35/36] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Review/Review.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 2ea9369..32afa5d 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -261,7 +261,7 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac $select->where("md.uuid = '$keyword'"); }else{ $whereSql = function(Sql\Where $where) use ($keyword){ - $where->OR->like('md.title',"%".$keyword."%"); + $where->AND->like('md.title',"%".$keyword."%"); $where->OR->like('md.title_en',"%".$keyword."%"); }; $select->where($whereSql,Sql\Predicate\PredicateSet::OP_AND); From cfa342845b5d8021998e5a3141f67f0568bbe4c9 Mon Sep 17 00:00:00 2001 From: Jack Freeman Date: Sat, 7 Feb 2015 21:49:08 +0800 Subject: [PATCH 36/36] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E8=AF=84=E5=AE=A1=E7=9A=84=E5=85=83=E6=95=B0=E6=8D=AE=E6=A3=80?= =?UTF-8?q?=E7=B4=A2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Westdc/Review/Review.php | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 32afa5d..cc90b88 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -347,6 +347,46 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac }//getAdminReviews + /** + * 获取通过评审的元数据 + * @return Sql\Select + */ + public function getReviewed(){ + + $select = new Sql\Select; + + $select->from(['m'=>'mdstatus']); + $select->columns(['id','status','ts_finished']); + + $select->join(["md"=>"metadata"], "md.uuid=m.uuid", ["title","uuid"], $select::JOIN_RIGHT); + $select->join(["u"=>"users"], "u.id=m.userid", ["username","realname"], $select::JOIN_LEFT); + + $select->where("m.status = ".self::REVIEW_STATUS_PUBLISH); + + 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->AND->like('md.title',"%".$keyword."%"); + $where->OR->like('md.title_en',"%".$keyword."%"); + }; + $select->where($whereSql,Sql\Predicate\PredicateSet::OP_AND); + } + + } + + $select->order("m.ts_finished DESC"); + + return $select; + + }//getReviewed(); + /** * 取消评审 * @param $id @@ -480,6 +520,37 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return false; }//changeAdmin(); + /** + * 重新评审 + * @param $id + * @return bool|string + */ + public function restart($id) + { + if((!is_numeric($id) && !is_array($id))) + return false; + + if(is_numeric($id)) + return $this->changeStatus($id,self::REVIEW_STATUS_EXPERT_ACCEPT); + + if(is_array($id)) + { + try{ + $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $this->db->beginTransaction(); + foreach($id as $item_id){ + $item_id = $item_id+0; + $this->db->exec("UPDATE mdstatus SET status=".self::REVIEW_STATUS_EXPERT_ACCEPT." WHERE id=$item_id"); + } + $this->db->commit(); + return true; + }catch (\Exception $e){ + $this->db->rollBack(); + return $e->getMessage(); + } + } + }//restart() + /** * 更改mdstatus中的status字段 * @param $id