You are here

public function AgreementHandler::lastAgreed in Agreement 3.0.x

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

Get the last agreement for the user for the agreement.

Parameters

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

\Drupal\user\UserInterface $account: The user account to check.

Return value

int The timestamp that the user last agreed or -1 if never agreed.

Overrides AgreementHandlerInterface::lastAgreed

File

src/AgreementHandler.php, line 107

Class

AgreementHandler
Agreement handler provides methods for looking up agreements.

Namespace

Drupal\agreement

Code

public function lastAgreed(Agreement $agreement, UserInterface $account) {
  $query = $this->connection
    ->select('agreement');
  $query
    ->fields('agreement', [
    'agreed_date',
  ])
    ->condition('uid', $account
    ->id())
    ->condition('type', $agreement
    ->id())
    ->range(0, 1);
  $agreed_date = $query
    ->execute()
    ->fetchField();
  return $agreed_date === FALSE || $agreed_date === NULL ? -1 : $agreed_date;
}