add odt1 action

This commit is contained in:
wlx 2013-06-02 14:53:47 +00:00
parent b0e020ddbc
commit 9cbb3bb7a2
1 changed files with 153 additions and 0 deletions

View File

@ -603,7 +603,160 @@ class ServiceController extends Zend_Controller_Action
$odf->setImage('thumb', 'http://deep.qherc.org/service/thumb/uuid/'.$row['uuid']); $odf->setImage('thumb', 'http://deep.qherc.org/service/thumb/uuid/'.$row['uuid']);
$odf->exportAsAttachedFile($row['title'].'.odt'); $odf->exportAsAttachedFile($row['title'].'.odt');
} }
public function odt1Action()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid=$this->_request->getParam('uuid');
$review=$this->_request->getParam('review');
//error_reporting(1);
if (!empty($uuid))
{
$sql="select x.data,m.title,m.citation,m.suppinfo,m.doi,m.filesize,m.fileformat,m.south,m.east,m.west,m.north,m.timebegin,m.timeend,m.title_en,m.uuid,m.description,g.id,m.projection,t.filetype
from xml x left join metadata m on m.id=x.id left join thumbnail t on x.id=t.id
left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=".$this->db->quote($uuid);
$row=$this->db->fetchRow($sql);
$sql="select cc.name as category, cc.name_zh from metadata m left join category c on m.id=c.id left join categorycode cc on c.code=cc.code where m.uuid=".$this->db->quote($uuid);
$cat=$this->db->fetchAll($sql);
$row['category_zh']='';
foreach($cat as $category)
{
$row['category_zh'].=$category['name_zh'].' ';
}
$sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$ref=$this->db->fetchAll($sql);
$reference="";
foreach($ref as $k=>$refer)
{
$reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n";
}
$row['reference']=$reference;
$sql="select u.uselimit from mdlimit ml left join metadata m on ml.uuid=m.uuid left join uselimit u on ml.lid=u.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$limits=$this->db->fetchAll($sql);
$uselimits="";
foreach($limits as $k=>$limit)
{
//$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
}
$row['uselimits']=$uselimits;
$sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$res=$this->db->fetchAll($sql);
$resource="";
foreach($res as $k=>$r)
{
$resource.=($k+1).". ".$r['name'].' '.$r['linkage']."\n";
}
$row['resources']=$resource;
$sql="select r.role,s.* from role r left join responsible s on r.resid=s.id left join metadata m on m.uuid=r.uuid where m.uuid=? order by r.role,r.id";
$sql=$this->db->quoteInto($sql,$uuid);
$contact=$this->db->fetchAll($sql);
$contacts="";
$party_zh=array('resourceProvider'=>'资源提供者','custodian'=>'维护者','owner'=>'拥有者','user'=>'用户','distributor'=>'数据服务联系人','originator'=>'创建者','pointOfContact'=>'联系人','principalInvestigator'=>'数据调查与处理者','processor'=>'处理者','publisher'=>'元数据发布者','author'=>'元数据作者');
foreach($contact as $k=>$c)
{
@$contacts.=($k+1).". ".$party_zh[$c['role']]."\n";
@$contacts.=$c['individual'].' 单位:'.$c['organisation']."\n";
@$contacts.='地址:'.$c['country'].' '.$c['administractive'].' '.$c['city'].' '.$c['delivery']."\n";
@$contacts.='邮编:'.$c['postal'].' 电话:'.$c['phone'].' 邮件:'.$c['email']."\n\n";
}
$row['contacts']=$contacts;
$sql="select k.keyword, k.keytype from keyword k left join metadata m on k.id=m.id where m.uuid=? order by k.keytype";
$sql=$this->db->quoteInto($sql,$uuid);
$keys=$this->db->fetchAll($sql);
$keyword=array();
foreach($keys as $key)
{
@$keyword[$key['keytype']].=$key['keyword'].'';
}
$row['keyword']=$keyword;
if (is_numeric($row['projection']))
{
$sql="select proj4text from spatial_ref_sys where auth_srid=?";
$rs=$this->db->fetchRow($sql,array($row['projection']));
if ($rs) $projection=$rs['proj4text'];
}
if (!empty($projection)) $row['projection']=$projection;
} else
$projection='';
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$xpath = new DOMXpath($dom);
$row['rfdenom']=@$dom->getElementsByTagName('rfDenom')->item(0)->nodeValue;
$row['resolution']=@$xpath->query('//scaleDist/value/Real')->item(0)->nodeValue;
$row['resolution'].=@$dom->getElementsByTagName('uomName')->item(0)->nodeValue;
//提前对表格进行预处理
$wiki=new WikiFormat();
$row['description']=$wiki->parseTable($row["description"]);
preg_match_all('/<table>[\s\S]*?<\/table>/im', $row['description'],$tables);
$search=array();
$replace=array();
foreach($tables as $k=>$table)
{
/*$search[]="<table>";
$replace[]='<table:table table:name="Table 3">'.str_repeat('<table:table-column />',substr_count($table[0],'<th>'));
$search[]="<tr>";
$replace[]="<table:table-row>";
$search[]="<td>";
$replace[]="<table:table-cell><text:p>";
$search[]="<th>";
$replace[]="<table:table-cell><text:p>";
$search[]="</td>";
$replace[]="</text:p></table:table-cell>";
$search[]="</th>";
$replace[]="</text:p></table:table-cell>";
$search[]="</tr>";
$replace[]="</table:table-row>";
$search[]="</table>";
$replace[]="</table:table>";
$table=str_replace($search,$replace,$table[0]);*/
$row['description']=@str_replace($tables[$k][0],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']);
}
require_once('odtphp/library/odf.php');
$config["PATH_TO_TMP"]="/tmp/zip";
$config["ZIP_PROXY"]="ZipArchive";
$odf=new Odf("../data/metadata-template-1.odt",$config);
$odf->setVars('title',$row['title'],true,'utf-8');
@$odf->setVars('title_en',$row['title_en'],true,'utf-8');
$odf->setVars('uuid',$row['uuid'],true,'utf-8');
$odf->setVars('datetime',date('Y-m-d'));
$odf->setVars('abstract',$row['description'],true,'utf-8');
@$odf->setVars('theme_keyword',$row['keyword']['theme'],true,'utf-8');
@$odf->setVars('place_keyword',$row['keyword']['place'],true,'utf-8');
@$odf->setVars('temporal_keyword',empty($row['keyword']['temporal'])?'':$row['keyword']['temporal'],true,'utf-8');
@$odf->setVars('discipline_keyword',$row['keyword']['discipline'],true,'utf-8');
@$odf->setVars('stratum_keyword',$row['keyword']['stratum'],true,'utf-8');
@$odf->setVars('category',$row['category_zh'],true,'utf-8');
@$odf->setVars('rfdenom',$row['rfdenom'],true,'utf-8');
@$odf->setVars('resolution',$row['resolution'],true,'utf-8');
@$odf->setVars('projection',$row['projection'],true,'utf-8');
@$odf->setVars('filesize',$row['filesize'],true,'utf-8');
@$odf->setVars('fileformat',$row['fileformat'],true,'utf-8');
@$odf->setVars('timebegin',$row['timebegin'],true,'utf-8');
@$odf->setVars('timeend',$row['timeend'],true,'utf-8');
@$odf->setVars('citation',$row['citation'],true,'utf-8');
@$odf->setVars('reference',$row['reference'],true,'utf-8');
@$odf->setVars('doi',$row['doi'],true,'utf-8');
@$odf->setVars('suppinfo',$row['suppinfo'],true,'utf-8');
@$odf->setVars('uselimits',$row['uselimits'],true,'utf-8');
@$odf->setVars('resources',$row['resources'],true,'utf-8');
@$odf->setVars('contacts',$row['contacts'],true,'utf-8');
@$odf->setVars('north',$row['north'],true,'utf-8');
@$odf->setVars('south',$row['south'],true,'utf-8');
@$odf->setVars('west',$row['west'],true,'utf-8');
@$odf->setVars('east',$row['east'],true,'utf-8');
$odf->setImage('bigthumb', 'http://deep.qherc.org/service/bigthumb/uuid/'.$row['uuid']);
$odf->setImage('thumb', 'http://deep.qherc.org/service/thumb/uuid/'.$row['uuid']);
$odf->exportAsAttachedFile($row['title'].'.odt');
}
function uploadAction(){ function uploadAction(){
$this->_helper->layout()->disableLayout(); $this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();