From 98c2bec78ec6bd0ddc96e6025db47410904ef785 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 6 Nov 2011 14:32:35 -0200 Subject: Renaming muamba_current_transaction() to muamba_current_transactions() --- muamba.db.inc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'muamba.db.inc') diff --git a/muamba.db.inc b/muamba.db.inc index 21e2d8c..6aa4782 100644 --- a/muamba.db.inc +++ b/muamba.db.inc @@ -107,19 +107,21 @@ function muamba_get_transaction($mid) { } /** - * Get current transaction for an item. + * Get current transaction for an item. Note that there might + * be more than one active transaction for a given item if they + * all are in the "requested" state. * * @param $data * Item nid or node object. * + * @param $uid + * Optional requester user id. + * * @return - * Data of the ongoing transaction. - * - * @todo - * There might be more than one active transaction for - * a given item if they all are in the "requested" state. + * Data of the ongoing transactions. If $uid is specified, + * then just one transaction is returned. */ -function muamba_current_transaction($data, $owner = NULL) { +function muamba_current_transactions($data, $uid = NULL) { if (is_object($data)) { $nid = (int) $data->nid; } @@ -134,6 +136,10 @@ function muamba_current_transaction($data, $owner = NULL) { ->condition('m.nid', $nid, '=') ->condition('m.active', '1', '='); + if ($uid != NULL) { + $query->condition('m.uid', (int) $uid, '='); + } + $results = $query->execute()->fetchAll(); // Sanitize the data before handing it off to the theme layer. @@ -141,9 +147,11 @@ function muamba_current_transaction($data, $owner = NULL) { $rows[] = array_map('check_plain', (array) $entry); } - if (isset($rows[0])) { + if ($uid != NULL && isset($rows[0])) { return $rows[0]; - } + } + + return $rows; } /** -- cgit v1.2.3