diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 17:41:54 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 17:41:54 -0300 |
commit | 4654eb2a446f64c66233b7bc38cc2a9b7bf151cc (patch) | |
tree | c68a1aa06acbd968a9f3d88b6e2d1a05cd771cbb | |
parent | 470cfd7fe8ea97b476eb4ca4fb430eae2ffae669 (diff) | |
download | muamba-4654eb2a446f64c66233b7bc38cc2a9b7bf151cc.tar.gz muamba-4654eb2a446f64c66233b7bc38cc2a9b7bf151cc.tar.bz2 |
Coding muamba_recover() and misc fixes
-rw-r--r-- | muamba.business.inc | 33 | ||||
-rw-r--r-- | muamba.module | 24 | ||||
-rw-r--r-- | muamba.theme.inc | 30 |
3 files changed, 78 insertions, 9 deletions
diff --git a/muamba.business.inc b/muamba.business.inc index 9d17f92..852add6 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -269,23 +269,38 @@ function muamba_return($mid) { * * @param $mid * Transaction id. - * - * @todo */ function muamba_recover($mid) { global $user; + $mid = (int) $mid; + $transaction = muamba_get_transaction($mid); + $node = node_load($transaction['nid']); - // TODO: load nid from db - $nid = (int) $nid; - $node = node_load($nid); - - if (!$node || $node->type != MUAMBA_NODE_TYPE) { + // Access check + if (!muamba_has_management_access($node)) { drupal_not_found(); } - if ($node->uid != $user->uid) { - // TODO: not node owner + // Status check + if ($transaction['status'] != MUAMBA_ACCEPTED || + $transaction['status'] != MUAMBA_RETURNED || + $transaction['status'] != MUAMBA_LOST) { + drupal_not_found(); } + + // Update database + $update = db_update('muamba') + ->fields(array( + 'status' => MUAMBA_RECOVERED, + )) + ->condition('mid', $mid, '=') + ->execute(); + + // Notify item owner + $message = theme('muamba_recover_message', array('transaction' => $transaction)); + $reply = privatemsg_reply($transaction['thread_id'], $message); + + return t('Recovered item.'); } /** diff --git a/muamba.module b/muamba.module index de1724c..4bff851 100644 --- a/muamba.module +++ b/muamba.module @@ -174,6 +174,30 @@ function muamba_theme($existing, $type, $theme, $path) { ), 'file' => 'muamba.theme.inc', ), + 'muamba_cancel_message' => array( + 'variables' => array( + 'transaction' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), + 'muamba_return_message' => array( + 'variables' => array( + 'transaction' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), + 'muamba_recover_message' => array( + 'variables' => array( + 'transaction' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), + 'muamba_lost_message' => array( + 'variables' => array( + 'transaction' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), ); } diff --git a/muamba.theme.inc b/muamba.theme.inc index ac8cdc7..4e201f7 100644 --- a/muamba.theme.inc +++ b/muamba.theme.inc @@ -34,6 +34,8 @@ function theme_muamba_transactions($variables) { } foreach($transactions as $transaction) { + $actions = array(); + foreach (muamba_actions_available($type, $transaction['status']) as $action) { $callback = muamba_actions($action); $actions[] = l(t($callback), 'muamba/'. $callback .'/'. $transaction['mid']); @@ -104,3 +106,31 @@ function theme_muamba_accept_message($transaction = NULL) { function theme_muamba_reject_message($transaction = NULL) { return t('I reject your item request'); } + +/** + * Theme callback. + */ +function theme_muamba_cancel_message($transaction = NULL) { + return t('I cancel my item request'); +} + +/** + * Theme callback. + */ +function theme_muamba_return_message($transaction = NULL) { + return t('I return your item'); +} + +/** + * Theme callback. + */ +function theme_muamba_recovered_message($transaction = NULL) { + return t('I recovered my item'); +} + +/** + * Theme callback. + */ +function theme_muamba_lost_message($transaction = NULL) { + return t('I declare that my item is lost'); +} |