diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-12 23:29:36 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-12 23:29:36 +0000 |
commit | b8996ea6be1b51de7c1567905b6c1688a4e81495 (patch) | |
tree | d426e2d9d098bd8c30843fd163011f651c270da9 | |
parent | e1f6f69e639881496a10a1888b66976c1f581e98 (diff) | |
download | elgg-b8996ea6be1b51de7c1567905b6c1688a4e81495.tar.gz elgg-b8996ea6be1b51de7c1567905b6c1688a4e81495.tar.bz2 |
Refs #650. Replaced count_annotations().
git-svn-id: http://code.elgg.org/elgg/trunk@8188 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/classes/ElggEntity.php | 32 | ||||
-rw-r--r-- | views/default/core/river/footer.php | 2 |
2 files changed, 26 insertions, 8 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 7bed1af7c..ea2a329d9 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -490,6 +490,22 @@ abstract class ElggEntity extends ElggData implements } /** + * Helper function to return annotation calculation results + * + * @param string $name The annotation name. + * @param string $calculation A valid MySQL function to run its values through + */ + private function getAnnotationCalculation($name, $calculation) { + $options = array( + 'guid' => $this->getGUID(), + 'annotation_name' => $name, + 'annotation_calculation' => $calculation + ); + + return elgg_get_annotations($options); + } + + /** * Adds an annotation to an entity. * * @warning By default, annotations are private. @@ -565,7 +581,7 @@ abstract class ElggEntity extends ElggData implements * @return int */ function countAnnotations($name = "") { - return count_annotations($this->getGUID(), "", "", $name); + return $this->getAnnotationCalculation($name, 'count'); } /** @@ -576,7 +592,7 @@ abstract class ElggEntity extends ElggData implements * @return int */ function getAnnotationsAvg($name) { - return get_annotations_avg($this->getGUID(), "", "", $name); + return $this->getAnnotationCalculation($name, 'avg'); } /** @@ -587,7 +603,7 @@ abstract class ElggEntity extends ElggData implements * @return int */ function getAnnotationsSum($name) { - return get_annotations_sum($this->getGUID(), "", "", $name); + return $this->getAnnotationCalculation($name, 'sum'); } /** @@ -598,7 +614,7 @@ abstract class ElggEntity extends ElggData implements * @return int */ function getAnnotationsMin($name) { - return get_annotations_min($this->getGUID(), "", "", $name); + return $this->getAnnotationCalculation($name, 'min'); } /** @@ -609,7 +625,7 @@ abstract class ElggEntity extends ElggData implements * @return int */ function getAnnotationsMax($name) { - return get_annotations_max($this->getGUID(), "", "", $name); + return $this->getAnnotationCalculation($name, 'max'); } /** @@ -622,10 +638,11 @@ abstract class ElggEntity extends ElggData implements $type = $this->getType(); $params = array('entity' => $this); $number = elgg_trigger_plugin_hook('comments:count', $type, $params, false); + if ($number) { return $number; } else { - return count_annotations($this->getGUID(), "", "", "generic_comment"); + return $this->getAnnotationCalculation('generic_comment', 'count'); } } @@ -639,10 +656,11 @@ abstract class ElggEntity extends ElggData implements $type = $this->getType(); $params = array('entity' => $this); $number = elgg_trigger_plugin_hook('likes:count', $type, $params, false); + if ($number) { return $number; } else { - return count_annotations($this->getGUID(), "", "", "likes"); + return $this->getAnnotationCalculation('likes', 'count'); } } diff --git a/views/default/core/river/footer.php b/views/default/core/river/footer.php index 04f7d8daa..ee9d5dc58 100644 --- a/views/default/core/river/footer.php +++ b/views/default/core/river/footer.php @@ -11,7 +11,7 @@ if ($item->annotation_id != 0 || !$object) { return true; } -$comment_count = count_annotations($object->getGUID(), '', '', 'generic_comment'); +$comment_count = $object->countComments(); $options = array( 'guid' => $object->getGUID(), |