diff --git a/application/default/controllers/GlacierController.php b/application/default/controllers/GlacierController.php new file mode 100644 index 00000000..377408d1 --- /dev/null +++ b/application/default/controllers/GlacierController.php @@ -0,0 +1,311 @@ +_helper->layout->setLayout('glacier'); + } + + function indexAction() + { + $sql="select m.uuid,m.title,m.id,m.description from normalmetadata m left join thumbnail t on m.id=t.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and length(t.data)>2 order by random() limit 3"; + $this->view->meatdata=$this->db->fetchAll($sql); + } + + /* + * 数据浏览 + */ + function browseAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') "); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata','*')->where(" uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ")->order('title desc')->limitPage($page,$this->limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$this->limit); + $this->view->offset=$offset+1; + } + + function thumbAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') "); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata as m','m.*') + ->where(" uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ") + ->order('m.title desc')->limitPage($page,$this->limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$this->limit); + } + + function documentAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $row=$this->db->fetchAll("select count(*) from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ))"); + $sum=$row[0]['count']; + $sql="select * from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') )) order by reference limit ? offset ?"; + $this->view->refs=$this->db->fetchAll($sql,array($this->limit,$offset)); + $this->view->page=new Pagination($sum,$page,$this->limit,"文献"); + $this->view->offset=$offset+1; + } + + function baseAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化' or keyword='基础地理' or keyword='遥感影像' or keyword='水文地质' or keyword='社会经济' or keyword='人口' or keyword='SWAT' or keyword='NPP' or keyword='WRF' or keyword='辐射' or keyword='NEP'))"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化' or keyword='基础地理' or keyword='遥感影像' or keyword='水文地质' or keyword='社会经济' or keyword='人口' or keyword='SWAT' or keyword='NPP' or keyword='WRF' or keyword='辐射' or keyword='NEP')) order by timebegin,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->offset=$offset+1; + } + + function geobaseAction() + { + $this->getmd('基础地理'); + } + + function coreAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='DEM' or keyword='土地利用' or keyword='土壤' or keyword='气象' or keyword='水文观测' or keyword='灌溉' or keyword='试验'))"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='DEM' or keyword='土地利用' or keyword='土壤' or keyword='气象' or keyword='水文观测' or keyword='灌溉' or keyword='试验')) order by timebegin,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->offset=$offset+1; + } + + function demAction() + { + $this->getmd('DEM'); + } + + function rsAction() + { + $this->getmd('遥感影像'); + } + + function waterAction() + { + $this->getmd('水文地质'); + } + + function modelAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='WRF' or keyword='NPP' or keyword='SWAT' or keyword='NEP' or keyword='辐射'))"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='WRF' or keyword='NPP' or keyword='SWAT' or keyword='NEP' or keyword='辐射')) order by timebegin,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->offset=$offset+1; + } + + function economicAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='人口' or keyword='社会经济'))"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='人口' or keyword='社会经济')) order by timebegin,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->offset=$offset+1; + } + + function landsurfaceAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化'))"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化')) order by timebegin,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->offset=$offset+1; + } + + function landuseAction() + { + $this->getmd('土地利用','theme'); + } + + function soilAction() + { + $this->getmd('土壤','theme'); + } + + function meteoAction() + { + $this->getmd('气象','theme'); + } + + function hydroAction() + { + $this->getmd('水文观测','theme'); + } + function irragationAction() + { + $this->getmd('灌溉','theme'); + } + + function obsAction() + { + $this->getmd('试验','theme'); + } + + function listAction() + { + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') order by timebegin,title"; + $this->view->metadata=$this->db->fetchAll($sql); + } + + function tagAction() + { + $key = $this->_request->getParam('key'); + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + if (!empty($key)) { + $this->view->codename=$key; + $sql=$this->db->quoteInto('select count(id) from keyword where keyword=?',$key); + $state=$this->db->query($sql); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $sql="select uuid,title,id,description from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keyword='".$key."') order by timebegin,title limit ? offset ?"; + $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); + $this->view->page=new Pagination($sum,$page,$this->limit); + } else { + $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='place' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by keyword.keyword order by count desc"); + $k1=$state->fetchAll(); + $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='theme' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); + $k2=$state->fetchAll(); + $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='discipline' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); + $k3=$state->fetchAll(); + $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='stratum' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); + $k4=$state->fetchAll(); + $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='temporal' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by keyword.keyword order by keyword.keyword"); + $k5=$state->fetchAll(); + $this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5); + } + } + + function searchAction() + { + $this->view->addHelperPath('helper','Zend_View_Helper_'); + $form=new SearchForm(); + $this->view->form=$form; + //$form->submit->setLabel('快速搜索'); + $key=$this->_request->getParam('q'); + if (!empty($key)) { + $search=new Search($key); + $where=$search->sql_expr(array("title","description")); + $page=@(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $row=$this->db->fetchAll("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and ".$where); + $sum=$row[0]['count']; + $sql="select uuid,title,id,description from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and ".$where." order by timebegin,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; + $this->view->offset=$offset+1; + } + } + + function timemapAction() + { + $sql="select id,uuid,west,south,north,east,title,timebegin,timeend from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and timebegin is not null"; + $this->view->rows=$this->db->fetchAll($sql); + } + + function timelineAction() + { + $fn="heihetime.xml"; + $rows=$this->db->fetchAll("select ts_created from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') 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"; + $rows=$this->db->fetchAll("select id,uuid,description,title,timebegin,timeend from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and timebegin is not null order by timebegin,title"); + $timexml=''; + foreach($rows as $row) { + $timexml.=''; + $desc_length=mb_strlen($row['description'],"UTF-8"); + $desc=mb_substr($row['description'],0,($desc_length>300)?300:$desc_length,"UTF-8"); + if ($desc_length>300) $desc.=" ..."; + $timexml.=htmlspecialchars($desc); + $timexml.="\n"; + } + $timexml.=''; + $fp=fopen($fn,'w'); + fwrite($fp,$timexml); + fclose($fp); + } + } + + function categoryAction() + { + $code = (int)$this->_request->getParam('code'); + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $this->view->category=$this->db->fetchAll("select c.code,name,name_zh,count(*) from category c left join normalmetadata m on c.id=m.id,categorycode cc where c.code=cc.code and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by c.code,cc.name,cc.name_zh"); + if ($code>0 && $code<20) { + $row=$this->db->fetchAll("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from category where code=".$code.")"); + $sum=$row[0]['count']; + $sql="select uuid,title,description,id from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select distinct id from category where code=".$code.") order by timebegin,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->offset=$offset+1; + $row=$this->db->fetchRow("select name,name_zh from categorycode where code=?",$code); + $this->view->codename=(empty($row['name_zh'])?$row['name']:$row['name_zh']); + } else { + //提供全部分类列表 + } + } + + private function getmd($keyword,$type='theme') + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='heihe' and m.id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."')"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + //@todo: add order with title + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."') order by timebegin,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->offset=$offset+1; + } +} \ No newline at end of file diff --git a/application/default/views/scripts/glacier/geobase.phtml b/application/default/views/scripts/glacier/geobase.phtml new file mode 100644 index 00000000..881c2bc4 --- /dev/null +++ b/application/default/views/scripts/glacier/geobase.phtml @@ -0,0 +1,34 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/water.css'); +$this->breadcrumb('首页'); +$this->breadcrumb(''.$this->config->title->data.''); +$this->breadcrumb(''.$this->config->title->glacier.''); +$this->breadcrumb('基础数据'); +$this->breadcrumb()->setSeparator(' > '); +?> + + + diff --git a/application/default/views/scripts/glacier/index.phtml b/application/default/views/scripts/glacier/index.phtml new file mode 100755 index 00000000..00ad9c3e --- /dev/null +++ b/application/default/views/scripts/glacier/index.phtml @@ -0,0 +1,75 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/water.css'); +$this->breadcrumb('首页'); +$this->breadcrumb(''.$this->config->title->data.''); +$this->headScript()->appendFile('/js/jquery-1.7.min.js'); +$this->breadcrumb($this->config->title->glacier); +$this->breadcrumb()->setSeparator(' > '); +?> + + + \ No newline at end of file diff --git a/application/default/views/scripts/glacier/navi.phtml b/application/default/views/scripts/glacier/navi.phtml new file mode 100644 index 00000000..9d22361f --- /dev/null +++ b/application/default/views/scripts/glacier/navi.phtml @@ -0,0 +1,57 @@ + + + + \ No newline at end of file