function getEntitiesFromCalculation($options)
{
if (isset($options['count']) && $options['count']) {
return elgg_get_entities_from_annotations($options);
}
$db_prefix = $this->db->prefix;
$defaults = array('calculation' => 'sum', 'order_by' => 'annotation_calculation desc');
$options = array_merge($defaults, $options);
$function = sanitize_string(elgg_extract('calculation', $options, 'sum', false));
// you must cast this as an int or it sorts wrong.
$options['selects'][] = 'e.*';
$options['selects'][] = "{$function}(CAST(n_table.value AS signed)) AS annotation_calculation";
// don't need access control because it's taken care of by elgg_get_annotations.
$options['group_by'] = 'n_table.entity_guid';
// do not default to a callback function used in elgg_get_annotation()
if (!isset($options['callback'])) {
$options['callback'] = 'entity_row_to_elggstar';
}
return elgg_get_annotations($options);
}