LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
DataConnector_oci.php
1<?php
2
4
5use ceLTIc\LTI;
16
24###
25# NB This class assumes that an Oracle connection has already been opened to the appropriate schema
26###
27
29{
30
37 public function __construct($db, $dbTableNamePrefix = '')
38 {
39 parent::__construct($db, $dbTableNamePrefix);
40 $this->dateFormat = 'd-M-Y';
41 }
42
43###
44### Platform methods
45###
46
54 public function loadPlatform($platform)
55 {
56 $allowMultiple = false;
57 if (!is_null($platform->getRecordId())) {
58 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
59 'platform_id, client_id, deployment_id, public_key, ' .
60 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
61 'profile, tool_proxy, settings, protected, enabled, ' .
62 'enable_from, enable_until, last_access, created, updated ' .
63 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
64 'WHERE consumer_pk = :id';
65 $query = oci_parse($this->db, $sql);
66 $id = $platform->getRecordId();
67 oci_bind_by_name($query, 'id', $id);
68 } elseif (!empty($platform->platformId)) {
69 if (empty($platform->clientId)) {
70 $allowMultiple = true;
71 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
72 'platform_id, client_id, deployment_id, public_key, ' .
73 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
74 'profile, tool_proxy, settings, protected, enabled, ' .
75 'enable_from, enable_until, last_access, created, updated ' .
76 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
77 'WHERE (platform_id = :platform_id) ';
78 $query = oci_parse($this->db, $sql);
79 oci_bind_by_name($query, 'platform_id', $platform->platformId);
80 } elseif (empty($platform->deploymentId)) {
81 $allowMultiple = true;
82 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
83 'platform_id, client_id, deployment_id, public_key, ' .
84 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
85 'profile, tool_proxy, settings, protected, enabled, ' .
86 'enable_from, enable_until, last_access, created, updated ' .
87 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
88 'WHERE (platform_id = :platform_id) AND (client_id = :client_id)';
89 $query = oci_parse($this->db, $sql);
90 oci_bind_by_name($query, 'platform_id', $platform->platformId);
91 oci_bind_by_name($query, 'client_id', $platform->clientId);
92 } else {
93 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
94 'platform_id, client_id, deployment_id, public_key, ' .
95 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
96 'profile, tool_proxy, settings, protected, enabled, ' .
97 'enable_from, enable_until, last_access, created, updated ' .
98 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
99 'WHERE (platform_id = :platform_id) AND (client_id = :client_id) AND (deployment_id = :deployment_id)';
100 $query = oci_parse($this->db, $sql);
101 oci_bind_by_name($query, 'platform_id', $platform->platformId);
102 oci_bind_by_name($query, 'client_id', $platform->clientId);
103 oci_bind_by_name($query, 'deployment_id', $platform->deploymentId);
104 }
105 } else {
106 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
107 'platform_id, client_id, deployment_id, public_key, ' .
108 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
109 'profile, tool_proxy, settings, protected, enabled, ' .
110 'enable_from, enable_until, last_access, created, updated ' .
111 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
112 'WHERE consumer_key = :key';
113 $query = oci_parse($this->db, $sql);
114 $consumerKey = $platform->getKey();
115 oci_bind_by_name($query, 'key', $consumerKey);
116 }
117 $ok = $this->executeQuery($sql, $query);
118 if ($ok) {
119 $row = oci_fetch_assoc($query);
120 $ok = ($row !== false) && ($allowMultiple || !oci_fetch_assoc($query));
121 }
122 if ($ok) {
123 $row = array_change_key_case($row);
124 $platform->setRecordId(intval($row['consumer_pk']));
125 $platform->name = $row['name'];
126 $platform->setkey($row['consumer_key']);
127 $platform->secret = $row['secret'];
128 $platform->platformId = $row['platform_id'];
129 $platform->clientId = $row['client_id'];
130 $platform->deploymentId = $row['deployment_id'];
131 $platform->rsaKey = $row['public_key'];
132 $platform->ltiVersion = $row['lti_version'];
133 $platform->signatureMethod = $row['signature_method'];
134 $platform->consumerName = $row['consumer_name'];
135 $platform->consumerVersion = $row['consumer_version'];
136 $platform->consumerGuid = $row['consumer_guid'];
137 $platform->profile = Util::jsonDecode($row['profile']);
138 $platform->toolProxy = $row['tool_proxy'];
139 $settingsValue = $row['settings']->load();
140 if (is_string($settingsValue)) {
141 $settings = Util::jsonDecode($settingsValue, true);
142 if (!is_array($settings)) {
143 $settings = @unserialize($settingsValue); // check for old serialized setting
144 }
145 if (!is_array($settings)) {
146 $settings = array();
147 }
148 } else {
149 $settings = array();
150 }
151 $platform->setSettings($settings);
152 $platform->protected = (intval($row['protected']) === 1);
153 $platform->enabled = (intval($row['enabled']) === 1);
154 $platform->enableFrom = null;
155 if (!is_null($row['enable_from'])) {
156 $platform->enableFrom = strtotime($row['enable_from']);
157 }
158 $platform->enableUntil = null;
159 if (!is_null($row['enable_until'])) {
160 $platform->enableUntil = strtotime($row['enable_until']);
161 }
162 $platform->lastAccess = null;
163 if (!is_null($row['last_access'])) {
164 $platform->lastAccess = strtotime($row['last_access']);
165 }
166 $platform->created = strtotime($row['created']);
167 $platform->updated = strtotime($row['updated']);
168 $this->fixPlatformSettings($platform, false);
169 }
170
171 return $ok;
172 }
173
181 public function savePlatform($platform)
182 {
183 $id = $platform->getRecordId();
184 $consumerKey = $platform->getKey();
185 $protected = ($platform->protected) ? 1 : 0;
186 $enabled = ($platform->enabled) ? 1 : 0;
187 $profile = (!empty($platform->profile)) ? json_encode($platform->profile) : null;
188 $this->fixPlatformSettings($platform, true);
189 $settingsValue = json_encode($platform->getSettings());
190 $this->fixPlatformSettings($platform, false);
191 $time = time();
192 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
193 $from = null;
194 if (!is_null($platform->enableFrom)) {
195 $from = date("{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
196 }
197 $until = null;
198 if (!is_null($platform->enableUntil)) {
199 $until = date("{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
200 }
201 $last = null;
202 if (!is_null($platform->lastAccess)) {
203 $last = date($this->dateFormat, $platform->lastAccess);
204 }
205 if (empty($id)) {
206 $pk = null;
207 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' (consumer_key, name, secret, ' .
208 'platform_id, client_id, deployment_id, public_key, ' .
209 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
210 'profile, tool_proxy, settings, protected, enabled, ' .
211 'enable_from, enable_until, last_access, created, updated) ' .
212 'VALUES (:key, :name, :secret, ' .
213 ':platform_id, :client_id, :deployment_id, :public_key, ' .
214 ':lti_version, :signature_method, ' .
215 ':consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' .
216 ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated) returning consumer_pk into :pk';
217 $query = oci_parse($this->db, $sql);
218 oci_bind_by_name($query, 'key', $consumerKey);
219 oci_bind_by_name($query, 'name', $platform->name);
220 oci_bind_by_name($query, 'secret', $platform->secret);
221 oci_bind_by_name($query, 'platform_id', $platform->platformId);
222 oci_bind_by_name($query, 'client_id', $platform->clientId);
223 oci_bind_by_name($query, 'deployment_id', $platform->deploymentId);
224 oci_bind_by_name($query, 'public_key', $platform->rsaKey);
225 oci_bind_by_name($query, 'lti_version', $platform->ltiVersion);
226 oci_bind_by_name($query, 'signature_method', $platform->signatureMethod);
227 oci_bind_by_name($query, 'consumer_name', $platform->consumerName);
228 oci_bind_by_name($query, 'consumer_version', $platform->consumerVersion);
229 oci_bind_by_name($query, 'consumer_guid', $platform->consumerGuid);
230 oci_bind_by_name($query, 'profile', $profile);
231 oci_bind_by_name($query, 'tool_proxy', $platform->toolProxy);
232 oci_bind_by_name($query, 'settings', $settingsValue);
233 oci_bind_by_name($query, 'protected', $protected);
234 oci_bind_by_name($query, 'enabled', $enabled);
235 oci_bind_by_name($query, 'enable_from', $from);
236 oci_bind_by_name($query, 'enable_until', $until);
237 oci_bind_by_name($query, 'last_access', $last);
238 oci_bind_by_name($query, 'created', $now);
239 oci_bind_by_name($query, 'updated', $now);
240 oci_bind_by_name($query, 'pk', $pk);
241 } else {
242 $sql = 'UPDATE ' . $this->dbTableNamePrefix . static::PLATFORM_TABLE_NAME . ' ' .
243 'SET consumer_key = :key, name = :name, secret = :secret, ' .
244 'platform_id = :platform_id, client_id = :client_id, deployment_id = :deployment_id, ' .
245 'public_key = :public_key, lti_version = :lti_version, signature_method = :signature_method, ' .
246 'consumer_name = :consumer_name, consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' .
247 'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' .
248 'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, last_access = :last_access, updated = :updated ' .
249 'WHERE consumer_pk = :id';
250 $query = oci_parse($this->db, $sql);
251 oci_bind_by_name($query, 'key', $consumerKey);
252 oci_bind_by_name($query, 'name', $platform->name);
253 oci_bind_by_name($query, 'secret', $platform->secret);
254 oci_bind_by_name($query, 'platform_id', $platform->platformId);
255 oci_bind_by_name($query, 'client_id', $platform->clientId);
256 oci_bind_by_name($query, 'deployment_id', $platform->deploymentId);
257 oci_bind_by_name($query, 'public_key', $platform->rsaKey);
258 oci_bind_by_name($query, 'lti_version', $platform->ltiVersion);
259 oci_bind_by_name($query, 'signature_method', $platform->signatureMethod);
260 oci_bind_by_name($query, 'consumer_name', $platform->consumerName);
261 oci_bind_by_name($query, 'consumer_version', $platform->consumerVersion);
262 oci_bind_by_name($query, 'consumer_guid', $platform->consumerGuid);
263 oci_bind_by_name($query, 'profile', $profile);
264 oci_bind_by_name($query, 'tool_proxy', $platform->toolProxy);
265 oci_bind_by_name($query, 'settings', $settingsValue);
266 oci_bind_by_name($query, 'protected', $protected);
267 oci_bind_by_name($query, 'enabled', $enabled);
268 oci_bind_by_name($query, 'enable_from', $from);
269 oci_bind_by_name($query, 'enable_until', $until);
270 oci_bind_by_name($query, 'last_access', $last);
271 oci_bind_by_name($query, 'updated', $now);
272 oci_bind_by_name($query, 'id', $id);
273 }
274 $ok = $this->executeQuery($sql, $query);
275 if ($ok) {
276 if (empty($id)) {
277 $platform->setRecordId(intval($pk));
278 $platform->created = $time;
279 }
280 $platform->updated = $time;
281 }
282
283 return $ok;
284 }
285
293 public function deletePlatform($platform)
294 {
295 $id = $platform->getRecordId();
296
297// Delete any access token for this consumer
298 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME . ' WHERE consumer_pk = :id';
299 $query = oci_parse($this->db, $sql);
300 oci_bind_by_name($query, 'id', $id);
301 $this->executeQuery($sql, $query);
302
303// Delete any nonce values for this consumer
304 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE consumer_pk = :id';
305 $query = oci_parse($this->db, $sql);
306 oci_bind_by_name($query, 'id', $id);
307 $this->executeQuery($sql, $query);
308
309// Delete any outstanding share keys for resource links for this consumer
310 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
311 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
312 'WHERE consumer_pk = :id)';
313 $query = oci_parse($this->db, $sql);
314 oci_bind_by_name($query, 'id', $id);
315 $this->executeQuery($sql, $query);
316
317// Delete any outstanding share keys for resource links for contexts in this consumer
318 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
319 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
320 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
321 $query = oci_parse($this->db, $sql);
322 oci_bind_by_name($query, 'id', $id);
323 $this->executeQuery($sql, $query);
324
325// Delete any users in resource links for this consumer
326 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
327 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
328 'WHERE consumer_pk = :id)';
329 $query = oci_parse($this->db, $sql);
330 oci_bind_by_name($query, 'id', $id);
331 $this->executeQuery($sql, $query);
332
333// Delete any users in resource links for contexts in this consumer
334 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
335 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
336 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
337 $query = oci_parse($this->db, $sql);
338 oci_bind_by_name($query, 'id', $id);
339 $this->executeQuery($sql, $query);
340
341// Update any resource links for which this consumer is acting as a primary resource link
342 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
343 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
344 'WHERE primary_resource_link_pk IN ' .
345 "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
346 'WHERE consumer_pk = :id)';
347 $query = oci_parse($this->db, $sql);
348 oci_bind_by_name($query, 'id', $id);
349 $this->executeQuery($sql, $query);
350
351// Update any resource links for contexts in which this consumer is acting as a primary resource link
352 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
353 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
354 'WHERE primary_resource_link_pk IN ' .
355 "(SELECT rl.resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
356 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ON rl.context_pk = c.context_pk ' .
357 'WHERE c.consumer_pk = :id)';
358 $query = oci_parse($this->db, $sql);
359 oci_bind_by_name($query, 'id', $id);
360 $this->executeQuery($sql, $query);
361
362// Delete any resource links for this consumer
363 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
364 'WHERE consumer_pk = :id';
365 $query = oci_parse($this->db, $sql);
366 oci_bind_by_name($query, 'id', $id);
367 $this->executeQuery($sql, $query);
368
369// Delete any resource links for contexts in this consumer
370 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
371 'WHERE context_pk IN (' .
372 "SELECT context_pk FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' . 'WHERE consumer_pk = :id)';
373 $query = oci_parse($this->db, $sql);
374 oci_bind_by_name($query, 'id', $id);
375 $this->executeQuery($sql, $query);
376
377// Delete any contexts for this consumer
378 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
379 'WHERE consumer_pk = :id';
380 $query = oci_parse($this->db, $sql);
381 oci_bind_by_name($query, 'id', $id);
382 $this->executeQuery($sql, $query);
383
384// Delete consumer
385 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
386 'WHERE consumer_pk = :id';
387 $query = oci_parse($this->db, $sql);
388 oci_bind_by_name($query, 'id', $id);
389 $ok = $this->executeQuery($sql, $query);
390
391 if ($ok) {
392 $platform->initialize();
393 }
394
395 return $ok;
396 }
397
403 public function getPlatforms()
404 {
405 $platforms = array();
406
407 $sql = 'SELECT consumer_pk, name, consumer_key, secret, ' .
408 'platform_id, client_id, deployment_id, public_key, ' .
409 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
410 'profile, tool_proxy, settings, protected, enabled, ' .
411 'enable_from, enable_until, last_access, created, updated ' .
412 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' ' .
413 'ORDER BY name';
414 $query = oci_parse($this->db, $sql);
415 $ok = ($query !== false);
416
417 if ($ok) {
418 $ok = $this->executeQuery($sql, $query);
419 }
420
421 if ($ok) {
422 while ($row = oci_fetch_assoc($query)) {
423 $row = array_change_key_case($row);
424 $platform = new Platform($this);
425 $platform->setRecordId(intval($row['consumer_pk']));
426 $platform->name = $row['name'];
427 $platform->setKey($row['consumer_key']);
428 $platform->secret = $row['secret'];
429 $platform->platformId = $row['platform_id'];
430 $platform->clientId = $row['client_id'];
431 $platform->deploymentId = $row['deployment_id'];
432 $platform->rsaKey = $row['public_key'];
433 $platform->ltiVersion = $row['lti_version'];
434 $platform->signatureMethod = $row['signature_method'];
435 $platform->consumerName = $row['consumer_name'];
436 $platform->consumerVersion = $row['consumer_version'];
437 $platform->consumerGuid = $row['consumer_guid'];
438 $platform->profile = Util::jsonDecode($row['profile']);
439 $platform->toolProxy = $row['tool_proxy'];
440 $settingsValue = $row['settings']->load();
441 if (is_string($settingsValue)) {
442 $settings = Util::jsonDecode($settingsValue, true);
443 if (!is_array($settings)) {
444 $settings = @unserialize($settingsValue); // check for old serialized setting
445 }
446 if (!is_array($settings)) {
447 $settings = array();
448 }
449 } else {
450 $settings = array();
451 }
452 $platform->setSettings($settings);
453 $platform->protected = (intval($row['protected']) === 1);
454 $platform->enabled = (intval($row['enabled']) === 1);
455 $platform->enableFrom = null;
456 if (!is_null($row['enable_from'])) {
457 $platform->enableFrom = strtotime($row['enable_from']);
458 }
459 $platform->enableUntil = null;
460 if (!is_null($row['enable_until'])) {
461 $platform->enableUntil = strtotime($row['enable_until']);
462 }
463 $platform->lastAccess = null;
464 if (!is_null($row['last_access'])) {
465 $platform->lastAccess = strtotime($row['last_access']);
466 }
467 $platform->created = strtotime($row['created']);
468 $platform->updated = strtotime($row['updated']);
469 $this->fixPlatformSettings($platform, false);
470 $platforms[] = $platform;
471 }
472 }
473
474 return $platforms;
475 }
476
477###
478### Context methods
479###
480
488 public function loadContext($context)
489 {
490 $ok = false;
491 if (!is_null($context->getRecordId())) {
492 $sql = 'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
493 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
494 'WHERE (context_pk = :id)';
495 $query = oci_parse($this->db, $sql);
496 $id = $context->getRecordId();
497 oci_bind_by_name($query, 'id', $id);
498 } else {
499 $sql = 'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
500 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
501 'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
502 $query = oci_parse($this->db, $sql);
503 $id = $context->getPlatform()->getRecordId();
504 oci_bind_by_name($query, 'cid', $id);
505 oci_bind_by_name($query, 'ctx', $context->ltiContextId);
506 }
507 $ok = $this->executeQuery($sql, $query);
508 if ($ok) {
509 $row = oci_fetch_assoc($query);
510 $ok = ($row !== false);
511 }
512 if ($ok) {
513 $row = array_change_key_case($row);
514 $context->setRecordId(intval($row['context_pk']));
515 $context->setPlatformId(intval($row['consumer_pk']));
516 $context->title = $row['title'];
517 $context->ltiContextId = $row['lti_context_id'];
518 $context->type = $row['type'];
519 $settingsValue = $row['settings']->load();
520 if (is_string($settingsValue)) {
521 $settings = Util::jsonDecode($settingsValue, true);
522 if (!is_array($settings)) {
523 $settings = @unserialize($settingsValue); // check for old serialized setting
524 }
525 if (!is_array($settings)) {
526 $settings = array();
527 }
528 } else {
529 $settings = array();
530 }
531 $context->setSettings($settings);
532 $context->created = strtotime($row['created']);
533 $context->updated = strtotime($row['updated']);
534 }
535
536 return $ok;
537 }
538
546 public function saveContext($context)
547 {
548 $time = time();
549 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
550 $settingsValue = json_encode($context->getSettings());
551 $id = $context->getRecordId();
552 $consumer_pk = $context->getPlatform()->getRecordId();
553 if (empty($id)) {
554 $pk = null;
555 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' (consumer_pk, title, ' .
556 'lti_context_id, type, settings, created, updated) ' .
557 'VALUES (:cid, :title, :ctx, :type, :settings, :created, :updated) returning context_pk into :pk';
558 $query = oci_parse($this->db, $sql);
559 oci_bind_by_name($query, 'cid', $consumer_pk);
560 oci_bind_by_name($query, 'title', $context->title);
561 oci_bind_by_name($query, 'ctx', $context->ltiContextId);
562 oci_bind_by_name($query, 'type', $context->type);
563 oci_bind_by_name($query, 'settings', $settingsValue);
564 oci_bind_by_name($query, 'created', $now);
565 oci_bind_by_name($query, 'updated', $now);
566 oci_bind_by_name($query, 'pk', $pk);
567 } else {
568 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' SET ' .
569 'title = :title, lti_context_id = :ctx, type = :type, settings = :settings, ' .
570 'updated = :updated ' .
571 'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
572 $query = oci_parse($this->db, $sql);
573 oci_bind_by_name($query, 'title', $context->title);
574 oci_bind_by_name($query, 'ctx', $context->ltiContextId);
575 oci_bind_by_name($query, 'type', $context->type);
576 oci_bind_by_name($query, 'settings', $settingsValue);
577 oci_bind_by_name($query, 'updated', $now);
578 oci_bind_by_name($query, 'cid', $consumer_pk);
579 oci_bind_by_name($query, 'ctxid', $id);
580 }
581 $ok = $this->executeQuery($sql, $query);
582 if ($ok) {
583 if (empty($id)) {
584 $context->setRecordId(intval($pk));
585 $context->created = $time;
586 }
587 $context->updated = $time;
588 }
589
590 return $ok;
591 }
592
600 public function deleteContext($context)
601 {
602 $id = $context->getRecordId();
603
604// Delete any outstanding share keys for resource links for this context
605 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
606 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
607 'WHERE context_pk = :id)';
608 $query = oci_parse($this->db, $sql);
609 oci_bind_by_name($query, 'id', $id);
610 $this->executeQuery($sql, $query);
611
612// Delete any users in resource links for this context
613 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
614 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
615 'WHERE context_pk = :id)';
616 $query = oci_parse($this->db, $sql);
617 oci_bind_by_name($query, 'id', $id);
618 $this->executeQuery($sql, $query);
619
620// Update any resource links for which this consumer is acting as a primary resource link
621 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
622 'SET primary_resource_link_pk = null, share_approved = null ' .
623 'WHERE primary_resource_link_pk IN ' .
624 "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' WHERE context_pk = :id)';
625 $query = oci_parse($this->db, $sql);
626 oci_bind_by_name($query, 'id', $id);
627 $this->executeQuery($sql, $query);
628
629// Delete any resource links for this consumer
630 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
631 'WHERE context_pk = :id';
632 $query = oci_parse($this->db, $sql);
633 oci_bind_by_name($query, 'id', $id);
634 $this->executeQuery($sql, $query);
635
636// Delete context
637 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' ' .
638 'WHERE context_pk = :id';
639 $query = oci_parse($this->db, $sql);
640 oci_bind_by_name($query, 'id', $id);
641 $ok = $this->executeQuery($sql, $query);
642
643 if ($ok) {
644 $context->initialize();
645 }
646
647 return $ok;
648 }
649
650###
651### ResourceLink methods
652###
653
661 public function loadResourceLink($resourceLink)
662 {
663 if (!is_null($resourceLink->getRecordId())) {
664 $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, title, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
665 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
666 'WHERE (resource_link_pk = :id)';
667 $query = oci_parse($this->db, $sql);
668 $id = $resourceLink->getRecordId();
669 oci_bind_by_name($query, 'id', $id);
670 } elseif (!is_null($resourceLink->getContext())) {
671 $sql = 'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.title, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
672 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r ' .
673 'WHERE (r.lti_resource_link_id = :rlid) AND ((r.context_pk = :id1) OR (r.consumer_pk IN (' .
674 'SELECT c.consumer_pk ' .
675 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' c ' .
676 'WHERE (c.context_pk = :id2)' .
677 ')))';
678 $query = oci_parse($this->db, $sql);
679 $rlid = $resourceLink->getId();
680 oci_bind_by_name($query, 'rlid', $rlid);
681 $id = $resourceLink->getContext()->getRecordId();
682 oci_bind_by_name($query, 'id1', $id);
683 oci_bind_by_name($query, 'id2', $id);
684 } else {
685 $sql = 'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.title, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
686 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' .
687 $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' .
688 ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
689 $query = oci_parse($this->db, $sql);
690 $id1 = $resourceLink->getPlatform()->getRecordId();
691 oci_bind_by_name($query, 'id1', $id1);
692 $id2 = $resourceLink->getPlatform()->getRecordId();
693 oci_bind_by_name($query, 'id2', $id2);
694 $id = $resourceLink->getId();
695 oci_bind_by_name($query, 'rlid', $id);
696 }
697 $ok = $this->executeQuery($sql, $query);
698 if ($ok) {
699 $row = oci_fetch_assoc($query);
700 $ok = ($row !== false);
701 }
702
703 if ($ok) {
704 $row = array_change_key_case($row);
705 $resourceLink->setRecordId(intval($row['resource_link_pk']));
706 if (!is_null($row['context_pk'])) {
707 $resourceLink->setContextId(intval($row['context_pk']));
708 } else {
709 $resourceLink->setContextId(null);
710 }
711 if (!is_null($row['consumer_pk'])) {
712 $resourceLink->setPlatformId(intval($row['consumer_pk']));
713 } else {
714 $resourceLink->setPlatformId(null);
715 }
716 $resourceLink->title = $row['title'];
717 $resourceLink->ltiResourceLinkId = $row['lti_resource_link_id'];
718 $settings = $row['settings']->load();
719 $settingsValue = $row['settings']->load();
720 if (is_string($settingsValue)) {
721 $settings = Util::jsonDecode($settingsValue, true);
722 if (!is_array($settings)) {
723 $settings = @unserialize($settingsValue); // check for old serialized setting
724 }
725 if (!is_array($settings)) {
726 $settings = array();
727 }
728 } else {
729 $settings = array();
730 }
731 $resourceLink->setSettings($settings);
732 if (!is_null($row['primary_resource_link_pk'])) {
733 $resourceLink->primaryResourceLinkId = intval($row['primary_resource_link_pk']);
734 } else {
735 $resourceLink->primaryResourceLinkId = null;
736 }
737 $resourceLink->shareApproved = (is_null($row['share_approved'])) ? null : (intval($row['share_approved']) === 1);
738 $resourceLink->created = strtotime($row['created']);
739 $resourceLink->updated = strtotime($row['updated']);
740 }
741
742 return $ok;
743 }
744
752 public function saveResourceLink($resourceLink)
753 {
754 if (is_null($resourceLink->shareApproved)) {
755 $approved = null;
756 } elseif ($resourceLink->shareApproved) {
757 $approved = 1;
758 } else {
759 $approved = 0;
760 }
761 $time = time();
762 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
763 $settingsValue = json_encode($resourceLink->getSettings());
764 if (!is_null($resourceLink->getContext())) {
765 $consumerId = null;
766 $contextId = $resourceLink->getContext()->getRecordId();
767 } elseif (!is_null($resourceLink->getContextId())) {
768 $consumerId = null;
769 $contextId = $resourceLink->getContextId();
770 } else {
771 $consumerId = $resourceLink->getPlatform()->getRecordId();
772 $contextId = null;
773 }
774 if (empty($resourceLink->primaryResourceLinkId)) {
775 $primaryResourceLinkId = null;
776 } else {
777 $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
778 }
779 $id = $resourceLink->getRecordId();
780 if (empty($id)) {
781 $pk = null;
782 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' .
783 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
784 'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated) returning resource_link_pk into :pk';
785 $query = oci_parse($this->db, $sql);
786 oci_bind_by_name($query, 'cid', $consumerId);
787 oci_bind_by_name($query, 'ctx', $contextId);
788 $rlid = $resourceLink->getId();
789 oci_bind_by_name($query, 'rlid', $rlid);
790 oci_bind_by_name($query, 'settings', $settingsValue);
791 oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
792 oci_bind_by_name($query, 'share_approved', $approved);
793 oci_bind_by_name($query, 'created', $now);
794 oci_bind_by_name($query, 'updated', $now);
795 oci_bind_by_name($query, 'pk', $pk);
796 } elseif (!is_null($contextId)) {
797 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' .
798 'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' .
799 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
800 'WHERE (resource_link_pk = :id)';
801 $query = oci_parse($this->db, $sql);
802 oci_bind_by_name($query, 'ctx', $contextId);
803 $rlid = $resourceLink->getId();
804 oci_bind_by_name($query, 'rlid', $rlid);
805 oci_bind_by_name($query, 'settings', $settingsValue);
806 oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
807 oci_bind_by_name($query, 'share_approved', $approved);
808 oci_bind_by_name($query, 'updated', $now);
809 oci_bind_by_name($query, 'id', $id);
810 } else {
811 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' SET ' .
812 'context_pk = NULL, lti_resource_link_id = :rlid, settings = :settings, ' .
813 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
814 'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
815 $query = oci_parse($this->db, $sql);
816 $rlid = $resourceLink->getId();
817 oci_bind_by_name($query, 'rlid', $rlid);
818 oci_bind_by_name($query, 'settings', $settingsValue);
819 oci_bind_by_name($query, 'prlid', $primaryResourceLinkId);
820 oci_bind_by_name($query, 'share_approved', $approved);
821 oci_bind_by_name($query, 'updated', $now);
822 oci_bind_by_name($query, 'cid', $consumerId);
823 oci_bind_by_name($query, 'id', $id);
824 }
825 $ok = $this->executeQuery($sql, $query);
826 if ($ok) {
827 if (empty($id)) {
828 $resourceLink->setRecordId(intval($pk));
829 $resourceLink->created = $time;
830 }
831 $resourceLink->updated = $time;
832 }
833
834 return $ok;
835 }
836
844 public function deleteResourceLink($resourceLink)
845 {
846 $id = $resourceLink->getRecordId();
847
848// Delete any outstanding share keys for resource links for this consumer
849 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
850 'WHERE (resource_link_pk = :id)';
851 $query = oci_parse($this->db, $sql);
852 oci_bind_by_name($query, 'id', $id);
853 $ok = $this->executeQuery($sql, $query);
854
855// Delete users
856 if ($ok) {
857 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
858 'WHERE (resource_link_pk = :id)';
859 $query = oci_parse($this->db, $sql);
860 oci_bind_by_name($query, 'id', $id);
861 $ok = $this->executeQuery($sql, $query);
862 }
863
864// Update any resource links for which this is the primary resource link
865 if ($ok) {
866 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
867 'SET primary_resource_link_pk = NULL ' .
868 'WHERE (primary_resource_link_pk = :id)';
869 $query = oci_parse($this->db, $sql);
870 oci_bind_by_name($query, 'id', $id);
871 $ok = $this->executeQuery($sql, $query);
872 }
873
874// Delete resource link
875 if ($ok) {
876 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' ' .
877 'WHERE (resource_link_pk = :id)';
878 $query = oci_parse($this->db, $sql);
879 oci_bind_by_name($query, 'id', $id);
880 $ok = $this->executeQuery($sql, $query);
881 }
882
883 if ($ok) {
884 $resourceLink->initialize();
885 }
886
887 return $ok;
888 }
889
902 public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
903 {
904 $id = $resourceLink->getRecordId();
905 $userResults = array();
906
907 if ($localOnly) {
908 $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
909 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' .
910 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
911 'ON u.resource_link_pk = rl.resource_link_pk ' .
912 'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
913 $query = oci_parse($this->db, $sql);
914 oci_bind_by_name($query, 'id', $id);
915 } else {
916 $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
917 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' u ' .
918 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' rl ' .
919 'ON u.resource_link_pk = rl.resource_link_pk ' .
920 'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
921 '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))';
922 $query = oci_parse($this->db, $sql);
923 oci_bind_by_name($query, 'id', $id);
924 oci_bind_by_name($query, 'pid', $id);
925 }
926 if ($this->executeQuery($sql, $query)) {
927 while ($row = oci_fetch_assoc($query)) {
928 $row = array_change_key_case($row);
929 $userresult = LTI\UserResult::fromRecordId($row['user_result_pk'], $resourceLink->getDataConnector());
930 $userresult->setRecordId(intval($row['user_result_pk']));
931 $userresult->ltiResultSourcedId = $row['lti_result_sourcedid'];
932 $userresult->created = strtotime($row['created']);
933 $userresult->updated = strtotime($row['updated']);
934 if (is_null($idScope)) {
935 $userResults[] = $userresult;
936 } else {
937 $userResults[$userresult->getId($idScope)] = $userresult;
938 }
939 }
940 }
941
942 return $userResults;
943 }
944
952 public function getSharesResourceLink($resourceLink)
953 {
954 $id = $resourceLink->getRecordId();
955
956 $shares = array();
957
958 $sql = 'SELECT c.consumer_name, r.resource_link_pk, r.title, r.share_approved ' .
959 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r ' .
960 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' c ON r.consumer_pk = c.consumer_pk ' .
961 'WHERE (r.primary_resource_link_pk = :id1) ' .
962 'UNION ' .
963 'SELECT c2.consumer_name, r2.resource_link_pk, r2.title, r2.share_approved ' .
964 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' r2 ' .
965 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME . ' x ON r2.context_pk = x.context_pk ' .
966 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME . ' c2 ON x.consumer_pk = c2.consumer_pk ' .
967 'WHERE (r2.primary_resource_link_pk = :id2) ' .
968 'ORDER BY consumer_name, title';
969 $query = oci_parse($this->db, $sql);
970 oci_bind_by_name($query, 'id1', $id);
971 oci_bind_by_name($query, 'id2', $id);
972 if ($this->executeQuery($sql, $query)) {
973 while ($row = oci_fetch_assoc($query)) {
974 $row = array_change_key_case($row);
975 $share = new LTI\ResourceLinkShare();
976 $share->consumerName = $row['consumer_name'];
977 $share->resourceLinkId = intval($row['resource_link_pk']);
978 $share->title = $row['title'];
979 $share->approved = (intval($row['share_approved']) === 1);
980 $shares[] = $share;
981 }
982 }
983
984 return $shares;
985 }
986
987###
988### PlatformNonce methods
989###
990
998 public function loadPlatformNonce($nonce)
999 {
1000 if (parent::useMemcache()) {
1001 $ok = parent::loadPlatformNonce($nonce);
1002 } else {
1003// Delete any expired nonce values
1004 $now = date("{$this->dateFormat} {$this->timeFormat}", time());
1005 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE expires <= :now';
1006 $query = oci_parse($this->db, $sql);
1007 oci_bind_by_name($query, 'now', $now);
1008 $this->executeQuery($sql, $query);
1009
1010// Load the nonce
1011 $id = $nonce->getPlatform()->getRecordId();
1012 $value = $nonce->getValue();
1013 $sql = "SELECT value T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE (consumer_pk = :id) AND (value = :value)';
1014 $query = oci_parse($this->db, $sql);
1015 oci_bind_by_name($query, 'id', $id);
1016 oci_bind_by_name($query, 'value', $value);
1017 $ok = $this->executeQuery($sql, $query, false);
1018 if ($ok) {
1019 $row = oci_fetch_assoc($query);
1020 if ($row === false) {
1021 $ok = false;
1022 }
1023 }
1024 }
1025
1026 return $ok;
1027 }
1028
1036 public function savePlatformNonce($nonce)
1037 {
1038 if (parent::useMemcache()) {
1039 $ok = parent::savePlatformNonce($nonce);
1040 } else {
1041 $id = $nonce->getPlatform()->getRecordId();
1042 $value = $nonce->getValue();
1043 $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
1044 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' (consumer_pk, value, expires) VALUES (:id, :value, :expires)';
1045 $query = oci_parse($this->db, $sql);
1046 oci_bind_by_name($query, 'id', $id);
1047 oci_bind_by_name($query, 'value', $value);
1048 oci_bind_by_name($query, 'expires', $expires);
1049 $ok = $this->executeQuery($sql, $query);
1050 }
1051
1052 return $ok;
1053 }
1054
1062 public function deletePlatformNonce($nonce)
1063 {
1064 if (parent::useMemcache()) {
1065 $ok = parent::deletePlatformNonce($nonce);
1066 } else {
1067 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME . ' WHERE (consumer_pk = :id) AND (value = :value)';
1068 $query = oci_parse($this->db, $sql);
1069 $id = $nonce->getPlatform()->getRecordId();
1070 oci_bind_by_name($query, 'id', $id);
1071 $value = $nonce->getValue();
1072 oci_bind_by_name($query, 'value', $value);
1073 $ok = $this->executeQuery($sql, $query);
1074 }
1075
1076 return $ok;
1077 }
1078
1079###
1080### AccessToken methods
1081###
1082
1090 public function loadAccessToken($accessToken)
1091 {
1092 if (parent::useMemcache()) {
1093 $ok = parent::loadAccessToken($accessToken);
1094 } else {
1095 $ok = false;
1096 $consumer_pk = $accessToken->getPlatform()->getRecordId();
1097 $sql = "SELECT scopes, token, expires, created, updated FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME . ' ' .
1098 'WHERE (consumer_pk = :consumer_pk)';
1099 $query = oci_parse($this->db, $sql);
1100 oci_bind_by_name($query, 'consumer_pk', $consumer_pk);
1101 $this->executeQuery($sql, $query, false);
1102 if ($this->executeQuery($sql, $query)) {
1103 $row = oci_fetch_assoc($query);
1104 if ($row !== false) {
1105 $row = array_change_key_case($row);
1106 $scopes = Util::jsonDecode($row['scopes']->load(), true);
1107 if (!is_array($scopes)) {
1108 $scopes = array();
1109 }
1110 $accessToken->scopes = $scopes;
1111 $accessToken->token = $row['token'];
1112 $accessToken->expires = strtotime($row['expires']);
1113 $accessToken->created = strtotime($row['created']);
1114 $accessToken->updated = strtotime($row['updated']);
1115 $ok = true;
1116 }
1117 }
1118 }
1119
1120 return $ok;
1121 }
1122
1130 public function saveAccessToken($accessToken)
1131 {
1132 if (parent::useMemcache()) {
1133 $ok = parent::saveAccessToken($accessToken);
1134 } else {
1135 $consumer_pk = $accessToken->getPlatform()->getRecordId();
1136 $scopes = json_encode($accessToken->scopes, JSON_UNESCAPED_SLASHES);
1137 $token = $accessToken->token;
1138 $expires = date("{$this->dateFormat} {$this->timeFormat}", $accessToken->expires);
1139 $time = time();
1140 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
1141 if (empty($accessToken->created)) {
1142 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME . ' ' .
1143 '(consumer_pk, scopes, token, expires, created, updated) ' .
1144 'VALUES (:consumer_pk, :scopes, :token, :expires, :created, :updated)';
1145 $query = oci_parse($this->db, $sql);
1146 oci_bind_by_name($query, 'consumer_pk', $consumer_pk);
1147 oci_bind_by_name($query, 'scopes', $scopes);
1148 oci_bind_by_name($query, 'token', $token);
1149 oci_bind_by_name($query, 'expires', $expires);
1150 oci_bind_by_name($query, 'created', $now);
1151 oci_bind_by_name($query, 'updated', $now);
1152 } else {
1153 $sql = 'UPDATE ' . $this->dbTableNamePrefix . static::ACCESS_TOKEN_TABLE_NAME . ' ' .
1154 'SET scopes = :scopes, token = :token, expires = :expires, updated = :updated ' .
1155 'WHERE consumer_pk = :consumer_pk';
1156 $query = oci_parse($this->db, $sql);
1157 oci_bind_by_name($query, 'scopes', $scopes);
1158 oci_bind_by_name($query, 'token', $token);
1159 oci_bind_by_name($query, 'expires', $expires);
1160 oci_bind_by_name($query, 'updated', $now);
1161 oci_bind_by_name($query, 'consumer_pk', $consumer_pk);
1162 }
1163 $ok = $this->executeQuery($sql, $query);
1164 }
1165
1166 return $ok;
1167 }
1168
1169###
1170### ResourceLinkShareKey methods
1171###
1172
1180 public function loadResourceLinkShareKey($shareKey)
1181 {
1182 $ok = false;
1183
1184// Clear expired share keys
1185 $now = date("{$this->dateFormat} {$this->timeFormat}", time());
1186 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE expires <= :now';
1187 $query = oci_parse($this->db, $sql);
1188 oci_bind_by_name($query, 'now', $now);
1189 $this->executeQuery($sql, $query);
1190
1191// Load share key
1192 $id = $shareKey->getId();
1193 $sql = 'SELECT resource_link_pk, auto_approve, expires ' .
1194 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
1195 'WHERE share_key_id = :id';
1196 $query = oci_parse($this->db, $sql);
1197 oci_bind_by_name($query, 'id', $id);
1198 if ($this->executeQuery($sql, $query)) {
1199 $row = oci_fetch_assoc($query);
1200 if ($row !== false) {
1201 $row = array_change_key_case($row);
1202 $shareKey->resourceLinkId = intval($row['resource_link_pk']);
1203 $shareKey->autoApprove = ($row['auto_approve'] === 1);
1204 $shareKey->expires = strtotime($row['expires']);
1205 $ok = true;
1206 }
1207 }
1208
1209 return $ok;
1210 }
1211
1219 public function saveResourceLinkShareKey($shareKey)
1220 {
1221 if ($shareKey->autoApprove) {
1222 $approve = 1;
1223 } else {
1224 $approve = 0;
1225 }
1226 $id = $shareKey->getId();
1227 $expires = date("{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
1228 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
1229 '(share_key_id, resource_link_pk, auto_approve, expires) ' .
1230 'VALUES (:id, :prlid, :approve, :expires)';
1231 $query = oci_parse($this->db, $sql);
1232 oci_bind_by_name($query, 'id', $id);
1233 oci_bind_by_name($query, 'prlid', $shareKey->resourceLinkId);
1234 oci_bind_by_name($query, 'approve', $approve);
1235 oci_bind_by_name($query, 'expires', $expires);
1236 $ok = $this->executeQuery($sql, $query);
1237
1238 return $ok;
1239 }
1240
1248 public function deleteResourceLinkShareKey($shareKey)
1249 {
1250 $id = $shareKey->getId();
1251 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE share_key_id = :id';
1252 $query = oci_parse($this->db, $sql);
1253 oci_bind_by_name($query, 'id', $id);
1254 $ok = $this->executeQuery($sql, $query);
1255
1256 if ($ok) {
1257 $shareKey->initialize();
1258 }
1259
1260 return $ok;
1261 }
1262
1263###
1264### UserResult Result methods
1265###
1266
1274 public function loadUserResult($userresult)
1275 {
1276 $ok = false;
1277 if (!is_null($userresult->getRecordId())) {
1278 $id = $userresult->getRecordId();
1279 $sql = 'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1280 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1281 'WHERE (user_result_pk = :id)';
1282 $query = oci_parse($this->db, $sql);
1283 oci_bind_by_name($query, 'id', $id);
1284 } else {
1285 $id = $userresult->getResourceLink()->getRecordId();
1286 $uid = $userresult->getId(LTI\Tool::ID_SCOPE_ID_ONLY);
1287 $sql = 'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1288 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1289 'WHERE (resource_link_pk = :id) AND (lti_user_id = :u_id)';
1290 $query = oci_parse($this->db, $sql);
1291 oci_bind_by_name($query, 'id', $id);
1292 oci_bind_by_name($query, 'u_id', $uid);
1293 }
1294 if ($this->executeQuery($sql, $query)) {
1295 $row = oci_fetch_assoc($query);
1296 if ($row !== false) {
1297 $row = array_change_key_case($row);
1298 $userresult->setRecordId(intval($row['user_result_pk']));
1299 $userresult->setResourceLinkId(intval($row['resource_link_pk']));
1300 $userresult->ltiUserId = $row['lti_user_id'];
1301 $userresult->ltiResultSourcedId = $row['lti_result_sourcedid'];
1302 $userresult->created = strtotime($row['created']);
1303 $userresult->updated = strtotime($row['updated']);
1304 $ok = true;
1305 }
1306 }
1307
1308 return $ok;
1309 }
1310
1318 public function saveUserResult($userresult)
1319 {
1320 $time = time();
1321 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
1322 if (is_null($userresult->created)) {
1323 $pk = null;
1324 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' (resource_link_pk, ' .
1325 'lti_user_id, lti_result_sourcedid, created, updated) ' .
1326 'VALUES (:rlid, :u_id, :sourcedid, :created, :updated) returning user_result_pk into :pk';
1327 $query = oci_parse($this->db, $sql);
1328 $rlid = $userresult->getResourceLink()->getRecordId();
1329 oci_bind_by_name($query, 'rlid', $rlid);
1330 $uid = $userresult->getId(LTI\Tool::ID_SCOPE_ID_ONLY);
1331 oci_bind_by_name($query, 'u_id', $uid);
1332 $sourcedid = $userresult->ltiResultSourcedId;
1333 oci_bind_by_name($query, 'sourcedid', $sourcedid);
1334 oci_bind_by_name($query, 'created', $now);
1335 oci_bind_by_name($query, 'updated', $now);
1336 oci_bind_by_name($query, 'pk', $pk);
1337 } else {
1338 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1339 'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
1340 'WHERE (user_result_pk = :id)';
1341 $query = oci_parse($this->db, $sql);
1342 $sourcedid = $userresult->ltiResultSourcedId;
1343 oci_bind_by_name($query, 'sourcedid', $sourcedid);
1344 oci_bind_by_name($query, 'updated', $now);
1345 $id = $userresult->getRecordId();
1346 oci_bind_by_name($query, 'id', $id);
1347 }
1348 $ok = $this->executeQuery($sql, $query);
1349 if ($ok) {
1350 if (is_null($userresult->created)) {
1351 $userresult->setRecordId(intval($pk));
1352 $userresult->created = $time;
1353 }
1354 $userresult->updated = $time;
1355 }
1356
1357 return $ok;
1358 }
1359
1367 public function deleteUserResult($userresult)
1368 {
1369 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' ' .
1370 'WHERE (user_result_pk = :id)';
1371 $query = oci_parse($this->db, $sql);
1372 $id = $userresult->getRecordId();
1373 oci_bind_by_name($query, 'id', $id);
1374 $ok = $this->executeQuery($sql, $query);
1375
1376 if ($ok) {
1377 $userresult->initialize();
1378 }
1379
1380 return $ok;
1381 }
1382
1383###
1384### Tool methods
1385###
1386
1394 public function loadTool($tool)
1395 {
1396 $ok = false;
1397 if (!is_null($tool->getRecordId())) {
1398 $sql = 'SELECT tool_pk, name, consumer_key, secret, ' .
1399 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1400 'lti_version, signature_method, settings, enabled, ' .
1401 'enable_from, enable_until, last_access, created, updated ' .
1402 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' ' .
1403 'WHERE tool_pk = :id';
1404 $query = oci_parse($this->db, $sql);
1405 $id = $tool->getRecordId();
1406 oci_bind_by_name($query, 'id', $id);
1407 } elseif (!empty($tool->initiateLoginUrl)) {
1408 $sql = 'SELECT tool_pk, name, consumer_key, secret, ' .
1409 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1410 'lti_version, signature_method, settings, enabled, ' .
1411 'enable_from, enable_until, last_access, created, updated ' .
1412 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' ' .
1413 'WHERE initiate_login_url = :initiate_login_url';
1414 $query = oci_parse($this->db, $sql);
1415 oci_bind_by_name($query, 'initiate_login_url', $tool->initiateLoginUrl);
1416 } else {
1417 $sql = 'SELECT tool_pk, name, consumer_key, secret, ' .
1418 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1419 'lti_version, signature_method, settings, enabled, ' .
1420 'enable_from, enable_until, last_access, created, updated ' .
1421 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' ' .
1422 'WHERE consumer_key = :key';
1423 $query = oci_parse($this->db, $sql);
1424 $consumerKey = $tool->getKey();
1425 oci_bind_by_name($query, 'key', $consumerKey);
1426 }
1427 $ok = $this->executeQuery($sql, $query);
1428 if ($ok) {
1429 $row = oci_fetch_assoc($query);
1430 $ok = ($row !== false);
1431 }
1432 if ($ok) {
1433 $row = array_change_key_case($row);
1434 $tool->setRecordId(intval($row['tool_pk']));
1435 $tool->name = $row['name'];
1436 $tool->setkey($row['consumer_key']);
1437 $tool->secret = $row['secret'];
1438 $tool->messageUrl = $row['message_url'];
1439 $tool->initiateLoginUrl = $row['initiate_login_url'];
1440 $redirectionUrisValue = $row['redirection_uris']->load();
1441 if (is_string($redirectionUrisValue)) {
1442 $redirectionUris = Util::jsonDecode($redirectionUrisValue, true);
1443 if (!is_array($redirectionUris)) {
1444 $redirectionUris = array();
1445 }
1446 } else {
1447 $redirectionUris = array();
1448 }
1449 $tool->redirectionUris = $redirectionUris;
1450 $tool->rsaKey = $row['public_key'];
1451 $tool->ltiVersion = $row['lti_version'];
1452 $tool->signatureMethod = $row['signature_method'];
1453 $settingsValue = $row['settings']->load();
1454 if (is_string($settingsValue)) {
1455 $settings = Util::jsonDecode($settingsValue, true);
1456 if (!is_array($settings)) {
1457 $settings = array();
1458 }
1459 } else {
1460 $settings = array();
1461 }
1462 $tool->setSettings($settings);
1463 $tool->enabled = (intval($row['enabled']) === 1);
1464 $tool->enableFrom = null;
1465 if (!is_null($row['enable_from'])) {
1466 $tool->enableFrom = strtotime($row['enable_from']);
1467 }
1468 $tool->enableUntil = null;
1469 if (!is_null($row['enable_until'])) {
1470 $tool->enableUntil = strtotime($row['enable_until']);
1471 }
1472 $tool->lastAccess = null;
1473 if (!is_null($row['last_access'])) {
1474 $tool->lastAccess = strtotime($row['last_access']);
1475 }
1476 $tool->created = strtotime($row['created']);
1477 $tool->updated = strtotime($row['updated']);
1478 $this->fixToolSettings($tool, false);
1479 $ok = true;
1480 }
1481
1482 return $ok;
1483 }
1484
1492 public function saveTool($tool)
1493 {
1494 $id = $tool->getRecordId();
1495 $consumerKey = $tool->getKey();
1496 $enabled = ($tool->enabled) ? 1 : 0;
1497 $redirectionUrisValue = json_encode($tool->redirectionUris);
1498 $this->fixToolSettings($tool, true);
1499 $settingsValue = json_encode($tool->getSettings());
1500 $this->fixToolSettings($tool, false);
1501 $time = time();
1502 $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
1503 $from = null;
1504 if (!is_null($tool->enableFrom)) {
1505 $from = date("{$this->dateFormat} {$this->timeFormat}", $tool->enableFrom);
1506 }
1507 $until = null;
1508 if (!is_null($tool->enableUntil)) {
1509 $until = date("{$this->dateFormat} {$this->timeFormat}", $tool->enableUntil);
1510 }
1511 $last = null;
1512 if (!is_null($tool->lastAccess)) {
1513 $last = date($this->dateFormat, $tool->lastAccess);
1514 }
1515 if (empty($id)) {
1516 $pk = null;
1517 $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' (name, consumer_key, secret, ' .
1518 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1519 'lti_version, signature_method, settings, enabled, enable_from, enable_until, ' .
1520 'last_access, created, updated) ' .
1521 'VALUES (:name, :key, :secret, ' .
1522 ':message_url, :initiate_login_url, :redirection_uris, :public_key, ' .
1523 ':lti_version, :signature_method, :settings, :enabled, :enable_from, :enable_until, ' .
1524 ':last_access, :created, :updated) returning tool_pk into :pk';
1525 $query = oci_parse($this->db, $sql);
1526 oci_bind_by_name($query, 'name', $tool->name);
1527 oci_bind_by_name($query, 'key', $consumerKey);
1528 oci_bind_by_name($query, 'secret', $tool->secret);
1529 oci_bind_by_name($query, 'message_url', $tool->messageUrl);
1530 oci_bind_by_name($query, 'initiate_login_url', $tool->initiateLoginUrl);
1531 oci_bind_by_name($query, 'redirection_uris', $redirectionUrisValue);
1532 oci_bind_by_name($query, 'public_key', $tool->rsaKey);
1533 oci_bind_by_name($query, 'lti_version', $tool->ltiVersion);
1534 oci_bind_by_name($query, 'signature_method', $tool->signatureMethod);
1535 oci_bind_by_name($query, 'settings', $settingsValue);
1536 oci_bind_by_name($query, 'enabled', $enabled);
1537 oci_bind_by_name($query, 'enable_from', $from);
1538 oci_bind_by_name($query, 'enable_until', $until);
1539 oci_bind_by_name($query, 'last_access', $last);
1540 oci_bind_by_name($query, 'created', $now);
1541 oci_bind_by_name($query, 'updated', $now);
1542 oci_bind_by_name($query, 'pk', $pk);
1543 } else {
1544 $sql = "UPDATE {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' SET ' .
1545 'name = :name, consumer_key = :key, secret= :secret, ' .
1546 'message_url = :message_url, initiate_login_url = :initiate_login_url, redirection_uris = :redirection_uris, public_key = :public_key, ' .
1547 'lti_version = :lti_version, signature_method = :signature_method, settings = :settings, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, ' .
1548 'last_access = :last_access, updated = :updated ' .
1549 'WHERE tool_pk = :id';
1550 $query = oci_parse($this->db, $sql);
1551 oci_bind_by_name($query, 'name', $tool->name);
1552 oci_bind_by_name($query, 'key', $consumerKey);
1553 oci_bind_by_name($query, 'secret', $tool->secret);
1554 oci_bind_by_name($query, 'message_url', $tool->messageUrl);
1555 oci_bind_by_name($query, 'initiate_login_url', $tool->initiateLoginUrl);
1556 oci_bind_by_name($query, 'redirection_uris', $redirectionUrisValue);
1557 oci_bind_by_name($query, 'public_key', $tool->rsaKey);
1558 oci_bind_by_name($query, 'lti_version', $tool->ltiVersion);
1559 oci_bind_by_name($query, 'signature_method', $tool->signatureMethod);
1560 oci_bind_by_name($query, 'settings', $settingsValue);
1561 oci_bind_by_name($query, 'enabled', $enabled);
1562 oci_bind_by_name($query, 'enable_from', $from);
1563 oci_bind_by_name($query, 'enable_until', $until);
1564 oci_bind_by_name($query, 'last_access', $last);
1565 oci_bind_by_name($query, 'updated', $now);
1566 oci_bind_by_name($query, 'id', $id);
1567 }
1568 $ok = $this->executeQuery($sql, $query);
1569 if ($ok) {
1570 if (empty($id)) {
1571 $tool->setRecordId(intval($pk));
1572 $tool->created = $time;
1573 }
1574 $tool->updated = $time;
1575 }
1576
1577 return $ok;
1578 }
1579
1587 public function deleteTool($tool)
1588 {
1589 $id = $tool->getRecordId();
1590
1591 $sql = "DELETE FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' ' .
1592 'WHERE tool_pk = :id';
1593 $query = oci_parse($this->db, $sql);
1594 oci_bind_by_name($query, 'id', $id);
1595 $ok = $this->executeQuery($sql, $query);
1596
1597 if ($ok) {
1598 $tool->initialize();
1599 }
1600
1601 return $ok;
1602 }
1603
1609 public function getTools()
1610 {
1611 $tools = array();
1612
1613 $sql = 'SELECT tool_pk, name, consumer_key, secret, ' .
1614 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1615 'lti_version, signature_method, settings, enabled, ' .
1616 'enable_from, enable_until, last_access, created, updated ' .
1617 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME . ' ' .
1618 'ORDER BY name';
1619 $query = oci_parse($this->db, $sql);
1620 $ok = ($query !== false);
1621
1622 if ($ok) {
1623 $ok = $this->executeQuery($sql, $query);
1624 }
1625
1626 if ($ok) {
1627 while ($row = oci_fetch_assoc($query)) {
1628 $row = array_change_key_case($row);
1629 $tool = new Tool($this);
1630 $tool->setRecordId(intval($row['tool_pk']));
1631 $tool->name = $row['name'];
1632 $tool->setkey($row['consumer_key']);
1633 $tool->secret = $row['secret'];
1634 $tool->messageUrl = $row['message_url'];
1635 $tool->initiateLoginUrl = $row['initiate_login_url'];
1636 $redirectionUrisValue = $row['redirection_uris']->load();
1637 if (is_string($redirectionUrisValue)) {
1638 $redirectionUris = Util::jsonDecode($redirectionUrisValue, true);
1639 if (!is_array($redirectionUris)) {
1640 $redirectionUris = array();
1641 }
1642 } else {
1643 $redirectionUris = array();
1644 }
1645 $tool->redirectionUris = $redirectionUris;
1646 $tool->rsaKey = $row['public_key'];
1647 $tool->ltiVersion = $row['lti_version'];
1648 $tool->signatureMethod = $row['signature_method'];
1649 $settingsValue = $row['settings']->load();
1650 if (is_string($settingsValue)) {
1651 $settings = Util::jsonDecode($settingsValue, true);
1652 if (!is_array($settings)) {
1653 $settings = array();
1654 }
1655 } else {
1656 $settings = array();
1657 }
1658 $tool->setSettings($settings);
1659 $tool->enabled = (intval($row['enabled']) === 1);
1660 $tool->enableFrom = null;
1661 if (!is_null($row['enable_from'])) {
1662 $tool->enableFrom = strtotime($row['enable_from']);
1663 }
1664 $tool->enableUntil = null;
1665 if (!is_null($row['enable_until'])) {
1666 $tool->enableUntil = strtotime($row['enable_until']);
1667 }
1668 $tool->lastAccess = null;
1669 if (!is_null($row['last_access'])) {
1670 $tool->lastAccess = strtotime($row['last_access']);
1671 }
1672 $tool->created = strtotime($row['created']);
1673 $tool->updated = strtotime($row['updated']);
1674 $this->fixToolSettings($tool, false);
1675 $tools[] = $tool;
1676 }
1677 }
1678
1679 return $tools;
1680 }
1681
1682###
1683### Other methods
1684###
1685
1697 private function executeQuery($sql, $query, $reportError = true)
1698 {
1699 $ok = oci_execute($query);
1700 if (!$ok && $reportError) {
1701 Util::logError($sql . $this->errorInfoToString(oci_error($query)));
1702 } else {
1703 Util::logDebug($sql);
1704 }
1705
1706 return $ok;
1707 }
1708
1716 private function errorInfoToString($errorInfo)
1717 {
1718 if (is_array($errorInfo) && !empty($errorInfo)) {
1719 $errors = PHP_EOL . "Error {$errorInfo['code']}: {$errorInfo['message']} (offset {$errorInfo['offset']})";
1720 } else {
1721 $errors = '';
1722 }
1723
1724 return $errors;
1725 }
1726
1727}
Class to represent an HTTP message.
Class to represent a platform context.
Definition Context.php:18
Class to represent an LTI Data Connector for Oracle connections.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
savePlatform($platform)
Save platform object.
deletePlatform($platform)
Delete platform object.
saveAccessToken($accessToken)
Save access token object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
loadAccessToken($accessToken)
Load access token object.
loadPlatform($platform)
Load platform object.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
__construct($db, $dbTableNamePrefix='')
Class constructor.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
loadResourceLink($resourceLink)
Load resource link object.
saveResourceLink($resourceLink)
Save resource link object.
deleteContext($context)
Delete context object.
deleteUserResult($userresult)
Delete user object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
deleteResourceLink($resourceLink)
Delete resource link object.
Class to provide a connection to a persistent store for LTI objects.
$dbTableNamePrefix
Prefix for database table names.
fixToolSettings($tool, $isSave)
Adjust the settings for any tool properties being stored as a setting value.
fixPlatformSettings($platform, $isSave)
Adjust the settings for any platform properties being stored as a setting value.
Class to represent a platform nonce.
Class to represent a platform.
Definition Platform.php:18
Class to represent a platform resource link share key.
Class to represent a platform resource link share.
Class to represent an LTI Tool.
Definition Tool.php:24
const ID_SCOPE_ID_ONLY
Use ID value only.
Definition Tool.php:34
Class to represent a platform user association with a resource link.
Class to implement utility methods.
Definition Util.php:15
static logError($message, $showSource=true)
Log an error message.
Definition Util.php:248
static jsonDecode($str, $associative=false)
Decode a JSON string.
Definition Util.php:560
static logDebug($message, $showSource=false)
Log a debug message.
Definition Util.php:274