392 lines
18 KiB
PHP
392 lines
18 KiB
PHP
<?php
|
|
class GlacierController extends DataController
|
|
{
|
|
private $limit=20;
|
|
|
|
function preDispatch()
|
|
{
|
|
parent::preDispatch();
|
|
//$this->_helper->layout->setLayout('glacier');
|
|
$acName = $this->_request->getActionName();
|
|
if(in_array($acName,array("rs","dem")))
|
|
{
|
|
$this->view->pageIn = "collapse1";
|
|
}
|
|
if(in_array($acName,array("glacier","lake")))
|
|
{
|
|
$this->view->pageIn = "collapse2";
|
|
}
|
|
if(in_array($acName,array("meteo","hydro","gps",'lidar','material','movement','physical','photogrammetry','frozensoil','vegetation','quatemary')))
|
|
{
|
|
$this->view->pageIn = "collapse3";
|
|
}
|
|
$this->view->pageID = "glacier-".$acName;
|
|
}
|
|
|
|
function indexAction()
|
|
{
|
|
$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='glacier') ");
|
|
$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='glacier') ")->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='glacier') ");
|
|
$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='glacier') ")
|
|
->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='glacier') ))");
|
|
$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='glacier') )) 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 geobaseAction()
|
|
{
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-基础数据','about');
|
|
$this->getmd(array('遥感影像','DEM'));
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function demAction()
|
|
{
|
|
$this->getmd('DEM');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-DEM','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function rsAction()
|
|
{
|
|
$this->getmd('遥感影像');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-遥感影像','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function inventoryAction()
|
|
{
|
|
$this->getmd(array('冰川编目','冰湖编目'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川冰湖编目','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function glacierAction()
|
|
{
|
|
$this->getmd('冰川编目');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川编目','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function lakeAction()
|
|
{
|
|
$this->getmd('冰湖编目');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰湖编目','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function fieldAction()
|
|
{
|
|
$this->getmd(array('水文','流量','水质','同位素','径流','水位','气象','雨量','GPS',
|
|
'雷达','雷达测厚','冰川厚度','物质平衡','花杆','运动速度','花杆消融观测','冰舌',
|
|
'冰雪物理过程','冰温','摄影测量','照片','第四纪','冻土','植被'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-野外考察与定位观测','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function meteoAction()
|
|
{
|
|
$this->getmd(array('气象','雨量'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-气象','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function hydroAction()
|
|
{
|
|
$this->getmd(array('水文','流量','水质','同位素','径流','水位'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-水文','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function gpsAction()
|
|
{
|
|
$this->getmd('GPS','theme');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-GPS','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function lidarAction()
|
|
{
|
|
$this->getmd(array('雷达','雷达测厚','冰川厚度'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-雷达测厚','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function materialAction()
|
|
{
|
|
$this->getmd(array('物质平衡','花杆'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-物质平衡','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function movementAction()
|
|
{
|
|
$this->getmd(array('运动速度','花杆消融观测','冰舌'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川运动','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function physicalAction()
|
|
{
|
|
$this->getmd(array('冰雪物理过程','冰温'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰雪物理过程','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function photogrammetryAction()
|
|
{
|
|
$this->getmd(array('摄影测量','照片'));
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-近景摄影测量','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function vegetationAction()
|
|
{
|
|
$this->getmd('植被');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-植被调查','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function frozensoilAction()
|
|
{
|
|
$this->getmd('冻土');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冻土调查','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
function quatemaryAction()
|
|
{
|
|
$this->getmd('第四纪');
|
|
$archive = new Archive($this->db);
|
|
$this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-第四纪','about');
|
|
$this->_helper->viewRenderer('base');
|
|
}
|
|
|
|
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='glacier') 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='glaicer') 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='glacier') 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 length(k.keyword)>0 and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') ";
|
|
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='glacier') 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='glacier') 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='glacier') and timebegin is not null";
|
|
$this->view->rows=$this->db->fetchAll($sql);
|
|
}
|
|
|
|
function timelineAction()
|
|
{
|
|
$fn="glaciertime.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='glacier') 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='glacier') 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="/glacier/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='glacier') 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='glacier') 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='glacier') 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='glacier' 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='glacier') and id in (select id from keyword where keytype='".$type."' and keyword in ".$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;
|
|
}
|
|
|
|
//获取多项条件并列关系的数据并必须满足limited条件
|
|
//$keyword:字符串或字符串数组
|
|
//$limited:限制字符串
|
|
private function getmdlimited($keyword,$limited)
|
|
{
|
|
$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='glacier' and m.id in (select id from keyword where keyword='".$limited."') and m.id in (select id from keyword where 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='glacier') and id in (select id from keyword where keyword='".$limited."') and id in (select id from keyword where 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;
|
|
}
|
|
} |