From 49e74d749168f844f82494169f0b6987da0e4234 Mon Sep 17 00:00:00 2001 From: icewing Date: Wed, 12 Mar 2008 12:39:55 +0000 Subject: Marcus Povey * Subtyping on annotations and metadata git-svn-id: https://code.elgg.org/elgg/trunk@187 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'engine/lib/annotations.php') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 5a2bed865..91a8dce01 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -143,14 +143,15 @@ * @param int $limit * @param int $offset */ - function get_annotations($entity_id = 0, $entity_type = "", $name = "", $value = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0) + function get_annotations($entity_id = 0, $entity_type = "", $entity_subtype = "", $name = "", $value = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0) { global $CONFIG; $entity_id = (int)$entity_id; $entity_type = sanitise_string(trim($entity_type)); + $entity_subtype = sanitise_string($entity_subtype); $name = sanitise_string(trim($name)); - $value = sanitise_string(trim($value)); + $value = get_metastring_id($value); $owner_id = (int)$owner_id; @@ -162,26 +163,29 @@ $where = array(); if ($entity_id != 0) - $where[] = "entity_id=$entity_id"; + $where[] = "o.entity_id=$entity_id"; if ($entity_type != "") - $where[] = "entity_type='$entity_type'"; + $where[] = "o.entity_type='$entity_type'"; if ($owner_id != 0) - $where[] = "owner_id=$owner_id"; + $where[] = "o.owner_id=$owner_id"; if ($name != "") - $where[] = "name='$name'"; + $where[] = "o.name='$name'"; if ($value != "") - $where[] = "value='$value'"; + $where[] = "o.value='$value'"; + + if ($entity_subtype != "") + $where[] = "s.id=" . get_entity_subtype($entity_id, $entity_type); // add access controls $access = get_access_list(); - $where[] = "(access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))"; + $where[] = "(o.access_id in {$access} or (o.access_id = 0 and o.owner_id = {$_SESSION['id']}))"; // construct query. - $query = "SELECT * from {$CONFIG->dbprefix}annotations where "; + $query = "SELECT * from {$CONFIG->dbprefix}annotations o LEFT JOIN {$CONFIG->dbprefix}entity_subtypes s on o.entity_id=s.entity_id and o.entity_type=s.entity_type where "; for ($n = 0; $n < count($where); $n++) { if ($n > 0) $query .= " and "; @@ -301,7 +305,7 @@ $entity_id = (int)$entity_id; $entity_type = sanitise_string($entity_type); $name = sanitise_string($name); - $value = sanitise_string($value); + $value = get_metastring_id($value); $value_type = sanitise_string($value_type); $owner_id = (int)$owner_id; $access = get_access_list(); -- cgit v1.2.3