25# NB This class assumes that a MS SQL Server connection has already been opened to the appropriate schema
45 $allowMultiple =
false;
46 if (!is_null($platform->getRecordId())) {
47 $sql = sprintf(
'SELECT consumer_pk, name, consumer_key, secret, ' .
48 'platform_id, client_id, deployment_id, public_key, ' .
49 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
50 'profile, tool_proxy, settings, protected, enabled, ' .
51 'enable_from, enable_until, last_access, created, updated ' .
52 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
53 "WHERE consumer_pk = %d", $platform->getRecordId());
54 } elseif (!empty($platform->platformId)) {
55 if (empty($platform->clientId)) {
56 $allowMultiple =
true;
57 $sql = sprintf(
'SELECT consumer_pk, name, consumer_key, secret, ' .
58 'platform_id, client_id, deployment_id, public_key, ' .
59 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
60 'profile, tool_proxy, settings, protected, enabled, ' .
61 'enable_from, enable_until, last_access, created, updated ' .
62 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
63 'WHERE (platform_id = %s) ', $this->
escape($platform->platformId));
64 } elseif (empty($platform->deploymentId)) {
65 $allowMultiple =
true;
66 $sql = sprintf(
'SELECT consumer_pk, name, consumer_key, secret, ' .
67 'platform_id, client_id, deployment_id, public_key, ' .
68 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
69 'profile, tool_proxy, settings, protected, enabled, ' .
70 'enable_from, enable_until, last_access, created, updated ' .
71 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
72 'WHERE (platform_id = %s) AND (client_id = %s)', $this->
escape($platform->platformId),
73 $this->escape($platform->clientId));
75 $sql = sprintf(
'SELECT consumer_pk, name, consumer_key, secret, ' .
76 'platform_id, client_id, deployment_id, public_key, ' .
77 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
78 'profile, tool_proxy, settings, protected, enabled, ' .
79 'enable_from, enable_until, last_access, created, updated ' .
80 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
81 'WHERE (platform_id = %s) AND (client_id = %s) AND (deployment_id = %s)', $this->
escape($platform->platformId),
82 $this->escape($platform->clientId), $this->escape($platform->deploymentId));
85 $sql = sprintf(
'SELECT consumer_pk, name, consumer_key, secret, ' .
86 'platform_id, client_id, deployment_id, public_key, ' .
87 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
88 'profile, tool_proxy, settings, protected, enabled, ' .
89 'enable_from, enable_until, last_access, created, updated ' .
90 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
91 "WHERE consumer_key = %s", $this->
escape($platform->getKey()));
93 $rsConsumer = $this->executeQuery($sql);
95 $row = sqlsrv_fetch_object($rsConsumer);
96 if ($row && ($allowMultiple || !sqlsrv_fetch_object($rsConsumer))) {
97 $platform->setRecordId(intval($row->consumer_pk));
98 $platform->name = $row->name;
99 $platform->setkey($row->consumer_key);
100 $platform->secret = $row->secret;
101 $platform->platformId = $row->platform_id;
102 $platform->clientId = $row->client_id;
103 $platform->deploymentId = $row->deployment_id;
104 $platform->rsaKey = $row->public_key;
105 $platform->ltiVersion = $row->lti_version;
106 $platform->signatureMethod = $row->signature_method;
107 $platform->consumerName = $row->consumer_name;
108 $platform->consumerVersion = $row->consumer_version;
109 $platform->consumerGuid = $row->consumer_guid;
111 $platform->toolProxy = $row->tool_proxy;
113 if (!is_array($settings)) {
114 $settings = @unserialize($row->settings);
116 if (!is_array($settings)) {
119 $platform->setSettings($settings);
120 $platform->protected = (intval($row->protected) === 1);
121 $platform->enabled = (intval($row->enabled) === 1);
122 $platform->enableFrom =
null;
123 if (!is_null($row->enable_from)) {
124 $platform->enableFrom = date_timestamp_get($row->enable_from);
126 $platform->enableUntil =
null;
127 if (!is_null($row->enable_until)) {
128 $platform->enableUntil = date_timestamp_get($row->enable_until);
130 $platform->lastAccess =
null;
131 if (!is_null($row->last_access)) {
132 $platform->lastAccess = date_timestamp_get($row->last_access);
134 $platform->created = date_timestamp_get($row->created);
135 $platform->updated = date_timestamp_get($row->updated);
153 $id = $platform->getRecordId();
154 $protected = ($platform->protected) ? 1 : 0;
155 $enabled = ($platform->enabled) ? 1 : 0;
156 $profile = (!empty($platform->profile)) ? json_encode($platform->profile) :
null;
158 $settingsValue = json_encode($platform->getSettings());
161 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
163 if (!is_null($platform->enableFrom)) {
164 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
167 if (!is_null($platform->enableUntil)) {
168 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
171 if (!is_null($platform->lastAccess)) {
172 $last = date($this->dateFormat, $platform->lastAccess);
175 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' (consumer_key, name, secret, ' .
176 'platform_id, client_id, deployment_id, public_key, ' .
177 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
178 'profile, tool_proxy, settings, protected, enabled, ' .
179 'enable_from, enable_until, last_access, created, updated) ' .
180 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s, %s, %s, %s, %s)',
181 $this->
escape($platform->getKey()), $this->escape($platform->name), $this->escape($platform->secret),
182 $this->escape($platform->platformId), $this->escape($platform->clientId), $this->escape($platform->deploymentId),
183 $this->escape($platform->rsaKey), $this->escape($platform->ltiVersion), $this->escape($platform->signatureMethod),
184 $this->escape($platform->consumerName), $this->escape($platform->consumerVersion),
185 $this->escape($platform->consumerGuid), $this->escape($profile), $this->escape($platform->toolProxy),
186 $this->escape($settingsValue), $protected, $enabled, $this->escape($from), $this->escape($until),
187 $this->escape($last), $this->escape($now), $this->escape($now));
189 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' SET ' .
190 'consumer_key = %s, name = %s, secret= %s, ' .
191 'platform_id = %s, client_id = %s, deployment_id = %s, public_key = %s, ' .
192 'lti_version = %s, signature_method = %s, ' .
193 'consumer_name = %s, consumer_version = %s, consumer_guid = %s, ' .
194 'profile = %s, tool_proxy = %s, settings = %s, ' .
195 'protected = %d, enabled = %d, enable_from = %s, enable_until = %s, last_access = %s, updated = %s ' .
196 'WHERE consumer_pk = %d', $this->
escape($platform->getKey()), $this->escape($platform->name),
197 $this->escape($platform->secret), $this->escape($platform->platformId), $this->escape($platform->clientId),
198 $this->escape($platform->deploymentId), $this->escape($platform->rsaKey), $this->escape($platform->ltiVersion),
199 $this->escape($platform->signatureMethod), $this->escape($platform->consumerName),
200 $this->escape($platform->consumerVersion), $this->escape($platform->consumerGuid), $this->escape($profile),
201 $this->escape($platform->toolProxy), $this->escape($settingsValue), $protected, $enabled, $this->escape($from),
202 $this->escape($until), $this->escape($last), $this->escape($now), $platform->getRecordId());
204 $ok = $this->executeQuery($sql);
207 $platform->setRecordId($this->insert_id());
208 $platform->created = $time;
210 $platform->updated = $time;
226 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' WHERE consumer_pk = %d',
227 $platform->getRecordId());
228 $this->executeQuery($sql);
231 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE consumer_pk = %d',
232 $platform->getRecordId());
233 $this->executeQuery($sql);
236 $sql = sprintf(
'DELETE sk ' .
237 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
238 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
239 'WHERE rl.consumer_pk = %d', $platform->getRecordId());
240 $this->executeQuery($sql);
243 $sql = sprintf(
'DELETE sk ' .
244 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
245 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
246 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
247 'WHERE c.consumer_pk = %d', $platform->getRecordId());
248 $this->executeQuery($sql);
251 $sql = sprintf(
'DELETE u ' .
252 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
253 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
254 'WHERE rl.consumer_pk = %d', $platform->getRecordId());
255 $this->executeQuery($sql);
258 $sql = sprintf(
'DELETE u ' .
259 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
260 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
261 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
262 'WHERE c.consumer_pk = %d', $platform->getRecordId());
263 $this->executeQuery($sql);
266 $sql = sprintf(
'UPDATE prl ' .
267 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
268 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' prl ' .
269 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
270 'WHERE rl.consumer_pk = %d', $platform->getRecordId());
271 $ok = $this->executeQuery($sql);
274 $sql = sprintf(
'UPDATE prl ' .
275 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
276 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' prl ' .
277 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
278 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
279 'WHERE c.consumer_pk = %d', $platform->getRecordId());
280 $ok = $this->executeQuery($sql);
283 $sql = sprintf(
'DELETE rl ' .
284 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
285 'WHERE rl.consumer_pk = %d', $platform->getRecordId());
286 $this->executeQuery($sql);
289 $sql = sprintf(
'DELETE rl ' .
290 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
291 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
292 'WHERE c.consumer_pk = %d', $platform->getRecordId());
293 $this->executeQuery($sql);
296 $sql = sprintf(
'DELETE c ' .
297 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ' .
298 'WHERE c.consumer_pk = %d', $platform->getRecordId());
299 $this->executeQuery($sql);
302 $sql = sprintf(
'DELETE c ' .
303 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' c ' .
304 'WHERE c.consumer_pk = %d', $platform->getRecordId());
305 $ok = $this->executeQuery($sql);
308 $platform->initialize();
321 $platforms = array();
323 $sql =
'SELECT consumer_pk, consumer_key, name, secret, ' .
324 'platform_id, client_id, deployment_id, public_key, ' .
325 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
326 'profile, tool_proxy, settings, protected, enabled, ' .
327 'enable_from, enable_until, last_access, created, updated ' .
328 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
330 $rsConsumers = $this->executeQuery($sql);
332 while ($row = sqlsrv_fetch_object($rsConsumers)) {
334 $platform->setRecordId(intval($row->consumer_pk));
335 $platform->name = $row->name;
336 $platform->setKey($row->consumer_key);
337 $platform->secret = $row->secret;
338 $platform->platformId = $row->platform_id;
339 $platform->clientId = $row->client_id;
340 $platform->deploymentId = $row->deployment_id;
341 $platform->rsaKey = $row->public_key;
342 $platform->ltiVersion = $row->lti_version;
343 $platform->signatureMethod = $row->signature_method;
344 $platform->consumerName = $row->consumer_name;
345 $platform->consumerVersion = $row->consumer_version;
346 $platform->consumerGuid = $row->consumer_guid;
348 $platform->toolProxy = $row->tool_proxy;
350 if (!is_array($settings)) {
351 $settings = @unserialize($row->settings);
353 if (!is_array($settings)) {
356 $platform->setSettings($settings);
357 $platform->protected = (intval($row->protected) === 1);
358 $platform->enabled = (intval($row->enabled) === 1);
359 $platform->enableFrom =
null;
360 if (!is_null($row->enable_from)) {
361 $platform->enableFrom = date_timestamp_get($row->enable_from);
363 $platform->enableUntil =
null;
364 if (!is_null($row->enable_until)) {
365 $platform->enableUntil = date_timestamp_get($row->enable_until);
367 $platform->lastAccess =
null;
368 if (!is_null($row->last_access)) {
369 $platform->lastAccess = date_timestamp_get($row->last_access);
371 $platform->created = date_timestamp_get($row->created);
372 $platform->updated = date_timestamp_get($row->updated);
374 $platforms[] = $platform;
376 sqlsrv_free_stmt($rsConsumers);
396 if (!is_null($context->getRecordId())) {
397 $sql = sprintf(
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
398 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
399 'WHERE (context_pk = %d)', $context->getRecordId());
401 $sql = sprintf(
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
402 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
403 'WHERE (consumer_pk = %d) AND (lti_context_id = %s)', $context->getPlatform()->getRecordId(),
404 $this->escape($context->ltiContextId));
406 $rsContext = $this->executeQuery($sql);
408 $row = sqlsrv_fetch_object($rsContext);
410 $context->setRecordId(intval($row->context_pk));
411 $context->setPlatformId(intval($row->consumer_pk));
412 $context->title = $row->title;
413 $context->ltiContextId = $row->lti_context_id;
414 $context->type = $row->type;
416 if (!is_array($settings)) {
417 $settings = @unserialize($row->settings);
419 if (!is_array($settings)) {
422 $context->setSettings($settings);
423 $context->created = date_timestamp_get($row->created);
424 $context->updated = date_timestamp_get($row->updated);
442 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
443 $settingsValue = json_encode($context->getSettings());
444 $id = $context->getRecordId();
445 $consumer_pk = $context->getPlatform()->getRecordId();
447 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' (consumer_pk, title, ' .
448 'lti_context_id, type, settings, created, updated) ' .
449 'VALUES (%d, %s, %s, %s, %s, %s, %s)', $consumer_pk, $this->
escape($context->title),
450 $this->escape($context->ltiContextId), $this->escape($context->type), $this->escape($settingsValue),
451 $this->escape($now), $this->escape($now));
453 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' SET ' .
454 'title = %s, lti_context_id = %s, type = %s, settings = %s, ' .
456 'WHERE (consumer_pk = %d) AND (context_pk = %d)', $this->
escape($context->title),
457 $this->escape($context->ltiContextId), $this->escape($context->type), $this->escape($settingsValue),
458 $this->escape($now), $consumer_pk, $id);
460 $ok = $this->executeQuery($sql);
463 $context->setRecordId($this->insert_id());
464 $context->created = $time;
466 $context->updated = $time;
482 $sql = sprintf(
'DELETE sk ' .
483 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
484 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
485 'WHERE rl.context_pk = %d', $context->getRecordId());
486 $this->executeQuery($sql);
489 $sql = sprintf(
'DELETE u ' .
490 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
491 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
492 'WHERE rl.context_pk = %d', $context->getRecordId());
493 $this->executeQuery($sql);
496 $sql = sprintf(
'UPDATE prl ' .
497 'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' .
498 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' prl ' .
499 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
500 'WHERE rl.context_pk = %d', $context->getRecordId());
501 $ok = $this->executeQuery($sql);
504 $sql = sprintf(
'DELETE rl ' .
505 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
506 'WHERE rl.context_pk = %d', $context->getRecordId());
507 $this->executeQuery($sql);
510 $sql = sprintf(
'DELETE c ' .
511 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ',
'WHERE c.context_pk = %d',
512 $context->getRecordId());
513 $ok = $this->executeQuery($sql);
515 $context->initialize();
522### ResourceLink methods
535 if (!is_null($resourceLink->getRecordId())) {
536 $sql = sprintf(
'SELECT resource_link_pk, context_pk, consumer_pk, title, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
537 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
538 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId());
539 } elseif (!is_null($resourceLink->getContext())) {
540 $sql = sprintf(
'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 ' .
541 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r ' .
542 'WHERE (r.lti_resource_link_id = %s) AND ((r.context_pk = %d) OR (r.consumer_pk IN (' .
543 'SELECT c.consumer_pk ' .
544 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ' .
545 'WHERE (c.context_pk = %d))))', $this->
escape($resourceLink->getId()), $resourceLink->getContext()->getRecordId(),
546 $resourceLink->getContext()->getRecordId());
548 $sql = sprintf(
'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 ' .
549 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r LEFT OUTER JOIN ' .
550 $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME .
' c ON r.context_pk = c.context_pk ' .
551 ' WHERE ((r.consumer_pk = %d) OR (c.consumer_pk = %d)) AND (lti_resource_link_id = %s)',
552 $resourceLink->getPlatform()->getRecordId(), $resourceLink->getPlatform()->getRecordId(),
553 $this->escape($resourceLink->getId()));
555 $rsResourceLink = $this->executeQuery($sql);
556 if ($rsResourceLink) {
557 $row = sqlsrv_fetch_object($rsResourceLink);
559 $resourceLink->setRecordId(intval($row->resource_link_pk));
560 if (!is_null($row->context_pk)) {
561 $resourceLink->setContextId(intval($row->context_pk));
563 $resourceLink->setContextId(
null);
565 if (!is_null($row->consumer_pk)) {
566 $resourceLink->setPlatformId(intval($row->consumer_pk));
568 $resourceLink->setPlatformId(
null);
570 $resourceLink->title = $row->title;
571 $resourceLink->ltiResourceLinkId = $row->lti_resource_link_id;
573 if (!is_array($settings)) {
574 $settings = @unserialize($row->settings);
576 if (!is_array($settings)) {
579 $resourceLink->setSettings($settings);
580 if (!is_null($row->primary_resource_link_pk)) {
581 $resourceLink->primaryResourceLinkId = intval($row->primary_resource_link_pk);
583 $resourceLink->primaryResourceLinkId =
null;
585 $resourceLink->shareApproved = (is_null($row->share_approved)) ?
null : (intval($row->share_approved) === 1);
586 $resourceLink->created = date_timestamp_get($row->created);
587 $resourceLink->updated = date_timestamp_get($row->updated);
604 if (is_null($resourceLink->shareApproved)) {
606 } elseif ($resourceLink->shareApproved) {
611 if (empty($resourceLink->primaryResourceLinkId)) {
612 $primaryResourceLinkId =
'NULL';
614 $primaryResourceLinkId = strval($resourceLink->primaryResourceLinkId);
617 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
618 $settingsValue = json_encode($resourceLink->getSettings());
619 if (!is_null($resourceLink->getContext())) {
620 $consumerId =
'NULL';
621 $contextId = strval($resourceLink->getContext()->getRecordId());
622 } elseif (!is_null($resourceLink->getContextId())) {
623 $consumerId =
'NULL';
624 $contextId = strval($resourceLink->getContextId());
626 $consumerId = strval($resourceLink->getPlatform()->getRecordId());
629 $id = $resourceLink->getRecordId();
631 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' (consumer_pk, context_pk, ' .
632 'title, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
633 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)', $consumerId, $contextId, $this->
escape($resourceLink->title),
634 $this->escape($resourceLink->getId()), $this->escape($settingsValue), $primaryResourceLinkId, $approved,
635 $this->escape($now), $this->escape($now));
636 } elseif ($contextId !==
'NULL') {
637 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
638 'consumer_pk = %s, title = %s, lti_resource_link_id = %s, settings = %s, ' .
639 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
640 'WHERE (context_pk = %s) AND (resource_link_pk = %d)', $consumerId, $this->
escape($resourceLink->title),
641 $this->escape($resourceLink->getId()), $this->escape($settingsValue), $primaryResourceLinkId, $approved,
642 $this->escape($now), $contextId, $id);
644 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
645 'context_pk = NULL, title = %s, lti_resource_link_id = %s, settings = %s, ' .
646 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
647 'WHERE (consumer_pk = %s) AND (resource_link_pk = %d)', $this->
escape($resourceLink->title),
648 $this->escape($resourceLink->getId()), $this->escape($settingsValue), $primaryResourceLinkId, $approved,
649 $this->escape($now), $consumerId, $id);
651 $ok = $this->executeQuery($sql);
654 $resourceLink->setRecordId($this->insert_id());
655 $resourceLink->created = $time;
657 $resourceLink->updated = $time;
673 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
674 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId());
675 $ok = $this->executeQuery($sql);
679 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
680 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId());
681 $ok = $this->executeQuery($sql);
686 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
687 'SET primary_resource_link_pk = NULL ' .
688 'WHERE (primary_resource_link_pk = %d)', $resourceLink->getRecordId());
689 $ok = $this->executeQuery($sql);
694 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
695 'WHERE (resource_link_pk = %s)', $resourceLink->getRecordId());
696 $ok = $this->executeQuery($sql);
700 $resourceLink->initialize();
720 $userResults = array();
723 $sql = sprintf(
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
724 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' AS u ' .
725 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' AS rl ' .
726 'ON u.resource_link_pk = rl.resource_link_pk ' .
727 "WHERE (rl.resource_link_pk = %d) AND (rl.primary_resource_link_pk IS NULL)", $resourceLink->getRecordId());
729 $sql = sprintf(
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
730 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' AS u ' .
731 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' AS rl ' .
732 'ON u.resource_link_pk = rl.resource_link_pk ' .
733 'WHERE ((rl.resource_link_pk = %d) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
734 '((rl.primary_resource_link_pk = %d) AND (share_approved = 1))', $resourceLink->getRecordId(),
735 $resourceLink->getRecordId());
737 $rsUser = $this->executeQuery($sql);
739 while ($row = sqlsrv_fetch_object($rsUser)) {
740 $userresult = LTI\UserResult::fromResourceLink($resourceLink, $row->lti_user_id);
741 if (is_null($idScope)) {
742 $userResults[] = $userresult;
744 $userResults[$userresult->getId($idScope)] = $userresult;
763 $sql = sprintf(
'SELECT c.consumer_name, r.resource_link_pk, r.title, r.share_approved ' .
764 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' AS r ' .
765 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' AS c ON r.consumer_pk = c.consumer_pk ' .
766 'WHERE (r.primary_resource_link_pk = %d) ' .
768 'SELECT c2.consumer_name, r2.resource_link_pk, r2.title, r2.share_approved ' .
769 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' AS r2 ' .
770 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' AS x ON r2.context_pk = x.context_pk ' .
771 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' AS c2 ON x.consumer_pk = c2.consumer_pk ' .
772 'WHERE (r2.primary_resource_link_pk = %d) ' .
773 'ORDER BY consumer_name, title', $resourceLink->getRecordId(), $resourceLink->getRecordId());
774 $rsShare = $this->executeQuery($sql);
776 while ($row = sqlsrv_fetch_object($rsShare)) {
778 $share->consumerName = $row->consumer_name;
779 $share->resourceLinkId = intval($row->resource_link_pk);
780 $share->title = $row->title;
781 $share->approved = (intval($row->share_approved) === 1);
790### PlatformNonce methods
802 if (parent::useMemcache()) {
803 $ok = parent::loadPlatformNonce($nonce);
808 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
809 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
" WHERE expires <= '{$now}'";
810 $this->executeQuery($sql);
813 $sql = sprintf(
"SELECT value AS T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' ' .
814 'WHERE (consumer_pk = %d) AND (value = %s)', $nonce->getPlatform()->getRecordId(), $this->escape($nonce->getValue()));
815 $rsNonce = $this->executeQuery($sql,
false);
817 if (sqlsrv_fetch_object($rsNonce)) {
835 if (parent::useMemcache()) {
836 $ok = parent::savePlatformNonce($nonce);
838 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
839 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
" (consumer_pk, value, expires) VALUES (%d, %s, %s)",
840 $nonce->getPlatform()->getRecordId(), $this->escape($nonce->getValue()), $this->escape($expires));
841 $ok = $this->executeQuery($sql);
856 if (parent::useMemcache()) {
857 $ok = parent::deletePlatformNonce($nonce);
859 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' ' .
860 'WHERE (consumer_pk = %d) AND (value = %s)', $nonce->getPlatform()->getRecordId(), $this->escape($nonce->getValue()));
861 $ok = $this->executeQuery($sql);
868### AccessToken methods
880 if (parent::useMemcache()) {
881 $ok = parent::loadAccessToken($accessToken);
884 $consumer_pk = $accessToken->getPlatform()->getRecordId();
885 $sql = sprintf(
'SELECT scopes, token, expires, created, updated ' .
886 "FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
887 'WHERE (consumer_pk = %d)', $consumer_pk);
888 $rsAccessToken = $this->executeQuery($sql,
false);
889 if ($rsAccessToken) {
890 $row = sqlsrv_fetch_object($rsAccessToken);
893 if (!is_array($scopes)) {
896 $accessToken->scopes = $scopes;
897 $accessToken->token = $row->token;
898 $accessToken->expires = date_timestamp_get($row->expires);
899 $accessToken->created = date_timestamp_get($row->created);
900 $accessToken->updated = date_timestamp_get($row->updated);
918 if (parent::useMemcache()) {
919 $ok = parent::saveAccessToken($accessToken);
921 $consumer_pk = $accessToken->getPlatform()->getRecordId();
922 $scopes = json_encode($accessToken->scopes, JSON_UNESCAPED_SLASHES);
923 $token = $accessToken->token;
924 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $accessToken->expires);
926 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
927 if (empty($accessToken->created)) {
928 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
929 '(consumer_pk, scopes, token, expires, created, updated) ' .
930 'VALUES (%d, %s, %s, %s, %s, %s)', $consumer_pk, $this->
escape($scopes), $this->
escape($token),
933 $sql = sprintf(
'UPDATE ' . $this->dbTableNamePrefix . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
934 'SET scopes = %s, token = %s, expires = %s, updated = %s WHERE consumer_pk = %d', $this->
escape($scopes),
937 $ok = $this->executeQuery($sql);
944### ResourceLinkShareKey methods
959 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
960 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
" WHERE expires <= '{$now}'";
961 $this->executeQuery($sql);
964 $id = $shareKey->getId();
965 $sql =
'SELECT resource_link_pk, auto_approve, expires ' .
966 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
967 "WHERE share_key_id = '{$id}'";
968 $rsShareKey = $this->executeQuery($sql);
970 $row = sqlsrv_fetch_object($rsShareKey);
972 $shareKey->resourceLinkId = intval($row->resource_link_pk);
973 $shareKey->autoApprove = (intval($row->auto_approve) === 1);
974 $shareKey->expires = date_timestamp_get($row->expires);
991 if ($shareKey->autoApprove) {
996 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
997 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
998 '(share_key_id, resource_link_pk, auto_approve, expires) ' .
999 "VALUES (%s, %d, {$approve}, '{$expires}')", $this->
escape($shareKey->getId()), $shareKey->resourceLinkId);
1000 $ok = $this->executeQuery($sql);
1014 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
" WHERE share_key_id = '{$shareKey->getId()}'";
1016 $ok = $this->executeQuery($sql);
1019 $shareKey->initialize();
1026### UserResult methods
1039 if (!is_null($userresult->getRecordId())) {
1040 $sql = sprintf(
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1041 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1042 'WHERE (user_result_pk = %d)', $userresult->getRecordId());
1044 $sql = sprintf(
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1045 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1046 'WHERE (resource_link_pk = %d) AND (lti_user_id = %s)', $userresult->getResourceLink()->getRecordId(),
1049 $rsUserResult = $this->executeQuery($sql);
1050 if ($rsUserResult) {
1051 $row = sqlsrv_fetch_object($rsUserResult);
1053 $userresult->setRecordId(intval($row->user_result_pk));
1054 $userresult->setResourceLinkId(intval($row->resource_link_pk));
1055 $userresult->ltiUserId = $row->lti_user_id;
1056 $userresult->ltiResultSourcedId = $row->lti_result_sourcedid;
1057 $userresult->created = date_timestamp_get($row->created);
1058 $userresult->updated = date_timestamp_get($row->updated);
1076 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1077 if (is_null($userresult->created)) {
1078 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' (resource_link_pk, ' .
1079 'lti_user_id, lti_result_sourcedid, created, updated) ' .
1080 'VALUES (%d, %s, %s, %s, %s)', $userresult->getResourceLink()->getRecordId(),
1081 $this->escape($userresult->getId(LTI\
Tool::ID_SCOPE_ID_ONLY)), $this->escape($userresult->ltiResultSourcedId),
1082 $this->escape($now), $this->escape($now));
1084 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1085 'SET lti_result_sourcedid = %s, updated = %s ' .
1086 'WHERE (user_result_pk = %d)', $this->
escape($userresult->ltiResultSourcedId), $this->escape($now),
1087 $userresult->getRecordId());
1089 $ok = $this->executeQuery($sql);
1091 if (is_null($userresult->created)) {
1092 $userresult->setRecordId($this->insert_id());
1093 $userresult->created = $time;
1095 $userresult->updated = $time;
1110 $sql = sprintf(
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1111 'WHERE (user_result_pk = %d)', $userresult->getRecordId());
1112 $ok = $this->executeQuery($sql);
1115 $userresult->initialize();
1135 if (!is_null($tool->getRecordId())) {
1136 $sql = sprintf(
'SELECT tool_pk, name, consumer_key, secret, ' .
1137 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1138 'lti_version, signature_method, settings, enabled, ' .
1139 'enable_from, enable_until, last_access, created, updated ' .
1140 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1141 'WHERE tool_pk = %d', $tool->getRecordId());
1142 } elseif (!empty($tool->initiateLoginUrl)) {
1143 $sql = sprintf(
'SELECT tool_pk, name, consumer_key, secret, ' .
1144 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1145 'lti_version, signature_method, settings, enabled, ' .
1146 'enable_from, enable_until, last_access, created, updated ' .
1147 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1148 'WHERE initiate_login_url = %s', $this->
escape($tool->initiateLoginUrl));
1150 $sql = sprintf(
'SELECT tool_pk, name, consumer_key, secret, ' .
1151 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1152 'lti_version, signature_method, settings, enabled, ' .
1153 'enable_from, enable_until, last_access, created, updated ' .
1154 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1155 'WHERE consumer_key = %s', $this->
escape($tool->getKey()));
1157 $rsTool = $this->executeQuery($sql);
1159 $row = sqlsrv_fetch_object($rsTool);
1161 $tool->setRecordId(intval($row->tool_pk));
1162 $tool->name = $row->name;
1163 $tool->setkey($row->consumer_key);
1164 $tool->secret = $row->secret;
1165 $tool->messageUrl = $row->message_url;
1166 $tool->initiateLoginUrl = $row->initiate_login_url;
1168 if (!is_array($tool->redirectionUris)) {
1169 $tool->redirectionUris = array();
1171 $tool->rsaKey = $row->public_key;
1172 $tool->ltiVersion = $row->lti_version;
1173 $tool->signatureMethod = $row->signature_method;
1175 if (!is_array($settings)) {
1176 $settings = array();
1178 $tool->setSettings($settings);
1179 $tool->enabled = (intval($row->enabled) === 1);
1180 $tool->enableFrom =
null;
1181 if (!is_null($row->enable_from)) {
1182 $tool->enableFrom = date_timestamp_get($row->enable_from);
1184 $tool->enableUntil =
null;
1185 if (!is_null($row->enable_until)) {
1186 $tool->enableUntil = date_timestamp_get($row->enable_until);
1188 $tool->lastAccess =
null;
1189 if (!is_null($row->last_access)) {
1190 $tool->lastAccess = date_timestamp_get($row->last_access);
1192 $tool->created = date_timestamp_get($row->created);
1193 $tool->updated = date_timestamp_get($row->updated);
1211 $id = $tool->getRecordId();
1212 $enabled = ($tool->enabled) ? 1 : 0;
1213 $redirectionUrisValue = json_encode($tool->redirectionUris);
1215 $settingsValue = json_encode($tool->getSettings());
1218 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1220 if (!is_null($tool->enableFrom)) {
1221 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableFrom);
1224 if (!is_null($tool->enableUntil)) {
1225 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableUntil);
1228 if (!is_null($tool->lastAccess)) {
1229 $last = date($this->dateFormat, $tool->lastAccess);
1232 $sql = sprintf(
"INSERT INTO {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' (name, consumer_key, secret, ' .
1233 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1234 'lti_version, signature_method, settings, enabled, enable_from, enable_until, ' .
1235 'last_access, created, updated) ' .
1236 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s)', $this->
escape($tool->name),
1237 $this->escape($tool->getKey()), $this->escape($tool->secret), $this->escape($tool->messageUrl),
1238 $this->escape($tool->initiateLoginUrl), $this->escape($redirectionUrisValue), $this->escape($tool->rsaKey),
1239 $this->escape($tool->ltiVersion), $this->escape($tool->signatureMethod), $this->escape($settingsValue), $enabled,
1240 $this->escape($from), $this->escape($until), $this->escape($last), $this->escape($now), $this->escape($now));
1242 $sql = sprintf(
"UPDATE {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' SET ' .
1243 'name = %s, consumer_key = %s, secret= %s, ' .
1244 'message_url = %s, initiate_login_url = %s, redirection_uris = %s, public_key = %s, ' .
1245 'lti_version = %s, signature_method = %s, settings = %s, enabled = %d, enable_from = %s, enable_until = %s, ' .
1246 'last_access = %s, updated = %s ' .
1247 'WHERE tool_pk = %d', $this->
escape($tool->name), $this->escape($tool->getKey()), $this->escape($tool->secret),
1248 $this->escape($tool->messageUrl), $this->escape($tool->initiateLoginUrl), $this->escape($redirectionUrisValue),
1249 $this->escape($tool->rsaKey), $this->escape($tool->ltiVersion), $this->escape($tool->signatureMethod),
1250 $this->escape($settingsValue), $enabled, $this->escape($from), $this->escape($until), $this->escape($last),
1251 $this->escape($now), $tool->getRecordId());
1253 $ok = $this->executeQuery($sql);
1256 $tool->setRecordId($this->insert_id());
1257 $tool->created = $time;
1259 $tool->updated = $time;
1274 $sql = sprintf(
'DELETE t ' .
1275 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' t ' .
1276 'WHERE t.tool_pk = %d', $tool->getRecordId());
1277 $ok = $this->executeQuery($sql);
1280 $tool->initialize();
1295 $sql =
'SELECT tool_pk, name, consumer_key, secret, ' .
1296 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1297 'lti_version, signature_method, settings, enabled, ' .
1298 'enable_from, enable_until, last_access, created, updated ' .
1299 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1301 $rsTools = $this->executeQuery($sql);
1303 while ($row = sqlsrv_fetch_object($rsTools)) {
1304 $tool =
new Tool($this);
1305 $tool->setRecordId(intval($row->tool_pk));
1306 $tool->name = $row->name;
1307 $tool->setkey($row->consumer_key);
1308 $tool->secret = $row->secret;
1309 $tool->messageUrl = $row->message_url;
1310 $tool->initiateLoginUrl = $row->initiate_login_url;
1312 if (!is_array($tool->redirectionUris)) {
1313 $tool->redirectionUris = array();
1315 $tool->rsaKey = $row->public_key;
1316 $tool->ltiVersion = $row->lti_version;
1317 $tool->signatureMethod = $row->signature_method;
1319 if (!is_array($settings)) {
1320 $settings = array();
1322 $tool->setSettings($settings);
1323 $tool->enabled = (intval($row->enabled) === 1);
1324 $tool->enableFrom =
null;
1325 if (!is_null($row->enable_from)) {
1326 $tool->enableFrom = date_timestamp_get($row->enable_from);
1328 $tool->enableUntil =
null;
1329 if (!is_null($row->enable_until)) {
1330 $tool->enableUntil = date_timestamp_get($row->enable_until);
1332 $tool->lastAccess =
null;
1333 if (!is_null($row->last_access)) {
1334 $tool->lastAccess = date_timestamp_get($row->last_access);
1336 $tool->created = date_timestamp_get($row->created);
1337 $tool->updated = date_timestamp_get($row->updated);
1341 sqlsrv_free_stmt($rsTools);
1362 public function escape($value, $addQuotes =
true)
1364 if (is_null($value)) {
1368 $value = str_replace(
"'",
"''", $value);
1369 $value =
"'{$value}'";
1381 private function insert_id()
1384 $sql =
'SELECT SCOPE_IDENTITY() AS insid;';
1385 $rsId = $this->executeQuery($sql);
1387 sqlsrv_fetch($rsId);
1388 $id = sqlsrv_get_field($rsId, 0, SQLSRV_PHPTYPE_INT);
1404 private function executeQuery($sql, $reportError =
true)
1406 $res = sqlsrv_query($this->db, $sql);
1407 if (($res ===
false) && $reportError) {
1408 Util::logError($sql . $this->errorListToString(sqlsrv_errors()));
1423 private function errorListToString($errorList)
1426 if (is_array($errorList) && !empty($errorList)) {
1427 if (count($errorList) <= 1) {
1430 $sep =
'Errors:' . PHP_EOL .
' ';
1432 foreach ($errorList as $error) {
1433 $errors .= PHP_EOL .
"{$sep}{$error['code']}/{$error['SQLSTATE']}: {$error['message']}";
Class to represent an HTTP message.
Class to represent a platform context.
Class to represent an LTI Data Connector for MS SQL Server.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
escape($value, $addQuotes=true)
Escape a string for use in a database query.
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.
getPlatforms()
Load all platforms from the database.
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.
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.