From a530bcee3645c07c0ca50e478392122e53d7e1ec Mon Sep 17 00:00:00 2001 From: icewing Date: Wed, 12 Mar 2008 15:01:23 +0000 Subject: Marcus Povey * Multiple searches. git-svn-id: https://code.elgg.org/elgg/trunk@189 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metadata.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index dc657ec34..202ef60ad 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -242,6 +242,9 @@ * * @param int $entity_id * @param string $entity_type + * @param string $entity_subtype + * @param mixed $name Either a string or an array of terms. + * @param mixed $value Either a string or an array of terms. * @param int $owner_id * @param string $order_by * @param int $limit @@ -255,8 +258,15 @@ $entity_id = (int)$entity_id; $entity_type = sanitise_string(trim($entity_type)); $entity_subtype = sanitise_string($entity_subtype); - $name = sanitise_string(trim($name)); - $value = get_metastring_id($value); + + if (!is_array($name)) + $name = sanitise_string($name); + if (!is_array($value)) + $value = get_metastring_id($value); + + if ((is_array($name)) && (is_array($value)) && (count($name)!=count($value))) + throw new InvalidParameterException("Name and value arrays not equal."); + $value_type = sanitise_string(trim($value_type)); $owner_id = (int)$owner_id; $order_by = sanitise_string($order_by); @@ -278,10 +288,16 @@ if ($owner_id != 0) $where[] = "o.owner_id=$owner_id"; - if ($name != "") + if (is_array($name)) { + foreach ($name as $n) + $where[]= "o.name='$n'"; + } else if ($name != "") $where[] = "o.name='$name'"; - - if ($value != "") + + if (is_array($value)) { + foreach ($value as $v) + $where[]= "o.value='$v'"; + } else if ($value != "") $where[] = "o.value='$value'"; if ($value_type != "") @@ -314,6 +330,9 @@ * * @param int $entity_id * @param string $entity_type + * @param string $entity_subtype + * @param mixed $name Either a string or an array of terms. + * @param mixed $value Either a string or an array of terms. * @param int $owner_id * @param string $order_by * @param int $limit -- cgit v1.2.3