aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-10 12:29:40 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-10 12:29:40 +0000
commit5cdc89efc54310bb6b60b47d9cd9fb1ef9bc6b90 (patch)
treec59828cd709a15eeefc6cf5c2dd61819b0f06466
parentdab73343aa7e5b6a46d9094bf5b39522e769392f (diff)
downloadelgg-5cdc89efc54310bb6b60b47d9cd9fb1ef9bc6b90.tar.gz
elgg-5cdc89efc54310bb6b60b47d9cd9fb1ef9bc6b90.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Simple maths functions added git-svn-id: https://code.elgg.org/elgg/trunk@132 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/annotations.php92
-rw-r--r--engine/lib/sites.php24
2 files changed, 96 insertions, 20 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 4c1d15cb0..3a950568f 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -326,6 +326,98 @@
}
/**
+ * Return the sum of a given integer annotation.
+ *
+ * @param $object_id int
+ * @param $object_type string
+ * @param $name string
+ */
+ function get_annotations_sum($object_id, $object_type, $name)
+ {
+ global $CONFIG;
+
+ $object_id = (int)$object_id;
+ $object_type = sanitise_string($object_type);
+ $name = santitise_string($name);
+
+ $row = get_data_row("SELECT sum(value) as sum from {$CONFIG->dbprefix}annotations where object_id=$object_id and object_type='$object_type' and value_type='integer' and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))");
+
+ if ($row)
+ return $row->sum;
+
+ return false;
+ }
+
+ /**
+ * Return the max of a given integer annotation.
+ *
+ * @param $object_id int
+ * @param $object_type string
+ * @param $name string
+ */
+ function get_annotations_max($object_id, $object_type, $name)
+ {
+ global $CONFIG;
+
+ $object_id = (int)$object_id;
+ $object_type = sanitise_string($object_type);
+ $name = santitise_string($name);
+
+ $row = get_data_row("SELECT max(value) as max from {$CONFIG->dbprefix}annotations where object_id=$object_id and object_type='$object_type' and value_type='integer' and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))");
+
+ if ($row)
+ return $row->max;
+
+ return false;
+ }
+
+ /**
+ * Return the minumum of a given integer annotation.
+ *
+ * @param $object_id int
+ * @param $object_type string
+ * @param $name string
+ */
+ function get_annotations_min($object_id, $object_type, $name)
+ {
+ global $CONFIG;
+
+ $object_id = (int)$object_id;
+ $object_type = sanitise_string($object_type);
+ $name = santitise_string($name);
+
+ $row = get_data_row("SELECT min(value) as min from {$CONFIG->dbprefix}annotations where object_id=$object_id and object_type='$object_type' and value_type='integer' and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))");
+
+ if ($row)
+ return $row->min;
+
+ return false;
+ }
+
+ /**
+ * Return the average of a given integer annotation.
+ *
+ * @param $object_id int
+ * @param $object_type string
+ * @param $name string
+ */
+ function get_annotations_avg($object_id, $object_type, $name)
+ {
+ global $CONFIG;
+
+ $object_id = (int)$object_id;
+ $object_type = sanitise_string($object_type);
+ $name = santitise_string($name);
+
+ $row = get_data_row("SELECT avg(value) as avg from {$CONFIG->dbprefix}annotations where object_id=$object_id and object_type='$object_type' and value_type='integer' and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))");
+
+ if ($row)
+ return $row->avg;
+
+ return false;
+ }
+
+ /**
* Delete a given annotation.
*
* @param $id int The id
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index e8c17b34c..546ef9161 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -517,11 +517,7 @@
* @param string $name
* @param int $site_id
*/
- function get_site_annotations_avg($name, $site_id)
- {
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
- }
+ function get_site_annotations_avg($name, $site_id) { return get_annotations_avg($object_id, $object_type, $name); }
/**
* Get the sum of integer type annotations of a given type.
@@ -529,11 +525,7 @@
* @param string $name
* @param int $site_id
*/
- function get_site_annotations_sum($name, $site_id)
- {
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
- }
+ function get_site_annotations_sum($name, $site_id) { return get_annotations_sum($object_id, $object_type, $name); }
/**
* Get the min of integer type annotations of a given type.
@@ -541,11 +533,7 @@
* @param string $name
* @param int $site_id
*/
- function get_site_annotations_min($name, $site_id)
- {
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
- }
+ function get_site_annotations_min($name, $site_id) { return get_annotations_min($object_id, $object_type, $name); }
/**
* Get the max of integer type annotations of a given type.
@@ -553,11 +541,7 @@
* @param string $name
* @param int $site_id
*/
- function get_site_annotations_max($name, $site_id)
- {
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
- }
+ function get_site_annotations_max($name, $site_id) { return get_annotations_max($object_id, $object_type, $name); }
/**
* Remove all site annotations, or site annotations of a given type.