23 # NB This class assumes that an Oracle connection has already been opened to the appropriate schema 38 $this->dateFormat =
'd-M-Y';
42 ### ToolConsumer methods 55 if (!is_null($consumer->getRecordId())) {
56 $sql =
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
57 'signature_method, consumer_name, consumer_version, consumer_guid, ' .
58 'profile, tool_proxy, settings, protected, enabled, ' .
59 'enable_from, enable_until, last_access, created, updated ' .
60 "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' ' .
61 'WHERE consumer_pk = :id';
62 $query = oci_parse($this->db, $sql);
63 $id = $consumer->getRecordId();
64 oci_bind_by_name($query,
'id', $id);
66 $sql =
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
67 'signature_method, consumer_name, consumer_version, consumer_guid, ' .
68 'profile, tool_proxy, settings, protected, enabled, ' .
69 'enable_from, enable_until, last_access, created, updated ' .
70 "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' ' .
71 'WHERE consumer_key256 = :key256';
72 $query = oci_parse($this->db, $sql);
73 $key256 = static::getConsumerKey($consumer->getKey());
74 oci_bind_by_name($query,
'key256', $key256);
77 if (oci_execute($query)) {
78 while ($row = oci_fetch_assoc($query)) {
79 $row = array_change_key_case($row);
80 if (empty($key256) || empty($row[
'consumer_key']) || ($consumer->getKey() === $row[
'consumer_key'])) {
81 $consumer->setRecordId(intval($row[
'consumer_pk']));
82 $consumer->name = $row[
'name'];
83 $consumer->setkey(empty($row[
'consumer_key']) ? $row[
'consumer_key256'] : $row[
'consumer_key']);
84 $consumer->secret = $row[
'secret'];
85 $consumer->ltiVersion = $row[
'lti_version'];
86 $consumer->signatureMethod = $row[
'signature_method'];
87 $consumer->consumerName = $row[
'consumer_name'];
88 $consumer->consumerVersion = $row[
'consumer_version'];
89 $consumer->consumerGuid = $row[
'consumer_guid'];
90 $consumer->profile = json_decode($row[
'profile']);
91 $consumer->toolProxy = $row[
'tool_proxy'];
92 $settingsValue = $row[
'settings']->load();
93 if (is_string($settingsValue)) {
94 $settings = json_decode($settingsValue, TRUE);
95 if (!is_array($settings)) {
96 $settings = @unserialize($settingsValue);
98 if (!is_array($settings)) {
104 $consumer->setSettings($settings);
105 $consumer->protected = (intval($row[
'protected']) === 1);
106 $consumer->enabled = (intval($row[
'enabled']) === 1);
107 $consumer->enableFrom =
null;
108 if (!is_null($row[
'enable_from'])) {
109 $consumer->enableFrom = strtotime($row[
'enable_from']);
111 $consumer->enableUntil =
null;
112 if (!is_null($row[
'enable_until'])) {
113 $consumer->enableUntil = strtotime($row[
'enable_until']);
115 $consumer->lastAccess =
null;
116 if (!is_null($row[
'last_access'])) {
117 $consumer->lastAccess = strtotime($row[
'last_access']);
119 $consumer->created = strtotime($row[
'created']);
120 $consumer->updated = strtotime($row[
'updated']);
139 $id = $consumer->getRecordId();
140 $key = $consumer->getKey();
142 if ($key === $key256) {
145 $protected = ($consumer->protected) ? 1 : 0;
146 $enabled = ($consumer->enabled) ? 1 : 0;
147 $profile = (!empty($consumer->profile)) ? json_encode($consumer->profile) :
null;
148 $settingsValue = json_encode($consumer->getSettings());
150 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
152 if (!is_null($consumer->enableFrom)) {
153 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $consumer->enableFrom);
156 if (!is_null($consumer->enableUntil)) {
157 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $consumer->enableUntil);
160 if (!is_null($consumer->lastAccess)) {
161 $last = date($this->dateFormat, $consumer->lastAccess);
164 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' (consumer_key256, consumer_key, name, ' .
165 'secret, lti_version, signature_method, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' .
166 'enable_from, enable_until, last_access, created, updated) ' .
167 'VALUES (:key256, :key, :name, :secret, :lti_version, :signature_method, :consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' .
168 ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated) returning consumer_pk into :pk';
169 $query = oci_parse($this->db, $sql);
170 oci_bind_by_name($query,
'key256', $key256);
171 oci_bind_by_name($query,
'key', $key);
172 oci_bind_by_name($query,
'name', $consumer->name);
173 oci_bind_by_name($query,
'secret', $consumer->secret);
174 oci_bind_by_name($query,
'lti_version', $consumer->ltiVersion);
175 oci_bind_by_name($query,
'signature_method', $consumer->signatureMethod);
176 oci_bind_by_name($query,
'consumer_name', $consumer->consumerName);
177 oci_bind_by_name($query,
'consumer_version', $consumer->consumerVersion);
178 oci_bind_by_name($query,
'consumer_guid', $consumer->consumerGuid);
179 oci_bind_by_name($query,
'profile', $profile);
180 oci_bind_by_name($query,
'tool_proxy', $consumer->toolProxy);
181 oci_bind_by_name($query,
'settings', $settingsValue);
182 oci_bind_by_name($query,
'protected', $protected);
183 oci_bind_by_name($query,
'enabled', $enabled);
184 oci_bind_by_name($query,
'enable_from', $from);
185 oci_bind_by_name($query,
'enable_until', $until);
186 oci_bind_by_name($query,
'last_access', $last);
187 oci_bind_by_name($query,
'created', $now);
188 oci_bind_by_name($query,
'updated', $now);
189 oci_bind_by_name($query,
'pk', $pk);
191 $sql =
'UPDATE ' . $this->dbTableNamePrefix . static::CONSUMER_TABLE_NAME .
' ' .
192 'SET consumer_key256 = :key256, consumer_key = :key, name = :name, secret = :secret, lti_version = :lti_version, ' .
193 'signature_method = :signature_method, consumer_name = :consumer_name, ' .
194 'consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' .
195 'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' .
196 'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, last_access = :last_access, updated = :updated ' .
197 'WHERE consumer_pk = :id';
198 $query = oci_parse($this->db, $sql);
199 oci_bind_by_name($query,
'key256', $key256);
200 oci_bind_by_name($query,
'key', $key);
201 oci_bind_by_name($query,
'name', $consumer->name);
202 oci_bind_by_name($query,
'secret', $consumer->secret);
203 oci_bind_by_name($query,
'lti_version', $consumer->ltiVersion);
204 oci_bind_by_name($query,
'signature_method', $consumer->signatureMethod);
205 oci_bind_by_name($query,
'consumer_name', $consumer->consumerName);
206 oci_bind_by_name($query,
'consumer_version', $consumer->consumerVersion);
207 oci_bind_by_name($query,
'consumer_guid', $consumer->consumerGuid);
208 oci_bind_by_name($query,
'profile', $profile);
209 oci_bind_by_name($query,
'tool_proxy', $consumer->toolProxy);
210 oci_bind_by_name($query,
'settings', $settingsValue);
211 oci_bind_by_name($query,
'protected', $protected);
212 oci_bind_by_name($query,
'enabled', $enabled);
213 oci_bind_by_name($query,
'enable_from', $from);
214 oci_bind_by_name($query,
'enable_until', $until);
215 oci_bind_by_name($query,
'last_access', $last);
216 oci_bind_by_name($query,
'updated', $now);
217 oci_bind_by_name($query,
'id', $id);
219 $ok = oci_execute($query);
222 $consumer->setRecordId(intval($pk));
223 $consumer->created = $time;
225 $consumer->updated = $time;
240 $id = $consumer->getRecordId();
243 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE consumer_pk = :id';
244 $query = oci_parse($this->db, $sql);
245 oci_bind_by_name($query,
'id', $id);
249 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
250 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
251 'WHERE consumer_pk = :id)';
252 $query = oci_parse($this->db, $sql);
253 oci_bind_by_name($query,
'id', $id);
257 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
258 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
259 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
260 $query = oci_parse($this->db, $sql);
261 oci_bind_by_name($query,
'id', $id);
265 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
266 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
267 'WHERE consumer_pk = :id)';
268 $query = oci_parse($this->db, $sql);
269 oci_bind_by_name($query,
'id', $id);
273 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
274 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
275 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
276 $query = oci_parse($this->db, $sql);
277 oci_bind_by_name($query,
'id', $id);
281 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
282 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
283 'WHERE primary_resource_link_pk IN ' .
284 "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
285 'WHERE consumer_pk = :id)';
286 $query = oci_parse($this->db, $sql);
287 oci_bind_by_name($query,
'id', $id);
291 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
292 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
293 'WHERE primary_resource_link_pk IN ' .
294 "(SELECT rl.resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
295 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
296 'WHERE c.consumer_pk = :id)';
297 $query = oci_parse($this->db, $sql);
298 oci_bind_by_name($query,
'id', $id);
302 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
303 'WHERE consumer_pk = :id';
304 $query = oci_parse($this->db, $sql);
305 oci_bind_by_name($query,
'id', $id);
309 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
310 'WHERE context_pk IN (' .
311 "SELECT context_pk FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
'WHERE consumer_pk = :id)';
312 $query = oci_parse($this->db, $sql);
313 oci_bind_by_name($query,
'id', $id);
317 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
318 'WHERE consumer_pk = :id';
319 $query = oci_parse($this->db, $sql);
320 oci_bind_by_name($query,
'id', $id);
324 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' ' .
325 'WHERE consumer_pk = :id';
326 $query = oci_parse($this->db, $sql);
327 oci_bind_by_name($query,
'id', $id);
328 $ok = oci_execute($query);
331 $consumer->initialize();
344 $consumers = array();
346 $sql =
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
347 'signature_method, consumer_name, consumer_version, consumer_guid, ' .
348 'profile, tool_proxy, settings, protected, enabled, ' .
349 'enable_from, enable_until, last_access, created, updated ' .
350 "FROM {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' ' .
352 $query = oci_parse($this->db, $sql);
353 $ok = ($query !== FALSE);
356 $ok = oci_execute($query);
360 while ($row = oci_fetch_assoc($query)) {
361 $row = array_change_key_case($row);
362 $key = empty($row[
'consumer_key']) ? $row[
'consumer_key256'] : $row[
'consumer_key'];
364 $consumer->setRecordId(intval($row[
'consumer_pk']));
365 $consumer->name = $row[
'name'];
366 $consumer->secret = $row[
'secret'];
367 $consumer->ltiVersion = $row[
'lti_version'];
368 $consumer->signatureMethod = $row[
'signature_method'];
369 $consumer->consumerName = $row[
'consumer_name'];
370 $consumer->consumerVersion = $row[
'consumer_version'];
371 $consumer->consumerGuid = $row[
'consumer_guid'];
372 $consumer->profile = json_decode($row[
'profile']);
373 $consumer->toolProxy = $row[
'tool_proxy'];
374 $settingsValue = $row[
'settings']->load();
375 if (is_string($settingsValue)) {
376 $settings = json_decode($settingsValue, TRUE);
377 if (!is_array($settings)) {
378 $settings = @unserialize($settingsValue);
380 if (!is_array($settings)) {
386 $consumer->setSettings($settings);
387 $consumer->protected = (intval($row[
'protected']) === 1);
388 $consumer->enabled = (intval($row[
'enabled']) === 1);
389 $consumer->enableFrom =
null;
390 if (!is_null($row[
'enable_from'])) {
391 $consumer->enableFrom = strtotime($row[
'enable_from']);
393 $consumer->enableUntil =
null;
394 if (!is_null($row[
'enable_until'])) {
395 $consumer->enableUntil = strtotime($row[
'enable_until']);
397 $consumer->lastAccess =
null;
398 if (!is_null($row[
'last_access'])) {
399 $consumer->lastAccess = strtotime($row[
'last_access']);
401 $consumer->created = strtotime($row[
'created']);
402 $consumer->updated = strtotime($row[
'updated']);
403 $consumers[] = $consumer;
424 if (!is_null($context->getRecordId())) {
425 $sql =
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
426 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
427 'WHERE (context_pk = :id)';
428 $query = oci_parse($this->db, $sql);
429 $id = $context->getRecordId();
430 oci_bind_by_name($query,
'id', $id);
432 $sql =
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
433 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
434 'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
435 $query = oci_parse($this->db, $sql);
436 $id = $context->getConsumer()->getRecordId();
437 oci_bind_by_name($query,
'cid', $id);
438 oci_bind_by_name($query,
'ctx', $context->ltiContextId);
440 $ok = oci_execute($query);
442 $row = oci_fetch_assoc($query);
443 $ok = ($row !== FALSE);
446 $row = array_change_key_case($row);
447 $context->setRecordId(intval($row[
'context_pk']));
448 $context->setConsumerId(intval($row[
'consumer_pk']));
449 $context->ltiContextId = $row[
'title'];
450 $context->ltiContextId = $row[
'lti_context_id'];
451 $context->type = $row[
'type'];
452 $settingsValue = $row[
'settings']->load();
453 if (is_string($settingsValue)) {
454 $settings = json_decode($settingsValue, TRUE);
455 if (!is_array($settings)) {
456 $settings = @unserialize($settingsValue);
458 if (!is_array($settings)) {
464 $context->setSettings($settings);
465 $context->created = strtotime($row[
'created']);
466 $context->updated = strtotime($row[
'updated']);
482 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
483 $settingsValue = json_encode($context->getSettings());
484 $id = $context->getRecordId();
485 $consumer_pk = $context->getConsumer()->getRecordId();
487 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' (consumer_pk, title, ' .
488 'lti_context_id, type, settings, created, updated) ' .
489 'VALUES (:cid, :title, :ctx, :type, :settings, :created, :updated) returning context_pk into :pk';
490 $query = oci_parse($this->db, $sql);
491 oci_bind_by_name($query,
'cid', $consumer_pk);
492 oci_bind_by_name($query,
'title', $context->title);
493 oci_bind_by_name($query,
'ctx', $context->ltiContextId);
494 oci_bind_by_name($query,
'type', $context->type);
495 oci_bind_by_name($query,
'settings', $settingsValue);
496 oci_bind_by_name($query,
'created', $now);
497 oci_bind_by_name($query,
'updated', $now);
498 oci_bind_by_name($query,
'pk', $pk);
500 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' SET ' .
501 'title = :title, lti_context_id = :ctx, type = :type, settings = :settings, ' .
502 'updated = :updated ' .
503 'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
504 $query = oci_parse($this->db, $sql);
505 oci_bind_by_name($query,
'title', $context->title);
506 oci_bind_by_name($query,
'ctx', $context->ltiContextId);
507 oci_bind_by_name($query,
'type', $context->type);
508 oci_bind_by_name($query,
'settings', $settingsValue);
509 oci_bind_by_name($query,
'updated', $now);
510 oci_bind_by_name($query,
'cid', $consumer_pk);
511 oci_bind_by_name($query,
'ctxid', $id);
513 $ok = oci_execute($query);
516 $context->setRecordId(intval($pk));
517 $context->created = $time;
519 $context->updated = $time;
534 $id = $context->getRecordId();
537 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
538 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
539 'WHERE context_pk = :id)';
540 $query = oci_parse($this->db, $sql);
541 oci_bind_by_name($query,
'id', $id);
545 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
546 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
547 'WHERE context_pk = :id)';
548 $query = oci_parse($this->db, $sql);
549 oci_bind_by_name($query,
'id', $id);
553 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
554 'SET primary_resource_link_pk = null, share_approved = null ' .
555 'WHERE primary_resource_link_pk IN ' .
556 "(SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' WHERE context_pk = :id)';
557 $query = oci_parse($this->db, $sql);
558 oci_bind_by_name($query,
'id', $id);
562 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
563 'WHERE context_pk = :id';
564 $query = oci_parse($this->db, $sql);
565 oci_bind_by_name($query,
'id', $id);
569 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
570 'WHERE context_pk = :id';
571 $query = oci_parse($this->db, $sql);
572 oci_bind_by_name($query,
'id', $id);
573 $ok = oci_execute($query);
576 $context->initialize();
583 ### ResourceLink methods 595 if (!is_null($resourceLink->getRecordId())) {
596 $sql =
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
597 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
598 'WHERE (resource_link_pk = :id)';
599 $query = oci_parse($this->db, $sql);
600 $id = $resourceLink->getRecordId();
601 oci_bind_by_name($query,
'id', $id);
602 } elseif (!is_null($resourceLink->getContext())) {
603 $sql =
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
604 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
605 'WHERE (context_pk = :id) AND (lti_resource_link_id = :rlid)';
606 $query = oci_parse($this->db, $sql);
607 $id = $resourceLink->getContext()->getRecordId();
608 oci_bind_by_name($query,
'id', $id);
609 $rlid = $resourceLink->getId();
610 oci_bind_by_name($query,
'rlid', $rlid);
612 $sql =
'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
613 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r LEFT OUTER JOIN ' .
614 $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME .
' c ON r.context_pk = c.context_pk ' .
615 ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
616 $query = oci_parse($this->db, $sql);
617 $id1 = $resourceLink->getConsumer()->getRecordId();
618 oci_bind_by_name($query,
'id1', $id1);
619 $id2 = $resourceLink->getConsumer()->getRecordId();
620 oci_bind_by_name($query,
'id2', $id2);
621 $id = $resourceLink->getId();
622 oci_bind_by_name($query,
'rlid', $id);
624 $ok = oci_execute($query);
626 $row = oci_fetch_assoc($query);
627 $ok = ($row !== FALSE);
631 $row = array_change_key_case($row);
632 $resourceLink->setRecordId(intval($row[
'resource_link_pk']));
633 if (!is_null($row[
'context_pk'])) {
634 $resourceLink->setContextId(intval($row[
'context_pk']));
636 $resourceLink->setContextId(
null);
638 if (!is_null($row[
'consumer_pk'])) {
639 $resourceLink->setConsumerId(intval($row[
'consumer_pk']));
641 $resourceLink->setConsumerId(
null);
643 $resourceLink->ltiResourceLinkId = $row[
'lti_resource_link_id'];
644 $settings = $row[
'settings']->load();
645 $settingsValue = $row[
'settings']->load();
646 if (is_string($settingsValue)) {
647 $settings = json_decode($settingsValue, TRUE);
648 if (!is_array($settings)) {
649 $settings = @unserialize($settingsValue);
651 if (!is_array($settings)) {
657 $resourceLink->setSettings($settings);
658 if (!is_null($row[
'primary_resource_link_pk'])) {
659 $resourceLink->primaryResourceLinkId = intval($row[
'primary_resource_link_pk']);
661 $resourceLink->primaryResourceLinkId =
null;
663 $resourceLink->shareApproved = (is_null($row[
'share_approved'])) ?
null : (intval($row[
'share_approved']) === 1);
664 $resourceLink->created = strtotime($row[
'created']);
665 $resourceLink->updated = strtotime($row[
'updated']);
681 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
682 $settingsValue = json_encode($resourceLink->getSettings());
683 if (!is_null($resourceLink->getContext())) {
685 $contextId = strval($resourceLink->getContext()->getRecordId());
686 } elseif (!is_null($resourceLink->getContextId())) {
688 $contextId = strval($resourceLink->getContextId());
690 $consumerId = strval($resourceLink->getConsumer()->getRecordId());
693 if (empty($resourceLink->primaryResourceLinkId)) {
694 $primaryResourceLinkId =
null;
696 $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
698 $id = $resourceLink->getRecordId();
700 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' (consumer_pk, context_pk, ' .
701 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
702 'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated) returning resource_link_pk into :pk';
703 $query = oci_parse($this->db, $sql);
704 oci_bind_by_name($query,
'cid', $consumerId);
705 oci_bind_by_name($query,
'ctx', $contextId);
706 $rlid = $resourceLink->getId();
707 oci_bind_by_name($query,
'rlid', $rlid);
708 oci_bind_by_name($query,
'settings', $settingsValue);
709 oci_bind_by_name($query,
'prlid', $primaryResourceLinkId);
710 oci_bind_by_name($query,
'share_approved', $resourceLink->shareApproved);
711 oci_bind_by_name($query,
'created', $now);
712 oci_bind_by_name($query,
'updated', $now);
713 oci_bind_by_name($query,
'pk', $pk);
714 } elseif (!is_null($contextId)) {
715 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
716 'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' .
717 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
718 'WHERE (resource_link_pk = :id)';
719 $query = oci_parse($this->db, $sql);
720 oci_bind_by_name($query,
'ctx', $contextId);
721 $rlid = $resourceLink->getId();
722 oci_bind_by_name($query,
'rlid', $rlid);
723 oci_bind_by_name($query,
'settings', $settingsValue);
724 oci_bind_by_name($query,
'prlid', $primaryResourceLinkId);
725 oci_bind_by_name($query,
'share_approved', $resourceLink->shareApproved);
726 oci_bind_by_name($query,
'updated', $now);
727 oci_bind_by_name($query,
'id', $id);
729 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
730 'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' .
731 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
732 'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
733 $query = oci_parse($this->db, $sql);
734 oci_bind_by_name($query,
'ctx', $contextId);
735 $rlid = $resourceLink->getId();
736 oci_bind_by_name($query,
'rlid', $rlid);
737 oci_bind_by_name($query,
'settings', $settingsValue);
738 oci_bind_by_name($query,
'prlid', $primaryResourceLinkId);
739 oci_bind_by_name($query,
'share_approved', $resourceLink->shareApproved);
740 oci_bind_by_name($query,
'updated', $now);
741 oci_bind_by_name($query,
'cid', $consumerId);
742 oci_bind_by_name($query,
'id', $id);
744 $ok = oci_execute($query);
747 $resourceLink->setRecordId(intval($pk));
748 $resourceLink->created = $time;
750 $resourceLink->updated = $time;
765 $id = $resourceLink->getRecordId();
768 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
769 'WHERE (resource_link_pk = :id)';
770 $query = oci_parse($this->db, $sql);
771 oci_bind_by_name($query,
'id', $id);
772 $ok = oci_execute($query);
776 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
777 'WHERE (resource_link_pk = :id)';
778 $query = oci_parse($this->db, $sql);
779 oci_bind_by_name($query,
'id', $id);
780 $ok = oci_execute($query);
785 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
786 'SET primary_resource_link_pk = NULL ' .
787 'WHERE (primary_resource_link_pk = :id)';
788 $query = oci_parse($this->db, $sql);
789 oci_bind_by_name($query,
'id', $id);
790 $ok = oci_execute($query);
795 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
796 'WHERE (resource_link_pk = :id)';
797 $query = oci_parse($this->db, $sql);
798 oci_bind_by_name($query,
'id', $id);
799 $ok = oci_execute($query);
803 $resourceLink->initialize();
823 $id = $resourceLink->getRecordId();
824 $userResults = array();
827 $sql =
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
828 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
829 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
830 'ON u.resource_link_pk = rl.resource_link_pk ' .
831 'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
832 $query = oci_parse($this->db, $sql);
833 oci_bind_by_name($query,
'id', $id);
835 $sql =
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
836 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
837 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
838 'ON u.resource_link_pk = rl.resource_link_pk ' .
839 'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
840 '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))';
841 $query = oci_parse($this->db, $sql);
842 oci_bind_by_name($query,
'id', $id);
843 oci_bind_by_name($query,
'pid', $id);
845 if (oci_execute($query)) {
846 while ($row = oci_fetch_assoc($query)) {
847 $row = array_change_key_case($row);
849 $userresult->setRecordId(intval($row[
'user_result_pk']));
850 $userresult->ltiResultSourcedId = $row[
'lti_result_sourcedid'];
851 $userresult->created = strtotime($row[
'created']);
852 $userresult->updated = strtotime($row[
'updated']);
853 if (is_null($idScope)) {
854 $userResults[] = $userresult;
856 $userResults[$userresult->getId($idScope)] = $userresult;
873 $id = $resourceLink->getRecordId();
877 $sql =
'SELECT c.consumer_name, r.resource_link_pk, r.title, r.share_approved ' .
878 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r ' .
879 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' c ON r.consumer_pk = c.consumer_pk ' .
880 'WHERE (r.primary_resource_link_pk = :id1) ' .
882 'SELECT c2.consumer_name, r2.resource_link_pk, r2.title, r2.share_approved ' .
883 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r2 ' .
884 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' x ON r2.context_pk = x.context_pk ' .
885 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONSUMER_TABLE_NAME .
' c2 ON x.consumer_pk = c2.consumer_pk ' .
886 'WHERE (r2.primary_resource_link_pk = :id2) ' .
887 'ORDER BY consumer_name, title';
888 $query = oci_parse($this->db, $sql);
889 oci_bind_by_name($query,
'id1', $id);
890 oci_bind_by_name($query,
'id2', $id);
891 if (oci_execute($query)) {
892 while ($row = oci_fetch_assoc($query)) {
893 $row = array_change_key_case($row);
895 $share->resourceLinkId = intval($row[
'resource_link_pk']);
896 $share->approved = (intval($row[
'share_approved']) === 1);
905 ### ConsumerNonce methods 918 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
919 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE expires <= :now';
920 $query = oci_parse($this->db, $sql);
921 oci_bind_by_name($query,
'now', $now);
925 $id = $nonce->getConsumer()->getRecordId();
926 $value = $nonce->getValue();
927 $sql =
"SELECT value T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE (consumer_pk = :id) AND (value = :value)';
928 $query = oci_parse($this->db, $sql);
929 oci_bind_by_name($query,
'id', $id);
930 oci_bind_by_name($query,
'value', $value);
931 $ok = oci_execute($query);
933 $row = oci_fetch_assoc($query);
934 if ($row ===
false) {
951 $id = $nonce->getConsumer()->getRecordId();
952 $value = $nonce->getValue();
953 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
954 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' (consumer_pk, value, expires) VALUES (:id, :value, :expires)';
955 $query = oci_parse($this->db, $sql);
956 oci_bind_by_name($query,
'id', $id);
957 oci_bind_by_name($query,
'value', $value);
958 oci_bind_by_name($query,
'expires', $expires);
959 $ok = oci_execute($query);
965 ### ResourceLinkShareKey methods 980 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
981 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' WHERE expires <= :now';
982 $query = oci_parse($this->db, $sql);
983 oci_bind_by_name($query,
'now', $now);
987 $id = $shareKey->getId();
988 $sql =
'SELECT resource_link_pk, auto_approve, expires ' .
989 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
990 'WHERE share_key_id = :id';
991 $query = oci_parse($this->db, $sql);
992 oci_bind_by_name($query,
'id', $id);
993 if (oci_execute($query)) {
994 $row = oci_fetch_assoc($query);
995 if ($row !== FALSE) {
996 $row = array_change_key_case($row);
997 if (intval($row[
'resource_link_pk']) === $shareKey->resourceLinkId) {
998 $shareKey->autoApprove = ($row[
'auto_approve'] === 1);
999 $shareKey->expires = strtotime($row[
'expires']);
1017 if ($shareKey->autoApprove) {
1022 $id = $shareKey->getId();
1023 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
1024 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1025 '(share_key_id, resource_link_pk, auto_approve, expires) ' .
1026 'VALUES (:id, :prlid, :approve, :expires)';
1027 $query = oci_parse($this->db, $sql);
1028 oci_bind_by_name($query,
'id', $id);
1029 oci_bind_by_name($query,
'prlid', $shareKey->resourceLinkId);
1030 oci_bind_by_name($query,
'approve', $approve);
1031 oci_bind_by_name($query,
'expires', $expires);
1032 $ok = oci_execute($query);
1046 $id = $shareKey->getId();
1047 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' WHERE share_key_id = :id';
1048 $query = oci_parse($this->db, $sql);
1049 oci_bind_by_name($query,
'id', $id);
1050 $ok = oci_execute($query);
1053 $shareKey->initialize();
1060 ### UserResult Result methods 1073 if (!is_null($userresult->getRecordId())) {
1074 $id = $userresult->getRecordId();
1075 $sql =
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1076 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1077 'WHERE (user_result_pk = :id)';
1078 $query = oci_parse($this->db, $sql);
1079 oci_bind_by_name($query,
'id', $id);
1081 $id = $userresult->getResourceLink()->getRecordId();
1083 $sql =
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1084 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1085 'WHERE (resource_link_pk = :id) AND (lti_user_id = :u_id)';
1086 $query = oci_parse($this->db, $sql);
1087 oci_bind_by_name($query,
'id', $id);
1088 oci_bind_by_name($query,
'u_id', $uid);
1090 if (oci_execute($query)) {
1091 $row = oci_fetch_assoc($query);
1092 if ($row !==
false) {
1093 $row = array_change_key_case($row);
1094 $userresult->setRecordId(intval($row[
'user_result_pk']));
1095 $userresult->setResourceLinkId(intval($row[
'resource_link_pk']));
1096 $userresult->ltiUserId = $row[
'lti_user_id'];
1097 $userresult->ltiResultSourcedId = $row[
'lti_result_sourcedid'];
1098 $userresult->created = strtotime($row[
'created']);
1099 $userresult->updated = strtotime($row[
'updated']);
1117 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1118 if (is_null($userresult->created)) {
1119 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' (resource_link_pk, ' .
1120 'lti_user_id, lti_result_sourcedid, created, updated) ' .
1121 'VALUES (:rlid, :u_id, :sourcedid, :created, :updated) returning user_result_pk into :pk';
1122 $query = oci_parse($this->db, $sql);
1123 $rlid = $userresult->getResourceLink()->getRecordId();
1124 oci_bind_by_name($query,
'rlid', $rlid);
1126 oci_bind_by_name($query,
'u_id', $uid);
1127 $sourcedid = $userresult->ltiResultSourcedId;
1128 oci_bind_by_name($query,
'sourcedid', $sourcedid);
1129 oci_bind_by_name($query,
'created', $now);
1130 oci_bind_by_name($query,
'updated', $now);
1131 oci_bind_by_name($query,
'pk', $pk);
1133 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1134 'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
1135 'WHERE (user_result_pk = :id)';
1136 $query = oci_parse($this->db, $sql);
1137 $sourcedid = $userresult->ltiResultSourcedId;
1138 oci_bind_by_name($query,
'sourcedid', $sourcedid);
1139 oci_bind_by_name($query,
'updated', $now);
1140 $id = $userresult->getRecordId();
1141 oci_bind_by_name($query,
'id', $id);
1143 $ok = oci_execute($query);
1145 if (is_null($userresult->created)) {
1146 $userresult->setRecordId(intval($pk));
1147 $userresult->created = $time;
1149 $userresult->updated = $time;
1164 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1165 'WHERE (user_result_pk = :id)';
1166 $query = oci_parse($this->db, $sql);
1167 $id = $userresult->getRecordId();
1168 oci_bind_by_name($query,
'id', $id);
1169 $ok = oci_execute($query);
1172 $userresult->initialize();
loadConsumerNonce($nonce)
Load nonce object.
$dbTableNamePrefix
Prefix for database table names.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
Class to provide a connection to a persistent store for LTI objects.
saveContext($context)
Save context object.
loadToolConsumer($consumer)
Load tool consumer object.
deleteUserResult($userresult)
Delete user object.
static getConsumerKey($key)
Return a hash of a consumer key for values longer than 255 characters.
Class to represent a tool consumer context.
saveToolConsumer($consumer)
Save tool consumer object.
loadContext($context)
Load context object.
loadUserResult($userresult)
Load user object.
loadResourceLink($resourceLink)
Load resource link object.
Class to represent a tool consumer nonce.
Class to represent a tool consumer resource link share.
saveResourceLink($resourceLink)
Save resource link object.
deleteContext($context)
Delete context object.
deleteToolConsumer($consumer)
Delete tool consumer object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
static fromRecordId($id, $dataConnector)
Load the user from the database.
saveUserResult($userresult)
Save user object.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
Class to represent a tool consumer user.
getToolConsumers()
Load tool consumer objects.
Class to represent a tool consumer resource link share key.
Class to represent a tool consumer resource link.
deleteResourceLink($resourceLink)
Delete resource link object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
saveConsumerNonce($nonce)
Save nonce object.
Class to represent an LTI Data Connector for Oracle connections.
__construct($db, $dbTableNamePrefix='')
Class constructor.