aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/metadata.php
diff options
context:
space:
mode:
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-21 16:11:26 +0000
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-21 16:11:26 +0000
commit355363b46fdf99364027fffac2801d7242242703 (patch)
tree251747dab31ddd2a5e511d6e90b367917a6b9eb2 /engine/lib/metadata.php
parent734e8279272e81a27fec8ef1327e8eab38dc07ce (diff)
downloadelgg-355363b46fdf99364027fffac2801d7242242703.tar.gz
elgg-355363b46fdf99364027fffac2801d7242242703.tar.bz2
Allowing entities to be retrieved by case-insensitive search.
Adding a new unit test for ElggMetadata. git-svn-id: http://code.elgg.org/elgg/trunk@3568 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/metadata.php')
-rw-r--r--engine/lib/metadata.php40
1 files changed, 32 insertions, 8 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 5ca39b586..dc8107583 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -544,17 +544,24 @@ function find_metadata($meta_name = "", $meta_value = "", $entity_type = "", $en
* @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 $case_sensitive If set to false this searches for the meta data without case sensitivity. (Default: true)
*
* @return int|array A list of entities, or a count if $count is set to true
*/
-function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = FALSE, $case_sensitive = TRUE) {
global $CONFIG;
$meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
+ $meta_v = get_metastring_id($meta_value, $case_sensitive);
$entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $entity_subtype_id = get_subtype_id($entity_type, $entity_subtype);
+ if ($entity_subtype != "" && $entity_subtype_id == FALSE) {
+ return false;
+ } else {
+ $entity_subtype = $entity_subtype_id;
+ }
+
$limit = (int)$limit;
$offset = (int)$offset;
if ($order_by == "") {
@@ -590,7 +597,16 @@ function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type =
$where[] = "m.name_id='$meta_n'";
}
if ($meta_value!=="") {
- $where[] = "m.value_id='$meta_v'";
+ if (is_array($meta_v)) {
+ $meta_v_string = "";
+ foreach ($meta_v as $v) {
+ $meta_v_string .= "'$v',";
+ }
+ $meta_v_string = rtrim($meta_v_string, ",");
+ $where[] = "m.value_id in ($meta_v_string)";
+ } else {
+ $where[] = "m.value_id='$meta_v'";
+ }
}
if ($site_guid > 0) {
$where[] = "e.site_guid = {$site_guid}";
@@ -641,11 +657,11 @@ function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type =
*
* @return string A list of entities suitable for display
*/
-function list_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true) {
+function list_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true, $case_sensitive = true ) {
$offset = (int) get_input('offset');
$limit = (int) $limit;
- $count = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true);
- $entities = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false);
+ $count = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true, $case_sensitive );
+ $entities = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false, $case_sensitive );
return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
}
@@ -972,4 +988,12 @@ function register_metadata_url_handler($function_name, $extender_name = "all") {
/** Register the hook */
register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2);
/** Call a function whenever an entity is updated **/
-register_elgg_event_handler('update','all','metadata_update'); \ No newline at end of file
+register_elgg_event_handler('update','all','metadata_update');
+
+// unit testing
+register_plugin_hook('unit_test', 'system', 'metadata_test');
+function metadata_test($hook, $type, $value, $params) {
+ global $CONFIG;
+ $value[] = $CONFIG->path . 'engine/tests/objects/metadata.php';
+ return $value;
+} \ No newline at end of file