public function RestfulDataProviderDbQuery::mapDbRowToPublicFields in RESTful 7
Prepares the output array from the database row object.
Parameters
object $row: The database row object.
Return value
array The structured array ready to be formatted.
Overrides RestfulDataProviderDbQueryInterface::mapDbRowToPublicFields
2 calls to RestfulDataProviderDbQuery::mapDbRowToPublicFields()
- RestfulDataProviderDbQuery::index in plugins/
restful/ RestfulDataProviderDbQuery.php - Get a list of entities.
- RestfulDataProviderDbQuery::viewMultiple in plugins/
restful/ RestfulDataProviderDbQuery.php - View a collection of items.
File
- plugins/
restful/ RestfulDataProviderDbQuery.php, line 534 - Contains \RestfulDataProviderDbQuery
Class
- RestfulDataProviderDbQuery
- @file Contains \RestfulDataProviderDbQuery
Code
public function mapDbRowToPublicFields($row) {
if ($this
->getMethod() == \RestfulInterface::GET) {
// For read operations cache the result.
$output = $this->staticCache
->get(__CLASS__ . '::' . __FUNCTION__ . '::' . $this
->getUniqueId($row));
if (isset($output)) {
return $output;
}
}
else {
// Clear the cache if the request is not GET.
$this->staticCache
->clear(__CLASS__ . '::' . __FUNCTION__ . '::' . $this
->getUniqueId($row));
}
$output = array();
// Loop over all the defined public fields.
foreach ($this
->getPublicFields() as $public_field_name => $info) {
$value = NULL;
if ($info['create_or_update_passthrough']) {
// The public field is a dummy one, meant only for passing data upon
// create or update.
continue;
}
// If there is a callback defined execute it instead of a direct mapping.
if ($info['callback']) {
$value = static::executeCallback($info['callback'], array(
$row,
));
}
elseif ($info['property']) {
$value = $row->{$info['property']};
}
// Execute the process callbacks.
if (isset($value) && $info['process_callbacks']) {
foreach ($info['process_callbacks'] as $process_callback) {
$value = static::executeCallback($process_callback, array(
$value,
));
}
}
$output[$public_field_name] = $value;
}
return $output;
}