From 16b989c38301edcb1f38997bf45187dc93b0d2da Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 17 Mar 2014 03:15:06 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E9=87=8F=E7=BB=9F=E8=AE=A1=E5=92=8C=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Metadata/Controller/IndexController.php | 1 + vendor/Westdc/Metadata/Outlink.php | 458 +++++++++--------- 2 files changed, 234 insertions(+), 225 deletions(-) diff --git a/module/Metadata/src/Metadata/Controller/IndexController.php b/module/Metadata/src/Metadata/Controller/IndexController.php index 23256090..070af217 100644 --- a/module/Metadata/src/Metadata/Controller/IndexController.php +++ b/module/Metadata/src/Metadata/Controller/IndexController.php @@ -58,6 +58,7 @@ class IndexController extends AbstractActionController $tags = new \Westdc\Metadata\Tags; $md = $metadata->fetch($uuid); + @$metadata->updateClickCount($uuid); $this->ViewModel->setVariable('data',$md); $this->ViewModel->setVariable('keys',$tags->getMetadataTags($md['id'])); diff --git a/vendor/Westdc/Metadata/Outlink.php b/vendor/Westdc/Metadata/Outlink.php index 8c9493c1..782cf4e0 100644 --- a/vendor/Westdc/Metadata/Outlink.php +++ b/vendor/Westdc/Metadata/Outlink.php @@ -1,226 +1,234 @@ -db = new PDO; - $this->config = Config::get(); - $this->table = new Table; - - $this->opt = new \stdClass(); - - $this->opt->sort = "DESC"; - $this->opt->logic = "AND"; - - $Listener = new Listener(); - $this->getEventManager()->attachAggregate($Listener); - } - - public function setEventManager(EventManagerInterface $events) - { - $events->setIdentifiers(array( - __CLASS__, - get_called_class(), - )); - $this->events = $events; - return $this; - } - - public function getEventManager() - { - if (NULL === $this->events) { - $this->setEventManager(new EventManager()); - } - return $this->events; - } - - public function fetchAll() - { - $wheresql = array(); - - if(isset($this->opt->where) && !empty($this->opt->where)) - $wheresql = array_merge($wheresql,$this->opt->where); - - if(count($wheresql)>0) - { - $wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." "); - }else{ - $wheresql = ''; - } - - if(!empty($this->opt->order)) - { - $order = $this->opt->order; - }else{ - $order = "m.id"; - } - - $sql = "SELECT - m.*,md.viewed, ds.id as datasetid ,ol.url - FROM {$this->table->metadata} m - LEFT join {$this->table->metadata_stat} md on m.uuid=md.uuid - LEFT JOIN mdstatus st ON md.uuid=st.uuid - left join dataset ds on m.uuid=ds.uuid - LEFT JOIN mdoutlink ol ON m.uuid = ol.uuid - $wheresql - ORDER BY $order {$this->opt->sort}"; - - if(!empty($this->opt->start)) - { - $sql .= " START {$this->opt->start} "; - } - - if(!empty($this->opt->limit)){ - $sql .= " LIMIT {$this->opt->limit} "; - } - //view::Dump($sql); - $rs = $this->db->query($sql); - return $rs->fetchAll(); - } - - public function fetchAllOutlink() - { - $wheresql = array(); - - if(isset($this->opt->where) && !empty($this->opt->where)) - $wheresql = array_merge($wheresql,$this->opt->where); - - if(count($wheresql)>0) - { - $wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." "); - }else{ - $wheresql = ''; - } - - if(!empty($this->opt->order)) - { - $order = $this->opt->order; - }else{ - $order = "ol.id"; - } - - $sql = "SELECT - ol.* - FROM {$this->table->metadata_outlink} ol - $wheresql - ORDER BY $order {$this->opt->sort}"; - - if(!empty($this->opt->start)) - { - $sql .= " START {$this->opt->start} "; - } - - if(!empty($this->opt->limit)){ - $sql .= " LIMIT {$this->opt->limit} "; - } - //view::Dump($sql); - $rs = $this->db->query($sql); - return $rs->fetchAll(); - } - - public function fetch($id) - { - $sql = "SELECT m.*,ol.url FROM {$this->table->metadata} m - LEFT JOIN mdoutlink ol ON m.uuid = ol.uuid \r\n"; - if(is_numeric($id)) - { - $sql .= "WHERE m.id=$id"; - }else if(\Sookon\Helpers\Uuid::test($id)){ - $sql .= "WHERE m.uuid='$id'"; - }else{ - return false; - } - //view::Dump($sql); - $rs = $this->db->query($sql); - return $rs->fetch(); - } - - public function getParam() - { - $request = new Request; - - $data = array( - 'uuid' => $request->getPost('uuid'), - 'url' => $request->getPost('url'), - 'remark' => $request->getPost('remark'), - 'status' => $request->getPost('status') - ); - - return $data; - } - - //添加 - public function add($data,$id = 0) - { - $params = compact('data'); - $results = $this->getEventManager()->trigger('submit.checkParam', $this, $params); - $cache_data = $results->last(); - - if($cache_data !== true) - { - return $cache_data; - } - - $results = $this->getEventManager()->trigger('submit.processData', $this, $params); - $data = $results->last(); - - $dbh = new dbh(); - - if(empty($id)) - { - $id = $dbh->insert($this->table->metadata_outlink,$data,true); - - if(!empty($id) && is_numeric($id)) - { - return true; - }else{ - if($id === false) - { - return '服务器开小差了,请稍后再试'; - }else{ - return '服务器处理中遇到错误,请联系管理员'; - } - } - }//add - - else{ - if(!$dbh->update($this->table->metadata_outlink,$data," id=$id ",true)) - { - return "修改失败!请重试"; - }else{ - return true; - } - }//edit - - }// add() - - //通过uuid获得url - public function getOutlinkByUuid($uuid) - { - $sql = "SELECT * FROM {$this->table->metadata_outlink} WHERE uuid='$uuid'"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } - +db = new PDO; + $this->config = Config::get(); + $this->table = new Table; + + $this->opt = new \stdClass(); + + $this->opt->sort = "DESC"; + $this->opt->logic = "AND"; + + $Listener = new Listener(); + $this->getEventManager()->attachAggregate($Listener); + } + + public function setEventManager(EventManagerInterface $events) + { + $events->setIdentifiers(array( + __CLASS__, + get_called_class(), + )); + $this->events = $events; + return $this; + } + + public function getEventManager() + { + if (NULL === $this->events) { + $this->setEventManager(new EventManager()); + } + return $this->events; + } + + public function fetchAll() + { + $wheresql = array(); + + if(isset($this->opt->where) && !empty($this->opt->where)) + $wheresql = array_merge($wheresql,$this->opt->where); + + if(count($wheresql)>0) + { + $wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." "); + }else{ + $wheresql = ''; + } + + if(!empty($this->opt->order)) + { + $order = $this->opt->order; + }else{ + $order = "m.id"; + } + + $sql = "SELECT + m.*,md.viewed, ds.id as datasetid ,ol.url + FROM {$this->table->metadata} m + LEFT join {$this->table->metadata_stat} md on m.uuid=md.uuid + LEFT JOIN mdstatus st ON md.uuid=st.uuid + left join dataset ds on m.uuid=ds.uuid + LEFT JOIN mdoutlink ol ON m.uuid = ol.uuid + $wheresql + ORDER BY $order {$this->opt->sort}"; + + if(!empty($this->opt->start)) + { + $sql .= " START {$this->opt->start} "; + } + + if(!empty($this->opt->limit)){ + $sql .= " LIMIT {$this->opt->limit} "; + } + //view::Dump($sql); + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + public function fetchAllOutlink() + { + $wheresql = array(); + + if(isset($this->opt->where) && !empty($this->opt->where)) + $wheresql = array_merge($wheresql,$this->opt->where); + + if(count($wheresql)>0) + { + $wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." "); + }else{ + $wheresql = ''; + } + + if(!empty($this->opt->order)) + { + $order = $this->opt->order; + }else{ + $order = "ol.id"; + } + + $sql = "SELECT + ol.* + FROM {$this->table->metadata_outlink} ol + $wheresql + ORDER BY $order {$this->opt->sort}"; + + if(!empty($this->opt->start)) + { + $sql .= " START {$this->opt->start} "; + } + + if(!empty($this->opt->limit)){ + $sql .= " LIMIT {$this->opt->limit} "; + } + //view::Dump($sql); + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + public function fetch($id) + { + $sql = "SELECT m.*,ol.url,ms.viewed as viewedcount FROM {$this->table->metadata} m + LEFT JOIN mdoutlink ol ON m.uuid = ol.uuid \r\n + LEFT JOIN mdstat ms ON m.uuid=ms.uuid"; + if(is_numeric($id)) + { + $sql .= "WHERE m.id=$id"; + }else if(\Sookon\Helpers\Uuid::test($id)){ + $sql .= "WHERE m.uuid='$id'"; + }else{ + return false; + } + //view::Dump($sql); + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + public function getParam() + { + $request = new Request; + + $data = array( + 'uuid' => $request->getPost('uuid'), + 'url' => $request->getPost('url'), + 'remark' => $request->getPost('remark'), + 'status' => $request->getPost('status') + ); + + return $data; + } + + //添加 + public function add($data,$id = 0) + { + $params = compact('data'); + $results = $this->getEventManager()->trigger('submit.checkParam', $this, $params); + $cache_data = $results->last(); + + if($cache_data !== true) + { + return $cache_data; + } + + $results = $this->getEventManager()->trigger('submit.processData', $this, $params); + $data = $results->last(); + + $dbh = new dbh(); + + if(empty($id)) + { + $id = $dbh->insert($this->table->metadata_outlink,$data,true); + + if(!empty($id) && is_numeric($id)) + { + return true; + }else{ + if($id === false) + { + return '服务器开小差了,请稍后再试'; + }else{ + return '服务器处理中遇到错误,请联系管理员'; + } + } + }//add + + else{ + if(!$dbh->update($this->table->metadata_outlink,$data," id=$id ",true)) + { + return "修改失败!请重试"; + }else{ + return true; + } + }//edit + + }// add() + + //通过uuid获得url + public function getOutlinkByUuid($uuid) + { + $sql = "SELECT * FROM {$this->table->metadata_outlink} WHERE uuid='$uuid'"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //更新计数 + public function updateClickCount($uuid) + { + $sql = "UPDATE {$this->table->metadata_stat} SET viewed=viewed+1 WHERE uuid='$uuid'"; + @$this->db->exec($sql); + } + } \ No newline at end of file