]> gitweb.fluxo.info Git - drupal/muamba.git/commitdiff
Fixing #34
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 6 Nov 2011 22:46:47 +0000 (20:46 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 6 Nov 2011 22:46:47 +0000 (20:46 -0200)
muamba-widget.tpl.php
muamba.module

index 1c79606d19b9d9b6551010c9c757c22b23c82f08..09b43bc795fa91c39c4486505bd4d6e63fc766e0 100644 (file)
@@ -16,31 +16,38 @@ drupal_add_css($path .'/muamba.css');
 $content = '';
 $output  = '';
 
-if (!user_is_logged_in()) {
-  print t('You have to be logged in to be able to ask for this item.');
-  return;
-}
-elseif (empty($transaction) && $node->uid != $user->uid) {
-  $content .= theme('muamba_widget_icon', array('status' => MUAMBA_REQUESTED, 'id' => $node->nid));
-}
-elseif ($transaction['uid'] == $user->uid) {
-  foreach (muamba_actions_available('sent', $transaction['status']) as $action) {
-    $content .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transaction['mid']));
+if ($node->uid != $user->uid) {
+  if (!user_is_logged_in()) {
+    print t('You have to be logged in to be able to ask for this item.');
+    return;
   }
-}
-elseif ($transaction['owner'] == $user->uid) {
-  foreach (muamba_actions_available('received', $transaction['status']) as $action) {
-    $content .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transaction['mid']));
+  elseif (!$available && $transactions['uid'] != $user->uid) {
+    $content .= theme('image',
+      array(
+        'path'  => $path .'/images/unavailable.png',
+        'alt'   => t('Item unavailable'),
+        'title' => t('Item unavailable'),
+      )
+    );
+  }
+  elseif ($transactions['uid'] == $user->uid) {
+    foreach (muamba_actions_available('sent', $transactions['status']) as $action) {
+      $content .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transactions['mid']));
+    }
+  }
+  else {
+    $content .= theme('muamba_widget_icon', array('status' => MUAMBA_REQUESTED, 'id' => $node->nid));
   }
 }
 else {
-  $content .= theme('image',
-    array(
-      'path'  => $path .'/images/unavailable.png',
-      'alt'   => t('Item unavailable'),
-      'title' => t('Item unavailable'),
-    )
-  );
+  foreach ($transactions as $transaction) {
+    $requester = user_load($transaction['uid']);
+    $content  .= t('Request from @name.', array('@name' => $requester->name));
+    $content  .= '<br />';
+    foreach (muamba_actions_available('received', $transaction['status']) as $action) {
+      $content .= theme('muamba_widget_icon', array('status' => $action, 'id' => $transaction['mid']));
+    }
+  }
 }
 
 if (!empty($content)) {
index 1e010dcb496d168d3b12ed1f6882ad2e504928f6..66e0b520da9c0660c8105b906629b070cb6cdf3c 100644 (file)
@@ -107,8 +107,6 @@ function muamba_menu() {
 
 /**
  * Implements hook_node_view()
- *
- * @todo
  */
 function muamba_node_view($node, $view_mode, $langcode) {
   global $user;
@@ -120,15 +118,27 @@ function muamba_node_view($node, $view_mode, $langcode) {
 
   if ($view_mode == 'full') {
     if ($node->uid != $user->uid) {
-      $transaction             = muamba_current_transactions($node, $user->uid);
+      $transactions            = muamba_current_transactions($node, $user->uid);
+      $available               = muamba_check_availability($node->nid);
       $node->content['muamba'] = array(
-        '#markup' => theme('muamba_widget', array('node' => $node, 'transaction' => $transaction)),
+        '#markup' => theme('muamba_widget', array(
+          'node'         => $node,
+          'transactions' => $transactions,
+          'available'    => $available,
+
+        )),
         '#weight' => 100,
       );
     }
     else {
-      // @todo: muamba_widget is not working anymore for item owners, make a custom
-      //        widget just for handling multiple requests, see #34
+      $transactions            = muamba_current_transactions($node);
+      $node->content['muamba'] = array(
+        '#markup' => theme('muamba_widget', array(
+          'node'         => $node,
+          'transactions' => $transactions
+        )),
+        '#weight' => 100,
+      );
     }
 
     return $node;
@@ -143,8 +153,9 @@ function muamba_theme($existing, $type, $theme, $path) {
     'muamba_widget' => array(
       'template'  => 'muamba-widget',
       'variables' => array(
-        'node'        => NULL,
-        'transaction' => NULL, 
+        'node'         => NULL,
+        'transactions' => NULL, 
+        'available'    => NULL,
       ),
     ),
     'muamba_powered' => array(