LTI Integration Library  3.1.0
PHP class library for building LTI integrations
DataConnector_oci.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use ceLTIc\LTI;
13 
22 ###
23 # NB This class assumes that an Oracle connection has already been opened to the appropriate schema
24 ###
25 
27 {
28 
35  public function __construct($db, $dbTableNamePrefix = '')
36  {
37  parent::__construct($db, $dbTableNamePrefix);
38  $this->dateFormat = 'd-M-Y';
39  }
40 
41 ###
42 ### ToolConsumer methods
43 ###
44 
52  public function loadToolConsumer($consumer)
53  {
54  $ok = false;
55  if (!is_null($consumer->getRecordId())) {
56  $sql = 'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
57  'signature_method, consumer_name, consumer_version, consumer_guid, ' .
58  'profile, tool_proxy, settings, protected, enabled, ' .
59  'enable_from, enable_until, last_access, created, updated ' .
60  "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' .
61  'WHERE consumer_pk = :id';
62  $query = oci_parse($this->db, $sql);
63  $id = $consumer->getRecordId();
64  oci_bind_by_name($query, 'id', $id);
65  } else {
66  $sql = 'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
67  'signature_method, consumer_name, consumer_version, consumer_guid, ' .
68  'profile, tool_proxy, settings, protected, enabled, ' .
69  'enable_from, enable_until, last_access, created, updated ' .
70  "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' .
71  'WHERE consumer_key256 = :key256';
72  $query = oci_parse($this->db, $sql);
73  $key256 = static::getConsumerKey($consumer->getKey());
74  oci_bind_by_name($query, 'key256', $key256);
75  }
76 
77  if (oci_execute($query)) {
78  while ($row = oci_fetch_assoc($query)) {
79  $row = array_change_key_case($row);
80  if (empty($key256) || empty($row['consumer_key']) || ($consumer->getKey() === $row['consumer_key'])) {
81  $consumer->setRecordId(intval($row['consumer_pk']));
82  $consumer->name = $row['name'];
83  $consumer->setkey(empty($row['consumer_key']) ? $row['consumer_key256'] : $row['consumer_key']);
84  $consumer->secret = $row['secret'];
85  $consumer->ltiVersion = $row['lti_version'];
86  $consumer->signatureMethod = $row['signature_method'];
87  $consumer->consumerName = $row['consumer_name'];
88  $consumer->consumerVersion = $row['consumer_version'];
89  $consumer->consumerGuid = $row['consumer_guid'];
90  $consumer->profile = json_decode($row['profile']);
91  $consumer->toolProxy = $row['tool_proxy'];
92  $settingsValue = $row['settings']->load();
93  if (is_string($settingsValue)) {
94  $settings = json_decode($settingsValue, TRUE);
95  if (!is_array($settings)) {
96  $settings = @unserialize($settingsValue); // check for old serialized setting
97  }
98  if (!is_array($settings)) {
99  $settings = array();
100  }
101  } else {
102  $settings = array();
103  }
104  $consumer->setSettings($settings);
105  $consumer->protected = (intval($row['protected']) === 1);
106  $consumer->enabled = (intval($row['enabled']) === 1);
107  $consumer->enableFrom = null;
108  if (!is_null($row['enable_from'])) {
109  $consumer->enableFrom = strtotime($row['enable_from']);
110  }
111  $consumer->enableUntil = null;
112  if (!is_null($row['enable_until'])) {
113  $consumer->enableUntil = strtotime($row['enable_until']);
114  }
115  $consumer->lastAccess = null;
116  if (!is_null($row['last_access'])) {
117  $consumer->lastAccess = strtotime($row['last_access']);
118  }
119  $consumer->created = strtotime($row['created']);
120  $consumer->updated = strtotime($row['updated']);
121  $ok = true;
122  break;
123  }
124  }
125  }
126 
127  return $ok;
128  }
129 
137  public function saveToolConsumer($consumer)
138  {
139  $id = $consumer->getRecordId();
140  $key = $consumer->getKey();
141  $key256 = $this->getConsumerKey($key);
142  if ($key === $key256) {
143  $key = null;
144  }
145  $protected = ($consumer->protected) ? 1 : 0;
146  $enabled = ($consumer->enabled) ? 1 : 0;
147  $profile = (!empty($consumer->profile)) ? json_encode($consumer->profile) : null;
148  $settingsValue = json_encode($consumer->getSettings());
149  $time = time();
150  $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
151  $from = null;
152  if (!is_null($consumer->enableFrom)) {
153  $from = date("{$this->dateFormat} {$this->timeFormat}", $consumer->enableFrom);
154  }
155  $until = null;
156  if (!is_null($consumer->enableUntil)) {
157  $until = date("{$this->dateFormat} {$this->timeFormat}", $consumer->enableUntil);
158  }
159  $last = null;
160  if (!is_null($consumer->lastAccess)) {
161  $last = date($this->dateFormat, $consumer->lastAccess);
162  }
163  if (empty($id)) {
164  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' (consumer_key256, consumer_key, name, ' .
165  'secret, lti_version, signature_method, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' .
166  'enable_from, enable_until, last_access, created, updated) ' .
167  'VALUES (:key256, :key, :name, :secret, :lti_version, :signature_method, :consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' .
168  ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated) returning consumer_pk into :pk';
169  $query = oci_parse($this->db, $sql);
170  oci_bind_by_name($query, 'key256', $key256);
171  oci_bind_by_name($query, 'key', $key);
172  oci_bind_by_name($query, 'name', $consumer->name);
173  oci_bind_by_name($query, 'secret', $consumer->secret);
174  oci_bind_by_name($query, 'lti_version', $consumer->ltiVersion);
175  oci_bind_by_name($query, 'signature_method', $consumer->signatureMethod);
176  oci_bind_by_name($query, 'consumer_name', $consumer->consumerName);
177  oci_bind_by_name($query, 'consumer_version', $consumer->consumerVersion);
178  oci_bind_by_name($query, 'consumer_guid', $consumer->consumerGuid);
179  oci_bind_by_name($query, 'profile', $profile);
180  oci_bind_by_name($query, 'tool_proxy', $consumer->toolProxy);
181  oci_bind_by_name($query, 'settings', $settingsValue);
182  oci_bind_by_name($query, 'protected', $protected);
183  oci_bind_by_name($query, 'enabled', $enabled);
184  oci_bind_by_name($query, 'enable_from', $from);
185  oci_bind_by_name($query, 'enable_until', $until);
186  oci_bind_by_name($query, 'last_access', $last);
187  oci_bind_by_name($query, 'created', $now);
188  oci_bind_by_name($query, 'updated', $now);
189  oci_bind_by_name($query, 'pk', $pk);
190  } else {
191  $sql = 'UPDATE ' . $this->dbTableNamePrefix . static::CONSUMER_TABLE_NAME . ' ' .
192  'SET consumer_key256 = :key256, consumer_key = :key, name = :name, secret = :secret, lti_version = :lti_version, ' .
193  'signature_method = :signature_method, consumer_name = :consumer_name, ' .
194  'consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' .
195  'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' .
196  'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, last_access = :last_access, updated = :updated ' .
197  'WHERE consumer_pk = :id';
198  $query = oci_parse($this->db, $sql);
199  oci_bind_by_name($query, 'key256', $key256);
200  oci_bind_by_name($query, 'key', $key);
201  oci_bind_by_name($query, 'name', $consumer->name);
202  oci_bind_by_name($query, 'secret', $consumer->secret);
203  oci_bind_by_name($query, 'lti_version', $consumer->ltiVersion);
204  oci_bind_by_name($query, 'signature_method', $consumer->signatureMethod);
205  oci_bind_by_name($query, 'consumer_name', $consumer->consumerName);
206  oci_bind_by_name($query, 'consumer_version', $consumer->consumerVersion);
207  oci_bind_by_name($query, 'consumer_guid', $consumer->consumerGuid);
208  oci_bind_by_name($query, 'profile', $profile);
209  oci_bind_by_name($query, 'tool_proxy', $consumer->toolProxy);
210  oci_bind_by_name($query, 'settings', $settingsValue);
211  oci_bind_by_name($query, 'protected', $protected);
212  oci_bind_by_name($query, 'enabled', $enabled);
213  oci_bind_by_name($query, 'enable_from', $from);
214  oci_bind_by_name($query, 'enable_until', $until);
215  oci_bind_by_name($query, 'last_access', $last);
216  oci_bind_by_name($query, 'updated', $now);
217  oci_bind_by_name($query, 'id', $id);
218  }
219  $ok = oci_execute($query);
220  if ($ok) {
221  if (empty($id)) {
222  $consumer->setRecordId(intval($pk));
223  $consumer->created = $time;
224  }
225  $consumer->updated = $time;
226  }
227 
228  return $ok;
229  }
230 
238  public function deleteToolConsumer($consumer)
239  {
240  $id = $consumer->getRecordId();
241 
242 // Delete any nonce values for this consumer
243  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id';
244  $query = oci_parse($this->db, $sql);
245  oci_bind_by_name($query, 'id', $id);
246  oci_execute($query);
247 
248 // Delete any outstanding share keys for resource links for this consumer
249  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
250  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
251  'WHERE consumer_pk = :id)';
252  $query = oci_parse($this->db, $sql);
253  oci_bind_by_name($query, 'id', $id);
254  oci_execute($query);
255 
256 // Delete any outstanding share keys for resource links for contexts in this consumer
257  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
258  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
259  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
260  $query = oci_parse($this->db, $sql);
261  oci_bind_by_name($query, 'id', $id);
262  oci_execute($query);
263 
264 // Delete any users in resource links for this consumer
265  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
266  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
267  'WHERE consumer_pk = :id)';
268  $query = oci_parse($this->db, $sql);
269  oci_bind_by_name($query, 'id', $id);
270  oci_execute($query);
271 
272 // Delete any users in resource links for contexts in this consumer
273  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
274  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
275  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
276  $query = oci_parse($this->db, $sql);
277  oci_bind_by_name($query, 'id', $id);
278  oci_execute($query);
279 
280 // Update any resource links for which this consumer is acting as a primary resource link
281  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
282  'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
283  'WHERE primary_resource_link_pk IN ' .
284  "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
285  'WHERE consumer_pk = :id)';
286  $query = oci_parse($this->db, $sql);
287  oci_bind_by_name($query, 'id', $id);
288  oci_execute($query);
289 
290 // Update any resource links for contexts in which this consumer is acting as a primary resource link
291  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
292  'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
293  'WHERE primary_resource_link_pk IN ' .
294  "(SELECT rl.resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
295  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' .
296  'WHERE c.consumer_pk = :id)';
297  $query = oci_parse($this->db, $sql);
298  oci_bind_by_name($query, 'id', $id);
299  oci_execute($query);
300 
301 // Delete any resource links for this consumer
302  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
303  'WHERE consumer_pk = :id';
304  $query = oci_parse($this->db, $sql);
305  oci_bind_by_name($query, 'id', $id);
306  oci_execute($query);
307 
308 // Delete any resource links for contexts in this consumer
309  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
310  'WHERE context_pk IN (' .
311  "SELECT context_pk FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id)';
312  $query = oci_parse($this->db, $sql);
313  oci_bind_by_name($query, 'id', $id);
314  oci_execute($query);
315 
316 // Delete any contexts for this consumer
317  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
318  'WHERE consumer_pk = :id';
319  $query = oci_parse($this->db, $sql);
320  oci_bind_by_name($query, 'id', $id);
321  oci_execute($query);
322 
323 // Delete consumer
324  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' .
325  'WHERE consumer_pk = :id';
326  $query = oci_parse($this->db, $sql);
327  oci_bind_by_name($query, 'id', $id);
328  $ok = oci_execute($query);
329 
330  if ($ok) {
331  $consumer->initialize();
332  }
333 
334  return $ok;
335  }
336 
342  public function getToolConsumers()
343  {
344  $consumers = array();
345 
346  $sql = 'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
347  'signature_method, consumer_name, consumer_version, consumer_guid, ' .
348  'profile, tool_proxy, settings, protected, enabled, ' .
349  'enable_from, enable_until, last_access, created, updated ' .
350  "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' ' .
351  'ORDER BY name';
352  $query = oci_parse($this->db, $sql);
353  $ok = ($query !== FALSE);
354 
355  if ($ok) {
356  $ok = oci_execute($query);
357  }
358 
359  if ($ok) {
360  while ($row = oci_fetch_assoc($query)) {
361  $row = array_change_key_case($row);
362  $key = empty($row['consumer_key']) ? $row['consumer_key256'] : $row['consumer_key'];
363  $consumer = new LTI\ToolConsumer($key, $this);
364  $consumer->setRecordId(intval($row['consumer_pk']));
365  $consumer->name = $row['name'];
366  $consumer->secret = $row['secret'];
367  $consumer->ltiVersion = $row['lti_version'];
368  $consumer->signatureMethod = $row['signature_method'];
369  $consumer->consumerName = $row['consumer_name'];
370  $consumer->consumerVersion = $row['consumer_version'];
371  $consumer->consumerGuid = $row['consumer_guid'];
372  $consumer->profile = json_decode($row['profile']);
373  $consumer->toolProxy = $row['tool_proxy'];
374  $settingsValue = $row['settings']->load();
375  if (is_string($settingsValue)) {
376  $settings = json_decode($settingsValue, TRUE);
377  if (!is_array($settings)) {
378  $settings = @unserialize($settingsValue); // check for old serialized setting
379  }
380  if (!is_array($settings)) {
381  $settings = array();
382  }
383  } else {
384  $settings = array();
385  }
386  $consumer->setSettings($settings);
387  $consumer->protected = (intval($row['protected']) === 1);
388  $consumer->enabled = (intval($row['enabled']) === 1);
389  $consumer->enableFrom = null;
390  if (!is_null($row['enable_from'])) {
391  $consumer->enableFrom = strtotime($row['enable_from']);
392  }
393  $consumer->enableUntil = null;
394  if (!is_null($row['enable_until'])) {
395  $consumer->enableUntil = strtotime($row['enable_until']);
396  }
397  $consumer->lastAccess = null;
398  if (!is_null($row['last_access'])) {
399  $consumer->lastAccess = strtotime($row['last_access']);
400  }
401  $consumer->created = strtotime($row['created']);
402  $consumer->updated = strtotime($row['updated']);
403  $consumers[] = $consumer;
404  }
405  }
406 
407  return $consumers;
408  }
409 
410 ###
411 ### Context methods
412 ###
413 
421  public function loadContext($context)
422  {
423  $ok = false;
424  if (!is_null($context->getRecordId())) {
425  $sql = 'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
426  "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
427  'WHERE (context_pk = :id)';
428  $query = oci_parse($this->db, $sql);
429  $id = $context->getRecordId();
430  oci_bind_by_name($query, 'id', $id);
431  } else {
432  $sql = 'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
433  "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
434  'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
435  $query = oci_parse($this->db, $sql);
436  $id = $context->getConsumer()->getRecordId();
437  oci_bind_by_name($query, 'cid', $id);
438  oci_bind_by_name($query, 'ctx', $context->ltiContextId);
439  }
440  $ok = oci_execute($query);
441  if ($ok) {
442  $row = oci_fetch_assoc($query);
443  $ok = ($row !== FALSE);
444  }
445  if ($ok) {
446  $row = array_change_key_case($row);
447  $context->setRecordId(intval($row['context_pk']));
448  $context->setConsumerId(intval($row['consumer_pk']));
449  $context->ltiContextId = $row['title'];
450  $context->ltiContextId = $row['lti_context_id'];
451  $context->type = $row['type'];
452  $settingsValue = $row['settings']->load();
453  if (is_string($settingsValue)) {
454  $settings = json_decode($settingsValue, TRUE);
455  if (!is_array($settings)) {
456  $settings = @unserialize($settingsValue); // check for old serialized setting
457  }
458  if (!is_array($settings)) {
459  $settings = array();
460  }
461  } else {
462  $settings = array();
463  }
464  $context->setSettings($settings);
465  $context->created = strtotime($row['created']);
466  $context->updated = strtotime($row['updated']);
467  }
468 
469  return $ok;
470  }
471 
479  public function saveContext($context)
480  {
481  $time = time();
482  $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
483  $settingsValue = json_encode($context->getSettings());
484  $id = $context->getRecordId();
485  $consumer_pk = $context->getConsumer()->getRecordId();
486  if (empty($id)) {
487  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' (consumer_pk, title, ' .
488  'lti_context_id, type, settings, created, updated) ' .
489  'VALUES (:cid, :title, :ctx, :type, :settings, :created, :updated) returning context_pk into :pk';
490  $query = oci_parse($this->db, $sql);
491  oci_bind_by_name($query, 'cid', $consumer_pk);
492  oci_bind_by_name($query, 'title', $context->title);
493  oci_bind_by_name($query, 'ctx', $context->ltiContextId);
494  oci_bind_by_name($query, 'type', $context->type);
495  oci_bind_by_name($query, 'settings', $settingsValue);
496  oci_bind_by_name($query, 'created', $now);
497  oci_bind_by_name($query, 'updated', $now);
498  oci_bind_by_name($query, 'pk', $pk);
499  } else {
500  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' SET ' .
501  'title = :title, lti_context_id = :ctx, type = :type, settings = :settings, ' .
502  'updated = :updated ' .
503  'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
504  $query = oci_parse($this->db, $sql);
505  oci_bind_by_name($query, 'title', $context->title);
506  oci_bind_by_name($query, 'ctx', $context->ltiContextId);
507  oci_bind_by_name($query, 'type', $context->type);
508  oci_bind_by_name($query, 'settings', $settingsValue);
509  oci_bind_by_name($query, 'updated', $now);
510  oci_bind_by_name($query, 'cid', $consumer_pk);
511  oci_bind_by_name($query, 'ctxid', $id);
512  }
513  $ok = oci_execute($query);
514  if ($ok) {
515  if (empty($id)) {
516  $context->setRecordId(intval($pk));
517  $context->created = $time;
518  }
519  $context->updated = $time;
520  }
521 
522  return $ok;
523  }
524 
532  public function deleteContext($context)
533  {
534  $id = $context->getRecordId();
535 
536 // Delete any outstanding share keys for resource links for this context
537  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
538  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
539  'WHERE context_pk = :id)';
540  $query = oci_parse($this->db, $sql);
541  oci_bind_by_name($query, 'id', $id);
542  oci_execute($query);
543 
544 // Delete any users in resource links for this context
545  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
546  "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
547  'WHERE context_pk = :id)';
548  $query = oci_parse($this->db, $sql);
549  oci_bind_by_name($query, 'id', $id);
550  oci_execute($query);
551 
552 // Update any resource links for which this consumer is acting as a primary resource link
553  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
554  'SET primary_resource_link_pk = null, share_approved = null ' .
555  'WHERE primary_resource_link_pk IN ' .
556  "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' WHERE context_pk = :id)';
557  $query = oci_parse($this->db, $sql);
558  oci_bind_by_name($query, 'id', $id);
559  oci_execute($query);
560 
561 // Delete any resource links for this consumer
562  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
563  'WHERE context_pk = :id';
564  $query = oci_parse($this->db, $sql);
565  oci_bind_by_name($query, 'id', $id);
566  oci_execute($query);
567 
568 // Delete context
569  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
570  'WHERE context_pk = :id';
571  $query = oci_parse($this->db, $sql);
572  oci_bind_by_name($query, 'id', $id);
573  $ok = oci_execute($query);
574 
575  if ($ok) {
576  $context->initialize();
577  }
578 
579  return $ok;
580  }
581 
582 ###
583 ### ResourceLink methods
584 ###
585 
593  public function loadResourceLink($resourceLink)
594  {
595  if (!is_null($resourceLink->getRecordId())) {
596  $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
597  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
598  'WHERE (resource_link_pk = :id)';
599  $query = oci_parse($this->db, $sql);
600  $id = $resourceLink->getRecordId();
601  oci_bind_by_name($query, 'id', $id);
602  } elseif (!is_null($resourceLink->getContext())) {
603  $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
604  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
605  'WHERE (context_pk = :id) AND (lti_resource_link_id = :rlid)';
606  $query = oci_parse($this->db, $sql);
607  $id = $resourceLink->getContext()->getRecordId();
608  oci_bind_by_name($query, 'id', $id);
609  $rlid = $resourceLink->getId();
610  oci_bind_by_name($query, 'rlid', $rlid);
611  } else {
612  $sql = 'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
613  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' .
614  $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' .
615  ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
616  $query = oci_parse($this->db, $sql);
617  $id1 = $resourceLink->getConsumer()->getRecordId();
618  oci_bind_by_name($query, 'id1', $id1);
619  $id2 = $resourceLink->getConsumer()->getRecordId();
620  oci_bind_by_name($query, 'id2', $id2);
621  $id = $resourceLink->getId();
622  oci_bind_by_name($query, 'rlid', $id);
623  }
624  $ok = oci_execute($query);
625  if ($ok) {
626  $row = oci_fetch_assoc($query);
627  $ok = ($row !== FALSE);
628  }
629 
630  if ($ok) {
631  $row = array_change_key_case($row);
632  $resourceLink->setRecordId(intval($row['resource_link_pk']));
633  if (!is_null($row['context_pk'])) {
634  $resourceLink->setContextId(intval($row['context_pk']));
635  } else {
636  $resourceLink->setContextId(null);
637  }
638  if (!is_null($row['consumer_pk'])) {
639  $resourceLink->setConsumerId(intval($row['consumer_pk']));
640  } else {
641  $resourceLink->setConsumerId(null);
642  }
643  $resourceLink->ltiResourceLinkId = $row['lti_resource_link_id'];
644  $settings = $row['settings']->load();
645  $settingsValue = $row['settings']->load();
646  if (is_string($settingsValue)) {
647  $settings = json_decode($settingsValue, TRUE);
648  if (!is_array($settings)) {
649  $settings = @unserialize($settingsValue); // check for old serialized setting
650  }
651  if (!is_array($settings)) {
652  $settings = array();
653  }
654  } else {
655  $settings = array();
656  }
657  $resourceLink->setSettings($settings);
658  if (!is_null($row['primary_resource_link_pk'])) {
659  $resourceLink->primaryResourceLinkId = intval($row['primary_resource_link_pk']);
660  } else {
661  $resourceLink->primaryResourceLinkId = null;
662  }
663  $resourceLink->shareApproved = (is_null($row['share_approved'])) ? null : (intval($row['share_approved']) === 1);
664  $resourceLink->created = strtotime($row['created']);
665  $resourceLink->updated = strtotime($row['updated']);
666  }
667 
668  return $ok;
669  }
670 
678  public function saveResourceLink($resourceLink)
679  {
680  $time = time();
681  $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
682  $settingsValue = json_encode($resourceLink->getSettings());
683  if (!is_null($resourceLink->getContext())) {
684  $consumerId = null;
685  $contextId = strval($resourceLink->getContext()->getRecordId());
686  } elseif (!is_null($resourceLink->getContextId())) {
687  $consumerId = null;
688  $contextId = strval($resourceLink->getContextId());
689  } else {
690  $consumerId = strval($resourceLink->getConsumer()->getRecordId());
691  $contextId = null;
692  }
693  if (empty($resourceLink->primaryResourceLinkId)) {
694  $primaryResourceLinkId = null;
695  } else {
696  $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
697  }
698  $id = $resourceLink->getRecordId();
699  if (empty($id)) {
700  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' .
701  'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
702  'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated) returning resource_link_pk into :pk';
703  $query = oci_parse($this->db, $sql);
704  oci_bind_by_name($query, 'cid', $consumerId);
705  oci_bind_by_name($query, 'ctx', $contextId);
706  $rlid = $resourceLink->getId();
707  oci_bind_by_name($query, 'rlid', $rlid);
708  oci_bind_by_name($query, 'settings', $settingsValue);
709  oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
710  oci_bind_by_name($query, 'share_approved', $resourceLink->shareApproved);
711  oci_bind_by_name($query, 'created', $now);
712  oci_bind_by_name($query, 'updated', $now);
713  oci_bind_by_name($query, 'pk', $pk);
714  } elseif (!is_null($contextId)) {
715  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' .
716  'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' .
717  'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
718  'WHERE (resource_link_pk = :id)';
719  $query = oci_parse($this->db, $sql);
720  oci_bind_by_name($query, 'ctx', $contextId);
721  $rlid = $resourceLink->getId();
722  oci_bind_by_name($query, 'rlid', $rlid);
723  oci_bind_by_name($query, 'settings', $settingsValue);
724  oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
725  oci_bind_by_name($query, 'share_approved', $resourceLink->shareApproved);
726  oci_bind_by_name($query, 'updated', $now);
727  oci_bind_by_name($query, 'id', $id);
728  } else {
729  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' .
730  'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' .
731  'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
732  'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
733  $query = oci_parse($this->db, $sql);
734  oci_bind_by_name($query, 'ctx', $contextId);
735  $rlid = $resourceLink->getId();
736  oci_bind_by_name($query, 'rlid', $rlid);
737  oci_bind_by_name($query, 'settings', $settingsValue);
738  oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
739  oci_bind_by_name($query, 'share_approved', $resourceLink->shareApproved);
740  oci_bind_by_name($query, 'updated', $now);
741  oci_bind_by_name($query, 'cid', $consumerId);
742  oci_bind_by_name($query, 'id', $id);
743  }
744  $ok = oci_execute($query);
745  if ($ok) {
746  if (empty($id)) {
747  $resourceLink->setRecordId(intval($pk));
748  $resourceLink->created = $time;
749  }
750  $resourceLink->updated = $time;
751  }
752 
753  return $ok;
754  }
755 
763  public function deleteResourceLink($resourceLink)
764  {
765  $id = $resourceLink->getRecordId();
766 
767 // Delete any outstanding share keys for resource links for this consumer
768  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
769  'WHERE (resource_link_pk = :id)';
770  $query = oci_parse($this->db, $sql);
771  oci_bind_by_name($query, 'id', $id);
772  $ok = oci_execute($query);
773 
774 // Delete users
775  if ($ok) {
776  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
777  'WHERE (resource_link_pk = :id)';
778  $query = oci_parse($this->db, $sql);
779  oci_bind_by_name($query, 'id', $id);
780  $ok = oci_execute($query);
781  }
782 
783 // Update any resource links for which this is the primary resource link
784  if ($ok) {
785  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
786  'SET primary_resource_link_pk = NULL ' .
787  'WHERE (primary_resource_link_pk = :id)';
788  $query = oci_parse($this->db, $sql);
789  oci_bind_by_name($query, 'id', $id);
790  $ok = oci_execute($query);
791  }
792 
793 // Delete resource link
794  if ($ok) {
795  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
796  'WHERE (resource_link_pk = :id)';
797  $query = oci_parse($this->db, $sql);
798  oci_bind_by_name($query, 'id', $id);
799  $ok = oci_execute($query);
800  }
801 
802  if ($ok) {
803  $resourceLink->initialize();
804  }
805 
806  return $ok;
807  }
808 
821  public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
822  {
823  $id = $resourceLink->getRecordId();
824  $userResults = array();
825 
826  if ($localOnly) {
827  $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
828  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' .
829  "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
830  'ON u.resource_link_pk = rl.resource_link_pk ' .
831  'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
832  $query = oci_parse($this->db, $sql);
833  oci_bind_by_name($query, 'id', $id);
834  } else {
835  $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
836  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' .
837  "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
838  'ON u.resource_link_pk = rl.resource_link_pk ' .
839  'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
840  '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))';
841  $query = oci_parse($this->db, $sql);
842  oci_bind_by_name($query, 'id', $id);
843  oci_bind_by_name($query, 'pid', $id);
844  }
845  if (oci_execute($query)) {
846  while ($row = oci_fetch_assoc($query)) {
847  $row = array_change_key_case($row);
848  $userresult = LTI\UserResult::fromRecordId($row['user_result_pk'], $resourceLink->getDataConnector());
849  $userresult->setRecordId(intval($row['user_result_pk']));
850  $userresult->ltiResultSourcedId = $row['lti_result_sourcedid'];
851  $userresult->created = strtotime($row['created']);
852  $userresult->updated = strtotime($row['updated']);
853  if (is_null($idScope)) {
854  $userResults[] = $userresult;
855  } else {
856  $userResults[$userresult->getId($idScope)] = $userresult;
857  }
858  }
859  }
860 
861  return $userResults;
862  }
863 
871  public function getSharesResourceLink($resourceLink)
872  {
873  $id = $resourceLink->getRecordId();
874 
875  $shares = array();
876 
877  $sql = 'SELECT c.consumer_name, r.resource_link_pk, r.title, r.share_approved ' .
878  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r ' .
879  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' c ON r.consumer_pk = c.consumer_pk ' .
880  'WHERE (r.primary_resource_link_pk = :id1) ' .
881  'UNION ' .
882  'SELECT c2.consumer_name, r2.resource_link_pk, r2.title, r2.share_approved ' .
883  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r2 ' .
884  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' x ON r2.context_pk = x.context_pk ' .
885  "INNER JOIN {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME . ' c2 ON x.consumer_pk = c2.consumer_pk ' .
886  'WHERE (r2.primary_resource_link_pk = :id2) ' .
887  'ORDER BY consumer_name, title';
888  $query = oci_parse($this->db, $sql);
889  oci_bind_by_name($query, 'id1', $id);
890  oci_bind_by_name($query, 'id2', $id);
891  if (oci_execute($query)) {
892  while ($row = oci_fetch_assoc($query)) {
893  $row = array_change_key_case($row);
894  $share = new LTI\ResourceLinkShare();
895  $share->resourceLinkId = intval($row['resource_link_pk']);
896  $share->approved = (intval($row['share_approved']) === 1);
897  $shares[] = $share;
898  }
899  }
900 
901  return $shares;
902  }
903 
904 ###
905 ### ConsumerNonce methods
906 ###
907 
915  public function loadConsumerNonce($nonce)
916  {
917 // Delete any expired nonce values
918  $now = date("{$this->dateFormat} {$this->timeFormat}", time());
919  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE expires <= :now';
920  $query = oci_parse($this->db, $sql);
921  oci_bind_by_name($query, 'now', $now);
922  oci_execute($query);
923 
924 // Load the nonce
925  $id = $nonce->getConsumer()->getRecordId();
926  $value = $nonce->getValue();
927  $sql = "SELECT value T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE (consumer_pk = :id) AND (value = :value)';
928  $query = oci_parse($this->db, $sql);
929  oci_bind_by_name($query, 'id', $id);
930  oci_bind_by_name($query, 'value', $value);
931  $ok = oci_execute($query);
932  if ($ok) {
933  $row = oci_fetch_assoc($query);
934  if ($row === false) {
935  $ok = false;
936  }
937  }
938 
939  return $ok;
940  }
941 
949  public function saveConsumerNonce($nonce)
950  {
951  $id = $nonce->getConsumer()->getRecordId();
952  $value = $nonce->getValue();
953  $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
954  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' (consumer_pk, value, expires) VALUES (:id, :value, :expires)';
955  $query = oci_parse($this->db, $sql);
956  oci_bind_by_name($query, 'id', $id);
957  oci_bind_by_name($query, 'value', $value);
958  oci_bind_by_name($query, 'expires', $expires);
959  $ok = oci_execute($query);
960 
961  return $ok;
962  }
963 
964 ###
965 ### ResourceLinkShareKey methods
966 ###
967 
975  public function loadResourceLinkShareKey($shareKey)
976  {
977  $ok = false;
978 
979 // Clear expired share keys
980  $now = date("{$this->dateFormat} {$this->timeFormat}", time());
981  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE expires <= :now';
982  $query = oci_parse($this->db, $sql);
983  oci_bind_by_name($query, 'now', $now);
984  oci_execute($query);
985 
986 // Load share key
987  $id = $shareKey->getId();
988  $sql = 'SELECT resource_link_pk, auto_approve, expires ' .
989  "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
990  'WHERE share_key_id = :id';
991  $query = oci_parse($this->db, $sql);
992  oci_bind_by_name($query, 'id', $id);
993  if (oci_execute($query)) {
994  $row = oci_fetch_assoc($query);
995  if ($row !== FALSE) {
996  $row = array_change_key_case($row);
997  if (intval($row['resource_link_pk']) === $shareKey->resourceLinkId) {
998  $shareKey->autoApprove = ($row['auto_approve'] === 1);
999  $shareKey->expires = strtotime($row['expires']);
1000  $ok = true;
1001  }
1002  }
1003  }
1004 
1005  return $ok;
1006  }
1007 
1015  public function saveResourceLinkShareKey($shareKey)
1016  {
1017  if ($shareKey->autoApprove) {
1018  $approve = 1;
1019  } else {
1020  $approve = 0;
1021  }
1022  $id = $shareKey->getId();
1023  $expires = date("{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
1024  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
1025  '(share_key_id, resource_link_pk, auto_approve, expires) ' .
1026  'VALUES (:id, :prlid, :approve, :expires)';
1027  $query = oci_parse($this->db, $sql);
1028  oci_bind_by_name($query, 'id', $id);
1029  oci_bind_by_name($query, 'prlid', $shareKey->resourceLinkId);
1030  oci_bind_by_name($query, 'approve', $approve);
1031  oci_bind_by_name($query, 'expires', $expires);
1032  $ok = oci_execute($query);
1033 
1034  return $ok;
1035  }
1036 
1044  public function deleteResourceLinkShareKey($shareKey)
1045  {
1046  $id = $shareKey->getId();
1047  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE share_key_id = :id';
1048  $query = oci_parse($this->db, $sql);
1049  oci_bind_by_name($query, 'id', $id);
1050  $ok = oci_execute($query);
1051 
1052  if ($ok) {
1053  $shareKey->initialize();
1054  }
1055 
1056  return $ok;
1057  }
1058 
1059 ###
1060 ### UserResult Result methods
1061 ###
1062 
1070  public function loadUserResult($userresult)
1071  {
1072  $ok = false;
1073  if (!is_null($userresult->getRecordId())) {
1074  $id = $userresult->getRecordId();
1075  $sql = 'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1076  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1077  'WHERE (user_result_pk = :id)';
1078  $query = oci_parse($this->db, $sql);
1079  oci_bind_by_name($query, 'id', $id);
1080  } else {
1081  $id = $userresult->getResourceLink()->getRecordId();
1082  $uid = $userresult->getId(LTI\ToolProvider::ID_SCOPE_ID_ONLY);
1083  $sql = 'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1084  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1085  'WHERE (resource_link_pk = :id) AND (lti_user_id = :u_id)';
1086  $query = oci_parse($this->db, $sql);
1087  oci_bind_by_name($query, 'id', $id);
1088  oci_bind_by_name($query, 'u_id', $uid);
1089  }
1090  if (oci_execute($query)) {
1091  $row = oci_fetch_assoc($query);
1092  if ($row !== false) {
1093  $row = array_change_key_case($row);
1094  $userresult->setRecordId(intval($row['user_result_pk']));
1095  $userresult->setResourceLinkId(intval($row['resource_link_pk']));
1096  $userresult->ltiUserId = $row['lti_user_id'];
1097  $userresult->ltiResultSourcedId = $row['lti_result_sourcedid'];
1098  $userresult->created = strtotime($row['created']);
1099  $userresult->updated = strtotime($row['updated']);
1100  $ok = true;
1101  }
1102  }
1103 
1104  return $ok;
1105  }
1106 
1114  public function saveUserResult($userresult)
1115  {
1116  $time = time();
1117  $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
1118  if (is_null($userresult->created)) {
1119  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' .
1120  'lti_user_id, lti_result_sourcedid, created, updated) ' .
1121  'VALUES (:rlid, :u_id, :sourcedid, :created, :updated) returning user_result_pk into :pk';
1122  $query = oci_parse($this->db, $sql);
1123  $rlid = $userresult->getResourceLink()->getRecordId();
1124  oci_bind_by_name($query, 'rlid', $rlid);
1125  $uid = $userresult->getId(LTI\ToolProvider::ID_SCOPE_ID_ONLY);
1126  oci_bind_by_name($query, 'u_id', $uid);
1127  $sourcedid = $userresult->ltiResultSourcedId;
1128  oci_bind_by_name($query, 'sourcedid', $sourcedid);
1129  oci_bind_by_name($query, 'created', $now);
1130  oci_bind_by_name($query, 'updated', $now);
1131  oci_bind_by_name($query, 'pk', $pk);
1132  } else {
1133  $sql = "UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1134  'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
1135  'WHERE (user_result_pk = :id)';
1136  $query = oci_parse($this->db, $sql);
1137  $sourcedid = $userresult->ltiResultSourcedId;
1138  oci_bind_by_name($query, 'sourcedid', $sourcedid);
1139  oci_bind_by_name($query, 'updated', $now);
1140  $id = $userresult->getRecordId();
1141  oci_bind_by_name($query, 'id', $id);
1142  }
1143  $ok = oci_execute($query);
1144  if ($ok) {
1145  if (is_null($userresult->created)) {
1146  $userresult->setRecordId(intval($pk));
1147  $userresult->created = $time;
1148  }
1149  $userresult->updated = $time;
1150  }
1151 
1152  return $ok;
1153  }
1154 
1162  public function deleteUserResult($userresult)
1163  {
1164  $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1165  'WHERE (user_result_pk = :id)';
1166  $query = oci_parse($this->db, $sql);
1167  $id = $userresult->getRecordId();
1168  oci_bind_by_name($query, 'id', $id);
1169  $ok = oci_execute($query);
1170 
1171  if ($ok) {
1172  $userresult->initialize();
1173  }
1174 
1175  return $ok;
1176  }
1177 
1178 }
$dbTableNamePrefix
Prefix for database table names.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
Class to provide a connection to a persistent store for LTI objects.
saveContext($context)
Save context object.
loadToolConsumer($consumer)
Load tool consumer object.
deleteUserResult($userresult)
Delete user object.
const ID_SCOPE_ID_ONLY
Use ID value only.
Class to represent a tool consumer.
static getConsumerKey($key)
Return a hash of a consumer key for values longer than 255 characters.
Class to represent a tool consumer context.
Definition: Context.php:17
saveToolConsumer($consumer)
Save tool consumer object.
loadContext($context)
Load context object.
loadUserResult($userresult)
Load user object.
loadResourceLink($resourceLink)
Load resource link object.
Class to represent a tool consumer nonce.
Class to represent a tool consumer resource link share.
saveResourceLink($resourceLink)
Save resource link object.
deleteContext($context)
Delete context object.
deleteToolConsumer($consumer)
Delete tool consumer object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
static fromRecordId($id, $dataConnector)
Load the user from the database.
Definition: UserResult.php:238
saveUserResult($userresult)
Save user object.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
Class to represent a tool consumer user.
Definition: UserResult.php:15
getToolConsumers()
Load tool consumer objects.
Class to represent a tool consumer resource link share key.
deleteResourceLink($resourceLink)
Delete resource link object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
Class to represent an LTI Data Connector for Oracle connections.
__construct($db, $dbTableNamePrefix='')
Class constructor.