You are here

function notifications_user in Notifications 6.4

Same name and namespace in other branches
  1. 5 notifications.module \notifications_user()
  2. 6 notifications.module \notifications_user()
  3. 6.2 notifications.module \notifications_user()
  4. 6.3 notifications.module \notifications_user()
  5. 7 notifications.module \notifications_user()

Implementation of hook_user().

File

./notifications.module, line 389
Notifications module

Code

function notifications_user($type, $edit, $user, $category = NULL) {
  switch ($type) {
    case 'delete':

      // Delete related data on tables
      notifications_delete_subscriptions(array(
        'uid' => $user->uid,
      ));
      break;
    case 'update':
      if (isset($edit['status'])) {
        if ($edit['status'] == 0) {

          // user is being blocked now
          // Delete pending notifications and block existing active subscriptions
          db_query('UPDATE {notifications} SET status = %d WHERE status = %d AND uid = %d', Notifications_Subscription::STATUS_BLOCKED, Notifications_Subscription::STATUS_ACTIVE, $user->uid);
          notifications_queue()
            ->queue_clean(array(
            'uid' => $user->uid,
          ));
        }
        else {

          // User may be being unblocked, unblock subscriptions if any
          db_query('UPDATE {notifications} SET status = %d WHERE status = %d AND uid = %d', Notifications_Subscription::STATUS_ACTIVE, Notifications_Subscription::STATUS_BLOCKED, $user->uid);
        }
      }
      break;
    case 'after_update':

      // Update language for all existing subscriptions
      if ($language = user_preferred_language($user)) {
        db_query("UPDATE {notifications} SET language = '%s' WHERE uid = %d", $language->language, $user->uid);
      }
      break;
  }
}