diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 16:22:12 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-10-06 16:22:12 -0300 |
commit | 79c10bc8fd6277ee349872551e314a38605dc66b (patch) | |
tree | 7d9401f26aadde61e4402597cdbf16adb355b33a | |
parent | 924fb6e2bdcdf46a21684d61d018cc3132dd4f04 (diff) | |
download | muamba-79c10bc8fd6277ee349872551e314a38605dc66b.tar.gz muamba-79c10bc8fd6277ee349872551e314a38605dc66b.tar.bz2 |
New functions muamba_current_transaction() and muamba_ongoing()
-rw-r--r-- | muamba.business.inc | 4 | ||||
-rw-r--r-- | muamba.db.inc | 61 | ||||
-rw-r--r-- | muamba.module | 3 |
3 files changed, 66 insertions, 2 deletions
diff --git a/muamba.business.inc b/muamba.business.inc index 708d97e..195409f 100644 --- a/muamba.business.inc +++ b/muamba.business.inc @@ -54,14 +54,14 @@ function muamba_actions_available($type = 'sent', $status) { case MUAMBA_ACCEPTED: $actions = array( MUAMBA_RECOVERED, - MUAMBA_LOST; + MUAMBA_LOST, ); break; case MUAMBA_RETURNED: $actions = array( MUAMBA_RECOVERED, - MUAMBA_LOST; + MUAMBA_LOST, ); break; diff --git a/muamba.db.inc b/muamba.db.inc index 224132f..4414a1a 100644 --- a/muamba.db.inc +++ b/muamba.db.inc @@ -87,6 +87,9 @@ function muamba_get_transactions($uid, $type = 'sent', $status = NULL) { * * @return * Transaction data. + * + * @todo + * When a node is provided, duplicate rows might occur. */ function muamba_get_transaction($data) { $query = db_select('muamba', 'm'); @@ -111,3 +114,61 @@ function muamba_get_transaction($data) { return $rows[0]; } } + +/** + * Check item availability. + * + * @param $nid + * Item nid. + * + * @param $uid + * Requester user nid. + * + * @return + * TRUE if user already requested an item, FALSE otherwise. + * + * @todo + */ +function muamba_check_availability($nid, $uid = NULL) { +} + +/** + * Get current transaction for an item. + * + * @param $nid + * Item nid. + * + * @return + * Transaction nid there's an ongoing transaction. + * + * @todo + */ +function muamba_current_transaction($nid) { + $query = db_select('muamba', 'm'); + $query->fields('m', array('mid', 'nid', 'uid', 'owner', 'status', 'thread_id')); + + $query->condition('m.nid', $nid, '='); + $query->condition( + db_or() + ->condition('m.status', MUAMBA_REQUESTED, '=') + ->condition('m.status', MUAMBA_ACCEPTED, '=') + ->condition('m.status', MUAMBA_RETURNED, '=') + ->condition('m.status', MUAMBA_LOST, '=') + ); + + $results = $query->execute()->fetchAll(); + + return $results; +} + +/** + * Define which status belongs to an ongoing transaction. + */ +function muamba_ongoing() { + return array( + MUAMBA_REQUESTED, + MUAMBA_ACCEPTED, + MUAMBA_RETURNED, + MUAMBA_LOST, + ); +} diff --git a/muamba.module b/muamba.module index f425d3e..2835dd9 100644 --- a/muamba.module +++ b/muamba.module @@ -106,6 +106,9 @@ function muamba_menu() { /** * Implements hook_node_view() + * + * @todo + * Use muamba_check_availability() before muamba_get_transaction() */ function muamba_node_view($node, $view_mode, $langcode) { global $user; |