aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-21 17:08:35 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-21 17:08:35 +0000
commitf48adf4356dccf8d7769e12421a6ca4fdf6925dc (patch)
treeb188b5b74230b1f6122f392a6d4c8ad4de269586 /engine
parent1bdab3286dba42516ea49ba047943c028bbc250a (diff)
downloadelgg-f48adf4356dccf8d7769e12421a6ca4fdf6925dc.tar.gz
elgg-f48adf4356dccf8d7769e12421a6ca4fdf6925dc.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Introducing find_metadata as a counterpart to get_entities_from_metadata git-svn-id: https://code.elgg.org/elgg/trunk@673 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/metadata.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index c099d6a9c..5de47d52e 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -318,6 +318,58 @@
}
/**
+ * Get the metadata where the entities they are referring to match a given criteria.
+ *
+ * @param mixed $meta_name
+ * @param mixed $meta_value
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @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.
+ */
+ function find_metadata($meta_name = "", $meta_value = "", $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
+ {
+ global $CONFIG;
+
+ $meta_n = get_metastring_id($meta_name);
+ $meta_v = get_metastring_id($meta_value);
+
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $access = get_access_list();
+
+ $where = array();
+
+ if ($entity_type!="")
+ $where[] = "e.type='$entity_type'";
+ if ($entity_subtype)
+ $where[] = "e.subtype=$entity_subtype";
+ if ($meta_name!="")
+ $where[] = "m.name_id='$meta_n'";
+ if ($meta_value!="")
+ $where[] = "m.value_id='$meta_v'";
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
+
+ $query = "SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where";
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= " (e.access_id in {$access} or (e.access_id = 0 and e.owner_guid = {$_SESSION['id']}))"; // Add access controls
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+
+ return get_data($query, "row_to_elggmetadata");
+ }
+
+ /**
* Return a list of entities based on the given search criteria.
*
* @param mixed $meta_name