return remove_private_setting($this->getGUID(), $name);
}
+ /**
+ * 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.
*
* @return int
*/
function countAnnotations($name = "") {
- return count_annotations($this->getGUID(), "", "", $name);
+ return $this->getAnnotationCalculation($name, 'count');
}
/**
* @return int
*/
function getAnnotationsAvg($name) {
- return get_annotations_avg($this->getGUID(), "", "", $name);
+ return $this->getAnnotationCalculation($name, 'avg');
}
/**
* @return int
*/
function getAnnotationsSum($name) {
- return get_annotations_sum($this->getGUID(), "", "", $name);
+ return $this->getAnnotationCalculation($name, 'sum');
}
/**
* @return int
*/
function getAnnotationsMin($name) {
- return get_annotations_min($this->getGUID(), "", "", $name);
+ return $this->getAnnotationCalculation($name, 'min');
}
/**
* @return int
*/
function getAnnotationsMax($name) {
- return get_annotations_max($this->getGUID(), "", "", $name);
+ return $this->getAnnotationCalculation($name, 'max');
}
/**
$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');
}
}
$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');
}
}