private function FrxDrupal::loadEntities in Forena Reports 7.3
Same name and namespace in other branches
- 7.4 plugins/FrxDrupal.inc \FrxDrupal::loadEntities()
Perform a bulk load of entities 100 at a time and then join data back onto the simplexml already created.
Parameters
$type Type of entity being loaded.:
$entity_map Map of entity ids to nodes.:
1 call to FrxDrupal::loadEntities()
- FrxDrupal::sqlData in plugins/
FrxDrupal.inc - Get data based on file data block in the repository.
File
- plugins/
FrxDrupal.inc, line 97 - Provides data blocks for native drupal connections using the default drupal connections.
Class
- FrxDrupal
- @file Provides data blocks for native drupal connections using the default drupal connections.
Code
private function loadEntities($type, $entity_map, $select_fields) {
// Do these 100 at a time for performance reasons
$chunks = array_chunk($entity_map, 100, TRUE);
foreach ($chunks as $chunk) {
$ids = array_keys($chunk);
$data = entity_load($type, $ids);
if ($data) {
foreach ($data as $id => $e) {
// Get node permissions
$access = $type == 'node' ? node_access('view', $e) : TRUE;
if (isset($entity_map[$id])) {
$row_node = $entity_map[$id];
$lang = isset($e->language) ? $e->language : 'und';
// remove elements we don't have access to
if (!$access) {
unset($row_node[0]);
}
else {
foreach ($e as $key => $val) {
if ($val) {
if (strpos($key, 'field_') === 0) {
//$fields = field_get_items('node', $node, $key);
$field = field_view_field($type, $e, $key);
$field['#theme'] = array(
'forena_inline_field',
);
$value = drupal_render($field);
$f = $row_node
->addChild($key, $value);
if (isset($field['#field_type'])) {
$f['type'] = $field['#field_type'];
}
if (isset($field['#field_name'])) {
$f['name'] = $field['#field_name'];
}
}
else {
if (is_array($val) && isset($val[$lang])) {
$tmp = $val[$lang][0];
if (isset($tmp['safe_value'])) {
$row_node
->addChild($key, $tmp['safe_value']);
}
else {
if (isset($tmp['value'])) {
$row_node
->addChild($key, $tmp['value']);
}
}
}
else {
if (is_array($val) && isset($val['und'])) {
$tmp = $val['und'][0];
if (isset($tmp['safe_value'])) {
$row_node
->addChild($key, $tmp['safe_value']);
}
else {
if (isset($tmp['value'])) {
$row_node
->addChild($key, $tmp['value']);
}
}
}
else {
if (is_scalar($val)) {
$row_node
->addChild($key, $val);
}
}
}
}
}
}
// Now add on select fields
if ($select_fields[$id]) {
foreach ($select_fields[$id] as $key => $val) {
if (!isset($row_node->{$key})) {
$row_node
->addChild($key, $val);
}
}
}
}
}
}
}
}
}