ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceHelper.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
11  protected $database;
12 
15 
21  public function __construct(
22  \ilDBInterface $database = null,
24  ) {
25  global $DIC;
26 
27  if (null === $database) {
28  $database = $DIC->database();
29  }
30  $this->database = $database;
31 
32  if (null === $dataGatewayFactory) {
33  $dataGatewayFactory = new \ilTermsOfServiceDataGatewayFactory();
34  $dataGatewayFactory->setDatabaseAdapter($this->database);
35  }
36  $this->dataGatewayFactory = $dataGatewayFactory;
37  }
38 
42  public static function isEnabled() : bool
43  {
44  global $DIC;
45 
46  return (bool) $DIC['ilSetting']->get('tos_status', false);
47  }
48 
52  public static function setStatus(bool $status)
53  {
54  global $DIC;
55 
56  $DIC['ilSetting']->set('tos_status', (int) $status);
57  }
58 
63  public function deleteAcceptanceHistoryByUser(int $userId)
64  {
65  $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
66  $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
67 
68  $databaseGateway->deleteAcceptanceHistoryByUser($entity->withUserId($userId));
69  }
70 
77  {
78  $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
79  $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
80 
81  return $databaseGateway->loadCurrentAcceptanceOfUser($entity->withUserId((int) $user->getId()));
82  }
83 
90  {
91  $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
92  $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
93 
94  return $databaseGateway->loadById($entity->withId($id));
95  }
96 
103  {
104  $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
105  $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
106 
107  $entity = $entity
108  ->withUserId((int) $user->getId())
109  ->withTimestamp(time())
110  ->withText((string) $document->content())
111  ->withHash(md5($document->content()))
112  ->withDocumentId((int) $document->id())
113  ->withTitle((string) $document->title());
114 
115  $criteriaBag = new \ilTermsOfServiceAcceptanceHistoryCriteriaBag($document->criteria());
116  $entity = $entity->withSerializedCriteria($criteriaBag->toJson());
117 
118  $databaseGateway->trackAcceptance($entity);
119 
120  $user->writeAccepted();
121 
123  }
124 
129  {
130  return new \ilTermsOfServiceEntityFactory();
131  }
132 
137  {
139  }
140 }
Class ilTermsOfServiceEntityFactory.
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
writeAccepted()
write accept date of user agreement to db
Class ilTermsOfServiceDataGatewayFactory.
getId()
get object id public
trackAcceptance(\ilObjUser $user, \ilTermsOfServiceSignableDocument $document)
getCurrentAcceptanceForUser(\ilObjUser $user)
$user
Definition: migrateto20.php:57
__construct(\ilDBInterface $database=null, \ilTermsOfServiceDataGatewayFactory $dataGatewayFactory=null)
ilTermsOfServiceHelper constructor.
Class ilTermsOfServiceHelper.
Class ilTermsOfServiceAcceptanceEntity.
Interface ilTermsOfServiceSignableDocument.
hasToAcceptTermsOfServiceInSession($status=null)