From a3336da7dd92a2b8d31f2f33a6106a1802b5a387 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 3 Oct 2011 17:12:53 -0300 Subject: Starting to code muamba_accept() --- muamba.business.inc | 16 ++++++++++++++++ muamba.db.inc | 26 ++++++++++++++++++++++++++ muamba.theme.inc | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/muamba.business.inc b/muamba.business.inc index b6128e3..b68443c 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -143,6 +143,22 @@ function muamba_request($nid) { * @todo */ function muamba_accept($mid) { + global $user; + $mid = (int) $mid; + $transaction = muamba_get_transaction($mid); + + // Access check + // TODO: also check if user owns the item + $node = node_load($transaction->nid); + if (!$node || $node->type != MUAMBA_NODE_TYPE || !node_access('view', $node)) { + drupal_not_found(); + } + + // TODO + // Update database + // Notify item owner + + return t('Accepted item request.'); } /** diff --git a/muamba.db.inc b/muamba.db.inc index 0e29ca6..e8e1c70 100644 --- a/muamba.db.inc +++ b/muamba.db.inc @@ -78,3 +78,29 @@ function muamba_get_transactions($uid, $type = 'sent', $status = NULL) { return $rows; } + +/** + * Get a single transaction. + * + * @param $mid + * Transaction id. + * + * @return + * Transaction data. + */ +function muamba_get_transaction($mid) { + $mid = (int) $mid; + $query = db_select('muamba', 'm'); + $query->fields('m', array('mid', 'nid', 'uid', 'owner', 'status', 'thread_id')); + $query->condition('m.mid', $mid, '='); + + $rows = array(); + $results = $query->execute()->fetchAll(); + + // Sanitize the data before handing it off to the theme layer. + foreach ($results as $entry) { + $rows[] = array_map('check_plain', (array) $entry); + } + + return $rows[0]; +} diff --git a/muamba.theme.inc b/muamba.theme.inc index c8db199..6254074 100644 --- a/muamba.theme.inc +++ b/muamba.theme.inc @@ -36,7 +36,7 @@ function theme_muamba_transactions($variables) { foreach($transactions as $transaction) { foreach (muamba_actions_available($type, $transaction['status']) as $action) { $callback = muamba_actions($action); - $actions[] = l(t($callback), $callback); + $actions[] = l(t($callback), 'muamba/'. $callback .'/'. $transaction['mid']); } $rows[] = array( -- cgit v1.2.3