2012-12-19 09:38:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Metadata 元数据
|
|
|
|
*/
|
|
|
|
class Metadata
|
|
|
|
{
|
|
|
|
public $db; //PDO
|
|
|
|
|
|
|
|
public $tbl_Metadata = "metadata"; //元数据数据表
|
|
|
|
public $tbl_Metadata_temp = "metadata_temp"; //新元数据缓存表
|
|
|
|
|
|
|
|
public $SavePath = "../data/metadata_temp/"; //临时元数据保存地址
|
|
|
|
public $SaveMethod = "JSON"; //临时元数据保存格式 XML or JSON
|
|
|
|
public $XMLNamespace = "metadata_temp"; //临时元数据XML的根域名称
|
|
|
|
|
|
|
|
public $MetadataFields; //元数据涉及的字段
|
|
|
|
|
|
|
|
|
|
|
|
function __construct($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
|
|
|
|
$this->_init_Fields();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始化简化版元数据的字段
|
|
|
|
function _init_Fields(){
|
|
|
|
|
|
|
|
$this->MetadataFields = array(
|
|
|
|
|
|
|
|
//中文标题
|
2012-12-21 09:17:32 +00:00
|
|
|
'title' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '中文标题',
|
2012-12-21 09:17:32 +00:00
|
|
|
'FieldName' => 'title', //元数据表的字段名称
|
|
|
|
'FieldName_temp' => 'title', //临时元数据字段名称和表单收集名称
|
2012-12-19 09:38:56 +00:00
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//英文标题
|
2012-12-21 09:17:32 +00:00
|
|
|
'title_en' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '英文标题',
|
|
|
|
'FieldName' => 'title_en',
|
|
|
|
'FieldName_temp' => 'title_en',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//摘要
|
2012-12-21 09:17:32 +00:00
|
|
|
'description' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '摘要',
|
|
|
|
'FieldName' => 'description',
|
|
|
|
'FieldName_temp' => 'description',
|
|
|
|
'Type' => 'text',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//开始时间
|
2012-12-21 09:17:32 +00:00
|
|
|
'timebegin' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '开始时间',
|
|
|
|
'FieldName' => 'timebegin',
|
|
|
|
'FieldName_temp' => 'timebegin',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 24,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//结束时间
|
2012-12-21 09:17:32 +00:00
|
|
|
'timeend' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '结束时间',
|
|
|
|
'FieldName' => 'timeend',
|
|
|
|
'FieldName_temp' => 'timeend',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 24,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//空间范围-东
|
2012-12-21 09:17:32 +00:00
|
|
|
'east' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '东',
|
|
|
|
'FieldName' => 'east',
|
|
|
|
'FieldName_temp' => 'east',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 20,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//空间范围-南
|
2012-12-21 09:17:32 +00:00
|
|
|
'south' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '南',
|
|
|
|
'FieldName' => 'south',
|
|
|
|
'FieldName_temp' => 'south',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 20,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//空间范围-西
|
2012-12-21 09:17:32 +00:00
|
|
|
'west' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '西',
|
|
|
|
'FieldName' => 'west',
|
|
|
|
'FieldName_temp' => 'west',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 20,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//空间范围-北
|
2012-12-21 09:17:32 +00:00
|
|
|
'north' => array(
|
2012-12-19 09:38:56 +00:00
|
|
|
'Title' => '北',
|
|
|
|
'FieldName' => 'north',
|
|
|
|
'FieldName_temp' => 'north',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 20,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
2012-12-21 09:17:32 +00:00
|
|
|
//数据引用方式
|
|
|
|
'citation' => array(
|
|
|
|
'Title' => '数据引用方式',
|
|
|
|
'FieldName' => 'citation',
|
|
|
|
'FieldName_temp' => 'citation',
|
|
|
|
'Type' => 'varchar',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//参考文献
|
|
|
|
'reference' => array(
|
|
|
|
'Title' => '数据参考文献',
|
|
|
|
'FieldName' => 'reference',
|
|
|
|
'FieldName_temp' => 'reference',
|
|
|
|
'Type' => 'array',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true
|
|
|
|
),
|
|
|
|
|
|
|
|
//联系人
|
|
|
|
'contact' => array(
|
|
|
|
'Title' => '联系人',
|
|
|
|
'FieldName' => 'contact',
|
|
|
|
'FieldName_temp' => 'contact',
|
|
|
|
'Type' => 'array',
|
|
|
|
'MaxLength' => 200,
|
|
|
|
'Required' => true,
|
|
|
|
'options' => array(
|
|
|
|
"数据作者",
|
|
|
|
"资源提供者",
|
|
|
|
"数据服务联系人"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
2012-12-19 09:38:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}//_init_Fields()
|
|
|
|
|
|
|
|
//记录
|
|
|
|
function Record($uid,$data,$uuid=''){
|
|
|
|
|
|
|
|
if(!is_array($data) || count($data)<1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = "";
|
|
|
|
|
|
|
|
if($this->SaveMethod == "XML")
|
|
|
|
{
|
|
|
|
$content = $this->RecordXML($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if($this->SaveMethod == "JSON")
|
|
|
|
{
|
|
|
|
$content = $this->RecordJSON($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$update = 0;
|
|
|
|
|
|
|
|
if(empty($uuid))
|
|
|
|
{
|
|
|
|
include_once("uuid.php");
|
|
|
|
@$unqid = new uuid();
|
|
|
|
$uuid = @$unqid->toString();
|
|
|
|
}else{
|
|
|
|
$update = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加一条新记录
|
|
|
|
if($update == 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
$temp = array(
|
|
|
|
"uuid" => $uuid,
|
|
|
|
"userid" => $uid,
|
|
|
|
"content" => $content,
|
|
|
|
);
|
|
|
|
|
|
|
|
if($this->db->insert($this->tbl_Metadata_temp,$temp))
|
|
|
|
{
|
|
|
|
return $uuid;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}//update == 0
|
|
|
|
|
|
|
|
//编辑或者更新已存在的记录
|
|
|
|
else{
|
|
|
|
|
|
|
|
$temp = array(
|
|
|
|
"content" => $content,
|
|
|
|
"ts_update" => 'now()'
|
|
|
|
);
|
|
|
|
|
|
|
|
$whereSql = "userid=$uid AND uuid='$uuid'";
|
|
|
|
|
|
|
|
if($this->db->update($this->tbl_Metadata_temp,$temp,$whereSql))
|
|
|
|
{
|
|
|
|
return $uuid;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}//update == 1
|
|
|
|
|
|
|
|
}//Record()
|
|
|
|
|
|
|
|
//返回XML内容
|
|
|
|
function RecordXML($data){
|
|
|
|
|
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
|
|
$dom->formatOutput = true;
|
|
|
|
|
|
|
|
$rootelement =$dom->createElement($this->XMLNamespace);
|
|
|
|
|
|
|
|
foreach($data as $dk=>$dv)
|
|
|
|
{
|
|
|
|
foreach($this->MetadataFields as $k=>$v)
|
|
|
|
{
|
|
|
|
if($dk == $v['FieldName'])
|
|
|
|
{
|
|
|
|
$nod = $dom->createElement($v['FieldName'], $dv);
|
|
|
|
$rootelement->appendChild($nod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$dom->appendChild($rootelement);
|
|
|
|
|
|
|
|
return $dom->saveHTML();
|
|
|
|
}//RecordXML
|
|
|
|
|
|
|
|
//返回JSON内容
|
|
|
|
function RecordJSON($data)
|
|
|
|
{
|
|
|
|
|
|
|
|
$content = json_encode($data);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
|
|
|
|
}//RecordJSON
|
|
|
|
|
|
|
|
}
|