]> gitweb.fluxo.info Git - drupal/muamba.git/commitdiff
Renaming muamba_current_transaction() to muamba_current_transactions()
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 6 Nov 2011 16:32:35 +0000 (14:32 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 6 Nov 2011 16:32:35 +0000 (14:32 -0200)
muamba.db.inc
muamba.module

index 21e2d8c8d5aa5ded9697c4eeffdef361452d4f73..6aa4782e7c83c464f168738aedbb9eb3c059e86c 100644 (file)
@@ -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;
 }
 
 /**
index dfe7b219c817dbbc1c427ae9c3324626f8094bc7..7d83ef445b3d1a1de1d4fa5482ba6d945867d530 100644 (file)
@@ -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,