You are here

protected function AgreementHandler::hasAuthenticatedUserAgreed in Agreement 3.0.x

Same name and namespace in other branches
  1. 8.2 src/AgreementHandler.php \Drupal\agreement\AgreementHandler::hasAuthenticatedUserAgreed()

Check the status of a user account for a particular agreement.

Parameters

\Drupal\agreement\Entity\Agreement $agreement: The agreement to check if a user has agreed.

\Drupal\Core\Session\AccountProxyInterface $account: The user account to check.

Return value

bool TRUE if the user account has agreed to this agreement.

1 call to AgreementHandler::hasAuthenticatedUserAgreed()
AgreementHandler::hasAgreed in src/AgreementHandler.php
Check the status of an user account for a particular agreement.

File

src/AgreementHandler.php, line 301

Class

AgreementHandler
Agreement handler provides methods for looking up agreements.

Namespace

Drupal\agreement

Code

protected function hasAuthenticatedUserAgreed(Agreement $agreement, AccountProxyInterface $account) {
  $settings = $agreement
    ->getSettings();
  $frequency = $settings['frequency'];
  $query = $this->connection
    ->select('agreement');
  $query
    ->fields('agreement', [
    'agreed',
  ])
    ->condition('uid', $account
    ->id())
    ->condition('type', $agreement
    ->id())
    ->range(0, 1);
  if ($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).
    $timestamp = $agreement
      ->getAgreementFrequencyTimestamp();
    if ($timestamp > 0) {
      $query
        ->condition('agreed_date', $agreement
        ->getAgreementFrequencyTimestamp(), '>=');
    }
  }
  $agreed = $query
    ->execute()
    ->fetchField();
  return $agreed !== NULL && $agreed > 0;
}