aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-10-03 17:12:53 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-10-03 17:12:53 -0300
commita3336da7dd92a2b8d31f2f33a6106a1802b5a387 (patch)
tree778908921605e91a9f79ed0ccfb9c341f5d09d3e
parent60d116ff8a60bc98fb09e0bbf4afb2c37437353b (diff)
downloadmuamba-a3336da7dd92a2b8d31f2f33a6106a1802b5a387.tar.gz
muamba-a3336da7dd92a2b8d31f2f33a6106a1802b5a387.tar.bz2
Starting to code muamba_accept()
-rw-r--r--muamba.business.inc16
-rw-r--r--muamba.db.inc26
-rw-r--r--muamba.theme.inc2
3 files changed, 43 insertions, 1 deletions
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(