protected function AgreementHandler::agreeWhileLoggedIn in Agreement 3.0.x
Same name and namespace in other branches
- 8.2 src/AgreementHandler.php \Drupal\agreement\AgreementHandler::agreeWhileLoggedIn()
Accept agreement for an authenticated user.
Parameters
\Drupal\Core\Session\AccountProxyInterface $account: The user account that is agreeing.
\Drupal\agreement\Entity\Agreement $agreement: The agreement that the user is agreeing to.
int $agreed: An optional integer to set the agreement status to. Defaults to 1.
Return value
bool TRUE if the operation was successful. Otherwise FALSE.
1 call to AgreementHandler::agreeWhileLoggedIn()
- AgreementHandler::agree in src/
AgreementHandler.php - Accept the agreement for an user account.
File
- src/
AgreementHandler.php, line 245
Class
- AgreementHandler
- Agreement handler provides methods for looking up agreements.
Namespace
Drupal\agreementCode
protected function agreeWhileLoggedIn(AccountProxyInterface $account, Agreement $agreement, $agreed) {
try {
$transaction = $this->connection
->startTransaction();
$this->connection
->delete('agreement')
->condition('uid', $account
->id())
->condition('type', $agreement
->id())
->execute();
$id = $this->connection
->insert('agreement')
->fields([
'uid' => $account
->id(),
'type' => $agreement
->id(),
'agreed' => $agreed,
'sid' => session_id(),
'agreed_date' => $this->time
->getRequestTime(),
])
->execute();
} catch (DatabaseExceptionWrapper $e) {
$transaction
->rollback();
return FALSE;
} catch (\Exception $e) {
$transaction
->rollback();
return FALSE;
}
return isset($id);
}