ILIAS  release_8 Revision v8.24
ilTermsOfServiceHelper Class Reference

Class ilTermsOfServiceHelper. More...

+ Collaboration diagram for ilTermsOfServiceHelper:

Public Member Functions

 __construct (?ilTermsOfServiceDataGatewayFactory $dataGatewayFactory=null, ?ilTermsOfServiceDocumentEvaluation $termsOfServiceEvaluation=null, ?ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory=null, ?ilObjTermsOfService $tos=null)
 
 isGloballyEnabled ()
 
 deleteAcceptanceHistoryByUser (int $userId)
 
 getCurrentAcceptanceForUser (ilObjUser $user)
 
 getById (int $id)
 
 trackAcceptance (ilObjUser $user, ilTermsOfServiceSignableDocument $document)
 
 resetAcceptance (ilObjUser $user)
 
 isIncludedUser (ilObjUser $user)
 
 hasToResignAcceptance (ilObjUser $user, ilLogger $logger)
 

Static Public Member Functions

static isEnabled ()
 

Protected Attributes

ilTermsOfServiceDataGatewayFactory $dataGatewayFactory
 
ilTermsOfServiceDocumentEvaluation $termsOfServiceEvaluation
 
ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory
 
ilObjTermsOfService $tos
 

Private Member Functions

 getEntityFactory ()
 
 getDataGatewayFactory ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilTermsOfServiceHelper::__construct ( ?ilTermsOfServiceDataGatewayFactory  $dataGatewayFactory = null,
?ilTermsOfServiceDocumentEvaluation  $termsOfServiceEvaluation = null,
?ilTermsOfServiceCriterionTypeFactoryInterface  $criterionTypeFactory = null,
?ilObjTermsOfService  $tos = null 
)

Definition at line 32 of file class.ilTermsOfServiceHelper.php.

37 {
38 global $DIC;
39
40 if (null === $dataGatewayFactory) {
43 }
44 $this->dataGatewayFactory = $dataGatewayFactory;
45
46 if (null === $termsOfServiceEvaluation) {
47 $termsOfServiceEvaluation = $DIC['tos.document.evaluator'];
48 }
49 $this->termsOfServiceEvaluation = $termsOfServiceEvaluation;
50
51 if (null === $criterionTypeFactory) {
52 $criterionTypeFactory = $DIC['tos.criteria.type.factory'];
53 }
54 $this->criterionTypeFactory = $criterionTypeFactory;
55
56 if (null === $tos) {
58 }
59 $this->tos = $tos;
60 }
Class ilObjTermsOfService.
ilTermsOfServiceDataGatewayFactory $dataGatewayFactory
ilTermsOfServiceDocumentEvaluation $termsOfServiceEvaluation
ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory
global $DIC
Definition: feed.php:28

References $criterionTypeFactory, $dataGatewayFactory, $DIC, $termsOfServiceEvaluation, $tos, and ilTermsOfServiceDataGatewayFactory\setDatabaseAdapter().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteAcceptanceHistoryByUser()

ilTermsOfServiceHelper::deleteAcceptanceHistoryByUser ( int  $userId)
Parameters
int$userId
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException

Definition at line 76 of file class.ilTermsOfServiceHelper.php.

76 : void
77 {
78 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
79 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
80
81 $databaseGateway->deleteAcceptanceHistoryByUser($entity->withUserId($userId));
82 }

References getDataGatewayFactory(), and getEntityFactory().

+ Here is the call graph for this function:

◆ getById()

ilTermsOfServiceHelper::getById ( int  $id)
Parameters
int$id
Returns
ilTermsOfServiceAcceptanceEntity
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException

Definition at line 102 of file class.ilTermsOfServiceHelper.php.

