You are here

function comment_notify_set_user_notification_setting in Comment Notify 7

Sets the notification preferences for a specific user.

Parameters

int $uid:

int $node_notification:

int $comment_notification:

Return value

bool

Throws

\Exception

2 calls to comment_notify_set_user_notification_setting()
comment_notify_comment_insert in ./comment_notify.module
Implements hook_comment_insert().
comment_notify_user_update in ./comment_notify.module

File

./comment_notify.inc, line 111
Contains functions which utilize the database and other internal helpers.

Code

function comment_notify_set_user_notification_setting($uid, $node_notification = NULL, $comment_notification = NULL) {
  if (!$uid) {
    throw new Exception('Cannot set user preference, uid missing');
  }
  $fields = array(
    'uid' => $uid,
  );
  if (!is_null($node_notification)) {
    $fields['node_notify'] = $node_notification;
  }
  if (!is_null($comment_notification)) {
    $fields['comment_notify'] = $comment_notification;
  }
  if (comment_notify_get_user_notification_setting($uid)) {
    $query = db_update('comment_notify_user_settings');
    $query
      ->condition('uid', $uid);
  }
  else {
    $query = db_insert('comment_notify_user_settings');
  }
  return (bool) $query
    ->fields($fields)
    ->execute();
}