You are here

function _agreement_status in Agreement 7.2

Same name and namespace in other branches
  1. 6.2 agreement.module \_agreement_status()
  2. 6 agreement.module \_agreement_status()

Internal function to get the user's "agreement status".

@internal

Parameters

object $uid: (Optional) UID for which the status should be checked. Defaults to current user.

int $frequency: (Optional) Frequency. This is here for legacy purposes.

int $reset: (Optional) Whether a "reset" has occurred on the agreement.

Return value

bool if agreement found in db.

Deprecated

See agreement_has_agreed().

File

./agreement.module, line 488
Agreement module code - agreement.module.

Code

function _agreement_status($uid = NULL, $frequency = 0, $reset = 0) {

  // If the UID is not specified, use the current user.
  if (empty($uid)) {
    global $user;
    $uid = $user->uid;
  }

  // Make sure we weren't passed some garbage as $uid.
  $uid = (int) $uid;
  $query = db_select('agreement', 'a');
  $query
    ->fields('a', array(
    'agreed',
  ))
    ->condition('a.uid', $uid, '=')
    ->condition('a.name', 'default', '=')
    ->range(0, 1);

  // Must agree on every login.
  if ($frequency == 0) {
    $query
      ->condition('a.sid', session_id(), '=');
  }
  else {

    // Must agree when frequency is set greater than zero (number of days).
    if ($frequency > 0) {
      $frequency_timestamp = time() - $frequency * 24 * 60 * 60;
    }
    else {
      $frequency_timestamp = 0;
    }
    $timestamp = max($reset, $frequency_timestamp);
    if ($timestamp > 0) {
      $query
        ->condition('agreed_date', $timestamp, '>=');
    }
  }
  return $query
    ->execute()
    ->fetchField();
}