103 {
104 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
105 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
106
107 return $databaseGateway->loadById($entity->withId($id));
108 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, getDataGatewayFactory(), and getEntityFactory().

+ Here is the call graph for this function:

◆ getCurrentAcceptanceForUser()

ilTermsOfServiceHelper::getCurrentAcceptanceForUser ( ilObjUser  $user)
Parameters
ilObjUser$user
Returns
ilTermsOfServiceAcceptanceEntity
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException

Definition at line 89 of file class.ilTermsOfServiceHelper.php.

90 {
91 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
92 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
93
94 return $databaseGateway->loadCurrentAcceptanceOfUser($entity->withUserId($user->getId()));
95 }

References getDataGatewayFactory(), getEntityFactory(), and ilObject\getId().

Referenced by hasToResignAcceptance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDataGatewayFactory()

ilTermsOfServiceHelper::getDataGatewayFactory ( )
private

Definition at line 222 of file class.ilTermsOfServiceHelper.php.

References $dataGatewayFactory.

Referenced by deleteAcceptanceHistoryByUser(), getById(), getCurrentAcceptanceForUser(), and trackAcceptance().

+ Here is the caller graph for this function:

◆ getEntityFactory()

ilTermsOfServiceHelper::getEntityFactory ( )
private

Definition at line 217 of file class.ilTermsOfServiceHelper.php.

218 {
220 }
Class ilTermsOfServiceEntityFactory.

Referenced by deleteAcceptanceHistoryByUser(), getById(), getCurrentAcceptanceForUser(), and trackAcceptance().

+ Here is the caller graph for this function:

◆ hasToResignAcceptance()

ilTermsOfServiceHelper::hasToResignAcceptance ( ilObjUser  $user,
ilLogger  $logger 
)

Definition at line 163 of file class.ilTermsOfServiceHelper.php.

163 : bool
164 {
165 $logger->debug(sprintf(
166 'Checking reevaluation of Terms of Service for user "%s" (id: %s) ...',
167 $user->getLogin(),
168 $user->getId()
169 ));
170
171 if (!$this->isGloballyEnabled()) {
172 $logger->debug('Terms of Service disabled, resigning not required ...');
173 return false;
174 }
175
176 if (!$this->isIncludedUser($user)) {
177 $logger->debug('User is not included for Terms of Service acceptance, resigning not required ...');
178 return false;
179 }
180
181 if (!$this->tos->shouldReevaluateOnLogin()) {
182 $logger->debug('Reevaluation of documents is not enabled, resigning not required ...');
183 return false;
184 }
185
186 if (!$user->getAgreeDate()) {
187 $logger->debug('Terms of Service currently not accepted by user, resigning not required ...');
188 return false;
189 }
190
191 $evaluator = $this->termsOfServiceEvaluation->withContextUser($user);
192 if (!$evaluator->hasDocument()) {
193 $logger->debug('No signable Terms of Service document found, resigning not required ...');
194 return false;
195 }
196
197 $entity = $this->getCurrentAcceptanceForUser($user);
198 if (!($entity->getId() > 0)) {
199 $logger->debug('No signed Terms of Service document found, resigning not required ...');
200 return false;
201 }
202
203 $historizedDocument = new ilTermsOfServiceHistorizedDocument(
204 $entity,
205 new ilTermsOfServiceAcceptanceHistoryCriteriaBag($entity->getSerializedCriteria())
206 );
207
208 if ($evaluator->evaluateDocument($historizedDocument)) {
209 $logger->debug('Current user values do still match historized criteria, resigning not required ...');
210 return false;
211 }
212
213 $logger->debug('Current user values do not match historized criteria, resigning required ...');
214 return true;
215 }
debug(string $a_message, array $a_context=array())

References ilLogger\debug(), ilObjUser\getAgreeDate(), getCurrentAcceptanceForUser(), ilObject\getId(), ilObjUser\getLogin(), isGloballyEnabled(), and isIncludedUser().

+ Here is the call graph for this function:

◆ isEnabled()

static ilTermsOfServiceHelper::isEnabled ( )
static

Definition at line 62 of file class.ilTermsOfServiceHelper.php.

62 : bool
63 {
64 return (new self())->tos->getStatus();
65 }

Referenced by ILIAS\Awareness\User\Collector\collectUsers(), ilObjUser\hasToAcceptTermsOfService(), ilAccountRegistrationGUI\initForm(), ilAccountRegistrationGUI\saveForm(), and ilPersonalProfileGUI\showUserAgreement().

+ Here is the caller graph for this function:

◆ isGloballyEnabled()

ilTermsOfServiceHelper::isGloballyEnabled ( )

Definition at line 67 of file class.ilTermsOfServiceHelper.php.

67 : bool
68 {
69 return $this->tos->getStatus();
70 }

Referenced by hasToResignAcceptance().

+ Here is the caller graph for this function:

◆ isIncludedUser()

ilTermsOfServiceHelper::isIncludedUser ( ilObjUser  $user)

Definition at line 145 of file class.ilTermsOfServiceHelper.php.

145 : bool
146 {
147 $excluded_roles = [];
148 if (defined('ANONYMOUS_USER_ID')) {
149 $excluded_roles[] = ANONYMOUS_USER_ID;
150 }
151 if (defined('SYSTEM_USER_ID')) {
152 $excluded_roles[] = SYSTEM_USER_ID;
153 }
154
155 return (
156 'root' !== $user->getLogin() &&
157 !in_array($user->getId(), $excluded_roles, true) &&
158 !$user->isAnonymous() &&
159 $user->getId() > 0
160 );
161 }
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, ilObject\getId(), ilObjUser\getLogin(), ilObjUser\isAnonymous(), and SYSTEM_USER_ID.

Referenced by hasToResignAcceptance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetAcceptance()

ilTermsOfServiceHelper::resetAcceptance ( ilObjUser  $user)

Definition at line 139 of file class.ilTermsOfServiceHelper.php.

139 : void
140 {
141 $user->setAgreeDate(null);
142 $user->update();
143 }
setAgreeDate(?string $a_str)

References ilObjUser\setAgreeDate(), and ilObjUser\update().

+ Here is the call graph for this function:

◆ trackAcceptance()

ilTermsOfServiceHelper::trackAcceptance ( ilObjUser  $user,
ilTermsOfServiceSignableDocument  $document 
)
Parameters
ilObjUser$user
ilTermsOfServiceSignableDocument$document
Exceptions
ilTermsOfServiceMissingDatabaseAdapterException
ilTermsOfServiceUnexpectedCriteriaBagContentException

Definition at line 116 of file class.ilTermsOfServiceHelper.php.

116 : void
117 {
118 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
119 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
120
121 $entity = $entity
122 ->withUserId($user->getId())
123 ->withTimestamp(time())
124 ->withText($document->content())
125 ->withHash(md5($document->content()))
126 ->withDocumentId($document->id())
127 ->withTitle($document->title());
128
129 $criteriaBag = new ilTermsOfServiceAcceptanceHistoryCriteriaBag($document->criteria());
130 $entity = $entity->withSerializedCriteria($criteriaBag->toJson());
131
132 $databaseGateway->trackAcceptance($entity);
133
134 $user->writeAccepted();
135
137 }
writeAccepted()
write accept date of user agreement
hasToAcceptTermsOfServiceInSession(?bool $status=null)

References ilTermsOfServiceSignableDocument\content(), ilTermsOfServiceSignableDocument\criteria(), getDataGatewayFactory(), getEntityFactory(), ilObject\getId(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilTermsOfServiceSignableDocument\id(), ilTermsOfServiceSignableDocument\title(), and ilObjUser\writeAccepted().

+ Here is the call graph for this function:

Field Documentation

◆ $criterionTypeFactory

ilTermsOfServiceCriterionTypeFactoryInterface ilTermsOfServiceHelper::$criterionTypeFactory
protected

Definition at line 29 of file class.ilTermsOfServiceHelper.php.

Referenced by __construct().

◆ $dataGatewayFactory

ilTermsOfServiceDataGatewayFactory ilTermsOfServiceHelper::$dataGatewayFactory
protected

Definition at line 27 of file class.ilTermsOfServiceHelper.php.

Referenced by __construct(), and getDataGatewayFactory().

◆ $termsOfServiceEvaluation

ilTermsOfServiceDocumentEvaluation ilTermsOfServiceHelper::$termsOfServiceEvaluation
protected

Definition at line 28 of file class.ilTermsOfServiceHelper.php.

Referenced by __construct().

◆ $tos

ilObjTermsOfService ilTermsOfServiceHelper::$tos
protected

Definition at line 30 of file class.ilTermsOfServiceHelper.php.

Referenced by __construct().


The documentation for this class was generated from the following file: