aboutsummaryrefslogtreecommitdiff
path: root/muamba.business.inc
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-09-24 20:42:57 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-09-24 20:42:57 -0300
commit5cd0054058a718e5694c8542f72f586f06b69fc8 (patch)
tree25c384738c580bd5e9b05a0943be1e79b82dce9d /muamba.business.inc
parent4f15de058dc6dadee6e79d16b441202b54161f02 (diff)
downloadmuamba-5cd0054058a718e5694c8542f72f586f06b69fc8.tar.gz
muamba-5cd0054058a718e5694c8542f72f586f06b69fc8.tar.bz2
Basic working code for an item request
Diffstat (limited to 'muamba.business.inc')
-rw-r--r--muamba.business.inc39
1 files changed, 26 insertions, 13 deletions
diff --git a/muamba.business.inc b/muamba.business.inc
index f7b9e05..59e4bd1 100644
--- a/muamba.business.inc
+++ b/muamba.business.inc
@@ -12,30 +12,43 @@
* Requested item.
*/
function muamba_request($nid) {
- // Sanitize
+ global $user;
$nid = (int) $nid;
$node = node_load($nid);
- if (!$node || $node->type != MUAMBA_NODE_TYPE) {
+ // Access check
+ if (!$node || $node->type != MUAMBA_NODE_TYPE || !node_access('view', $node)) {
drupal_not_found();
}
- global $user;
-
- // TODO: check if user has permission to access the node.
- // TODO: check if user is not blocked by privatemsg?
+ // Check if user is blocked by the item owner
+ if (module_exists('pm_block_user')) {
+ $owner = user_load($node->uid);
+ if (pm_block_user_has_blocked($user, $owner)) {
+ return t('The item owner has blocked you from asking this item.');
+ }
+ }
// Check if user already requested the item
if (muamba_check_user_request($nid, $user->uid)) {
- // TODO
+ return t('You already requested this item.');
}
// Notify item owner
$thread = privatemsg_new_thread(array(user_load($node->uid)), t('Item request'), 'User has requested an item');
- $thread_id = $thread['message']['thread_id'];
+ $thread_id = $thread['message']->thread_id;
// Issue item request
- // TODO
+ $request = db_insert('muamba')
+ ->fields(
+ array(
+ 'nid' => $nid,
+ 'uid' => $user->uid,
+ 'status' => MUAMBA_REQUESTED,
+ 'thread_id' => $thread_id,
+ )
+ )
+ ->execute();
// User output
return t('You have requested an item');
@@ -54,15 +67,15 @@ function muamba_request($nid) {
* 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;
- }
+ $nid = (int) $nid;
+ $uid = (int) $uid;
$query = db_select('muamba', 'm');
$query
->condition('m.nid', $nid, '=')
- ->condition('m.uid', $uid, '=');
+ ->condition('m.uid', $uid, '=')
+ ->condition('m.status', MUAMBA_REQUESTED, '=');
$result = $query->countQuery()->execute()->fetchField();