You are here

function _pm_email_notify_is_enabled in Privatemsg 7

Same name and namespace in other branches
  1. 6 pm_email_notify/pm_email_notify.module \_pm_email_notify_is_enabled()

Retrieve notification setting of a user.

This function retrieves user's pm notification preference from database, if user preference doesn't exist - it uses default value instead

Parameters

$uid: User uid

2 calls to _pm_email_notify_is_enabled()
pm_email_notify_form_alter in pm_email_notify/pm_email_notify.module
Implements hook_form_alter().
pm_email_notify_privatemsg_message_insert in pm_email_notify/pm_email_notify.module
Implements hook_privatemsg_message_insert().

File

pm_email_notify/pm_email_notify.module, line 17
Notifies users about new Private Messages via Email.

Code

function _pm_email_notify_is_enabled($uid) {
  $notifications =& drupal_static(__FUNCTION__, array());

  // Cache the result set in case this method is executed in batched operation which will perform many unnecessary repeated selects for the same user
  if (!isset($notifications[$uid])) {
    $mail_notification = db_query('SELECT email_notify_is_enabled FROM {pm_email_notify} WHERE user_id = :uid', array(
      ':uid' => $uid,
    ))
      ->fetchField();
    if ($mail_notification === FALSE) {

      //db_result returns FALSE if result was not found.
      $mail_notification = variable_get('pm_email_notify_default', TRUE);
    }
    $notifications[$uid] = $mail_notification;
  }
  return $notifications[$uid];
}