ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DataConnector_pdo_sqlite.php
Go to the documentation of this file.
1 <?php
2 
4 
8 use PDO;
9 
22 {
23 
24 ###
25 ### ToolConsumer methods
26 ###
27 
35  public function deleteToolConsumer($consumer)
36  {
37 
38  $id = $consumer->getRecordId();
39 
40 // Delete any nonce values for this consumer
41  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id';
42  $query = $this->db->prepare($sql);
43  $query->bindValue('id', $id, PDO::PARAM_INT);
44  $query->execute();
45 
46 // Delete any outstanding share keys for resource links for this consumer
47  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
48  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
49  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))';
50  $query = $this->db->prepare($sql);
51  $query->bindValue('id', $id, PDO::PARAM_INT);
52  $query->execute();
53 
54 // Delete any outstanding share keys for resource links for contexts in this consumer
55  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
56  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
57  "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' .
58  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))';
59  $query = $this->db->prepare($sql);
60  $query->bindValue('id', $id, PDO::PARAM_INT);
61  $query->execute();
62 
63 // Delete any users in resource links for this consumer
64  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
65  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
66  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))';
67  $query = $this->db->prepare($sql);
68  $query->bindValue('id', $id, PDO::PARAM_INT);
69  $query->execute();
70 
71 // Delete any users in resource links for contexts in this consumer
72  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
73  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
74  "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' .
75  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))';
76  $query = $this->db->prepare($sql);
77  $query->bindValue('id', $id, PDO::PARAM_INT);
78  $query->execute();
79 
80 // Update any resource links for which this consumer is acting as a primary resource link
81  $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
82  'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
83  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
84  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.consumer_pk = :id))';
85  $query = $this->db->prepare($sql);
86  $query->bindValue('id', $id, PDO::PARAM_INT);
87  $query->execute();
88 
89 // Update any resource links for contexts in which this consumer is acting as a primary resource link
90  $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
91  'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
92  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
93  "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' .
94  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (c.consumer_pk = :id))';
95  $query = $this->db->prepare($sql);
96  $query->bindValue('id', $id, PDO::PARAM_INT);
97  $query->execute();
98 
99 // Delete any resource links for this consumer
100  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
101  'WHERE consumer_pk = :id';
102  $query = $this->db->prepare($sql);
103  $query->bindValue('id', $id, PDO::PARAM_INT);
104  $query->execute();
105 
106 // Delete any resource links for contexts in this consumer
107  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
108  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ' .
109  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.context_pk = c.context_pk) AND (c.consumer_pk = :id))';
110  $query = $this->db->prepare($sql);
111  $query->bindValue('id', $id, PDO::PARAM_INT);
112  $query->execute();
113 
114 // Delete any contexts for this consumer
115  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' .
116  'WHERE consumer_pk = :id';
117  $query = $this->db->prepare($sql);
118  $query->bindValue('id', $id, PDO::PARAM_INT);
119  $query->execute();
120 
121 // Delete consumer
122  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONSUMER_TABLE_NAME . ' ' .
123  'WHERE consumer_pk = :id';
124  $query = $this->db->prepare($sql);
125  $query->bindValue('id', $id, PDO::PARAM_INT);
126  $ok = $query->execute();
127 
128  if ($ok) {
129  $consumer->initialize();
130  }
131 
132  return $ok;
133 
134  }
135 
136 ###
137 ### Context methods
138 ###
139 
147  public function deleteContext($context)
148  {
149 
150  $id = $context->getRecordId();
151 
152 // Delete any outstanding share keys for resource links for this context
153  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
154  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
155  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))';
156  $query = $this->db->prepare($sql);
157  $query->bindValue('id', $id, PDO::PARAM_INT);
158  $query->execute();
159 
160 // Delete any users in resource links for this context
161  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
162  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
163  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . '.resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))';
164  $query = $this->db->prepare($sql);
165  $query->bindValue('id', $id, PDO::PARAM_INT);
166  $query->execute();
167 
168 // Update any resource links for which this consumer is acting as a primary resource link
169  $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
170  'SET primary_resource_link_pk = null, share_approved = null ' .
171  "WHERE EXISTS (SELECT * FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
172  "WHERE ({$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . '.primary_resource_link_pk = rl.resource_link_pk) AND (rl.context_pk = :id))';
173  $query = $this->db->prepare($sql);
174  $query->bindValue('id', $id, PDO::PARAM_INT);
175  $query->execute();
176 
177 // Delete any resource links for this consumer
178  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
179  'WHERE context_pk = :id';
180  $query = $this->db->prepare($sql);
181  $query->bindValue('id', $id, PDO::PARAM_INT);
182  $query->execute();
183 
184 // Delete context
185  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' .
186  'WHERE context_pk = :id';
187  $query = $this->db->prepare($sql);
188  $query->bindValue('id', $id, PDO::PARAM_INT);
189  $ok = $query->execute();
190 
191  if ($ok) {
192  $context->initialize();
193  }
194 
195  return $ok;
196 
197  }
198 
199 }
const RESOURCE_LINK_TABLE_NAME
Default name for database table used to store resource links.
const RESOURCE_LINK_SHARE_KEY_TABLE_NAME
Default name for database table used to store resource link share keys.
$context
Definition: webdav.php:25
if(!array_key_exists('StateId', $_REQUEST)) $id
const NONCE_TABLE_NAME
Default name for database table used to store nonce values.
const CONSUMER_TABLE_NAME
Default name for database table used to store tool consumers.
const CONTEXT_TABLE_NAME
Default name for database table used to store contexts.
Class to represent an LTI Data Connector for PDO connections.
$query
Class to represent an LTI Data Connector for PDO variations for SQLite connections.
const USER_RESULT_TABLE_NAME
Default name for database table used to store users.