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 +++++++++++++++++--------- muamba.module | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) 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; } /** diff --git a/muamba.module b/muamba.module index dfe7b21..7d83ef4 100644 --- a/muamba.module +++ b/muamba.module @@ -120,7 +120,7 @@ function muamba_node_view($node, $view_mode, $langcode) { if ($view_mode == 'full') { // @todo: there might be more than one transaction - $transaction = muamba_current_transactions($node); + $transaction = muamba_current_transactions($node, $user->uid); $node->content['muamba'] = array( '#markup' => theme('muamba_widget', array('node' => $node, 'transaction' => $transaction)), '#weight' => 100, -- cgit v1.2.3