From 6ae3223a84b2f5b459bc36e8f8f307ed118c8011 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 4 Nov 2013 07:08:58 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E7=8C=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=98=BE=E7=A4=BA=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=89=E5=B9=B4=E6=98=BE=E7=A4=BA=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 29 +++- .../views/scripts/data/attachmentsadd.phtml | 3 +- .../admin/views/scripts/data/ref-nav.phtml | 5 +- .../admin/views/scripts/data/ref.phtml | 46 ++--- application/module/Helpers/Table.php | 7 + application/module/Helpers/dbh.php | 28 +++ application/module/Open/App.php | 162 +++++++++++++++++- application/module/Open/Open.php | 70 +++----- application/module/Reference/Reference.php | 58 +++++++ 9 files changed, 328 insertions(+), 80 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ed9cf60e..5389eabf 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1128,6 +1128,7 @@ class Admin_DataController extends Zend_Controller_Action $keyword = $this->view->q = trim($this->_getParam('q')); $order = $this->view->search_order = trim($this->_getParam('order')); $sort = $this->view->search_sort = trim($this->_getParam('sort')); + $field = $this->view->search_field = $this->_getParam('field'); $reference = new Reference(); @@ -1136,6 +1137,11 @@ class Admin_DataController extends Zend_Controller_Action $reference->keyword = $keyword; } + if(!empty($field)) + { + $reference->field = $field; + } + if(!empty($order)) { $reference->order = $order; @@ -1146,11 +1152,18 @@ class Admin_DataController extends Zend_Controller_Action $reference->sort = $sort; } + $this->view->reference = $reference; + //文献首页 if(empty($ac)) { $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchReferences(),$this,12); + + $this->view->page = $this->_getParam('page'); + $this->view->pagelimit = 12; + + view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); + $this->view->years = $reference->countByYear(); return true; } else if ($ac == "water") @@ -1172,6 +1185,8 @@ class Admin_DataController extends Zend_Controller_Action return true; } + unset($this->view->reference); + //添加 if($ac == "add") { @@ -1378,6 +1393,18 @@ class Admin_DataController extends Zend_Controller_Action return true; }//ris单篇更新 + + //ris导出 + if($ac == "risoutput") + { + $this->_helper->viewRenderer('ref-risoutput'); + $this->view->years = $reference->countByYear(); + + if(!empty($submit)) + { + + } + }//ris output }//文献管理 refAction() diff --git a/application/admin/views/scripts/data/attachmentsadd.phtml b/application/admin/views/scripts/data/attachmentsadd.phtml index 5660ef70..3c7c33f4 100644 --- a/application/admin/views/scripts/data/attachmentsadd.phtml +++ b/application/admin/views/scripts/data/attachmentsadd.phtml @@ -28,7 +28,6 @@
-

