private function TripalContentService_v0_1::sanitizeFieldKeys
3.x TripalContentService_v0_1.inc | private TripalContentService_v0_1::sanitizeFieldKeys($resource, $value, $bundle, $service_path) |
Rewrites the keys of a field's items array for use with web services.
1 call to TripalContentService_v0_1::sanitizeFieldKeys()
- TripalContentService_v0_1::addEntityField in tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc - Adds the field as a property of the entity resource.
File
- tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc, line 426
Class
Code
private function sanitizeFieldKeys($resource, $value, $bundle, $service_path) {
// If the entity is set to hide fields that have no values then we
// want to honor that in the web services too.
$hide_fields = tripal_get_bundle_variable('hide_empty_field', $bundle->id, 'hide');
$new_value = '';
// If the value is an array rather than a scalar then map the sub elements
// to controlled vocabulary terms.
if (is_array($value)) {
$temp = array();
foreach ($value as $k => $v) {
// exclude fields that have no values so we can hide them
if (!isset($v) and $hide_fields == 'hide') {
continue;
}
$matches = array();
if (preg_match('/^(.+):(.+)$/', $k, $matches)) {
$vocabulary = $matches[1];
$accession = $matches[2];
$term = tripal_get_term_details($vocabulary, $accession);
$key = $this->addContextTerm($resource, $term, array('lowercase', 'spacing'));
if (is_array($v)) {
$temp[$key] = $this->sanitizeFieldKeys($resource, $v, $bundle, $service_path);
}
else {
$temp[$key] = $v;
}
$term['name'] = $key;
}
else {
// TODO: this is an error, if we get here then we have
// a key that isn't using the proper format... what to do?
}
}
$new_value = $temp;
// Recurse through the values array and set the entity elements
// and add the fields to the context.
$this->sanitizeFieldEntity($new_value, $service_path);
}
else {
$new_value = $value;
}
return $new_value;
}