function _ctools_export_unpack_object in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 includes/export.inc \_ctools_export_unpack_object()
Unpack data loaded from the database onto an object.
Parameters
$schema: The schema from drupal_get_schema().
$data: The data as loaded by db_fetch_object().
$object: If an object, data will be unpacked onto it. If a string an object of that type will be created.
2 calls to _ctools_export_unpack_object()
- ctools_export_load_object in includes/
export.inc - Load some number of exportable objects.
- ctools_export_unpack_object in includes/
export.inc - Unpack data loaded from the database onto an object.
File
- includes/
export.inc, line 599 - Contains code to make it easier to have exportable objects.
Code
function _ctools_export_unpack_object($schema, $data, $object = 'stdClass') {
if (is_string($object)) {
if (class_exists($object)) {
$object = new $object();
}
else {
$object = new stdClass();
}
}
// Go through our schema and build correlations.
foreach ($schema['fields'] as $field => $info) {
if (isset($data->{$field})) {
$object->{$field} = empty($info['serialize']) ? $data->{$field} : unserialize(db_decode_blob($data->{$field}));
}
else {
$data->{$field} = NULL;
}
}
if (isset($schema['join'])) {
foreach ($schema['join'] as $join_key => $join) {
$join_schema = ctools_export_get_schema($join['table']);
if (!empty($join['load'])) {
foreach ($join['load'] as $field) {
$info = $join_schema['fields'][$field];
$object->{$field} = empty($info['serialize']) ? $data->{$field} : unserialize(db_decode_blob($data->{$field}));
}
}
}
}
return $object;
}