aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-02 10:40:53 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-02 10:40:53 +0000
commit132e9c18ecd10ada97d4bb2b7dfaf63404f540bd (patch)
tree0ab0e0bf22190d4962308cf18a3c8c87c784662f /engine/lib
parentb987959fdc751152484f695701f08e76b5b9580b (diff)
downloadelgg-132e9c18ecd10ada97d4bb2b7dfaf63404f540bd.tar.gz
elgg-132e9c18ecd10ada97d4bb2b7dfaf63404f540bd.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* get_metadata_byname better handles single/multiple return values git-svn-id: https://code.elgg.org/elgg/trunk@337 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/metadata.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 2f6087f8a..01a981945 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -255,6 +255,7 @@
* Return the metadata values that match your query.
*
* @param string $meta_name
+ * @return mixed either a value, an array of ElggMetadata or false.
*/
function get_metadata_byname($entity_guid, $meta_name)
{
@@ -264,8 +265,14 @@
$entity_guid = (int)$entity_guid;
$access = get_access_list();
- echo "SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid=$entity_guid and m.name_id='$meta_name' and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))";
- return get_data("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid=$entity_guid and m.name_id='$meta_name' and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))", "row_to_elggmetadata");
+ $result = get_data("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid=$entity_guid and m.name_id='$meta_name' and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))", "row_to_elggmetadata");
+ if (!$result)
+ return false;
+
+ if (count($result) == 1)
+ return $result[0]->value;
+
+ return $result;
}
/**