You are here

function notifications_custom_account_update in Notifications 6

Same name and namespace in other branches
  1. 6.4 notifications_custom/notifications_custom.module \notifications_custom_account_update()

Update custom subscriptions for user account

Parameters

$account: User account

$update: Array of type => status

Return value

int The number of updated subscriptions

2 calls to notifications_custom_account_update()
notifications_custom_user_overview_submit in notifications_custom/notifications_custom.module
Form submission with custom notifications
notifications_custom_user_save in notifications_custom/notifications_custom.module
Save user subscription

File

notifications_custom/notifications_custom.module, line 208
Custom notifications module

Code

function notifications_custom_account_update($account, $update) {
  $changed = 0;
  foreach ($update as $type => $value) {
    $user_subs = notifications_custom_get_subscription($type, $account->uid);
    if ($value && !$user_subs) {

      // Add new subscription
      $subscription = notifications_custom_build_subscription($type);
      $subscription->uid = $account->uid;
      notifications_save_subscription($subscription);
      $changed++;
    }
    elseif (!$value && $user_subs) {

      // Disable existing subscription
      notifications_delete_subscription($user_subs->sid);
      $changed++;
    }
  }
  return $changed;
}