ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 ilTermsOfServiceHelper constructor. More...
 
 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

 $dataGatewayFactory
 
 $termsOfServiceEvaluation
 
 $criterionTypeFactory
 
 $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 
)

ilTermsOfServiceHelper constructor.

Parameters
ilTermsOfServiceDataGatewayFactory | null$dataGatewayFactory
ilTermsOfServiceDocumentEvaluation | null$termsOfServiceEvaluation
ilTermsOfServiceCriterionTypeFactoryInterface | null$criterionTypeFactory
ilObjTermsOfService | null$tos

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

31 {
32 global $DIC;
33
34 if (null === $dataGatewayFactory) {
36 $dataGatewayFactory->setDatabaseAdapter($DIC->database());
37 }
38 $this->dataGatewayFactory = $dataGatewayFactory;
39
40 if (null === $termsOfServiceEvaluation) {
41 $termsOfServiceEvaluation = $DIC['tos.document.evaluator'];
42 }
43 $this->termsOfServiceEvaluation = $termsOfServiceEvaluation;
44
45 if (null === $criterionTypeFactory) {
46 $criterionTypeFactory = $DIC['tos.criteria.type.factory'];
47 }
48 $this->criterionTypeFactory = $criterionTypeFactory;
49
50 if (null === $tos) {
52 }
53 $this->tos = $tos;
54 }
Class ilObjTermsOfService.
global $DIC
Definition: goto.php:24

References $criterionTypeFactory, $dataGatewayFactory, $DIC, $termsOfServiceEvaluation, and $tos.

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 }
Class ilTermsOfServiceAcceptanceEntity.

References 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((int) $user->getId()));
95 }
getId()
get object id @access public

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

◆ getEntityFactory()

ilTermsOfServiceHelper::getEntityFactory ( )
private
Returns
ilTermsOfServiceEntityFactory

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

242 {
244 }
Class ilTermsOfServiceEntityFactory.

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

+ Here is the caller graph for this function:

◆ hasToResignAcceptance()

ilTermsOfServiceHelper::hasToResignAcceptance ( ilObjUser  $user,
ilLogger  $logger 
)
Parameters
ilObjUser$user
ilLogger$logger
Returns
bool

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

167 : bool
168 {
169 $logger->debug(sprintf(
170 'Checking reevaluation of Terms of Service for user "%s" (id: %s) ...',
171 $user->getLogin(),
172 $user->getId()
173 ));
174
175 if (!$this->isGloballyEnabled()) {
176 $logger->debug(sprintf(
177 'Terms of Service disabled, resigning not required ...'
178 ));
179 return false;
180 }
181
182 if (!$this->isIncludedUser($user)) {
183 $logger->debug(sprintf(
184 'User is not included for Terms of Service acceptance, resigning not required ...'
185 ));
186 return false;
187 }
188
189 if (!$this->tos->shouldReevaluateOnLogin()) {
190 $logger->debug(sprintf(
191 'Reevaluation of documents is not enabled, resigning not required ...'
192 ));
193 return false;
194 }
195
196 if (!$user->getAgreeDate()) {
197 $logger->debug(sprintf(
198 'Terms of Service currently not accepted by user, resigning not required ...'
199 ));
200 return false;
201 }
202
203 $evaluator = $this->termsOfServiceEvaluation->withContextUser($user);
204 if (!$evaluator->hasDocument()) {
205 $logger->debug(sprintf(
206 'No signable Terms of Service document found, resigning not required ...'
207 ));
208 return false;
209 }
210
211 $entity = $this->getCurrentAcceptanceForUser($user);
212 if (!($entity->getId() > 0)) {
213 $logger->debug(sprintf(
214 'No signed Terms of Service document found, resigning not required ...'
215 ));
216 return false;
217 }
218
219 $historizedDocument = new ilTermsOfServiceHistorizedDocument(
220 $entity,
221 new ilTermsOfServiceAcceptanceHistoryCriteriaBag($entity->getSerializedCriteria()),
222 $this->criterionTypeFactory
223 );
224
225 if ($evaluator->evaluateDocument($historizedDocument)) {
226 $logger->debug(sprintf(
227 'Current user values do still match historized criteria, resigning not required ...'
228 ));
229 return false;
230 }
231
232 $logger->debug(sprintf(
233 'Current user values do not match historized criteria, resigning required ...'
234 ));
235 return true;
236 }
debug($a_message, $a_context=array())
getAgreeDate()
get the date when the user accepted the user agreement @access public
getLogin()
get login / username @access public

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
Returns
bool

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

59 : bool
60 {
61 return (new static())->tos->getStatus();
62 }

Referenced by ilAccountRegistrationGUI\__initForm(), ilAwarenessUserCollector\collectUsers(), ilObjUser\hasToAcceptTermsOfService(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilAccountRegistrationGUI\saveForm(), and ilPersonalProfileGUI\showUserAgreement().

+ Here is the caller graph for this function:

◆ isGloballyEnabled()

ilTermsOfServiceHelper::isGloballyEnabled ( )
Returns
bool

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)
Parameters
ilObjUser$user
Returns
bool

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

152 : bool
153 {
154 return (
155 'root' !== $user->getLogin() &&
156 !in_array($user->getId(), [ANONYMOUS_USER_ID, SYSTEM_USER_ID]) &&
157 !$user->isAnonymous() &&
158 (int) $user->getId() > 0
159 );
160 }
const SYSTEM_USER_ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: constants.php:24
const ANONYMOUS_USER_ID
Definition: constants.php:25

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)
Parameters
ilObjUser$user

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

142 : void
143 {
144 $user->setAgreeDate(null);
145 $user->update();
146 }
setAgreeDate($a_str)
set date the user account was accepted by the user nullindicates that the user has not accepted his a...
update()
update object in db

References ilObjUser\setAgreeDate(), and ilObject\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((int) $user->getId())
123 ->withTimestamp(time())
124 ->withText((string) $document->content())
125 ->withHash(md5($document->content()))
126 ->withDocumentId((int) $document->id())
127 ->withTitle((string) $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 to db
hasToAcceptTermsOfServiceInSession($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

ilTermsOfServiceHelper::$criterionTypeFactory
protected

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

Referenced by __construct().

◆ $dataGatewayFactory

ilTermsOfServiceHelper::$dataGatewayFactory
protected

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

Referenced by __construct(), and getDataGatewayFactory().

◆ $termsOfServiceEvaluation

ilTermsOfServiceHelper::$termsOfServiceEvaluation
protected

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

Referenced by __construct().

◆ $tos

ilTermsOfServiceHelper::$tos
protected

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

Referenced by __construct().


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