融合最新版本的ISO 19115类
This commit is contained in:
parent
51dcd4f6b1
commit
a41eaa51fb
|
@ -122,6 +122,8 @@ class ISO19115
|
|||
private $dom;
|
||||
public $keytypecode=array(1=>'discipline','place','stratum','temporal','theme');
|
||||
public $author;
|
||||
public $error=array();
|
||||
public $xml;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
@ -140,7 +142,8 @@ class ISO19115
|
|||
*/
|
||||
function loadXML($str)
|
||||
{
|
||||
$this->dom->loadXML($str);
|
||||
@$this->dom->loadXML($str);
|
||||
$this->xml=$str;
|
||||
$this->parse();
|
||||
}
|
||||
/**
|
||||
|
@ -163,16 +166,15 @@ class ISO19115
|
|||
function loadUUID($uuid)
|
||||
{
|
||||
}
|
||||
function saveDB($db,$xml)
|
||||
function saveDB($db,$xml='')
|
||||
{
|
||||
$this->loadXML($xml);
|
||||
if (!empty($xml)) $this->loadXML($xml);
|
||||
//先删除已有元数据,然后再插入新数据
|
||||
$sql="delete from metadata where uuid=?";
|
||||
$db->query($sql,array($this->uuid));
|
||||
//删除所有未用到的responsible数据
|
||||
$sql="delete from responsible where id not in (select distinct(resid) from role)";
|
||||
$db->query($sql);
|
||||
$this->view->config = Zend_Registry::get('config');
|
||||
|
||||
//if (!empty($this->doi)) $row->doi=$this->doi;
|
||||
//生成空白统计数据,可以转移到数据库端处理(todo)
|
||||
|
@ -184,21 +186,31 @@ class ISO19115
|
|||
//do nothing.
|
||||
//说明数据库中已存在该信息
|
||||
}
|
||||
|
||||
$dbmode=$db->getFetchMode();
|
||||
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
||||
//save metadata into database
|
||||
try {
|
||||
$sql="insert into metadata (uuid,title,title_en,description,citation,suppinfo,fileformat,projection,datatype,filesize,ts_created,
|
||||
timebegin,timeend,west,south,north,east,doi) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
$db->query($sql,array($this->uuid,$this->resTitle,$this->resAltTitle,$this->idAbs,$this->citation,$this->suppinfo,$this->fileformat,
|
||||
if ($this->refDate)
|
||||
{
|
||||
$sql="insert into metadata (uuid,title,title_en,description,citation,suppinfo,fileformat,projection,datatype,filesize,ts_created,
|
||||
timebegin,timeend,west,south,north,east,doi,ts_published) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
$db->query($sql,array($this->uuid,$this->resTitle,$this->resAltTitle,$this->idAbs,$this->citation,$this->suppinfo,$this->fileformat,
|
||||
$this->projection,$this->datatype,$this->filesize,$this->mdDateSt,$this->timebegin,$this->timeend,$this->geoBox['w'],
|
||||
$this->geoBox['s'],$this->geoBox['n'],$this->geoBox['e'],$this->doi,$this->refDate));
|
||||
} else {
|
||||
$sql="insert into metadata (uuid,title,title_en,description,citation,suppinfo,fileformat,projection,datatype,filesize,ts_created,
|
||||
timebegin,timeend,west,south,north,east,doi) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
$db->query($sql,array($this->uuid,$this->resTitle,$this->resAltTitle,$this->idAbs,$this->citation,$this->suppinfo,$this->fileformat,
|
||||
$this->projection,$this->datatype,$this->filesize,$this->mdDateSt,$this->timebegin,$this->timeend,$this->geoBox['w'],
|
||||
$this->geoBox['s'],$this->geoBox['n'],$this->geoBox['e'],$this->doi));
|
||||
}
|
||||
$id=$db->lastInsertId('metadata','id');
|
||||
//处理在线资源
|
||||
if ($this->onlineresource) foreach($this->onlineresource as $resource)
|
||||
{
|
||||
$sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)";
|
||||
if (!isset($resource['name'])) $resource['name']='';
|
||||
if (!isset($resource['description'])) $resource['description']='';
|
||||
$db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['name'],$resource['description']));
|
||||
}
|
||||
//处理缩略图
|
||||
|
@ -211,11 +223,7 @@ class ISO19115
|
|||
$r=$db->fetchRow($sql,array($this->uuid));
|
||||
if ($r)
|
||||
{
|
||||
$geonetwork="http://".$_SERVER['SERVER_NAME'];
|
||||
if ($this->view->config)
|
||||
$geonetwork.=$this->view->config->geonetwork->url;
|
||||
else
|
||||
$geonetwork.='/geonetwork/';
|
||||
$geonetwork='http://'.$_SERVER['HTTP_HOST'].'/geonetwork/';
|
||||
$thumb=base64_encode(file_get_contents($geonetwork.'srv/cn/resources.get?access=public&id='.$r->gid.'&fname='.urlencode($this->graph['filename'])));
|
||||
$sql="insert into thumbnail (id,data,filetype,filedesc,filename) values(?,?,?,?,?)";
|
||||
$db->query($sql,array($id,$thumb,$this->graph['filetype'],$this->graph['filedesc'],$this->graph['filename']));
|
||||
|
@ -228,12 +236,16 @@ class ISO19115
|
|||
foreach($keys as $key)
|
||||
{
|
||||
$sql="insert into keyword (id,keyword,keytype) values(?,?,?)";
|
||||
if (!empty($key)) $db->query($sql,array($id,$key,$keytype));
|
||||
try {
|
||||
$db->query($sql,array($id,$key,$keytype));
|
||||
} catch(Exception $e) {
|
||||
//忽略关键词错误
|
||||
}
|
||||
}
|
||||
}
|
||||
//处理数据集序列
|
||||
//M:N relation
|
||||
if ($this->datasetSeries) foreach($this->datasetSeries as $ds)
|
||||
if ($this->datasetSeries) foreach($this->datasetSeries as $ds) if (!empty($ds['seriesName']))
|
||||
{
|
||||
$sql="select id from series where name=?";
|
||||
$sth=$db->prepare($sql);
|
||||
|
@ -249,9 +261,6 @@ class ISO19115
|
|||
$sql="insert into dataseries (id,sid) values(?,?)";
|
||||
$db->query($sql,array($id,$sid));
|
||||
}
|
||||
//处理XML入库
|
||||
$sql="insert into xml (id,data) values(?,?)";
|
||||
$db->query($sql,array($id,$xml));
|
||||
//处理数据分类
|
||||
foreach($this->tpCat as $cat){
|
||||
if (is_numeric($cat)) {
|
||||
|
@ -315,6 +324,10 @@ class ISO19115
|
|||
}
|
||||
}
|
||||
$this->save("../data/import/$this->uuid.xml");
|
||||
//处理XML入库
|
||||
if (!empty($xml)) $this->xml=$xml;
|
||||
$sql="insert into xml (id,data) values(?,?)";
|
||||
$db->query($sql,array($id,$this->xml));
|
||||
} catch (Exception $e) {
|
||||
//数据重复插入,此处忽略所有错误
|
||||
print $this->uuid.' has error: '.$e->getMessage().'<br />';
|
||||
|
@ -322,6 +335,37 @@ class ISO19115
|
|||
$db->setFetchMode($dbmode);
|
||||
}
|
||||
|
||||
//检查元数据的错误信息
|
||||
function validate()
|
||||
{
|
||||
//uuid
|
||||
if (empty($this->uuid)) $this->error[]='错误:数据的UUID不能为空!';
|
||||
if (empty($this->resTitle)) $this->error[]='错误:数据标题不能为空!';
|
||||
if (!is_numeric($this->filesize)) $this->error[]='错误:数据的大小(传输量)必须为数字,单位为MB!';
|
||||
//空间范围
|
||||
if (!is_numeric($this->geoBox['w']) || !is_numeric($this->geoBox['e']) || !is_numeric($this->geoBox['s']) ||!is_numeric($this->geoBox['n']))
|
||||
$this->error[]='错误:数据的空间范围必须为数字格式的经纬度!';
|
||||
//时间范围
|
||||
if (!empty($this->timebegin) && !strtotime($this->timebegin))
|
||||
$this->error[]='错误:数据的开始时间格式不正确!';
|
||||
if (!empty($this->timeend) && !strtotime($this->timeend))
|
||||
$this->error[]='错误:数据的结束时间格式不正确!';
|
||||
//关键词不能有空白(即使关键词类型不一样)
|
||||
foreach($this->keyword as $k1=>$keyt)
|
||||
{
|
||||
foreach($keyt as $k2=>$keyword)
|
||||
{
|
||||
if (empty($keyword)) $this->error[]='错误:数据的关键词不能为空!';
|
||||
}
|
||||
}
|
||||
//联系人必须有email地址?
|
||||
//todo
|
||||
|
||||
//建议有缩略图
|
||||
if (empty($this->graph)) $this->error[]='建议:请提供一张能反应或代表数据的图片(800像素以上)。';
|
||||
return count($this->error);
|
||||
}
|
||||
|
||||
function parse()
|
||||
{
|
||||
$this->resTitle=$this->dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
|
||||
|
@ -335,7 +379,7 @@ class ISO19115
|
|||
//项目支持信息
|
||||
@$this->suppinfo=$this->dom->getElementsByTagName('suppInfo')->item(0)->nodeValue;
|
||||
//DOI,自定义项
|
||||
@$cittype=$this->dom->getElementsByTagName('citIdType')->item(0)->nodeValue;
|
||||
$cittype=$this->dom->getElementsByTagName('citIdType')->item(0)->nodeValue;
|
||||
if ($cittype=='DOI')
|
||||
$this->doi=$this->dom->getElementsByTagName('citId')->item(0)->nodeValue;
|
||||
//数据大小,以MB为单位
|
||||
|
@ -356,14 +400,14 @@ class ISO19115
|
|||
{
|
||||
$this->author[$k]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||||
$this->author[$k]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||||
$this->author[$k]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
@$this->author[$k]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
@$this->author[$k]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||||
$this->author[$k]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||||
$this->author[$k]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||||
@$this->author[$k]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||||
@$this->author[$k]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||||
$this->author[$k]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
|
||||
$this->author[$k]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
|
||||
$this->author[$k]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
|
||||
@$this->author[$k]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||||
$this->author[$k]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||||
@$this->author[$k]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
|
||||
}
|
||||
$cnt=$k+1;
|
||||
|
@ -372,14 +416,14 @@ class ISO19115
|
|||
{
|
||||
$this->author[$cnt+$j]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
@$this->author[$cnt+$j]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||||
@$this->author[$cnt+$j]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$j]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
|
||||
}
|
||||
$cnt+=$j+1;
|
||||
|
@ -388,7 +432,7 @@ class ISO19115
|
|||
{
|
||||
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
@$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||||
|
@ -404,7 +448,7 @@ class ISO19115
|
|||
{
|
||||
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
@$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
|
||||
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
|
||||
|
@ -475,10 +519,7 @@ class ISO19115
|
|||
//在线资源
|
||||
$this->onlineresource[$k]['linkage']=$src->getElementsByTagName('linkage')->item(0)->nodeValue;
|
||||
if ($src->getElementsByTagName('protocol')->item(0)) $this->onlineresource[$k]['protocol']=$src->getElementsByTagName('protocol')->item(0)->nodeValue;
|
||||
if ($src->getElementsByTagName('orName')->item(0))
|
||||
$this->onlineresource[$k]['name']=$src->getElementsByTagName('orName')->item(0)->nodeValue;
|
||||
else
|
||||
$this->onlineresource[$k]['name']='';
|
||||
if ($src->getElementsByTagName('orName')->item(0)) $this->onlineresource[$k]['name']=$src->getElementsByTagName('orName')->item(0)->nodeValue;
|
||||
$this->onlineresource[$k]['description']=$src->getElementsByTagName('orDesc')->item(0)->nodeValue;
|
||||
}
|
||||
}
|
||||
|
@ -515,13 +556,22 @@ class ISO19115
|
|||
}
|
||||
}
|
||||
}
|
||||
//resRefDate
|
||||
$refdates=$this->dom->getElementsByTagName('resRefDate');
|
||||
foreach($refdates as $refdate)
|
||||
{
|
||||
if ($refdate->getElementsByTagName('DateTypCd')->item(0) && $refdate->getElementsByTagName('DateTypCd')->item(0)->hasAttributes() && $refdate->getElementsByTagName('DateTypCd')->item(0)->attributes->getNamedItem('value')->nodeValue=="publication")
|
||||
{
|
||||
$this->refDate=$refdate->getElementsByTagName('refDate')->item(0)->nodeValue;
|
||||
}
|
||||
}
|
||||
//in ISO 19115 draft.
|
||||
$ds=$this->dom->getElementsByTagName('datasetSeries');
|
||||
foreach($ds as $k=>$dataset)
|
||||
{
|
||||
$this->datasetSeries[$k]['seriesName']=$dataset->getElementsByTagName('seriesName')->item(0)->nodeValue;
|
||||
$this->datasetSeries[$k]['issId']=$dataset->getElementsByTagName('issId')->item(0)->nodeValue;
|
||||
$this->datasetSeries[$k]['artPage']=$dataset->getElementsByTagName('artPage')->item(0)->nodeValue;
|
||||
@$this->datasetSeries[$k]['issId']=$dataset->getElementsByTagName('issId')->item(0)->nodeValue;
|
||||
@$this->datasetSeries[$k]['artPage']=$dataset->getElementsByTagName('artPage')->item(0)->nodeValue;
|
||||
}
|
||||
//unsure which one.
|
||||
$ds=$this->dom->getElementsByTagName('Series');
|
||||
|
@ -550,8 +600,8 @@ class ISO19115
|
|||
}
|
||||
//根据mdFileID来判断uuid
|
||||
//如果mdFileID为uuid的组织形式,则进行提取
|
||||
if (strlen($this->mdFileID)==36 && empty($this->uuid))
|
||||
$this->uuid=$this->mdFileID;
|
||||
if (strlen(trim($this->mdFileID))==36 && empty($this->uuid))
|
||||
$this->uuid=trim($this->mdFileID);
|
||||
//仍然没有UUID信息,则创建一个
|
||||
if (empty($this->uuid))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue