diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 17:18:53 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 17:18:53 -0300 |
commit | 470cfd7fe8ea97b476eb4ca4fb430eae2ffae669 (patch) | |
tree | a2d6f2e93f05e978df6f8fc6757f4fdba82c21dd | |
parent | 5e044ecbd0e1914d93ebde1514b4567e8a17b1de (diff) | |
download | muamba-470cfd7fe8ea97b476eb4ca4fb430eae2ffae669.tar.gz muamba-470cfd7fe8ea97b476eb4ca4fb430eae2ffae669.tar.bz2 |
Coding muamba_reject()
-rw-r--r-- | muamba.business.inc | 39 | ||||
-rw-r--r-- | muamba.module | 16 | ||||
-rw-r--r-- | muamba.theme.inc | 7 |
3 files changed, 52 insertions, 10 deletions
diff --git a/muamba.business.inc b/muamba.business.inc index cd9dc5d..9d17f92 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -127,7 +127,10 @@ function muamba_request($nid) { return t('The item owner has blocked you from asking this item.'); } - // TODO: check if the item is available + // Check if the item is available + if (!muamba_check_availability($nid)) { + return t('Item not available'); + } // Check if user already requested the item if (muamba_check_user_request($nid, $user->uid)) { @@ -175,7 +178,7 @@ function muamba_accept($mid) { global $user; $mid = (int) $mid; $transaction = muamba_get_transaction($mid); - $node = node_load($transaction->nid); + $node = node_load($transaction['nid']); // Access check if (!muamba_has_management_access($node)) { @@ -183,7 +186,7 @@ function muamba_accept($mid) { } // Status check - if ($transaction->status != MUAMBA_REQUESTED) { + if ($transaction['status'] != MUAMBA_REQUESTED) { drupal_not_found(); } @@ -207,10 +210,36 @@ function muamba_accept($mid) { * * @param $mid * Transaction id. - * - * @todo */ function muamba_reject($mid) { + global $user; + $mid = (int) $mid; + $transaction = muamba_get_transaction($mid); + $node = node_load($transaction['nid']); + + // Access check + if (!muamba_has_management_access($node)) { + drupal_not_found(); + } + + // Status check + if ($transaction['status'] != MUAMBA_REQUESTED) { + drupal_not_found(); + } + + // Update database + $update = db_update('muamba') + ->fields(array( + 'status' => MUAMBA_REJECTED, + )) + ->condition('mid', $mid, '=') + ->execute(); + + // Notify item owner + $message = theme('muamba_reject_message', array('transaction' => $transaction)); + $reply = privatemsg_reply($transaction['thread_id'], $message); + + return t('Rejected item request.'); } /** diff --git a/muamba.module b/muamba.module index 5a92f35..de1724c 100644 --- a/muamba.module +++ b/muamba.module @@ -57,7 +57,7 @@ function muamba_menu() { $items['muamba/accept'] = array( 'title' => 'Accept an item request', 'page callback' => 'muamba_accept', - 'access arguments' => array('accept item'), + 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'muamba.business.inc', ); @@ -65,7 +65,7 @@ function muamba_menu() { $items['muamba/reject'] = array( 'title' => 'Reject an item request', 'page callback' => 'muamba_reject', - 'access arguments' => array('reject item'), + 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'muamba.business.inc', ); @@ -73,7 +73,7 @@ function muamba_menu() { $items['muamba/cancel'] = array( 'title' => 'Cancel a request', 'page callback' => 'muamba_cancel', - 'access arguments' => array('cancel item'), + 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'muamba.business.inc', ); @@ -89,7 +89,7 @@ function muamba_menu() { $items['muamba/return'] = array( 'title' => 'Return an item', 'page callback' => 'muamba_return', - 'access arguments' => array('return item'), + 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'muamba.business.inc', ); @@ -97,7 +97,7 @@ function muamba_menu() { $items['muamba/lost'] = array( 'title' => 'Report a lost item', 'page callback' => 'muamba_lost', - 'access arguments' => array('lost item'), + 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'muamba.business.inc', ); @@ -168,6 +168,12 @@ function muamba_theme($existing, $type, $theme, $path) { ), 'file' => 'muamba.theme.inc', ), + 'muamba_reject_message' => array( + 'variables' => array( + 'transaction' => NULL, + ), + 'file' => 'muamba.theme.inc', + ), ); } diff --git a/muamba.theme.inc b/muamba.theme.inc index af15da9..ac8cdc7 100644 --- a/muamba.theme.inc +++ b/muamba.theme.inc @@ -97,3 +97,10 @@ function theme_muamba_request_message($transaction = NULL) { function theme_muamba_accept_message($transaction = NULL) { return t('I accept your item request'); } + +/** + * Theme callback. + */ +function theme_muamba_reject_message($transaction = NULL) { + return t('I reject your item request'); +} |