function _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 from the database.

$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 815

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($data->{$field});
        }
        else {
            $object->{$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($data->{$field});
                }
            }
        }
    }
    return $object;
}