private function FrxDrupal::loadEntities in Forena Reports 7.4
Same name and namespace in other branches
- 7.3 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 152 - 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, $display = array()) {
// 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])) {
foreach ($entity_map[$id] as $entry) {
$row_node = $entry;
$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 && !isset($row_node->{$key})) {
if (strpos($key, 'field_') === 0) {
//$fields = field_get_items('node', $node, $key);
if (!$display) {
$display = 'default';
}
$field = field_view_field($type, $e, $key, $display);
$field['#theme'] = array(
'forena_inline_field',
);
$value = drupal_render($field);
$f = $row_node
->addChild($key, htmlspecialchars($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 = reset($val[$lang]);
if (isset($tmp['safe_value'])) {
$row_node
->addChild($key, htmlspecialchars($tmp['safe_value']));
}
else {
if (isset($tmp['value']) && !is_array($tmp['value'])) {
$row_node
->addChild($key, htmlspecialchars($tmp['value']));
}
}
}
else {
if (is_array($val) && isset($val['und'])) {
$tmp = $val['und'][0];
if (isset($tmp['safe_value'])) {
$row_node
->addChild($key, htmlspecialchars($tmp['safe_value']));
}
else {
if (isset($tmp['value'])) {
$row_node
->addChild($key, htmlspecialchars($tmp['value']));
}
}
}
else {
if (is_scalar($val)) {
$row_node
->addChild($key, htmlspecialchars($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, htmlspecialchars($val));
}
}
}
}
}
}
}
}
}
}