using right array name and better filter position, refactoring to move funtion to parent class

This commit is contained in:
Jacson Passold 2018-04-04 01:39:18 -03:00
parent 35c143d6bc
commit 8e353e0536
1 changed files with 14 additions and 13 deletions

View File

@ -7,34 +7,35 @@ class Dublin_Core extends Mapper {
public $name = 'Dublin Core';
public $allow_extra_fields = true;
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
public $header = '';
const XML_DC_NAMESPACE = 'http://purl.org/dc/elements/1.1/';
const XML_RDF_NAMESPACE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
public $options = [];
public function rest_response($item_arr, $request) {
if(array_key_exists('field', $item_arr)){ // getting a unique field
$field_mapping = $item_arr['field']['exposer_mapping'];
if(array_key_exists('dublin-core', $field_mapping)) {
$ret = ['dc:'.$field_mapping['dublin-core']['name'] => $item_arr['value']];
return $ret;
$item_arr = ['dc:'.$field_mapping['dublin-core']['name'] => $item_arr['value']];
}
} else { // array of elements
$ret = [];
$item_arr = [];
foreach ($item_arr as $item_field) {
$field_mapping = $item_field['field']['exposer_mapping'];
if(array_key_exists('dublin-core', $field_mapping)) {
$ret['dc:'.$field_mapping['dublin-core']['name']] = $item_field['value'];
$item_arr['dc:'.$field_mapping['dublin-core']['name']] = $item_field['value'];
}
}
$body = json_decode( $request->get_body(), true );
if( // treat special cases TODO better way
is_array($body) && array_key_exists('exposer-type', $body) &&
strtolower($body['exposer-type']) == 'xml'
) {
add_filter('tainacan-exposer-head', [$this, 'tainacan_xml_exposer_head']);
add_filter('tainacan-xml-namespace', function($namespace) {return self::XML_DC_NAMESPACE;});
add_filter('tainacan-xml-root', function($xml) { return $xml->addChild('rdf:Description'); });
}
return $ret;
}
if( // treat special cases TODO better way
is_array($body) && array_key_exists('exposer-type', $body) &&
strtolower($body['exposer-type']) == 'xml'
) {
add_filter('tainacan-exposer-head', [$this, 'tainacan_xml_exposer_head']);
add_filter('tainacan-xml-namespace', function($namespace) {return self::XML_DC_NAMESPACE;});
add_filter('tainacan-xml-root', function($xml) { return $xml->addChild('rdf:Description'); });
}
return $item_arr;
}