From f8a758f6d8b460a4c22a7aa8835ffa57708e800f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 8 Nov 2011 20:20:14 -0200 Subject: Adding muamba_availability_info() --- muamba.business.inc | 37 +++++++++++++++++++++++++++++++++++++ muamba.handlers.inc | 25 +++++-------------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/muamba.business.inc b/muamba.business.inc index 56a1237..d7de834 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -50,6 +50,12 @@ function muamba_actions_available($type = 'sent', $status) { ); break; + case MUAMBA_REJECTED: + $actions = array( + MUAMBA_REQUESTED, + ); + break; + default: $actions = array(); } @@ -399,3 +405,34 @@ function muamba_widget($node, $size = 'small') { 'size' => $size, )); } + +/** + * Return availability information. + * + * @param $nid + * Muamba node id. + * + * @return + * Human-readable availability information. + */ +function muamba_availability_info($nid) { + global $user; + $available = muamba_check_availability($nid); + $node = node_load($nid); + + if ($node->uid == $user->uid) { + return t('You own the item'); + } + elseif (!$available) { + $transaction = muamba_current_transactions($nid, $user->uid); + + if (isset($transaction['uid']) && $transaction['uid'] == $user->uid) { + return t('You requested'); + } + else { + return t('No'); + } + } + + return t('Yes'); +} diff --git a/muamba.handlers.inc b/muamba.handlers.inc index 2745130..06c80b1 100644 --- a/muamba.handlers.inc +++ b/muamba.handlers.inc @@ -47,28 +47,13 @@ class views_handler_field_muamba_available extends views_handler_field { * Renders the field. */ function render($values) { - if (!isset($values->nid)) { - return; - } - - global $user; - $available = muamba_check_availability($values->nid); - - if ($values->users_node_uid == $user->uid) { - return t('You own the item'); + if (isset($values->mid)) { + $transaction = muamba_get_transaction($values->mid); + return muamba_availability_info($transaction['nid']); } - elseif (!$available) { - $transaction = muamba_current_transactions($values->nid, $user->uid); - - if (isset($transaction['uid']) && $transaction['uid'] == $user->uid) { - return t('You requested'); - } - else { - return t('No'); - } + elseif (isset($values->nid)) { + return muamba_availability_info($values->nid); } - - return t('Yes'); } } -- cgit v1.2.3