]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5564 count works with elgg_get_entities_from_annotation_calculation()
authorcash <cash.costello@gmail.com>
Fri, 31 May 2013 01:04:09 +0000 (21:04 -0400)
committercash <cash.costello@gmail.com>
Fri, 31 May 2013 01:04:09 +0000 (21:04 -0400)
engine/lib/annotations.php
engine/lib/metastrings.php
engine/tests/api/entity_getter_functions.php

index 81755f16938da78ab41c192c8c669805768115a6..124e67e0f1d47eda21761a5aba27d5b1694d7245 100644 (file)
@@ -419,8 +419,8 @@ function elgg_list_entities_from_annotations($options = array()) {
 function elgg_get_entities_from_annotation_calculation($options) {
        $db_prefix = elgg_get_config('dbprefix');
        $defaults = array(
-               'calculation'   =>      'sum',
-               'order_by'              =>      'annotation_calculation desc'
+               'calculation' => 'sum',
+               'order_by' => 'annotation_calculation desc'
        );
 
        $options = array_merge($defaults, $options);
@@ -457,6 +457,12 @@ function elgg_get_entities_from_annotation_calculation($options) {
  * @return string
  */
 function elgg_list_entities_from_annotation_calculation($options) {
+       $defaults = array(
+               'calculation' => 'sum',
+               'order_by' => 'annotation_calculation desc'
+       );
+       $options = array_merge($defaults, $options);
+
        return elgg_list_entities($options, 'elgg_get_entities_from_annotation_calculation');
 }
 
index 39a81c6d039f77139514cd67940e680e642e729f..57d876c062a979389fe52163768b8242801d0886 100644 (file)
@@ -425,7 +425,7 @@ function elgg_get_metastring_based_objects($options) {
                $wheres[] = get_access_sql_suffix('n_table');
        }
 
-       if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) {
+       if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) {
                $selects = array_unique($selects);
                // evalutate selects
                $select_str = '';
@@ -436,6 +436,9 @@ function elgg_get_metastring_based_objects($options) {
                }
 
                $query = "SELECT DISTINCT n_table.*{$select_str} FROM {$db_prefix}$type n_table";
+       } elseif ($options['count']) {
+               // count is over the entities
+               $query = "SELECT count(DISTINCT e.guid) as calculation FROM {$db_prefix}$type n_table";
        } else {
                $query = "SELECT {$options['metastring_calculation']}(v.string) as calculation FROM {$db_prefix}$type n_table";
        }
@@ -464,7 +467,7 @@ function elgg_get_metastring_based_objects($options) {
                        $defaults['order_by']);
        }
 
-       if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) {
+       if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) {
                if (isset($options['group_by'])) {
                        $options['group_by'] = sanitise_string($options['group_by']);
                        $query .= " GROUP BY {$options['group_by']}";
index 7bf8ef04a101b70cc5494f842c4c085cbeeceedb..0492b1fb09dfb2562bfd9130cdf94d4a61cf3be4 100644 (file)
@@ -2755,7 +2755,7 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
                        'calculation' => 'count',
                        'count' => true,
                );
-               $count = (int)elgg_get_entities_from_annotation_calculation($options);
+               $count = elgg_get_entities_from_annotation_calculation($options);
                $this->assertEqual(1, $count);
        }