@@ -71,7 +70,7 @@ var upload = { makeFileHtml : function(data){ return '
' + '' - + data.realname + + '' +data.realname + '' +'' +'
'; }, diff --git a/application/admin/views/scripts/data/ref-nav.phtml b/application/admin/views/scripts/data/ref-nav.phtml index 85329fdd..c3406955 100644 --- a/application/admin/views/scripts/data/ref-nav.phtml +++ b/application/admin/views/scripts/data/ref-nav.phtml @@ -1,10 +1,11 @@ \ No newline at end of file diff --git a/application/admin/views/scripts/data/ref.phtml b/application/admin/views/scripts/data/ref.phtml index b1298c2b..7813e18a 100644 --- a/application/admin/views/scripts/data/ref.phtml +++ b/application/admin/views/scripts/data/ref.phtml @@ -37,6 +37,13 @@ table thead tr th {background:#EBF2F6;} msg)) { ?> msg ?> + + years)) { ?> + years as $k=>$v){ ?> + () + + +
paginator)): ?> @@ -45,8 +52,7 @@ table thead tr th {background:#EBF2F6;} - @@ -58,37 +64,31 @@ table thead tr th {background:#EBF2F6;} - page > 1) + { + $autoindex = ($this->page - 1) * $this->pagelimit; + }else{ + $autoindex=0; + } foreach ($this->paginator as $item): $autoindex++;?> - - - - + - - - - - - - - - - -
标题 - 年份 + 年份
+ []  + {reference->getAuthorByReference($item['id'],true); echo count($authors) ? join(",",$authors):'未知作者'; ?>}  + {未知标题':$item['title'] ?>}  + {未知期刊':$item['publisher'] ?>}  + {未知年份':$item['year'] ?>}  + + 编辑 RIS编辑 数据(+) 删除
- 编辑 - RIS编辑 - 数据 - 删除 -
diff --git a/application/module/Helpers/Table.php b/application/module/Helpers/Table.php index 87ceade0..69256584 100644 --- a/application/module/Helpers/Table.php +++ b/application/module/Helpers/Table.php @@ -20,4 +20,11 @@ class Table //元数据 public $metadata = "metadata"; + + //会员 + public $member = "users"; + + //开放平台 + public $oauth_clients = "oauth_clients"; + public $oauth_access_tokens = "oauth_access_tokens"; } \ No newline at end of file diff --git a/application/module/Helpers/dbh.php b/application/module/Helpers/dbh.php index 83791cd1..b9f2e7a8 100644 --- a/application/module/Helpers/dbh.php +++ b/application/module/Helpers/dbh.php @@ -1,11 +1,15 @@ debug == 1) + { + view::Dump($sql,false); + } + try{ return $this->db->exec($sql); }catch (Exception $e) { @@ -53,6 +63,12 @@ class dbh } }else{ $sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas) RETURNING id"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + try{ $sth = $this->db->prepare($sql); if($sth->execute()) @@ -108,6 +124,12 @@ class dbh try{ $sql = "UPDATE \"".$table."\" SET $fields $wheresql"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + if($this->db->exec($sql)) { return true; @@ -125,6 +147,12 @@ class dbh }else{ try{ $sql = "UPDATE \"".$table."\" SET $fields $wheresql"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + return $this->db->exec($sql); }catch (Exception $e) { if($this->product) diff --git a/application/module/Open/App.php b/application/module/Open/App.php index 23d3b377..a4da49a0 100644 --- a/application/module/Open/App.php +++ b/application/module/Open/App.php @@ -1,15 +1,72 @@ load(); + if(empty($db)) + { + $this->db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); + } + + 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; + } + + public function appStatus() + { + return array( + -1 => '关闭', + 0 => '测试', + 1 => '启用' + ); + } + + //检查用户资料完整性 + public function checkinfo() + { + $uid = view::User('id'); + $sql = "SELECT * FROM ".$this->table->member. " WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + foreach($this->checkFiled as $v) + { + if(empty($row[$v])) + { + return "请完善个人信息"; + } + } + + return true; } //获得用户创建的app @@ -17,10 +74,10 @@ class app extends open implements openbase { if(empty($uid)) { - $uid = $this->user->id; + $uid = view::User('id'); } - $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE user_id=".$this->user->id; + $sql = "SELECT * FROM ".$this->table->oauth_clients." WHERE user_id=".$uid ." ORDER BY id DESC"; $rs = $this->db->query($sql); $rows = $rs->fetchAll(); @@ -34,12 +91,103 @@ class app extends open implements openbase { return false; } - $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE id=".$id; + $sql = "SELECT * FROM ".$this->table->oauth_clients." WHERE id=".$id; $rs = $this->db->query($sql); $rows = $rs->fetch(); return $rows; } + //收集创建应用的参数 + public function getAppCreateParam(\Zend_Controller_Request_Abstract $request = NULL) + { + $request = new \Zend_Controller_Request_Http(); + $data = array( + 'subject' => trim($request->getParam('subject')), + 'client_domain' => trim($request->getParam('client_domain')), + 'redirect_uri' => trim($request->getParam('redirect_uri')), + 'status' => (int)$request->getParam('status') + ); + return $data; + }//getAppCreateParam + //添加或者编辑 + public function appCreate($id = NULL) + { + if(!empty($id)) + { + if(!is_numeric($id) || $id<1) + { + return "参数错误"; + } + } + + $data = $this->getAppCreateParam(); + + $params = compact('data'); + $results = $this->events()->trigger('app.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if(!empty($id)) + { + $params = compact('data','id'); + } + + $results = $this->events()->trigger('app.processData', $this, $params); + $data = $results->bottom(); + + $dbh = new dbh(); + + if(empty($id)) + { + $id = $dbh->insert($this->table->oauth_clients,$data,true); + if($id > 0) + { + $results = $this->events()->trigger('app.created', $this, compact("data","id")); + $cache_data = $results->bottom(); + return $id; + }else{ + return "应用创建中发生错误,请重试!"; + } + }else{ + $status = $dbh->update($this->table->oauth_clients,$data," id=$id "); + if($status) + { + $results = $this->events()->trigger('app.eidted', $this, compact("data","id")); + $cache_data = $results->bottom(); + return true; + }else{ + return "应用编辑中发生错误,请重试"; + } + } + + }//appCreate + + //删除App + public function delete($id) + { + if(!is_numeric($id) || $id<1) + { + return "参数错误"; + } + + try{ + $sql = "DELETE FROM {$this->table->oauth_clients} WHERE id=$id"; + $rs = $this->db->exec($sql); + if($rs) + { + return true; + }else{ + return "删除失败"; + } + }catch(Excaption $e){ + return "服务器处理中遇到错误"; + } + + }//delete } \ No newline at end of file diff --git a/application/module/Open/Open.php b/application/module/Open/Open.php index 8a6445df..29534eb9 100644 --- a/application/module/Open/Open.php +++ b/application/module/Open/Open.php @@ -1,26 +1,18 @@ config = \Zend_Registry::get('config'); + + public function __construct($db = NULL,$auth = NULL){ if(empty($db)) { $this->db = \Zend_Registry::get('db'); @@ -28,39 +20,27 @@ abstract class open extends \Zend_Controller_Plugin_Abstract implements openexte $this->db = $db; } - if(empty($auth)) - { - $this->auth = \Zend_Auth::getInstance(); - if($this->auth->hasIdentity()) - { - $this->user = $this->auth->getIdentity(); - } - }else{ - $this->auth = false; - } + $this->config = \Zend_Registry::get('config'); + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); } - //检查用户资料完整性 - public function checkinfo() + 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; + } + + public function clientCredentials() { - if($this->auth === false) - { - return "未登陆"; - } - include_once("Users.php"); - $user = new \Users($this->db); - $info = $user->getUserInfo($this->user->id); - - foreach($this->checkFiled as $v) - { - if(empty($info[$v])) - { - return "请完善个人信息"; - } - } - - return true; } } \ No newline at end of file diff --git a/application/module/Reference/Reference.php b/application/module/Reference/Reference.php index bb9731dd..0b8fc73c 100644 --- a/application/module/Reference/Reference.php +++ b/application/module/Reference/Reference.php @@ -16,6 +16,7 @@ class Reference public $keyword; public $order; public $sort = "DESC"; + public $field; public $reftype; @@ -176,6 +177,24 @@ class Reference { $wheresql[] = " ({$this->table->reference}.title LIKE '%{$this->keyword}%' OR {$this->table->reference}.reference LIKE '%{$this->keyword}%') "; } + + if(!empty($this->field)) + { + foreach($this->field as $k=>$v) + { + if(!empty($v)) + { + if(!is_numeric($v)) $v="'{$v}'"; + $wheresql[] = " ({$this->table->reference}.{$k}={$v} ) "; + }else{ + if(is_numeric($v)) + $wheresql[] = " ({$this->table->reference}.{$k} IS NULL OR {$this->table->reference}.{$k}=0 ) "; + else + $wheresql[] = " ({$this->table->reference}.{$k} IS NULL ) "; + }//if(empty($v) + }//foreach + } + if(count($wheresql)>0) { $wheresql = " WHERE ".join(" AND ",$wheresql); @@ -517,4 +536,43 @@ class Reference } } + //按年份获得文献数量 + public function countByYear() + { + $sql = "SELECT count(id) as num,year FROM {$this->table->reference} GROUP BY year ORDER BY year DESC"; + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + + return $rows; + } + + //获得作者 + public function getAuthorByReference($id,$join = false) + { + if(is_numeric($id)) + { + $sql = "SELECT * FROM {$this->table->reference_author} WHERE id=$id ORDER BY place ASC"; + $rs = $this->db->query($sql); + if(!$join) + { + return $rs->fetchAll(); + }else{ + foreach($rows = $rs->fetchAll() as $k=>$v) + { + $rows[$k] = (string)$v['firstname'].$v['lastname']; + } + return $rows; + } + } + + if(is_array($id)) + { + $sql = "SELECT * FROM {$this->table->reference_author} WHERE id IN (".join(",",$id).")"; + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + return; + } + }