You are here

function agreement_has_agreed in Agreement 7.2

Has the user account agreed to the agreement yet?

Parameters

object $account: The user account.

array $info: The agreement type..

Return value

bool TRUE if the user has agreed.

2 calls to agreement_has_agreed()
agreement_page in ./agreement.pages.inc
Callback for agreement URL.
agreement_type_get_best_match in ./agreement.module
Get the best match agreement type for a user and path.

File

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

Code

function agreement_has_agreed($account, $info) {
  $type = $info['name'];

  // Check the user account data for the agreement.
  if (isset($account->data['agreement']) && isset($account->data['agreement'][$type])) {
    return $info['settings']['frequency'] ? session_id() === $account->data['agreement'] : TRUE;
  }
  $query = db_select('agreement');
  $query
    ->fields('agreement', array(
    'agreed',
  ))
    ->condition('type', $type)
    ->condition('uid', $account->uid)
    ->range(0, 1);
  if ($info['settings']['frequency'] == 0) {

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

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