diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-09-26 21:11:41 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-09-26 21:11:41 -0300 |
commit | 461a0d5737e8aec766758c9887904d53eb177e8f (patch) | |
tree | eecf527ea1642577a3d1a225c3cfc4fe572bf4d3 | |
parent | 8bc407811575c36fc24dda235e263e9366efbe1e (diff) | |
download | muamba-461a0d5737e8aec766758c9887904d53eb177e8f.tar.gz muamba-461a0d5737e8aec766758c9887904d53eb177e8f.tar.bz2 |
Adding more transaction logic
-rw-r--r-- | muamba.business.inc | 60 | ||||
-rw-r--r-- | muamba.db.inc | 9 | ||||
-rw-r--r-- | muamba.misc.inc | 80 | ||||
-rw-r--r-- | muamba.module | 1 | ||||
-rw-r--r-- | muamba.theme.inc | 16 |
5 files changed, 162 insertions, 4 deletions
diff --git a/muamba.business.inc b/muamba.business.inc index 5efb469..1b40d1b 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -10,6 +10,66 @@ include_once('muamba.db.inc'); include_once('muamba.misc.inc'); /** + * Determine possible actions for a transaction. + * + * @param $type + * Transaction type (sent or received). + * + * @param $status + * Current transaction status. + * + * @return + * Array of available action codes. + */ +function muamba_actions_available($type = 'sent', $status) { + if ($type == 'sent') { + switch ($status) { + case MUAMBA_REQUESTED: + $actions = array( + MUAMBA_ACCEPTED, + MUAMBA_REJECTED, + ); + break; + + case MUAMBA_ACCEPTED: + $actions = array( + MUAMBA_RELEASED, + ); + break; + + case MUAMBA_RETURNED: + $actions = array( + MUAMBA_RELEASED, + ); + break; + + default: + $actions = array(); + } + } + else { + switch ($status) { + case MUAMBA_REQUESTED: + $actions = array( + MUAMBA_CANCELLED, + ); + break; + + case MUAMBA_ACCEPTED: + $actions = array( + MUAMBA_RETURNED, + ); + break; + + default: + $actions = array(); + } + } + + return $actions; +} + +/** * Transaction management page. */ function muamba() { diff --git a/muamba.db.inc b/muamba.db.inc index 93eb5bc..bd2322f 100644 --- a/muamba.db.inc +++ b/muamba.db.inc @@ -42,6 +42,15 @@ function muamba_check_user_request($nid, $uid) { * * @param $uid * Requester user uid. + * + * @param $type + * Transaction type (sent or received). + * + * @param $status + * Current transaction status. + * + * @return + * Array of existing transactions. */ function muamba_get_transactions($uid, $type = 'sent', $status = MUAMBA_REQUESTED) { $uid = (int) $uid; diff --git a/muamba.misc.inc b/muamba.misc.inc new file mode 100644 index 0000000..4b2d2e6 --- /dev/null +++ b/muamba.misc.inc @@ -0,0 +1,80 @@ +<?php + +/** + * @fils + * Miscelaneous functions. + */ + +// Load requirements. +include_once('muamba.misc.inc'); + +/** + * Builds detailed transaction information. + * + * @param $transactions + * Array with transactions. + * + * @return + * Array with summarized transactions. + */ +function muamba_transactions_summary($transactions) { + for ($n = 0; $n < sizeof($transactions); $n++) { + $transactions[$n]['node'] = node_load($transactions[$n]['nid']); + $transactions[$n]['user'] = user_load($transactions[$n]['uid']); + $transactions[$n]['owner'] = user_load($transactions[$n]['owner']); + } + + return $transactions; +} + +/** + * Get status descriptions. + * + * @param $code + * Optional status code. + * + * @return + * Array of status descriptions or code + * description if $code is supplied. + */ +function muamba_statuses($code = NULL) { + $status = array( + MUAMBA_REQUESTED => 'requested', + MUAMBA_ACCEPTED => 'accepted', + MUAMBA_REJECTED => 'rejected', + MUAMBA_RELEASED => 'released', + MUAMBA_RETURNED => 'returned', + ); + + if ($code == NULL) { + return $status; + } + + return $status[$code]; +} + +/** + * Get status callback name. + * + * @param $code + * Optional status code. + * + * @return + * Array of callback names or callback + * name if $code is supplied. + */ +function muamba_actions($code = NULL) { + $status = array( + MUAMBA_REQUESTED => 'request', + MUAMBA_ACCEPTED => 'accept', + MUAMBA_REJECTED => 'reject', + MUAMBA_RELEASED => 'releas', + MUAMBA_RETURNED => 'return', + ); + + if ($code == NULL) { + return $status; + } + + return $status[$code]; +} diff --git a/muamba.module b/muamba.module index 9588dac..6476093 100644 --- a/muamba.module +++ b/muamba.module @@ -14,6 +14,7 @@ define('MUAMBA_ACCEPTED', 1); define('MUAMBA_REJECTED', 2); define('MUAMBA_RELEASED', 3); define('MUAMBA_RETURNED', 4); +define('MUAMBA_CANCELLED', 4); /** * Implements hook_permission() diff --git a/muamba.theme.inc b/muamba.theme.inc index 771c80b..1bec871 100644 --- a/muamba.theme.inc +++ b/muamba.theme.inc @@ -5,12 +5,15 @@ * Misc theme functions. */ +/** + * Theme callback. + */ function theme_muamba_transactions($variables) { $rows = array(); $type = $variables['type']; $transactions = $variables['transactions']; - $output = '<div class="muamba-transactions">'; + $output = '<div class="muamba-transactions">'; if ($type == 'sent') { $title = t('Items I requested from people'); @@ -19,7 +22,7 @@ function theme_muamba_transactions($variables) { $title = t('My items that people requested'); } - $output .= '<h2>'. $title .'</h2>'; + $output .= '<h2>'. $title .'</h2>'; if (empty($transactions)) { $output .= t('There are no transactions.'); @@ -28,11 +31,16 @@ function theme_muamba_transactions($variables) { } foreach($transactions as $transaction) { + foreach (muamba_actions_available($type, $transaction['status']) as $action) { + $callback = muamba_actions($action); + $available_actions[] = l(t($callback), $callback); + } + $rows[] = array( 'asset' => $transaction['node']->title, 'user' => $transaction['user']->name, - 'status' => muamba_statuses($transaction['status']), - 'actions' => 'accept', // TODO + 'status' => t(muamba_statuses($transaction['status'])), + 'available_actions' => implode($available_actions, '|'), ); } |