fix #409, 元数据中添加错误检查
This commit is contained in:
parent
f3a5313a56
commit
0128cfec55
|
@ -122,6 +122,7 @@ class ISO19115
|
|||
private $dom;
|
||||
public $keytypecode=array(1=>'discipline','place','stratum','temporal','theme');
|
||||
public $author;
|
||||
public $error=array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
@ -163,9 +164,9 @@ 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));
|
||||
|
@ -226,7 +227,11 @@ class ISO19115
|
|||
foreach($keys as $key)
|
||||
{
|
||||
$sql="insert into keyword (id,keyword,keytype) values(?,?,?)";
|
||||
$db->query($sql,array($id,$key,$keytype));
|
||||
try {
|
||||
$db->query($sql,array($id,$key,$keytype));
|
||||
} catch(Exception $e) {
|
||||
//忽略关键词错误
|
||||
}
|
||||
}
|
||||
}
|
||||
//处理数据集序列
|
||||
|
@ -320,6 +325,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;
|
||||
|
|
Loading…
Reference in New Issue