ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceAcceptanceDatabaseGateway.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 $db;
12 
17  public function __construct(\ilDBInterface $db)
18  {
19  $this->db = $db;
20  }
21 
26  {
27  $res = $this->db->queryF(
28  'SELECT id FROM tos_versions WHERE hash = %s AND doc_id = %s',
29  array('text', 'integer'),
30  array($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 
66  {
67  $this->db->setLimit(1, 0);
68 
69  $res = $this->db->queryF(
70  '
71  SELECT tos_versions.*,
72  tos_acceptance_track.ts accepted_ts,
73  tos_acceptance_track.criteria,
74  tos_acceptance_track.usr_id
75  FROM tos_acceptance_track
76  INNER JOIN tos_versions ON id = tosv_id
77  WHERE usr_id = %s
78  ORDER BY tos_acceptance_track.ts DESC
79  ',
80  ['integer'],
81  [$entity->getUserId()]
82  );
83  $row = $this->db->fetchAssoc($res);
84 
85  $entity = $entity
86  ->withId((int) $row['id'])
87  ->withUserId((int) $row['usr_id'])
88  ->withText((string) $row['text'])
89  ->withTimestamp((int) $row['accepted_ts'])
90  ->withHash((string) $row['hash'])
91  ->withDocumentId((int) $row['doc_id'])
92  ->withTitle((string) $row['title'])
93  ->withSerializedCriteria((string) $row['criteria']);
94 
95  return $entity;
96  }
97 
102  {
103  $res = $this->db->queryF(
104  '
105  SELECT *
106  FROM tos_versions
107  WHERE id = %s
108  ',
109  array('integer'),
110  array($entity->getId())
111  );
112  $row = $this->db->fetchAssoc($res);
113 
114  $entity = $entity
115  ->withId($row['id'])
116  ->withText($row['text'])
117  ->withHash($row['hash'])
118  ->withDocumentId($row['doc_id'])
119  ->withTitle($row['title']);
120 
121  return $entity;
122  }
123 
128  {
129  $this->db->manipulate(
130  'DELETE FROM tos_acceptance_track WHERE usr_id = ' . $this->db->quote($entity->getUserId(), 'integer')
131  );
132  }
133 }
deleteAcceptanceHistoryByUser(\ilTermsOfServiceAcceptanceEntity $entity)
foreach($_POST as $key=> $value) $res
$row
Class ilTermsOfServiceAcceptanceEntity.
__construct(\ilDBInterface $db)
ilTermsOfServiceAcceptanceDatabaseGateway constructor.
loadCurrentAcceptanceOfUser(\ilTermsOfServiceAcceptanceEntity $entity)
Interface ilTermsOfServiceAcceptanceDataGateway.