ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceAcceptanceDatabaseGateway.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 $db;
12 
17  public function __construct(ilDBInterface $db)
18  {
19  $this->db = $db;
20  }
21 
25  public function trackAcceptance(ilTermsOfServiceAcceptanceEntity $entity) : void
26  {
27  $res = $this->db->queryF(
28  'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
29  ['text', 'integer'],
30  [$entity->getHash(), $entity->getDocumentId()]
31  );
32 
33  if ($this->db->numRows($res)) {
34  $row = $this->db->fetchAssoc($res);
35  $versionId = $row['id'];
36  } else {
37  $versionId = $this->db->nextId('tos_versions');
38  $this->db->insert(
39  'tos_versions',
40  [
41  'id' => ['integer', $versionId],
42  'text' => ['clob', $entity->getText()],
43  'hash' => ['text', $entity->getHash()],
44  'doc_id' => ['integer', $entity->getDocumentId()],
45  'title' => ['text', $entity->getTitle()],
46  'ts' => ['integer', $entity->getTimestamp()]
47  ]
48  );
49  }
50 
51  $this->db->insert(
52  'tos_acceptance_track',
53  [
54  'tosv_id' => ['integer', $versionId],
55  'usr_id' => ['integer', $entity->getUserId()],
56  'criteria' => ['clob', $entity->getSerializedCriteria()],
57  'ts' => ['integer', $entity->getTimestamp()]
58  ]
59  );
60  }
61 
65  public function loadCurrentAcceptanceOfUser(
68  $this->db->setLimit(1, 0);
69 
70  $res = $this->db->queryF(
71  '
72  SELECT tos_versions.*,
73  tos_acceptance_track.ts accepted_ts,
74  tos_acceptance_track.criteria,
75  tos_acceptance_track.usr_id
76  FROM tos_acceptance_track
77  INNER JOIN tos_versions ON id = tosv_id
78  WHERE usr_id = %s
79  ORDER BY tos_acceptance_track.ts DESC
80  ',
81  ['integer'],
82  [$entity->getUserId()]
83  );
84  $row = $this->db->fetchAssoc($res);
85 
86  $entity = $entity
87  ->withId((int) $row['id'])
88  ->withUserId((int) $row['usr_id'])
89  ->withText((string) $row['text'])
90  ->withTimestamp((int) $row['accepted_ts'])
91  ->withHash((string) $row['hash'])
92  ->withDocumentId((int) $row['doc_id'])
93  ->withTitle((string) $row['title'])
94  ->withSerializedCriteria((string) $row['criteria']);
95 
96  return $entity;
97  }
98 
103  {
104  $res = $this->db->queryF(
105  '
106  SELECT *
107  FROM tos_versions
108  WHERE id = %s
109  ',
110  ['integer'],
111  [$entity->getId()]
112  );
113  $row = $this->db->fetchAssoc($res);
114 
115  $entity = $entity
116  ->withId($row['id'])
117  ->withText($row['text'])
118  ->withHash($row['hash'])
119  ->withDocumentId($row['doc_id'])
120  ->withTitle($row['title']);
121 
122  return $entity;
123  }
124 
129  {
130  $this->db->manipulate(
131  'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $this->db->quote($entity->getUserId(), 'integer')
132  );
133  }
134 }
__construct(ilDBInterface $db)
ilTermsOfServiceAcceptanceDatabaseGateway constructor.
loadById(ilTermsOfServiceAcceptanceEntity $entity)
ilTermsOfServiceAcceptanceEntity
foreach($_POST as $key=> $value) $res
loadCurrentAcceptanceOfUser(ilTermsOfServiceAcceptanceEntity $entity)
ilTermsOfServiceAcceptanceEntity
Class ilTermsOfServiceAcceptanceEntity.
deleteAcceptanceHistoryByUser(ilTermsOfServiceAcceptanceEntity $entity)
Interface ilTermsOfServiceAcceptanceDataGateway.