aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-14 23:06:51 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-14 23:06:51 +0000
commite60d45a1e8025a10220a42285d3ff17335af5214 (patch)
tree47637729aea23c056f2c503715966712fd08f11d /engine/lib
parent842031dd358282f608c232094422cd281117c21f (diff)
downloadelgg-e60d45a1e8025a10220a42285d3ff17335af5214.tar.gz
elgg-e60d45a1e8025a10220a42285d3ff17335af5214.tar.bz2
Refs #3195. Changed the way annotation calculations are performed. Seems to be working better, but will want to test more before closing.
git-svn-id: http://code.elgg.org/elgg/trunk@9000 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/annotations.php41
-rw-r--r--engine/lib/deprecated-1.8.php8
-rw-r--r--engine/lib/metastrings.php12
3 files changed, 40 insertions, 21 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 1178a079f..7a4e62921 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -386,21 +386,27 @@ function elgg_list_entities_from_annotations($options = array()) {
}
/**
- * Get entities ordered by a mathematical calculation
+ * Get entities ordered by a mathematical calculation on annotation values
+ *
+ * @todo I think at some point this could run through elgg_get_annotations() and pass a the callback
+ * as entity_row_to_elggstar
*
* @param array $options An options array:
- * 'calculation' => The calculation to use. Must be a valid MySQL function.
- * Defaults to sum. Result selected as 'calculated'.
- * 'order_by' => The order for the sorting. Defaults to 'calculated desc'.
+ * 'annotation_calculation' => The calculation to use. Must be a valid MySQL function.
+ * Defaults to sum. Result selected as 'annotation_calculation'.
+ * 'order_by' => The order for the sorting. Defaults to 'calculation desc'.
+ * 'annotation_names' => The names of annotations on the entity.
+ * 'annotation_values' => The values of annotations on the entity.
+ *
+ * 'metadata_names' => The name of metadata on the entity.
+ * 'metadata_values' => The value of metadata on the entitiy.
*
* @return mixed
*/
function elgg_get_entities_from_annotation_calculation($options) {
- global $CONFIG;
-
$defaults = array(
- 'calculation' => 'sum',
- 'order_by' => 'calculated desc',
+ 'calculation' => 'sum',
+ 'order_by' => 'calculation desc'
);
$options = array_merge($defaults, $options);
@@ -408,17 +414,20 @@ function elgg_get_entities_from_annotation_calculation($options) {
$function = sanitize_string(elgg_extract('calculation', $options, 'sum', false));
// you must cast this as an int or it sorts wrong.
- $options['selects'][] = "$function(cast(msv.string as signed)) as calculated";
- $options['selects'][] = "msn.string as value";
- $options['order_by'] = 'calculated desc';
+ $options['selects'][] = 'e.*';
+ $options['selects'][] = "$function(cast(v.string as signed)) as calculation";
// need our own join to get the values.
- $db_prefix = get_config('dbprefix');
- $options['joins'][] = "JOIN {$db_prefix}annotations calc_table on e.guid = calc_table.entity_guid";
- $options['joins'][] = "JOIN {$db_prefix}metastrings msv on calc_table.value_id = msv.id";
- $options['wheres'][] = "calc_table.name_id = n_table.name_id";
+// $options['joins'][] = "JOIN {$db_prefix}metastrings msv ON a.value_id = msv.id";
+// $options['joins'][] = "JOIN {$db_prefix}entities ae ON a.entity_guid = ae.guid";
+
+ $options['wheres'][] = get_access_sql_suffix('n_table');
+// $options['wheres'][] = "e.guid = a.entity_guid";
+ $options['group_by'] = 'n_table.entity_guid';
+
+ $options['callback'] = 'entity_row_to_elggstar';
- return elgg_get_entities_from_annotations($options);
+ return elgg_get_annotations($options);
}
/**
diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php
index 165546d31..27a973601 100644
--- a/engine/lib/deprecated-1.8.php
+++ b/engine/lib/deprecated-1.8.php
@@ -115,7 +115,7 @@ function get_entities_from_annotations_calculate_x($sum = "sum", $entity_type =
$options['limit'] = $limit;
$options['offset'] = $offset;
- $options['order_by'] = "calculated $orderdir";
+ $options['order_by'] = "calculation $orderdir";
$options['count'] = $count;
@@ -179,7 +179,7 @@ function get_entities_from_annotation_count($entity_type = "", $entity_subtype =
$options['limit'] = $limit;
$options['offset'] = $offset;
- $options['order_by'] = "calculated $orderdir";
+ $options['order_by'] = "calculation $orderdir";
$options['count'] = $count;
@@ -241,7 +241,7 @@ function list_entities_from_annotation_count($entity_type = "", $entity_subtype
$options['limit'] = $limit;
- $options['order_by'] = "calculated $orderdir";
+ $options['order_by'] = "calculation $orderdir";
return elgg_get_entities_from_annotation_calculation($options);
}
@@ -3492,7 +3492,7 @@ $asc = false, $fullview = true, $listtypetoggle = false, $pagination = true, $or
$options['limit'] = $limit;
- $options['order_by'] = "calculated $orderdir";
+ $options['order_by'] = "calculation $orderdir";
return elgg_get_entities_from_annotation_calculation($options);
}
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php
index 913d33a7d..604c7f765 100644
--- a/engine/lib/metastrings.php
+++ b/engine/lib/metastrings.php
@@ -406,8 +406,18 @@ function elgg_get_metastring_based_objects($options) {
}
if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) {
+ // evalutate selects
+ if ($options['selects']) {
+ $selects = '';
+ foreach ($options['selects'] as $select) {
+ $selects .= ", $select";
+ }
+ } else {
+ $selects = '';
+ }
+
$query = "SELECT DISTINCT n_table.*, n.string as name,
- v.string as value FROM {$db_prefix}$type n_table";
+ v.string as value{$selects} FROM {$db_prefix}$type n_table";
} else {
$query = "SELECT {$options['metastring_calculation']}(v.string) as calculation FROM {$db_prefix}$type n_table";
}