]> gitweb.fluxo.info Git - drupal/muamba.git/commitdiff
Starting to code muamba_accept()
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 3 Oct 2011 20:12:53 +0000 (17:12 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 3 Oct 2011 20:12:53 +0000 (17:12 -0300)
muamba.business.inc
muamba.db.inc
muamba.theme.inc

index b6128e357463ec811fc04a49d50b2fb3629843ad..b68443c559d6ab96ac931e717519cca38b365d72 100644 (file)
@@ -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.');
 }
 
 /**
index 0e29ca62000dd3b2643b46294b17e2333896093d..e8e1c708b9b554736461867ca9bdd6880bfeedec 100644 (file)
@@ -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];
+}
index c8db1995406d95cd18ae90a0b164270c66bcdf4c..625407464dbb4d914b3d001555ff6f84ef972182 100644 (file)
@@ -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(