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

227 lines
7.5 KiB
PHP

<?php
class WaterController extends DataController
{
private $limit=20;
function indexAction()
{
//关键词
$state=$this->db->query("select keyword.keyword,count(*) from keyword left join metadata on keyword.id=metadata.id where keyword.keytype='place' and metadata.source='0595169a-279e-4b95-819f-129d0ba4280d' 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 metadata m on k.id=m.id where k.keytype='theme' and m.source='0595169a-279e-4b95-819f-129d0ba4280d' group by k.keyword order by count(k.keyword) desc");
$k2=$state->fetchAll();
$state=$this->db->query("select keyword.keyword,count(*) from keyword left join metadata on keyword.id=metadata.id where keyword.keytype='temporal' and metadata.source='0595169a-279e-4b95-819f-129d0ba4280d' group by keyword.keyword order by count desc");
$k5=$state->fetchAll();
$this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5);
$searchform=new SearchForm();
$this->view->searchform=$searchform;
}
function documentAction()
{
}
function coldAction()
{
$this->getmd('上游寒区水文试验区');
//$this->view->searchform=new SearchForm();
}
function bgAction()
{
//metadata
// 必须确认时间范围信息检查!
$this->getmd('冰沟流域加密观测区');
}
function arAction()
{
$this->getmd('阿柔加密观测区');
}
function bdkAction()
{
$this->getmd('扁都口加密观测区');
}
function ebAction()
{
$this->getmd('峨堡加密观测区');
}
function forestAction()
{
$this->getmd('森林水文试验区');
}
function dykAction()
{
$this->getmd('大野口流域加密观测区');
}
function plgAction()
{
$this->getmd('排露沟流域加密观测区');
}
function aridAction()
{
$this->getmd('中游干旱区水文试验区');
}
function hzzAction()
{
$this->getmd('花寨子加密观测区');
}
function ykAction()
{
$this->getmd('盈科绿洲加密观测区');
}
function zyAction()
{
$this->getmd('张掖市加密观测区');
}
function zynocAction()
{
$this->getmd('观象台加密观测区');
}
function lzgAction()
{
$this->getmd('临泽草地加密观测区');
}
function lzsAction()
{
$this->getmd('临泽站加密观测区');
}
function meteoAction()
{
$this->getmd('气象水文','theme');
}
function autometeoAction()
{
$this->getmd('气象观测','theme');
}
function ecAction()
{
$this->getmd('涡动相关','theme');
}
function lasAction()
{
$this->getmd('大孔径闪烁仪','theme');
}
function normalmeteoAction()
{
$this->getmd('常规气象观测','theme');
}
function regionalmeteoAction()
{
$this->getmd('区域气象观测','theme');
}
function dopplerAction()
{
$this->getmd('降雨','theme');
}
function hydroAction()
{
$this->getmd('水文','theme');
}
function airsoundingAction()
{
$this->getmd('大气廓线','theme');
}
function aireboneAction()
{
$this->getmd('航空遥感','theme');
}
function radiometerAction()
{
$this->getmd('微波辐射计','theme');
}
function lidarAction()
{
$this->getmd('激光雷达','theme');
}
function widasAction()
{
$this->getmd('WiDAS','theme');
}
function asdAction()
{
$this->getmd('成像光谱仪','theme');
}
function satelliteAction()
{
$this->getmd('卫星遥感','theme');
}
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 metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and id in (select id from keyword where keyword='".$key."') order by timebegin limit ? offset ?";
$this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset));
$this->view->page=new Pagination($sum,$page,$this->limit);
}
}
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 metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and ".$where);
$sum=$row[0]['count'];
$sql="select uuid,title,id,description from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and ".$where." order by timebegin 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 timelineAction()
{
$fn="watertime.xml";
$rows=$this->db->fetchAll("select ts_created from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' 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 metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and timebegin is not null order by timebegin");
$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(mb_substr($row['title'],11,mb_strlen($row['title'],'UTF-8')-10,'UTF-8')).'" image="/images/westdc_40w.gif" link="/water/'.$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);
}
}
private function getmd($keyword,$type='place')
{
$page=(int)$this->_request->getParam('page');
if (empty($page)) $page=1;
$offset=$this->limit*($page-1);
$state=$this->db->query("select count(*) from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."')");
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d' and id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."') order by timebegin 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;
}
}