From 417e587dbc28112e576b536e6664118942f39820 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 11 Jun 2014 14:14:14 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=88=86=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 190 +++--------------- application/layouts/layout.phtml | 2 +- 2 files changed, 30 insertions(+), 162 deletions(-) diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 19915175..0eb2e133 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -84,7 +84,9 @@ class DataController extends Zend_Controller_Action //展示最近20条离线神情记录情况 function offlineappAction() { - $sql="select * from offlineapp where ts_approved is not null and pdflink<>'' and status>=0 order by ts_created desc limit 20"; + $sql="select * from offlineapp where ts_approved is not null and pdflink<>'' and status>=0 + and id in (select offlineappid from dataorder where uuid in (select uuid from $this->submd)) + order by ts_created desc limit 20"; $this->view->rows=$this->db->fetchAll($sql); } function requestAction() @@ -110,11 +112,11 @@ class DataController extends Zend_Controller_Action if (empty($page)) $page=1; $limit=10; $offset=$limit*($page-1); - $state=$this->db->query('select count(*) from metadata'); + $state=$this->db->query('select count(*) from $this->submd'); $row=$state->fetchAll(); $sum=$row[0]['count']; $select=$this->db->select(); - $select->from('metadata','*')->order('id desc')->limitPage($page,$limit); + $select->from($this->submd,'*')->order('id desc')->limitPage($page,$limit); $this->view->metadata = $this->db->fetchAll($select); $this->view->page=new Pagination($sum,$page,$limit); } @@ -187,7 +189,7 @@ class DataController extends Zend_Controller_Action if (empty($page)) $page=1; $limit=10; $offset=$limit*($page-1); - $state=$this->db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id group by s.id,s.name'); + $state=$this->db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id and d.id in (select id from '.$this->submd.') group by s.id,s.name'); $this->view->serie=$state->fetchAll(); if ($id>0) { //$where=$this->db->quoteInto('id = ?',$id); @@ -195,22 +197,24 @@ class DataController extends Zend_Controller_Action $this->view->codename=$row['name']; if (!empty($keyword)) { - $sql='select count(m.id) as count from normalmetadata m,dataseries d,keyword k where m.id=d.id and m.id=k.id and d.sid=? and k.keyword=?'; + $sql="select count(m.id) as count from $this->submd m,dataseries d,keyword k where m.id=d.id and m.id=k.id and d.sid=? and k.keyword=?"; $row=$this->db->fetchAll($sql,array($id,$keyword)); $this->view->codename.="【关键词:".$keyword."】"; }else{ - $sql='select count(m.id) as count from normalmetadata m,dataseries d where m.id=d.id and d.sid=?'; + $sql="select count(m.id) as count from $this->submd m,dataseries d where m.id=d.id and d.sid=?"; $row=$this->db->fetchAll($sql,array($id)); } $sum=$row[0]['count']; $select=$this->db->select(); - $select->from('normalmetadata','*')->join('dataseries','normalmetadata.id=dataseries.id')->where('dataseries.sid=?',$id)->order('normalmetadata.title')->limitPage($page,$limit); - if (!empty($keyword)) $select->join('keyword','keyword.id=normalmetadata.id')->where('keyword.keyword=?',$keyword); + $select->from($this->submd. ' as m','*')->join('dataseries','m.id=dataseries.id')->where('dataseries.sid=?',$id)->order('m.title')->limitPage($page,$limit); + if (!empty($keyword)) $select->join('keyword','keyword.id=m.id')->where('keyword.keyword=?',$keyword); $this->view->metadata=$this->db->fetchAll($select); $this->view->page=new Pagination($sum,$page,$limit); //$this->view->showtools=($sum>$page)?true:false; //$this->view->form=new SearchForm(); - $sql=$this->db->quoteInto("select keyword,count(*) as count from (select t.keyword,t.id from keyword t left join dataseries d on t.id=d.id where t.keytype='place' and d.sid=?) as f group by keyword order by count desc limit 30",$id); + $sql=$this->db->quoteInto("select keyword,count(*) as count from + (select t.keyword,t.id from keyword t left join dataseries d on t.id=d.id where t.keytype='place' and d.id in (select id from $this->submd) and d.sid=?) as f + group by keyword order by count desc limit 30",$id); $state=$this->db->query($sql); $row=$state->fetchAll(); $this->view->places=$row; @@ -226,17 +230,17 @@ class DataController extends Zend_Controller_Action { $page = $this->_request->getParam('page'); $code = (int)$this->_request->getParam('code'); - $state=$this->db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh'); + $state=$this->db->query("select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code and c.id in (select id from $this->submd) group by c.code,cc.name,cc.name_zh"); $this->view->category=$state->fetchAll(); if ($code>0 && $code<20) { $where=$this->db->quoteInto('code = ?',$code); $row=$this->db->fetchRow("select * from categorycode where ".$where); $this->view->codename=(empty($row['name_zh'])?$row['name']:$row['name_zh']); - $sql='select count(m.id) from normalmetadata m left join category c on m.id=c.id where c.code=?'; + $sql="select count(m.id) from $this->submd m left join category c on m.id=c.id where c.code=?"; $row=$this->db->fetchRow($sql,array($code)); $sum=$row['count']; $select=$this->db->select(); - $select->from('normalmetadata as m','*')->joinLeft('category as c','m.id=c.id')->where('c.code=?',$code)->order('m.title')->limitPage($page,$this->limit); + $select->from($this->submd.' as m','*')->joinLeft('category as c','m.id=c.id')->where('c.code=?',$code)->order('m.title')->limitPage($page,$this->limit); $this->view->metadata=$this->db->fetchAll($select); $this->view->page=new Pagination($sum,$page,$this->limit); } else { @@ -250,14 +254,12 @@ class DataController extends Zend_Controller_Action function timelineAction() { $fn="time1.xml"; - $rows=$this->db->fetchAll("select ts_created from normalmetadata order by ts_created desc limit 1"); + $rows=$this->db->fetchAll("select ts_created from $this->submd order by ts_created desc limit 1"); $last_update=strtotime($rows[0]['ts_created']); if (!file_exists($fn) || (filemtime($fn)<$last_update)) { $dateformat="M j Y"; - $md = new MetadataTable(); - $db=$md->getAdapter(); - $state=$db->query('select id,uuid,description,title,timebegin,timeend from normalmetadata where timebegin is not null order by timebegin'); + $state=$this->db->query("select id,uuid,description,title,timebegin,timeend from $this->submd where timebegin is not null order by timebegin"); $rows=$state->fetchAll(); $timexml=''; foreach($rows as $row) { @@ -291,13 +293,11 @@ class DataController extends Zend_Controller_Action */ function jsonAction() { - $md=new MetadataTable(); - $db=$md->getAdapter(); $id = (int)$this->_request->getParam('id'); $where=''; if (!empty($id)) { $where=' where id='.$id; } - $sql='select id,uuid,west,south,north,east,title from normalmetadata'.$where; - $state=$db->query($sql); + $sql="select id,uuid,west,south,north,east,title from $this->submd".$where; + $state=$this->db->query($sql); $rows=$state->fetchAll(); $geomd=new GeoMetaData(); foreach($rows as $row){ @@ -320,7 +320,7 @@ class DataController extends Zend_Controller_Action */ function timemapAction() { - $sql='select id,uuid,west,south,north,east,title,timebegin,timeend from normalmetadata where timebegin is not null'; + $sql="select id,uuid,west,south,north,east,title,timebegin,timeend from $this->submd where timebegin is not null"; $this->view->rows=$this->db->fetchAll($sql); } /* @@ -329,7 +329,7 @@ class DataController extends Zend_Controller_Action function xmlAction() { $uuid=$this->_request->getParam('uuid'); - $row=$this->db->fetchRow("select xml.data from xml left join metadata on xml.id=metadata.id where metadata.uuid=?",array($uuid)); + $row=$this->db->fetchRow("select xml.data from xml left join $this->submd m on xml.id=m.id where m.uuid=?",array($uuid)); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'text/xml') @@ -357,37 +357,7 @@ class DataController extends Zend_Controller_Action //$this->getResponse()->setHeader('Content-Type', 'text/html') // ->setBody($proc->transformToXML($xml)); } - function feedAction() - { - $feedArray = array( - 'title' => '中国西部环境与生态科学数据中心', - 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/feed', - 'description' => '共享西部计划产生的数据', - 'language' => 'zh-CN', - 'charset' => 'utf-8', - 'published' => time(), - //'generator' => 'Zend Framework Zend_Feed', - 'entries' => array() - ); - $sql="select * from normalmetadata order by ts_created desc"; - $rs=$this->db->fetchAll($sql); - $feedArray['published']=strtotime($rs[0]['ts_created']); - foreach($rs as $r) - { - $feedArray['entries'][] = array( - 'title' => $r['title'], - 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], - 'guid' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], - //'content'=>$r['description'], - 'description' => $r['description'], - 'lastUpdate' => strtotime($r['ts_created']) - ); - } - $feed = Zend_Feed::importArray($feedArray,'rss'); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $feed->send(); - } + /* * todo: search */ @@ -407,58 +377,15 @@ class DataController extends Zend_Controller_Action $offset=$this->limit*($page-1); $search=new Search($key); $where=$search->sql_expr(array("title","description")); - $row=$this->db->fetchAll("select count(*) from normalmetadata where ".$where); + $row=$this->db->fetchAll("select count(*) from $this->submd where ".$where); $sum=$row[0]['count']; - $sql="select uuid,title,id,description from normalmetadata where ".$where." order by title limit ? offset ?"; + $sql="select uuid,title,id,description from $this->submd where ".$where." order by title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->key=$key; } } - /* - * todo: 高级搜索 - */ - function advancesearchAction() - { - $this->view->addHelperPath('helper','Zend_View_Helper_'); - //$form=new SearchForm(); - //$this->view->form=$form; - $md=new MetadataTable(); - $db=$md->getAdapter(); - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=10; - $offset=$limit*($page-1); - $key=$this->_request->getParam('q'); - $n=(int)$this->_request->getParam('n'); - $s=(int)$this->_request->getParam('s'); - $e=(int)$this->_request->getParam('e'); - $w=(int)$this->_request->getParam('w'); - if (!(empty($n) && empty($key))) { - if (empty($n)) $n=90; - if (empty($s)) $s=-90; - if (empty($e)) $e=180; - if (empty($w)) $w=-180; - $start=$this->_request->getParam('start'); - $end=$this->_request->getParam('end'); - if (!empty($key)) { - $sql='select count(*) from normalmetadata where east? and north? and (title ilike ? or description ilike ?)'; - $row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%')); - } else { - $sql='select count(*) from normalmetadata where east? and north?'; - $row=$db->fetchAll($sql,array($e,$w,$n,$s)); - } - $sum=$row[0]['count']; - $select=$db->select(); - $select->from('normalmetadata','*')->where('eastwhere('west>?',$w)->where('northwhere('south>?',$s); - if (!empty($key)) $select->where('(title ilike ? or description ilike ?)','%'.$key.'%'); - $select->order('title')->limit($limit,$offset); - $this->view->metadata = $db->fetchAll($select); - $this->view->page=new Pagination($sum,$page); - $this->view->key=$key; - } - } /* * 根据id或uuid来查看元数据 * id为一组数字,uuid为唯一标识符 @@ -466,7 +393,7 @@ class DataController extends Zend_Controller_Action function viewAction() { $id = (int)$this->_request->getParam('id'); - $sql="select m.*,s.status,g.id as gid,t.filename,i.doi as datadoi,i.authors,i.author_en,i.publisher,i.publisher_en, date_part('year',i.ts_published) as publish_year from normalmetadata m left join mdstatus s on m.uuid=s.uuid + $sql="select m.*,s.status,g.id as gid,t.filename,i.doi as datadoi,i.authors,i.author_en,i.publisher,i.publisher_en, date_part('year',i.ts_published) as publish_year from $this->submd m left join mdstatus s on m.uuid=s.uuid left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid left join datadoi i on i.uuid=m.uuid where "; if (empty($id)) { $uuid = $this->_request->getParam('uuid'); @@ -1981,65 +1908,6 @@ class DataController extends Zend_Controller_Action } - - /* - * 西部计划项目及其数据产出 - */ - public function westeeAction() - { - //$sql="select w.*,m.uuid from westee w left join westeemd m on w.id=m.eeid order by w.id"; - $sql="select * from westee order by id"; - $this->view->westee=$this->db->fetchAll($sql); - $sql="select w.eeid,m.title,m.uuid from westeemd w left join metadata m on w.uuid=m.uuid order by w.eeid"; - $this->view->westeemd=$this->db->fetchAll($sql); - } - - public function pingbackAction() - { - $this->_helper->ViewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); - $server = new Zend_XmlRpc_Server(); - $server->setClass('PingbackRpc', 'pingback'); - echo $server->handle(); - } - - public function pingtestAction() - { - $this->_helper->ViewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); - $client = new Zend_XmlRpc_Client('http://test.westgis.ac.cn/data/pingback'); - $arg1 = 'http://wlx.westgis.ac.cn/567/'; - $arg2 = 'http://test.westgis.ac.cn/data/487591d0-d437-4114-b810-cbef7c4ee4b2'; - //$result = $client->call('pingback.ping', array($arg1, $arg2)); - $test = $client->getProxy('pingback'); - $test->ping($arg1,$arg2); - //var_dump($result); - } - public function outputAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $sql="select title,datatype,filesize,id from normalmetadata"; - $md=$this->db->fetchAll($sql); - foreach($md as $m) - { - print $m["title"].","; - print ($m["datatype"]?"内部":"公开").","; - print ($m["filesize"]==1?" ":$m["filesize"]).","; - $sql1="select keyword from keyword where id=".$m["id"]." and keytype='place'"; - $kd=$this->db->fetchAll($sql1); - foreach ($kd as $p) print $p["keyword"]." "; - print ","; - $sql1="select keyword from keyword where id=".$m["id"]." and keytype='temporal'"; - $kd=$this->db->fetchAll($sql1); - foreach ($kd as $p) print $p["keyword"]." "; - print ","; - print "
"; - } - - } - - public function jsonexit($data){ $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); return true; @@ -2053,7 +1921,7 @@ class DataController extends Zend_Controller_Action $this->view->organisation=$state->fetchAll(); if (!empty($name)) { $this->view->codename=$name; - $sql="select distinct m.* from normalmetadata m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.organisation=?"; + $sql="select distinct m.* from $this->submd m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.organisation=?"; $sth = $this->db->prepare($sql); $sth->execute(array($name)); $rows = $sth->fetchAll(); @@ -2074,7 +1942,7 @@ class DataController extends Zend_Controller_Action $sql="select * from fund where id=?"; $this->view->fund=$this->db->fetchRow($sql,array($id)); if ($this->view->fund) { - $sql="select distinct m.* from normalmetadata m left join mdfund mf on m.uuid=mf.uuid where mf.fid=?"; + $sql="select distinct m.* from $this->submd m left join mdfund mf on m.uuid=mf.uuid where mf.fid=?"; $sth = $this->db->prepare($sql); $sth->execute(array($id)); $rows = $sth->fetchAll(); @@ -2087,7 +1955,7 @@ class DataController extends Zend_Controller_Action } } else { //提供全部分类列表 - $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize from fund f left join mdfund m on f.id=m.fid left join metadata md on m.uuid=md.uuid where m.id is not null group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by datacount desc,f.ts_created desc"; + $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize from fund f left join mdfund m on f.id=m.fid left join $this->submd md on m.uuid=md.uuid where m.id is not null group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by datacount desc,f.ts_created desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); diff --git a/application/layouts/layout.phtml b/application/layouts/layout.phtml index 89bed1c3..271e7700 100755 --- a/application/layouts/layout.phtml +++ b/application/layouts/layout.phtml @@ -28,7 +28,7 @@ headLink() ?> headStyle() ?> - +