From c205ae2d3a8eafcd8a07d2f0bcac1b2ea48a6a0f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 6 Nov 2011 22:01:21 -0200 Subject: Partial views_handler_field_muamba_actions() --- muamba.handlers.inc | 36 +++++++++++++++++++++++++++++++----- muamba.module | 32 +++++++++++++------------------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/muamba.handlers.inc b/muamba.handlers.inc index 7a1c3f3..f6c0982 100644 --- a/muamba.handlers.inc +++ b/muamba.handlers.inc @@ -58,7 +58,7 @@ class views_handler_field_muamba_available extends views_handler_field { elseif (!$available) { $transaction = muamba_current_transactions($values->nid, $user->uid); - if ($transaction['uid'] == $user->uid) { + if (isset($transaction['uid']) && $transaction['uid'] == $user->uid) { return t('You requested'); } else { @@ -74,6 +74,7 @@ class views_handler_field_muamba_available extends views_handler_field { * Field handler for muamba transaction status. * * @todo + * Show widget also in a transaction view. */ class views_handler_field_muamba_actions extends views_handler_field { /** @@ -88,11 +89,36 @@ class views_handler_field_muamba_actions extends views_handler_field { /** * Renders the field. - * - * @todo */ function render($values) { - dpm($values); - return "TODO"; + global $user; + + if (isset($values->mid)) { + $transaction = muamba_get_transaction($values->mid); + // @todo + return 'TODO'; + } + elseif (isset($values->nid)) { + $available = muamba_check_availability($values->nid); + $node = node_load($values->nid); + + // Check if widget can be shown + if ($node->type != MUAMBA_NODE_TYPE || !muamba_has_request_access($node)) { + return; + } + + if ($node->uid != $user->uid) { + $transactions = muamba_current_transactions($values->nid, $user->uid); + } + else { + $transactions = muamba_current_transactions($values->nid); + } + + return theme('muamba_widget', array( + 'node' => $node, + 'transactions' => $transactions, + 'available' => $available, + )); + } } } diff --git a/muamba.module b/muamba.module index 66e0b52..2b76df9 100644 --- a/muamba.module +++ b/muamba.module @@ -117,30 +117,24 @@ function muamba_node_view($node, $view_mode, $langcode) { } if ($view_mode == 'full') { - if ($node->uid != $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, - 'transactions' => $transactions, - 'available' => $available, + $available = muamba_check_availability($node->nid); - )), - '#weight' => 100, - ); + if ($node->uid != $user->uid) { + $transactions = muamba_current_transactions($node, $user->uid); } else { - $transactions = muamba_current_transactions($node); - $node->content['muamba'] = array( - '#markup' => theme('muamba_widget', array( - 'node' => $node, - 'transactions' => $transactions - )), - '#weight' => 100, - ); + $transactions = muamba_current_transactions($node); } + $node->content['muamba'] = array( + '#markup' => theme('muamba_widget', array( + 'node' => $node, + 'transactions' => $transactions, + 'available' => $available, + )), + '#weight' => 100, + ); + return $node; } } -- cgit v1.2.3