25# NB This class assumes that an Oracle connection has already been opened to the appropriate schema
40 $this->dateFormat =
'd-M-Y';
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);
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);
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);
117 $ok = $this->executeQuery($sql, $query);
119 $row = oci_fetch_assoc($query);
120 $ok = ($row !==
false) && ($allowMultiple || !oci_fetch_assoc($query));
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'];
138 $platform->toolProxy = $row[
'tool_proxy'];
139 $settingsValue = $row[
'settings']->load();
140 if (is_string($settingsValue)) {
142 if (!is_array($settings)) {
143 $settings = @unserialize($settingsValue);
145 if (!is_array($settings)) {
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']);
158 $platform->enableUntil =
null;
159 if (!is_null($row[
'enable_until'])) {
160 $platform->enableUntil = strtotime($row[
'enable_until']);
162 $platform->lastAccess =
null;
163 if (!is_null($row[
'last_access'])) {
164 $platform->lastAccess = strtotime($row[
'last_access']);
166 $platform->created = strtotime($row[
'created']);
167 $platform->updated = strtotime($row[
'updated']);
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;
189 $settingsValue = json_encode($platform->getSettings());
192 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
194 if (!is_null($platform->enableFrom)) {
195 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
198 if (!is_null($platform->enableUntil)) {
199 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
202 if (!is_null($platform->lastAccess)) {
203 $last = date($this->dateFormat, $platform->lastAccess);
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);
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);
274 $ok = $this->executeQuery($sql, $query);
277 $platform->setRecordId(intval($pk));
278 $platform->created = $time;
280 $platform->updated = $time;
295 $id = $platform->getRecordId();
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
392 $platform->initialize();
405 $platforms = array();
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 .
' ' .
414 $query = oci_parse($this->db, $sql);
415 $ok = ($query !==
false);
418 $ok = $this->executeQuery($sql, $query);
422 while ($row = oci_fetch_assoc($query)) {
423 $row = array_change_key_case($row);
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'];
439 $platform->toolProxy = $row[
'tool_proxy'];
440 $settingsValue = $row[
'settings']->load();
441 if (is_string($settingsValue)) {
443 if (!is_array($settings)) {
444 $settings = @unserialize($settingsValue);
446 if (!is_array($settings)) {
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']);
459 $platform->enableUntil =
null;
460 if (!is_null($row[
'enable_until'])) {
461 $platform->enableUntil = strtotime($row[
'enable_until']);
463 $platform->lastAccess =
null;
464 if (!is_null($row[
'last_access'])) {
465 $platform->lastAccess = strtotime($row[
'last_access']);
467 $platform->created = strtotime($row[
'created']);
468 $platform->updated = strtotime($row[
'updated']);
470 $platforms[] = $platform;
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);
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);
507 $ok = $this->executeQuery($sql, $query);
509 $row = oci_fetch_assoc($query);
510 $ok = ($row !==
false);
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)) {
522 if (!is_array($settings)) {
523 $settings = @unserialize($settingsValue);
525 if (!is_array($settings)) {
531 $context->setSettings($settings);
532 $context->created = strtotime($row[
'created']);
533 $context->updated = strtotime($row[
'updated']);
549 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
550 $settingsValue = json_encode($context->getSettings());
551 $id = $context->getRecordId();
552 $consumer_pk = $context->getPlatform()->getRecordId();
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);
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);
581 $ok = $this->executeQuery($sql, $query);
584 $context->setRecordId(intval($pk));
585 $context->created = $time;
587 $context->updated = $time;
602 $id = $context->getRecordId();
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);
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);
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);
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);
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);
644 $context->initialize();
651### ResourceLink methods
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)' .
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);
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);
697 $ok = $this->executeQuery($sql, $query);
699 $row = oci_fetch_assoc($query);
700 $ok = ($row !==
false);
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']));
709 $resourceLink->setContextId(
null);
711 if (!is_null($row[
'consumer_pk'])) {
712 $resourceLink->setPlatformId(intval($row[
'consumer_pk']));
714 $resourceLink->setPlatformId(
null);
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)) {
722 if (!is_array($settings)) {
723 $settings = @unserialize($settingsValue);
725 if (!is_array($settings)) {
731 $resourceLink->setSettings($settings);
732 if (!is_null($row[
'primary_resource_link_pk'])) {
733 $resourceLink->primaryResourceLinkId = intval($row[
'primary_resource_link_pk']);
735 $resourceLink->primaryResourceLinkId =
null;
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']);
754 if (is_null($resourceLink->shareApproved)) {
756 } elseif ($resourceLink->shareApproved) {
762 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
763 $settingsValue = json_encode($resourceLink->getSettings());
764 if (!is_null($resourceLink->getContext())) {
766 $contextId = $resourceLink->getContext()->getRecordId();
767 } elseif (!is_null($resourceLink->getContextId())) {
769 $contextId = $resourceLink->getContextId();
771 $consumerId = $resourceLink->getPlatform()->getRecordId();
774 if (empty($resourceLink->primaryResourceLinkId)) {
775 $primaryResourceLinkId =
null;
777 $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
779 $id = $resourceLink->getRecordId();
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);
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);
825 $ok = $this->executeQuery($sql, $query);
828 $resourceLink->setRecordId(intval($pk));
829 $resourceLink->created = $time;
831 $resourceLink->updated = $time;
846 $id = $resourceLink->getRecordId();
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);
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);
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);
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);
884 $resourceLink->initialize();
904 $id = $resourceLink->getRecordId();
905 $userResults = array();
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);
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);
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;
937 $userResults[$userresult->getId($idScope)] = $userresult;
954 $id = $resourceLink->getRecordId();
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) ' .
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);
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);
988### PlatformNonce methods
1000 if (parent::useMemcache()) {
1001 $ok = parent::loadPlatformNonce($nonce);
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);
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);
1019 $row = oci_fetch_assoc($query);
1020 if ($row ===
false) {
1038 if (parent::useMemcache()) {
1039 $ok = parent::savePlatformNonce($nonce);
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);
1064 if (parent::useMemcache()) {
1065 $ok = parent::deletePlatformNonce($nonce);
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);
1080### AccessToken methods
1092 if (parent::useMemcache()) {
1093 $ok = parent::loadAccessToken($accessToken);
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);
1107 if (!is_array($scopes)) {
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']);
1132 if (parent::useMemcache()) {
1133 $ok = parent::saveAccessToken($accessToken);
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);
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);
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);
1163 $ok = $this->executeQuery($sql, $query);
1170### ResourceLinkShareKey methods
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);
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']);
1221 if ($shareKey->autoApprove) {
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);
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);
1257 $shareKey->initialize();
1264### UserResult Result methods
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);
1285 $id = $userresult->getResourceLink()->getRecordId();
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);
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']);
1321 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1322 if (is_null($userresult->created)) {
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);
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);
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);
1348 $ok = $this->executeQuery($sql, $query);
1350 if (is_null($userresult->created)) {
1351 $userresult->setRecordId(intval($pk));
1352 $userresult->created = $time;
1354 $userresult->updated = $time;
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);
1377 $userresult->initialize();
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);
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);
1427 $ok = $this->executeQuery($sql, $query);
1429 $row = oci_fetch_assoc($query);
1430 $ok = ($row !==
false);
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)) {
1443 if (!is_array($redirectionUris)) {
1444 $redirectionUris = array();
1447 $redirectionUris = array();
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)) {
1456 if (!is_array($settings)) {
1457 $settings = array();
1460 $settings = array();
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']);
1468 $tool->enableUntil =
null;
1469 if (!is_null($row[
'enable_until'])) {
1470 $tool->enableUntil = strtotime($row[
'enable_until']);
1472 $tool->lastAccess =
null;
1473 if (!is_null($row[
'last_access'])) {
1474 $tool->lastAccess = strtotime($row[
'last_access']);
1476 $tool->created = strtotime($row[
'created']);
1477 $tool->updated = strtotime($row[
'updated']);
1494 $id = $tool->getRecordId();
1495 $consumerKey = $tool->getKey();
1496 $enabled = ($tool->enabled) ? 1 : 0;
1497 $redirectionUrisValue = json_encode($tool->redirectionUris);
1499 $settingsValue = json_encode($tool->getSettings());
1502 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1504 if (!is_null($tool->enableFrom)) {
1505 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableFrom);
1508 if (!is_null($tool->enableUntil)) {
1509 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableUntil);
1512 if (!is_null($tool->lastAccess)) {
1513 $last = date($this->dateFormat, $tool->lastAccess);
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);
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);
1568 $ok = $this->executeQuery($sql, $query);
1571 $tool->setRecordId(intval($pk));
1572 $tool->created = $time;
1574 $tool->updated = $time;
1589 $id = $tool->getRecordId();
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);
1598 $tool->initialize();
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 .
' ' .
1619 $query = oci_parse($this->db, $sql);
1620 $ok = ($query !==
false);
1623 $ok = $this->executeQuery($sql, $query);
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)) {
1639 if (!is_array($redirectionUris)) {
1640 $redirectionUris = array();
1643 $redirectionUris = array();
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)) {
1652 if (!is_array($settings)) {
1653 $settings = array();
1656 $settings = array();
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']);
1664 $tool->enableUntil =
null;
1665 if (!is_null($row[
'enable_until'])) {
1666 $tool->enableUntil = strtotime($row[
'enable_until']);
1668 $tool->lastAccess =
null;
1669 if (!is_null($row[
'last_access'])) {
1670 $tool->lastAccess = strtotime($row[
'last_access']);
1672 $tool->created = strtotime($row[
'created']);
1673 $tool->updated = strtotime($row[
'updated']);
1697 private function executeQuery($sql, $query, $reportError =
true)
1699 $ok = oci_execute($query);
1700 if (!$ok && $reportError) {
1701 Util::logError($sql . $this->errorInfoToString(oci_error($query)));
1716 private function errorInfoToString($errorInfo)
1718 if (is_array($errorInfo) && !empty($errorInfo)) {
1719 $errors = PHP_EOL .
"Error {$errorInfo['code']}: {$errorInfo['message']} (offset {$errorInfo['offset']})";
Class to represent an HTTP message.
Class to represent a platform context.
Class to represent an LTI Data Connector for Oracle connections.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
saveUserResult($userresult)
Save user object.
loadContext($context)
Load context object.
deleteTool($tool)
Delete tool object.
savePlatform($platform)
Save platform object.
deletePlatform($platform)
Delete platform object.
saveAccessToken($accessToken)
Save access token object.
deletePlatformNonce($nonce)
Delete nonce object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
saveContext($context)
Save context object.
loadPlatformNonce($nonce)
Load nonce object.
loadAccessToken($accessToken)
Load access token object.
loadTool($tool)
Load tool object.
getTools()
Load tool objects.
loadPlatform($platform)
Load platform object.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
__construct($db, $dbTableNamePrefix='')
Class constructor.
getPlatforms()
Load platform objects.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
loadResourceLink($resourceLink)
Load resource link object.
savePlatformNonce($nonce)
Save nonce object.
saveResourceLink($resourceLink)
Save resource link object.
deleteContext($context)
Delete context object.
loadUserResult($userresult)
Load user object.
deleteUserResult($userresult)
Delete user object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
saveTool($tool)
Save tool 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 resource link share key.
Class to represent a platform resource link share.
Class to represent a platform resource link.
Class to represent a platform user association with a resource link.
Class to implement utility methods.
static logError($message, $showSource=true)
Log an error message.
static jsonDecode($str, $associative=false)
Decode a JSON string.
static logDebug($message, $showSource=false)
Log a debug message.