ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTermsOfServiceHelper.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $database;
12
15
21 public function __construct(
24 ) {
25 global $DIC;
26
27 if (null === $database) {
28 $database = $DIC->database();
29 }
30 $this->database = $database;
31
32 if (null === $dataGatewayFactory) {
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) : void
53 {
54 global $DIC;
55
56 $DIC['ilSetting']->set('tos_status', (int) $status);
57 }
58
63 public function deleteAcceptanceHistoryByUser(int $userId) : void
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
89 public function getById(int $id) : ilTermsOfServiceAcceptanceEntity
90 {
91 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
92 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
93
94 return $databaseGateway->loadById($entity->withId($id));
95 }
96
103 public function trackAcceptance(ilObjUser $user, ilTermsOfServiceSignableDocument $document) : void
104 {
105 $entity = $this->getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
106 $databaseGateway = $this->getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
107
108 $entity = $entity
109 ->withUserId((int) $user->getId())
110 ->withTimestamp(time())
111 ->withText((string) $document->content())
112 ->withHash(md5($document->content()))
113 ->withDocumentId((int) $document->id())
114 ->withTitle((string) $document->title());
115
116 $criteriaBag = new ilTermsOfServiceAcceptanceHistoryCriteriaBag($document->criteria());
117 $entity = $entity->withSerializedCriteria($criteriaBag->toJson());
118
119 $databaseGateway->trackAcceptance($entity);
120
121 $user->writeAccepted();
122
124 }
125
130 {
132 }
133
138 {
140 }
141}
An exception for terminatinating execution or to throw for unit testing.
writeAccepted()
write accept date of user agreement to db
hasToAcceptTermsOfServiceInSession($status=null)
getId()
get object id @access public
Class ilTermsOfServiceAcceptanceEntity.
Class ilTermsOfServiceEntityFactory.
Class ilTermsOfServiceHelper.
__construct(ilDBInterface $database=null, ilTermsOfServiceDataGatewayFactory $dataGatewayFactory=null)
ilTermsOfServiceHelper constructor.
trackAcceptance(ilObjUser $user, ilTermsOfServiceSignableDocument $document)
Interface ilDBInterface.
Interface ilTermsOfServiceSignableDocument.
$DIC
Definition: xapitoken.php:46