westdc-zf1/application/default/controllers/HiwaterController.php

441 lines
16 KiB
PHP
Raw Normal View History

2012-12-13 03:59:48 +00:00
<?php
class HiwaterController extends DataController
{
private $limit=20;
function preDispatch()
{
parent::preDispatch();
2013-04-16 09:19:06 +00:00
//$this->_helper->layout->setLayout('hiwater');
2012-12-13 03:59:48 +00:00
$this->debug = 1;
2013-04-16 09:19:06 +00:00
$acName = $this->_request->getActionName();
2013-05-24 16:24:31 +00:00
if(in_array($acName,array("aviation","radiometer","lidar","widas","nearvis","thermal")))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse1";
}
2013-05-25 02:19:17 +00:00
else if(in_array($acName,array("airborne","vegstructure","vegtype","vegparam","dem","dsm","temperature","soilmoisture")))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse2";
}
2013-05-25 02:19:17 +00:00
else if(in_array($acName,array("hmon","autometeo","ec",'las','prec')))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse3";
}
2013-05-25 02:19:17 +00:00
else if(in_array($acName,array("cgs","calibration","ground",'sync')))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse4";
}
2013-05-25 02:19:17 +00:00
else if(in_array($acName,array("wsn","waternet","soilnet","bnunet",'bnulai')))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse5";
}
2013-05-25 02:19:17 +00:00
else if(in_array($acName,array("other")))
2013-04-16 09:19:06 +00:00
{
$this->view->pageIn = "collapse6";
}
$this->view->pageID = "hiwater-".$acName;
2012-12-13 03:59:48 +00:00
}
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='hiwater') and length(t.data)>2 order by random() limit 3";
$this->view->meatdata=$this->db->fetchAll($sql);
$archive = new Archive($this->db);
2012-12-13 06:07:06 +00:00
$this->view->info = $archive->getOneArchive('HiWATER黑河流域生态-水文过程综合遥感观测联合试验','about');
2012-12-13 03:59:48 +00:00
}
/*
* 数据浏览
*/
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='hiwater') ");
$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='hiwater') ")->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='hiwater') ");
$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='hiwater') ")
->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='hiwater') ))");
$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='hiwater') )) 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;
}
2013-05-24 16:24:31 +00:00
function aviationAction()
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('航空遥感','WiDAS','PLMR','Lidar','CASI','热红外高光谱数据'));
2013-05-24 16:24:31 +00:00
$this->_helper->viewRenderer('base');
}
function radiometerAction()
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','PLMR'));
2013-05-24 16:24:31 +00:00
$this->_helper->viewRenderer('base');
}
function lidarAction()
{
$this->getmd(array('','Lidar'));
$this->_helper->viewRenderer('base');
}
function widasAction()
{
$this->getmd(array('','WiDAS'));
$this->_helper->viewRenderer('base');
}
function nearvisAction()
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','CASI'));
2013-05-24 16:24:31 +00:00
$this->_helper->viewRenderer('base');
}
function thermalAction()
{
$this->getmd(array('','热红外高光谱数据'));
$this->_helper->viewRenderer('base');
}
2013-05-25 02:19:17 +00:00
function airborneAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('航空遥感产品','种植结构图','植被类型图','植被结构参数','数字高程模型','数字表面模型','地表温度','地表土壤水文'));
$this->_helper->viewRenderer('base');
}
function vegstructureAction()
{
$this->getmd(array('','种植结构图'));
$this->_helper->viewRenderer('base');
}
function vegtypeAction()
{
$this->getmd(array('','植被类型图'));
$this->_helper->viewRenderer('base');
}
function vegparamAction()
{
$this->getmd(array('','植被结构参数'));
$this->_helper->viewRenderer('base');
}
function demAction()
{
$this->getmd(array('','数字高程模型'));
$this->_helper->viewRenderer('base');
}
function dsmAction()
{
$this->getmd(array('','数字表面模型'));
$this->_helper->viewRenderer('base');
}
function temperatureAction()
{
$this->getmd(array('','地表温度'));
$this->_helper->viewRenderer('base');
}
function soilmoistureAction()
{
$this->getmd(array('','地表土壤水文'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function hmonAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('自动气象站','涡动相关仪','大孔径闪烁仪','河川径流观测'));
$this->_helper->viewRenderer('base');
}
function autometeoAction()
{
$this->getmd(array('','自动气象站'));
$this->_helper->viewRenderer('base');
}
function ecAction()
{
$this->getmd(array('','涡动相关仪'));
$this->_helper->viewRenderer('base');
}
function lasAction()
{
$this->getmd(array('','大孔径闪烁仪'));
$this->_helper->viewRenderer('base');
}
function precAction()
{
$this->getmd(array('','河川径流观测'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function cgsAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('定标观测','地基遥感观测','地面同步观测'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function calibrationAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','定标观测'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function groundAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','地基遥感观测'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function syncAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','地面同步观测'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function wsnAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('WATERNET','SoilNET','BNUNET','BNULAI'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function waternetAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','WATERNET'));
$this->_helper->viewRenderer('base');
}
function soilnetAction()
{
$this->getmd(array('','SoilNET'));
$this->_helper->viewRenderer('base');
}
function bnunetAction()
{
$this->getmd(array('','BNUNET'));
$this->_helper->viewRenderer('base');
}
function bnulaiAction()
{
$this->getmd(array('','BNULAI'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
2013-05-25 02:19:17 +00:00
function satelliteAction()
2012-12-13 03:59:48 +00:00
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','卫星遥感'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
function soilAction()
{
2013-05-25 02:19:17 +00:00
$this->getmd(array('','卫星遥感'));
$this->_helper->viewRenderer('base');
2012-12-13 03:59:48 +00:00
}
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='hiwater') order by timebegin,title";
$this->view->metadata=$this->db->fetchAll($sql);
}
function tagAction()
{
$key = $this->_request->getParam('key');
2013-05-25 03:46:38 +00:00
$keytype = $this->_request->getParam('keytype');
2012-12-13 03:59:48 +00:00
$page=(int)$this->_request->getParam('page');
if (empty($page)) $page=1;
$offset=$this->limit*($page-1);
if (!empty($key)) {
$this->view->codename=$key;
2013-05-25 03:46:38 +00:00
$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='hiwater') and k.keyword=?",$key);
2012-12-13 03:59:48 +00:00
$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='hiwater') 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 {
2013-05-25 03:46:38 +00:00
$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='hiwater') ";
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();
2012-12-13 03:59:48 +00:00
}
}
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)) {
2013-05-25 02:19:17 +00:00
$search=new SimpleSearch($key);
2012-12-13 03:59:48 +00:00
$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='hiwater') 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='hiwater') 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='hiwater') and timebegin is not null";
$this->view->rows=$this->db->fetchAll($sql);
}
function timelineAction()
{
2013-05-25 03:46:38 +00:00
$fn="hiwatertime.xml";
2012-12-13 03:59:48 +00:00
$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='hiwater') 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='hiwater') 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="/hiwater/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='hiwater') 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='hiwater') 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='hiwater') 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 {
//提供全部分类列表
}
}
2013-05-25 03:46:38 +00:00
function viewAction()
{
parent::viewAction();
$this->_helper->viewRenderer('hiwater/view');
}
2012-12-13 03:59:48 +00:00
private function getmd($keyword,$type='theme')
{
$page=(int)$this->_request->getParam('page');
if (empty($page)) $page=1;
$offset=$this->limit*($page-1);
2013-05-24 16:24:31 +00:00
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='hiwater' and m.id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.")");
2012-12-13 03:59:48 +00:00
$row=$state->fetchAll();
$sum=$row[0]['count'];
//@todo: add order with title
2013-05-24 16:24:31 +00:00
$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='hiwater') and id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.") order by timebegin,title limit ? offset ?";
2012-12-13 03:59:48 +00:00
$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;
}
//从pgsql读取数组并拆分为php数组
function getArray($str){
if(strlen($str)>3)
{
return explode(",",substr($str,1,-1));
}else{
return NULL;
}
}
//将php数组组装成pgsql中的数组
function mkArray($array){
if(!is_array($array))
{
return "{".$array."}";
}
if(count($array)==1)
{
$key = max(array_keys($array));
return "{".$array[$key]."}";
}
if(count($array)>1)
{
return "{".join(",",$array)."}";
}
}
2013-05-24 16:24:31 +00:00
2012-12-13 03:59:48 +00:00
}