ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTermsOfServiceAcceptanceDatabaseGateway.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/TermsOfService/interfaces/interface.ilTermsOfServiceAcceptanceDataGateway.php';
5 
11 {
15  protected $db;
16 
21  public function __construct(ilDBInterface $db)
22  {
23  $this->db = $db;
24  }
25 
30  {
31  $query = 'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s';
32  $res = $this->db->queryF(
33  $query,
34  array('text', 'text'),
35  array($entity->getHash(), $entity->getIso2LanguageCode())
36  );
37 
38  if($this->db->numRows($res))
39  {
40  $row = $this->db->fetchAssoc($res);
41  $tosv_id = $row['id'];
42  }
43  else
44  {
45  $tosv_id = $this->db->nextId('tos_versions');
46  $this->db->insert(
47  'tos_versions',
48  array(
49  'id' => array('integer', $tosv_id),
50  'lng' => array('text', $entity->getIso2LanguageCode()),
51  'src' => array('text', $entity->getSource()),
52  'src_type' => array('integer', $entity->getSourceType()),
53  'text' => array('clob', $entity->getText()),
54  'hash' => array('text', $entity->getHash()),
55  'ts' => array('integer', $entity->getTimestamp())
56  )
57  );
58  }
59 
60  $this->db->insert(
61  'tos_acceptance_track',
62  array(
63  'tosv_id' => array('integer', $tosv_id),
64  'usr_id' => array('integer', $entity->getUserId()),
65  'ts' => array('integer', $entity->getTimestamp())
66  )
67  );
68  }
69 
75  {
76  $this->db->setLimit(1, 0);
77  $res = $this->db->queryF('
78  SELECT tos_versions.*, tos_acceptance_track.ts accepted_ts
79  FROM tos_acceptance_track
80  INNER JOIN tos_versions ON id = tosv_id
81  WHERE usr_id = %s
82  ORDER BY tos_acceptance_track.ts DESC
83  ',
84  array('integer'),
85  array($entity->getUserId())
86  );
87  $row = $this->db->fetchAssoc($res);
88 
89  $entity->setId($row['id']);
90  $entity->setUserId($row['usr_id']);
91  $entity->setIso2LanguageCode($row['lng']);
92  $entity->setSource($row['src']);
93  $entity->setSourceType($row['src_type']);
94  $entity->setText($row['text']);
95  $entity->setTimestamp($row['accepted_ts']);
96  $entity->setHash($row['hash']);
97 
98  return $entity;
99  }
100 
106  {
107  $res = $this->db->queryF('
108  SELECT *
109  FROM tos_versions
110  WHERE id = %s
111  ',
112  array('integer'),
113  array($entity->getId())
114  );
115  $row = $this->db->fetchAssoc($res);
116 
117  $entity->setId($row['id']);
118  $entity->setIso2LanguageCode($row['lng']);
119  $entity->setSource($row['src']);
120  $entity->setSourceType($row['src_type']);
121  $entity->setText($row['text']);
122  $entity->setTimestamp($row['ts']);
123  $entity->setHash($row['hash']);
124 
125  return $entity;
126  }
127 
132  {
133  $this->db->manipulate('DELETE FROM tos_acceptance_track WHERE usr_id = ' . $this->db->quote($entity->getUserId(), 'integer'));
134  }
135 }
__construct(ilDBInterface $db)
ilTermsOfServiceAcceptanceDatabaseGateway constructor.
Interface ilDBInterface.
Create styles array
The data for the language used.