You are here

function invite_notifications_invite_accept in Invite 7.4

Implements hook_invite_accept().

File

modules/invite_notifications/invite_notifications.module, line 133
Main file for the Invite Notifications.

Code

function invite_notifications_invite_accept($invite) {
  $message = array(
    'iid' => $invite->iid,
    'uid' => $invite->uid,
    'inviter' => $invite->uid,
    'invitee' => $invite->invitee,
    'message_type' => 'inviter_notification',
  );

  // Flag the inviting user, this triggers status notifications and
  // saves us some queries otherwise.
  if (drupal_write_record('invite_notifications', $message) == SAVED_NEW) {
    $inviter = user_load($invite->uid);
    user_save($inviter, array(
      'data' => array(
        'notification_received' => TRUE,
      ),
    ));
    $invitee = user_load($invite->invitee);
    user_save($invitee, array(
      'data' => array(
        'notification_received' => FALSE,
      ),
    ));
    db_update('invite_notifications')
      ->fields(array(
      'status' => 0,
    ))
      ->condition('iid', $invite->iid, '=')
      ->execute();
  }
}