exposer mapper options

This commit is contained in:
Jacson Passold 2018-04-23 15:50:56 -03:00
parent 0d2a01b80c
commit 8bb1bae3f4
5 changed files with 77 additions and 25 deletions

View File

@ -164,13 +164,13 @@ class Fields extends Repository {
'validation' => v::boolType()
],
'exposer_mapping' => [
'map' => 'meta',
'title' => __('exposer_mapping', 'tainacan'),
'type' => 'array',
'description'=> __('The field mapping options', 'tainacan'),
'on_error' => __('Invalid Field Mapping', 'tainacan'),
'validation' => v::arrayType(),
'default' => []
'map' => 'meta',
'title' => __('exposer_mapping', 'tainacan'),
'type' => 'array',
'description'=> __('The field mapping options', 'tainacan'),
'on_error' => __('Invalid Field Mapping', 'tainacan'),
//'validation' => v::arrayType(),
'default' => []
],
]);
}
@ -501,11 +501,7 @@ class Fields extends Repository {
'field_type' => 'Tainacan\Field_Types\Core_Description',
'status' => 'publish',
'exposer_mapping' => [
'dublin-core' => [
'name' => 'description',
'label' => __('Description', 'tainacan'),
'URI' => 'http://purl.org/dc/terms/description',
]
'dublin-core' => 'description'
]
],
'core_title' => [
@ -515,11 +511,7 @@ class Fields extends Repository {
'field_type' => 'Tainacan\Field_Types\Core_Title',
'status' => 'publish',
'exposer_mapping' => [
'dublin-core' => [
'name' => 'title',
'label' => __('Title', 'tainacan'),
'URI' => 'http://purl.org/dc/terms/title',
]
'dublin-core' => 'title'
]
]
];

View File

@ -118,7 +118,10 @@ class Exposers {
$ret = $item_arr;
$field_mapping = $item_arr['field']['exposer_mapping'];
if(array_key_exists($mapper->slug, $field_mapping)) {
$ret = [$mapper->prefix.$field_mapping[$mapper->slug]['name'].$mapper->sufix => $item_arr['value']];
if(is_array($mapper->options) && !array_key_exists( $field_mapping[$mapper->slug], $mapper->options) ) {
throw new \Exception('Invalid Mapper Option');
}
$ret = [$mapper->prefix.$field_mapping[$mapper->slug].$mapper->sufix => $item_arr['value']]; //TODO Validate option
} else if($mapper->slug == 'value') {
$ret = [$item_arr['field']['name'] => $item_arr['value']];
}

View File

@ -9,7 +9,68 @@ class Dublin_Core extends Mapper {
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
public $header = '<?xml version="1.0"?><!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" ></rdf:RDF>';
public $prefix = 'dc:';
public $options = [];
public $options = [
'contributor' => [
'URI' => 'http://purl.org/dc/elements/1.1/contributor',
'label' => 'Contributor'
],
'coverage' => [
'URI' => 'http://purl.org/dc/elements/1.1/coverage',
'label' => 'Coverage'
],
'creator' => [
'URI' => 'http://purl.org/dc/elements/1.1/creator',
'label' => 'Creator'
],
'date' => [
'URI' => 'http://purl.org/dc/elements/1.1/date',
'label' => 'Date'
],
'description' => [
'URI' => 'http://purl.org/dc/elements/1.1/description',
'label' => 'Description'
],
'format' => [
'URI' => 'http://purl.org/dc/elements/1.1/format',
'label' => 'Format'
],
'identifier' => [
'URI' => 'http://purl.org/dc/elements/1.1/identifier',
'label' => 'Identifier'
],
'language' => [
'URI' => 'http://purl.org/dc/elements/1.1/language',
'label' => 'Language'
],
'publisher' => [
'URI' => 'http://purl.org/dc/elements/1.1/publisher',
'label' => 'Publisher'
],
'relation' => [
'URI' => 'http://purl.org/dc/elements/1.1/relation',
'label' => 'Relation'
],
'rights' => [
'URI' => 'http://purl.org/dc/elements/1.1/rights',
'label' => 'Rights'
],
'source' => [
'URI' => 'http://purl.org/dc/elements/1.1/source',
'label' => 'Source'
],
'subject' => [
'URI' => 'http://purl.org/dc/elements/1.1/subject',
'label' => 'Subject'
],
'title' => [
'URI' => 'http://purl.org/dc/elements/1.1/title',
'label' => 'Title'
],
'type' => [
'URI' => 'http://purl.org/dc/elements/1.1/type',
'label' => 'Type'
]
];
/** XML especial case **/
const XML_DC_NAMESPACE = 'http://purl.org/dc/elements/1.1/';

View File

@ -7,7 +7,7 @@ abstract class Mapper {
public $name = null;
public $allow_extra_fields = true;
public $context_url = null;
public $opstions = false;
public $options = false;
public $prefix = '';
public $sufix = '';
public $header = false;

View File

@ -31,11 +31,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'field_type' => $type,
'exposer_mapping' => [
'dublin-core' => [
'name' => 'language',
'label' => 'language',
'URI' => 'http://purl.org/dc/terms/language',
]
'dublin-core' => 'language'
]
),
true,