aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-06-04 14:37:50 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-06-04 14:37:50 +0000
commite56e8dfe2b4182ef59ce48bc80f4aa566dc3a4a8 (patch)
tree589fe0e468004a9e77f13d081d2ae85ab0870b65
parent38f3a3c0b320906005eb8399315caa4dd8ab419d (diff)
downloadelgg-e56e8dfe2b4182ef59ce48bc80f4aa566dc3a4a8.tar.gz
elgg-e56e8dfe2b4182ef59ce48bc80f4aa566dc3a4a8.tar.bz2
Closes #998 : Operator selection on get by metadata multi
git-svn-id: https://code.elgg.org/elgg/trunk@3318 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/metadata.php17
1 files changed, 11 insertions, 6 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index da189fe30..ebc425f17 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -602,10 +602,11 @@
* @param int $offset
* @param string $order_by Optional ordering.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * @param string $meta_array_operator Operator used for joining the metadata array together
* @return int|array List of ElggEntities, or the total number if count is set to false
*/
- function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
+ function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false, $meta_array_operator = 'and')
{
global $CONFIG;
@@ -616,17 +617,21 @@
$where = array();
$mindex = 1;
- $join = "";
+ $join = "";
+ $metawhere = array();
+ $meta_array_operator = sanitise_string($meta_array_operator);
foreach($meta_array as $meta_name => $meta_value) {
$meta_n = get_metastring_id($meta_name);
$meta_v = get_metastring_id($meta_value);
$join .= " JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid ";
- if ($meta_name!=="")
+ /*if ($meta_name!=="")
$where[] = "m{$mindex}.name_id='$meta_n'";
if ($meta_value!=="")
- $where[] = "m{$mindex}.value_id='$meta_v'";
+ $where[] = "m{$mindex}.value_id='$meta_v'";*/
+ $metawhere[] = "(m{$mindex}.name_id='$meta_n' AND m{$mindex}.value_id='$meta_v')";
$mindex++;
- }
+ }
+ $where[] = "(".implode($meta_array_operator, $metawhere).")";
$entity_type = sanitise_string($entity_type);
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);