}
/**
- * 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;
}
->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.
$rows[] = array_map('check_plain', (array) $entry);
}
- if (isset($rows[0])) {
+ if ($uid != NULL && isset($rows[0])) {
return $rows[0];
- }
+ }
+
+ return $rows;
}
/**
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,