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
$icon = theme('image',
array(
- 'path' => $path .'/images/request.png',
+ 'path' => $path .'/images/basket.png',
'alt' => t('Request item'),
'title' => t('Request item'),
)
dependencies[] = muamba_interface
dependencies[] = muamba_system
dependencies[] = privatemsg
+dependencies[] = l10n_update
* 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.',
$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') {
+}
* Multiple-user Asset Manager and Borrowing Ambient.
*/
+/**
+ * Definitions.
+ */
+define('MUAMBA_NODE_TYPE', 'muamba');
+
/**
* Implements hook_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;
}
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;
}