]> gitweb.fluxo.info Git - drupal/muamba.git/commitdiff
Adding more muamba actions
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 24 Sep 2011 14:37:21 +0000 (11:37 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 24 Sep 2011 14:37:21 +0000 (11:37 -0300)
CREDITS.txt
images/basket.orig.png [new file with mode: 0644]
images/basket.png [new file with mode: 0644]
images/home.orig.png [new file with mode: 0644]
images/inbox.orig.png [new file with mode: 0644]
muamba-widget.tpl.php
muamba.info
muamba.install
muamba.misc.inc
muamba.module

index ba1a84179412a2048a916721f57a81f914ea145a..ee9123995794354f9c0f1b97baca58007ae4c5b1 100644 (file)
@@ -14,3 +14,6 @@ http://www.openclipart.org/detail/152557/capitalism-kills-by-worker-152557
 http://www.openclipart.org/detail/2213/crystal-earth-recycle-by-kuba
 http://www.openclipart.org/detail/27073/recycling-by-egore911
 http://www.openclipart.org/detail/57079/recover-symbol-by-doctormo
+http://www.openclipart.org/detail/147421/home-by-netalloy-147421
+http://www.openclipart.org/detail/107473/folder-inbox-by-anonymous
+http://www.openclipart.org/detail/160369/eshop-by-lbear
diff --git a/images/basket.orig.png b/images/basket.orig.png
new file mode 100644 (file)
index 0000000..8a57989
Binary files /dev/null and b/images/basket.orig.png differ
diff --git a/images/basket.png b/images/basket.png
new file mode 100644 (file)
index 0000000..33e689d
Binary files /dev/null and b/images/basket.png differ
diff --git a/images/home.orig.png b/images/home.orig.png
new file mode 100644 (file)
index 0000000..112c0b4
Binary files /dev/null and b/images/home.orig.png differ
diff --git a/images/inbox.orig.png b/images/inbox.orig.png
new file mode 100644 (file)
index 0000000..a106ae4
Binary files /dev/null and b/images/inbox.orig.png differ
index ff5c14092c92519698ad7e9342de5b3bf912e91a..1b2a598513829cf0d0de2428b7df7b844b28d498 100644 (file)
@@ -16,7 +16,7 @@ drupal_add_css($path .'/muamba.css');
 
 $icon = theme('image',
   array(
-    'path'  => $path .'/images/request.png',
+    'path'  => $path .'/images/basket.png',
     'alt'   => t('Request item'),
     'title' => t('Request item'),
   )
index 0b16b587502a55b92423ad2acccde9159767022d..05c134ed417828e75276c2858ed853d8a2a3514d 100644 (file)
@@ -9,3 +9,4 @@ dependencies[] = strongarm
 dependencies[] = muamba_interface
 dependencies[] = muamba_system
 dependencies[] = privatemsg
+dependencies[] = l10n_update
index 6e68603598d2413abda7fdcfefe95d307e560085..ab0bcef0122084e0fa987b7b2a5ad442d2b9474f 100644 (file)
@@ -5,9 +5,18 @@
  * Muamba installation functions.
  */
 
+/**
+ * Implements hook_install()
+ */
 function muamba_install() {
 }
 
+/**
+ * Implements hook_schema()
+ *
+ * @todo
+ *   Add privatemsg thread_id into muamba table.
+ */
 function muamba_schema() {
   $schema['muamba'] = array(
     'description' => 'The base table for muamba assets.',
index 25fceac21ed59d9bbeda172d2269b61690bae4ac..c164664bbe36676a656bcf53c829cd69a645aa5e 100644 (file)
@@ -16,14 +16,95 @@ function muamba_request($nid) {
   $nid  = (int) $nid;
   $node = node_load($nid);
 
-  if (!$node) {
-    // TODO: error
-    return;
+  if (!$node || $node->type != MUAMBA_NODE_TYPE) {
+    drupal_not_found();
   }
 
   global $user;
 
-  // TODO: check if user is not blocked?
-  privatemsg_new_thread(array(user_load($node->uid)), 'User request', 'User has requested an item');
+  // TODO: check if user has permission to access the node.
+  // TODO: check if user is not blocked by privatemsg?
+
+  // Check if user already requested the item
+  if (muamba_check_user_request($nid, $user->uid)) {
+    // TODO
+  }
+
+  // Issue item request
+  // TODO
+
+  // Notify item owner
+  privatemsg_new_thread(array(user_load($node->uid)), t('Item request'), 'User has requested an item');
+
+  // User output
   return t('You have requested an item');
 }
+
+/**
+ * Check if user already requested an item.
+ *
+ * @param $nid
+ *   Item nid.
+ *
+ * @param $uid
+ *   Requester user nid.
+ *
+ * @return
+ *   TRUE if user already requested an item, FALSE otherwise.
+ */
+function muamba_check_user_request($nid, $uid) {
+  if (!is_int($nid) || !is_int($uid)) {
+    return FALSE;
+  }
+
+  $query = db_select('muamba', 'm');
+
+  $query
+    ->condition('m.nid', $nid, '=')
+    ->condition('m.uid', $uid, '=');
+
+  $result = $query->countQuery()->execute()->fetchField();
+
+  if ($result > 0) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+ * Release an item requested by a given user.
+ *
+ * @param $nid
+ *   Item nid.
+ *
+ * @param $uid
+ *   Requester user uid.
+ *
+ * @todo
+ */
+function muamba_release($nid, $uid) {
+  global $user;
+
+  $nid  = (int) $nid;
+  $node = node_load($nid);
+
+  if (!$node || $node->type != MUAMBA_NODE_TYPE) {
+    drupal_not_found();
+  }
+
+  if ($node->uid != $user->uid) {
+    // TODO: not node owner
+  }
+}
+
+/**
+ * Get the requests sent or received.
+ *
+ * @param $uid
+ *   Requester user uid.
+ *
+ * @todo
+ */
+function muamba_get_requests($nid, $type = 'sent') {
+}
index 8a2da287a593e3a7d22ca7f6a9d57442de88c47c..a36b2681168425b5dd26189f73ccba3375403d8d 100644 (file)
@@ -5,6 +5,11 @@
  * Multiple-user Asset Manager and Borrowing Ambient.
  */
 
+/**
+ * Definitions.
+ */
+define('MUAMBA_NODE_TYPE', 'muamba');
+
 /**
  * Implements hook_permission()
  */
@@ -22,13 +27,45 @@ function muamba_permission() {
  */
 function muamba_menu() {
   $items['muamba/request'] = array(
-    'title'            => 'Request item',
+    'title'            => 'Request an item',
     'page callback'    => 'muamba_request',
     'access arguments' => array('request item'),
     'type'             => MENU_SUGGESTED_ITEM,
     'file'             => 'muamba.misc.inc',
   );
 
+  $items['muamba/accept'] = array(
+    'title'            => 'Accept an item request',
+    'page callback'    => 'muamba_accept',
+    'access arguments' => array('accept item'),
+    'type'             => MENU_SUGGESTED_ITEM,
+    'file'             => 'muamba.misc.inc',
+  );
+
+  $items['muamba/reject'] = array(
+    'title'            => 'Reject an item request',
+    'page callback'    => 'muamba_reject',
+    'access arguments' => array('reject item'),
+    'type'             => MENU_SUGGESTED_ITEM,
+    'file'             => 'muamba.misc.inc',
+  );
+
+  $items['muamba/release'] = array(
+    'title'            => 'Release an item',
+    'page callback'    => 'muamba_release',
+    'access arguments' => array('release item'),
+    'type'             => MENU_SUGGESTED_ITEM,
+    'file'             => 'muamba.misc.inc',
+  );
+
+  $items['muamba/return'] = array(
+    'title'            => 'Return an item',
+    'page callback'    => 'muamba_return',
+    'access arguments' => array('return item'),
+    'type'             => MENU_SUGGESTED_ITEM,
+    'file'             => 'muamba.misc.inc',
+  );
+
   return $items;
 }
 
@@ -43,7 +80,7 @@ function muamba_node_view($node, $view_mode, $langcode) {
   global $user;
 
   // Do not show widget to the owner or on non-muamba content types
-  if ($node->uid == $user->uid || $node->type != 'muamba') {
+  if ($node->uid == $user->uid || $node->type != MUAMBA_NODE_TYPE) {
     return;
   }