aboutsummaryrefslogtreecommitdiff
path: root/muamba.db.inc
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-11-09 13:50:38 -0200
committerSilvio Rhatto <rhatto@riseup.net>2011-11-09 13:50:38 -0200
commit024bd20549c58317e8565e7772eec5630295d33c (patch)
tree710a454814efe6e6d64f23c173125aa0bd82a487 /muamba.db.inc
parent3bae0572ed01c0dfc80a4d52e3eb05b766a73649 (diff)
downloadmuamba-024bd20549c58317e8565e7772eec5630295d33c.tar.gz
muamba-024bd20549c58317e8565e7772eec5630295d33c.tar.bz2
Adding views_handler_field_muamba_total()
Diffstat (limited to 'muamba.db.inc')
-rw-r--r--muamba.db.inc38
1 files changed, 38 insertions, 0 deletions
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();
+}