From 024bd20549c58317e8565e7772eec5630295d33c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 9 Nov 2011 13:50:38 -0200 Subject: Adding views_handler_field_muamba_total() --- muamba.db.inc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'muamba.db.inc') diff --git a/muamba.db.inc b/muamba.db.inc index 4275dde..ff682f5 100644 --- a/muamba.db.inc +++ b/muamba.db.inc @@ -228,3 +228,41 @@ function muamba_finish($mid) { ->condition('mid', $mid, '=') ->execute(); } + +/** + * Return total transactions. + * + * @param $nid + * Muamba node id. + * + * @param $type + * Type of transactions. + * + * @return + * Number of transactions. + */ +function muamba_total($nid, $type = 'transactions') { + $nid = (int) $nid; + $query = db_select('muamba', 'm'); + $query->condition('m.nid', $nid, '='); + + if ($type != 'transactions') { + if ($type == 'requested') { + $query->condition('m.status', MUAMBA_REQUESTED, '='); + } + elseif ($type == 'rejected') { + $query->condition('m.status', MUAMBA_REJECTED, '='); + } + elseif ($type == 'borrowed') { + $query->condition( + db_or() + ->condition('m.status', MUAMBA_ACCEPTED, '=') + ->condition('m.status', MUAMBA_RETURNED, '=') + ->condition('m.status', MUAMBA_RECOVERED, '=') + ->condition('m.status', MUAMBA_LOST, '=') + ); + } + } + + return $query->countQuery()->execute()->fetchField(); +} -- cgit v1.2.3