405 lines
17 KiB
PHP
405 lines
17 KiB
PHP
<?php
|
|
class YrnmrController extends DataController
|
|
{
|
|
private $limit=20;
|
|
|
|
function preDispatch()
|
|
{
|
|
parent::preDispatch();
|
|
//$this->_helper->layout->setLayout('yrnmr');
|
|
$acName = $this->_request->getActionName();
|
|
$this->view->pageID = "yrnmr-".$acName;
|
|
}
|
|
|
|
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='yrnmr') and length(t.data)>2 order by random() limit 3";
|
|
$this->view->meatdata=$this->db->fetchAll($sql);
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('黄河上游宁蒙河段:数据简介','about');
|
|
}
|
|
|
|
/*
|
|
* 数据浏览
|
|
*/
|
|
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='yrnmr') ");
|
|
$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='yrnmr') ")->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='yrnmr') ");
|
|
$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='yrnmr') ")
|
|
->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='yrnmr') ))");
|
|
$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='yrnmr') )) 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()
|
|
{
|
|
$this->getmd(array('基础地理','陆地表层','遥感影像','水文地质','社会经济'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-基础数据','about');
|
|
}
|
|
|
|
function geobaseAction()
|
|
{
|
|
$this->getmd('基础地理');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-基础地理','about');
|
|
}
|
|
|
|
function landsurfaceAction()
|
|
{
|
|
$this->getmd('陆地表层');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-陆地表层','about');
|
|
}
|
|
|
|
function rsAction()
|
|
{
|
|
$this->getmd('遥感影像');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-遥感影像','about');
|
|
}
|
|
|
|
function waterAction()
|
|
{
|
|
$this->getmd('水文地质');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-水文地质','about');
|
|
}
|
|
|
|
function modelAction()
|
|
{
|
|
$this->getmd('模型数据');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-模型数据','about');
|
|
}
|
|
|
|
function economicAction()
|
|
{
|
|
$this->getmd('社会经济');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-社会经济','about');
|
|
}
|
|
|
|
function coreAction()
|
|
{
|
|
$this->getmd(array('DEM','土地利用','土壤','气象','水文观测','实验'));
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-核心数据','about');
|
|
}
|
|
|
|
function demAction()
|
|
{
|
|
$this->getmd('DEM');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-DEM','about');
|
|
}
|
|
|
|
function landuseAction()
|
|
{
|
|
$this->getmd('土地利用');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-土地利用','about');
|
|
}
|
|
|
|
function soilAction()
|
|
{
|
|
$this->getmd('土壤');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-土地利用','about');
|
|
}
|
|
|
|
function meteoAction()
|
|
{
|
|
$this->getmd('气象');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-气象','about');
|
|
}
|
|
|
|
function expAction()
|
|
{
|
|
$this->getmd('实验');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-实验','about');
|
|
}
|
|
|
|
function obsAction()
|
|
{
|
|
$this->getmd('观测');
|
|
$this->_helper->viewRenderer('base');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('YRNMR-观测','about');
|
|
}
|
|
|
|
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='yrnmr') order by timebegin,title";
|
|
$this->view->metadata=$this->db->fetchAll($sql);
|
|
}
|
|
|
|
function tagAction()
|
|
{
|
|
$key = $this->_request->getParam('key');
|
|
$keytype = $this->_request->getParam('keytype');
|
|
$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(k.id) from keyword k left join normalmetadata m on k.id=m.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='yrnmr') and k.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='yrnmr') 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 {
|
|
$sql="select k.keyword,count(*),k.keytype from keyword k left join normalmetadata m on k.id=m.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='yrnmr') ";
|
|
if (!empty($keytype) && ($keytype=='place' || $keytype=='theme' || $keytype=='discipline'||$keytype=='temporal')) $sql.=" and k.keytype='".$keytype."'";
|
|
$sql.=' group by k.keyword,k.keytype order by k.keytype,k.keyword,count desc';
|
|
$state=$this->db->query($sql);
|
|
$this->view->keytype=$keytype;
|
|
$this->view->keywords=$state->fetchAll();
|
|
}
|
|
}
|
|
|
|
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='yrnmr') 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='yrnmr') 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='yrnmr') and timebegin is not null";
|
|
$this->view->rows=$this->db->fetchAll($sql);
|
|
}
|
|
|
|
function timelineAction()
|
|
{
|
|
$fn="yrnmrtime.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='yrnmr') 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='yrnmr') and timebegin is not null order by timebegin,title");
|
|
$timexml='<data>';
|
|
foreach($rows as $row) {
|
|
$timexml.='<event start="'.date($dateformat,strtotime($row['timebegin'])).' GMT+0800" ';
|
|
if ($row['timeend']!='' && $row['timeend']!=$row['timebegin']) $timexml.=' end="'.date($dateformat,strtotime($row['timeend'])).'" isDuration="true"';
|
|
$timexml.= ' title="'.htmlspecialchars($row['title']).'" image="/images/westdc_40w.gif" link="/yrnmr/view/uuid/'.$row['uuid'].'">';
|
|
$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.="</event>\n";
|
|
}
|
|
$timexml.='</data>';
|
|
$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='yrnmr') 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='yrnmr') 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='yrnmr') 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);
|
|
if (!is_array($keyword))
|
|
{
|
|
$keyword=array($keyword);
|
|
}
|
|
$key="(";
|
|
foreach($keyword as $k)
|
|
{
|
|
$key.="'".$k."',";
|
|
}
|
|
$key=substr($key,0,-1);
|
|
$key.=")";
|
|
$keyword=$key;
|
|
|
|
$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='yrnmr' and m.id in (select id from keyword where keytype='".$type."' and keyword in ".$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='yrnmr') and id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.") 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->offset=$offset+1;
|
|
}
|
|
|
|
//获取多项条件并列关系的数据并必须满足limited条件
|
|
//$keyword:字符串或字符串数组
|
|
//$limited:限制字符串
|
|
//$without:明确不包含的字符串数组
|
|
private function getmdlimited($keyword,$limited,$without='')
|
|
{
|
|
$page=(int)$this->_request->getParam('page');
|
|
if (empty($page)) $page=1;
|
|
$offset=$this->limit*($page-1);
|
|
if (!is_array($keyword))
|
|
{
|
|
$keyword=array($keyword);
|
|
}
|
|
$key="(";
|
|
foreach($keyword as $k)
|
|
{
|
|
$key.="'".$k."',";
|
|
}
|
|
$key=substr($key,0,-1);
|
|
$key.=")";
|
|
$keyword=$key;
|
|
|
|
if (!empty($without))
|
|
{
|
|
if (!is_array($without))
|
|
{
|
|
$without=array($without);
|
|
}
|
|
$withoutkey="(";
|
|
foreach ($without as $wo)
|
|
{
|
|
$withoutkey.="'".$wo."',";
|
|
}
|
|
$withoutkey=substr($withoutkey,0,-1);
|
|
$withoutkey.=")";
|
|
}
|
|
|
|
$sql="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='yrnmr' and m.id in (select id from keyword where keyword='".$limited."')
|
|
and m.id in (select id from keyword where keyword in ".$keyword.")";
|
|
if (!empty($without)) $sql.=" and m.id not in (select id from keyword where keyword in $withoutkey)";
|
|
$state=$this->db->query($sql);
|
|
$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='yrnmr')
|
|
and id in (select id from keyword where keyword='".$limited."')
|
|
and id in (select id from keyword where keyword in ".$keyword.")";
|
|
if (!empty($without)) $sql.=" and id not in (select id from keyword where keyword in $withoutkey)";
|
|
$sql.=" 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->offset=$offset+1;
|
|
}
|
|
|
|
//获取多项必须满足的条件
|
|
//$keyword:字符串或字符串数组
|
|
private function getmdrestricted($keyword)
|
|
{
|
|
$page=(int)$this->_request->getParam('page');
|
|
if (empty($page)) $page=1;
|
|
$offset=$this->limit*($page-1);
|
|
if (!is_array($keyword))
|
|
{
|
|
$keyword=array($keyword);
|
|
}
|
|
$key="(";
|
|
foreach($keyword as $k)
|
|
{
|
|
$key.="m.id in (select id from keyword where keyword='".$k."') and ";
|
|
}
|
|
$key=substr($key,0,-4);
|
|
$key.=")";
|
|
$keyword=$key;
|
|
|
|
$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='yrnmr' and $keyword");
|
|
$row=$state->fetchAll();
|
|
$sum=$row[0]['count'];
|
|
//@todo: add order with title
|
|
$sql="select uuid,title from normalmetadata m where m.uuid in
|
|
(select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='yrnmr')
|
|
and $keyword
|
|
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->offset=$offset+1;
|
|
}
|
|
} |