39 $allowMultiple =
false;
40 if (!is_null($platform->getRecordId())) {
41 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
42 'platform_id, client_id, deployment_id, public_key, ' .
43 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
44 'profile, tool_proxy, settings, protected, enabled, ' .
45 'enable_from, enable_until, last_access, created, updated ' .
46 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
47 'WHERE consumer_pk = :id';
48 $query = $this->db->prepare($sql);
49 $id = $platform->getRecordId();
50 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
51 } elseif (!empty($platform->platformId)) {
52 if (empty($platform->clientId)) {
53 $allowMultiple =
true;
54 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
55 'platform_id, client_id, deployment_id, public_key, ' .
56 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
57 'profile, tool_proxy, settings, protected, enabled, ' .
58 'enable_from, enable_until, last_access, created, updated ' .
59 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
60 'WHERE (platform_id = :platform_id) ';
61 $query = $this->db->prepare($sql);
62 $query->bindValue(
'platform_id', $platform->platformId, \PDO::PARAM_STR);
63 } elseif (empty($platform->deploymentId)) {
64 $allowMultiple =
true;
65 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
66 'platform_id, client_id, deployment_id, public_key, ' .
67 'lti_version, 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::PLATFORM_TABLE_NAME .
' ' .
71 'WHERE (platform_id = :platform_id) AND (client_id = :client_id)';
72 $query = $this->db->prepare($sql);
73 $query->bindValue(
'platform_id', $platform->platformId, \PDO::PARAM_STR);
74 $query->bindValue(
'client_id', $platform->clientId, \PDO::PARAM_STR);
76 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
77 'platform_id, client_id, deployment_id, public_key, ' .
78 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
79 'profile, tool_proxy, settings, protected, enabled, ' .
80 'enable_from, enable_until, last_access, created, updated ' .
81 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
82 'WHERE (platform_id = :platform_id) AND (client_id = :client_id) AND (deployment_id = :deployment_id)';
83 $query = $this->db->prepare($sql);
84 $query->bindValue(
'platform_id', $platform->platformId, \PDO::PARAM_STR);
85 $query->bindValue(
'client_id', $platform->clientId, \PDO::PARAM_STR);
86 $query->bindValue(
'deployment_id', $platform->deploymentId, \PDO::PARAM_STR);
89 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
90 'platform_id, client_id, deployment_id, public_key, ' .
91 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
92 'profile, tool_proxy, settings, protected, enabled, ' .
93 'enable_from, enable_until, last_access, created, updated ' .
94 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
95 'WHERE (consumer_key = :key)';
96 $query = $this->db->prepare($sql);
97 $consumer_key = $platform->getKey();
98 $query->bindValue(
'key', $consumer_key, \PDO::PARAM_STR);
102 $row = $query->fetch(\PDO::FETCH_ASSOC);
103 $ok = ($row !==
false) && ($allowMultiple || !$query->fetch(\PDO::FETCH_ASSOC));
106 $row = array_change_key_case($row);
107 $platform->setRecordId(intval($row[
'consumer_pk']));
108 $platform->name = $row[
'name'];
109 $platform->setkey($row[
'consumer_key']);
110 $platform->secret = $row[
'secret'];
111 $platform->platformId = $row[
'platform_id'];
112 $platform->clientId = $row[
'client_id'];
113 $platform->deploymentId = $row[
'deployment_id'];
114 $platform->rsaKey = $row[
'public_key'];
115 $platform->ltiVersion = $row[
'lti_version'];
116 $platform->signatureMethod = $row[
'signature_method'];
117 $platform->consumerName = $row[
'consumer_name'];
118 $platform->consumerVersion = $row[
'consumer_version'];
119 $platform->consumerGuid = $row[
'consumer_guid'];
121 $platform->toolProxy = $row[
'tool_proxy'];
123 if (!is_array($settings)) {
124 $settings = @unserialize($row[
'settings']);
126 if (!is_array($settings)) {
129 $platform->setSettings($settings);
130 $platform->protected = (intval($row[
'protected']) === 1);
131 $platform->enabled = (intval($row[
'enabled']) === 1);
132 $platform->enableFrom =
null;
133 if (!is_null($row[
'enable_from'])) {
134 $platform->enableFrom = strtotime($row[
'enable_from']);
136 $platform->enableUntil =
null;
137 if (!is_null($row[
'enable_until'])) {
138 $platform->enableUntil = strtotime($row[
'enable_until']);
140 $platform->lastAccess =
null;
141 if (!is_null($row[
'last_access'])) {
142 $platform->lastAccess = strtotime($row[
'last_access']);
144 $platform->created = strtotime($row[
'created']);
145 $platform->updated = strtotime($row[
'updated']);
161 $id = $platform->getRecordId();
162 $protected = ($platform->protected) ? 1 : 0;
163 $enabled = ($platform->enabled) ? 1 : 0;
164 $profile = (!empty($platform->profile)) ? json_encode($platform->profile) :
null;
166 $settingsValue = json_encode($platform->getSettings());
169 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
171 if (!is_null($platform->enableFrom)) {
172 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
175 if (!is_null($platform->enableUntil)) {
176 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
179 if (!is_null($platform->lastAccess)) {
180 $last = date($this->dateFormat, $platform->lastAccess);
183 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' (consumer_key, name, secret, ' .
184 'platform_id, client_id, deployment_id, public_key, ' .
185 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
186 'profile, tool_proxy, settings, protected, enabled, ' .
187 'enable_from, enable_until, last_access, created, updated) ' .
188 'VALUES (:key, :name, :secret, ' .
189 ':platform_id, :client_id, :deployment_id, :public_key, ' .
190 ':lti_version, :signature_method, ' .
191 ':consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' .
192 ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated)';
193 $query = $this->db->prepare($sql);
194 $query->bindValue(
'key', $platform->getKey(), \PDO::PARAM_STR);
195 $query->bindValue(
'name', $platform->name, \PDO::PARAM_STR);
196 $query->bindValue(
'secret', $platform->secret, \PDO::PARAM_STR);
197 $query->bindValue(
'platform_id', $platform->platformId, \PDO::PARAM_STR);
198 $query->bindValue(
'client_id', $platform->clientId, \PDO::PARAM_STR);
199 $query->bindValue(
'deployment_id', $platform->deploymentId, \PDO::PARAM_STR);
200 $query->bindValue(
'public_key', $platform->rsaKey, \PDO::PARAM_STR);
201 $query->bindValue(
'lti_version', $platform->ltiVersion, \PDO::PARAM_STR);
202 $query->bindValue(
'signature_method', $platform->signatureMethod, \PDO::PARAM_STR);
203 $query->bindValue(
'consumer_name', $platform->consumerName, \PDO::PARAM_STR);
204 $query->bindValue(
'consumer_version', $platform->consumerVersion, \PDO::PARAM_STR);
205 $query->bindValue(
'consumer_guid', $platform->consumerGuid, \PDO::PARAM_STR);
206 $query->bindValue(
'profile', $profile, \PDO::PARAM_STR);
207 $query->bindValue(
'tool_proxy', $platform->toolProxy, \PDO::PARAM_STR);
208 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
209 $query->bindValue(
'protected', $protected, \PDO::PARAM_INT);
210 $query->bindValue(
'enabled', $enabled, \PDO::PARAM_INT);
211 $query->bindValue(
'enable_from', $from, \PDO::PARAM_STR);
212 $query->bindValue(
'enable_until', $until, \PDO::PARAM_STR);
213 $query->bindValue(
'last_access', $last, \PDO::PARAM_STR);
214 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
215 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
217 $sql =
'UPDATE ' . $this->dbTableNamePrefix . static::PLATFORM_TABLE_NAME .
' ' .
218 'SET consumer_key = :key, name = :name, secret = :secret, ' .
219 'platform_id = :platform_id, client_id = :client_id, deployment_id = :deployment_id, ' .
220 'public_key = :public_key, lti_version = :lti_version, signature_method = :signature_method, ' .
221 'consumer_name = :consumer_name, consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' .
222 'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' .
223 'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, ' .
224 'last_access = :last_access, updated = :updated ' .
225 'WHERE consumer_pk = :id';
226 $query = $this->db->prepare($sql);
227 $query->bindValue(
'key', $platform->getKey(), \PDO::PARAM_STR);
228 $query->bindValue(
'name', $platform->name, \PDO::PARAM_STR);
229 $query->bindValue(
'secret', $platform->secret, \PDO::PARAM_STR);
230 $query->bindValue(
'platform_id', $platform->platformId, \PDO::PARAM_STR);
231 $query->bindValue(
'client_id', $platform->clientId, \PDO::PARAM_STR);
232 $query->bindValue(
'deployment_id', $platform->deploymentId, \PDO::PARAM_STR);
233 $query->bindValue(
'public_key', $platform->rsaKey, \PDO::PARAM_STR);
234 $query->bindValue(
'lti_version', $platform->ltiVersion, \PDO::PARAM_STR);
235 $query->bindValue(
'signature_method', $platform->signatureMethod, \PDO::PARAM_STR);
236 $query->bindValue(
'consumer_name', $platform->consumerName, \PDO::PARAM_STR);
237 $query->bindValue(
'consumer_version', $platform->consumerVersion, \PDO::PARAM_STR);
238 $query->bindValue(
'consumer_guid', $platform->consumerGuid, \PDO::PARAM_STR);
239 $query->bindValue(
'profile', $profile, \PDO::PARAM_STR);
240 $query->bindValue(
'tool_proxy', $platform->toolProxy, \PDO::PARAM_STR);
241 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
242 $query->bindValue(
'protected', $protected, \PDO::PARAM_INT);
243 $query->bindValue(
'enabled', $enabled, \PDO::PARAM_INT);
244 $query->bindValue(
'enable_from', $from, \PDO::PARAM_STR);
245 $query->bindValue(
'enable_until', $until, \PDO::PARAM_STR);
246 $query->bindValue(
'last_access', $last, \PDO::PARAM_STR);
247 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
248 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
253 $platform->setRecordId($this->
getLastInsertId(static::PLATFORM_TABLE_NAME));
254 $platform->created = $time;
256 $platform->updated = $time;
271 $id = $platform->getRecordId();
274 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' WHERE consumer_pk = :id';
275 $query = $this->db->prepare($sql);
276 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
280 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE consumer_pk = :id';
281 $query = $this->db->prepare($sql);
282 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
286 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
287 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
288 'WHERE consumer_pk = :id)';
289 $query = $this->db->prepare($sql);
290 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
294 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
295 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
296 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
297 $query = $this->db->prepare($sql);
298 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
302 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
303 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
304 'WHERE consumer_pk = :id)';
305 $query = $this->db->prepare($sql);
306 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
310 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
311 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
312 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk WHERE c.consumer_pk = :id)';
313 $query = $this->db->prepare($sql);
314 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
318 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
319 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
320 'WHERE primary_resource_link_pk IN ' .
321 "(SELECT resource_link_pk FROM (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
322 'WHERE consumer_pk = :id) t)';
323 $query = $this->db->prepare($sql);
324 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
328 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
329 'SET primary_resource_link_pk = NULL, share_approved = NULL ' .
330 'WHERE primary_resource_link_pk IN ' .
331 "(SELECT resource_link_pk FROM (SELECT rl.resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
332 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
333 'WHERE c.consumer_pk = :id) t)';
334 $query = $this->db->prepare($sql);
335 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
339 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
340 'WHERE consumer_pk = :id';
341 $query = $this->db->prepare($sql);
342 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
346 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
347 'WHERE context_pk IN (' .
348 "SELECT context_pk FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
'WHERE consumer_pk = :id)';
349 $query = $this->db->prepare($sql);
350 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
354 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
355 'WHERE consumer_pk = :id';
356 $query = $this->db->prepare($sql);
357 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
361 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
362 'WHERE consumer_pk = :id';
363 $query = $this->db->prepare($sql);
364 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
368 $platform->initialize();
381 $platforms = array();
383 $sql =
'SELECT consumer_pk, name, consumer_key, secret, ' .
384 'platform_id, client_id, deployment_id, public_key, ' .
385 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
386 'profile, tool_proxy, settings, protected, enabled, ' .
387 'enable_from, enable_until, last_access, created, updated ' .
388 "FROM {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' ' .
390 $query = $this->db->prepare($sql);
391 $ok = ($query !==
false);
398 while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
399 $row = array_change_key_case($row);
401 $platform->setRecordId(intval($row[
'consumer_pk']));
402 $platform->name = $row[
'name'];
403 $platform->secret = $row[
'secret'];
404 $platform->platformId = $row[
'platform_id'];
405 $platform->clientId = $row[
'client_id'];
406 $platform->deploymentId = $row[
'deployment_id'];
407 $platform->rsaKey = $row[
'public_key'];
408 $platform->ltiVersion = $row[
'lti_version'];
409 $platform->signatureMethod = $row[
'signature_method'];
410 $platform->consumerName = $row[
'consumer_name'];
411 $platform->consumerVersion = $row[
'consumer_version'];
412 $platform->consumerGuid = $row[
'consumer_guid'];
414 $platform->toolProxy = $row[
'tool_proxy'];
416 if (!is_array($settings)) {
417 $settings = @unserialize($row[
'settings']);
419 if (!is_array($settings)) {
422 $platform->setSettings($settings);
423 $platform->protected = (intval($row[
'protected']) === 1);
424 $platform->enabled = (intval($row[
'enabled']) === 1);
425 $platform->enableFrom =
null;
426 if (!is_null($row[
'enable_from'])) {
427 $platform->enableFrom = strtotime($row[
'enable_from']);
429 $platform->enableUntil =
null;
430 if (!is_null($row[
'enable_until'])) {
431 $platform->enableUntil = strtotime($row[
'enable_until']);
433 $platform->lastAccess =
null;
434 if (!is_null($row[
'last_access'])) {
435 $platform->lastAccess = strtotime($row[
'last_access']);
437 $platform->created = strtotime($row[
'created']);
438 $platform->updated = strtotime($row[
'updated']);
440 $platforms[] = $platform;
461 if (!is_null($context->getRecordId())) {
462 $sql =
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
463 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
464 'WHERE (context_pk = :id)';
465 $query = $this->db->prepare($sql);
466 $query->bindValue(
'id', $context->getRecordId(), \PDO::PARAM_INT);
468 $sql =
'SELECT context_pk, consumer_pk, title, lti_context_id, type, settings, created, updated ' .
469 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
470 'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
471 $query = $this->db->prepare($sql);
472 $query->bindValue(
'cid', $context->getPlatform()->getRecordId(), \PDO::PARAM_INT);
473 $query->bindValue(
'ctx', $context->ltiContextId, \PDO::PARAM_STR);
477 $row = $query->fetch(\PDO::FETCH_ASSOC);
478 $ok = ($row !==
false);
481 $row = array_change_key_case($row);
482 $context->setRecordId(intval($row[
'context_pk']));
483 $context->setPlatformId(intval($row[
'consumer_pk']));
484 $context->title = $row[
'title'];
485 $context->ltiContextId = $row[
'lti_context_id'];
486 $context->type = $row[
'type'];
488 if (!is_array($settings)) {
489 $settings = @unserialize($row[
'settings']);
491 if (!is_array($settings)) {
494 $context->setSettings($settings);
495 $context->created = strtotime($row[
'created']);
496 $context->updated = strtotime($row[
'updated']);
512 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
513 $settingsValue = json_encode($context->getSettings());
514 $id = $context->getRecordId();
515 $consumer_pk = $context->getPlatform()->getRecordId();
517 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' (consumer_pk, title, ' .
518 'lti_context_id, type, settings, created, updated) ' .
519 'VALUES (:cid, :title, :ctx, :type, :settings, :created, :updated)';
520 $query = $this->db->prepare($sql);
521 $query->bindValue(
'cid', $consumer_pk, \PDO::PARAM_INT);
522 $query->bindValue(
'title', $context->title, \PDO::PARAM_STR);
523 $query->bindValue(
'ctx', $context->ltiContextId, \PDO::PARAM_STR);
524 $query->bindValue(
'type', $context->type, \PDO::PARAM_STR);
525 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
526 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
527 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
529 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' SET ' .
530 'title = :title, lti_context_id = :ctx, type = :type, settings = :settings, ' .
531 'updated = :updated ' .
532 'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
533 $query = $this->db->prepare($sql);
534 $query->bindValue(
'title', $context->title, \PDO::PARAM_STR);
535 $query->bindValue(
'ctx', $context->ltiContextId, \PDO::PARAM_STR);
536 $query->bindValue(
'type', $context->type, \PDO::PARAM_STR);
537 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
538 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
539 $query->bindValue(
'cid', $consumer_pk, \PDO::PARAM_INT);
540 $query->bindValue(
'ctxid', $id, \PDO::PARAM_INT);
545 $context->setRecordId($this->
getLastInsertId(static::CONTEXT_TABLE_NAME));
546 $context->created = $time;
548 $context->updated = $time;
563 $id = $context->getRecordId();
566 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
567 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
568 'WHERE context_pk = :id)';
569 $query = $this->db->prepare($sql);
570 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
574 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
575 "WHERE resource_link_pk IN (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
576 'WHERE context_pk = :id)';
577 $query = $this->db->prepare($sql);
578 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
582 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
583 'SET primary_resource_link_pk = null, share_approved = null ' .
584 'WHERE primary_resource_link_pk IN ' .
585 "(SELECT resource_link_pk FROM (SELECT resource_link_pk FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' WHERE context_pk = :id) t)';
586 $query = $this->db->prepare($sql);
587 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
591 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
592 'WHERE context_pk = :id';
593 $query = $this->db->prepare($sql);
594 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
598 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' ' .
599 'WHERE context_pk = :id';
600 $query = $this->db->prepare($sql);
601 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
605 $context->initialize();
612### ResourceLink methods
624 if (!is_null($resourceLink->getRecordId())) {
625 $sql =
'SELECT resource_link_pk, context_pk, consumer_pk, title, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
626 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
627 'WHERE (resource_link_pk = :id)';
628 $query = $this->db->prepare($sql);
629 $query->bindValue(
'id', $resourceLink->getRecordId(), \PDO::PARAM_INT);
630 } elseif (!is_null($resourceLink->getContext())) {
631 $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 ' .
632 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r ' .
633 'WHERE (r.lti_resource_link_id = :rlid) AND ((r.context_pk = :id1) OR (r.consumer_pk IN (' .
634 'SELECT c.consumer_pk ' .
635 "FROM {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' c ' .
636 'WHERE (c.context_pk = :id2)' .
638 $query = $this->db->prepare($sql);
639 $query->bindValue(
'rlid', $resourceLink->getId(), \PDO::PARAM_STR);
640 $query->bindValue(
'id1', $resourceLink->getContext()->getRecordId(), \PDO::PARAM_INT);
641 $query->bindValue(
'id2', $resourceLink->getContext()->getRecordId(), \PDO::PARAM_INT);
643 $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 ' .
644 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r LEFT OUTER JOIN ' .
645 $this->dbTableNamePrefix . static::CONTEXT_TABLE_NAME .
' c ON r.context_pk = c.context_pk ' .
646 ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
647 $query = $this->db->prepare($sql);
648 $query->bindValue(
'id1', $resourceLink->getPlatform()->getRecordId(), \PDO::PARAM_INT);
649 $query->bindValue(
'id2', $resourceLink->getPlatform()->getRecordId(), \PDO::PARAM_INT);
650 $query->bindValue(
'rlid', $resourceLink->getId(), \PDO::PARAM_STR);
654 $row = $query->fetch(\PDO::FETCH_ASSOC);
655 $ok = ($row !==
false);
659 $row = array_change_key_case($row);
660 $resourceLink->setRecordId(intval($row[
'resource_link_pk']));
661 if (!is_null($row[
'context_pk'])) {
662 $resourceLink->setContextId(intval($row[
'context_pk']));
664 $resourceLink->setContextId(
null);
666 if (!is_null($row[
'consumer_pk'])) {
667 $resourceLink->setPlatformId(intval($row[
'consumer_pk']));
669 $resourceLink->setPlatformId(
null);
671 $resourceLink->title = $row[
'title'];
672 $resourceLink->ltiResourceLinkId = $row[
'lti_resource_link_id'];
674 if (!is_array($settings)) {
675 $settings = @unserialize($row[
'settings']);
677 if (!is_array($settings)) {
680 $resourceLink->setSettings($settings);
681 if (!is_null($row[
'primary_resource_link_pk'])) {
682 $resourceLink->primaryResourceLinkId = intval($row[
'primary_resource_link_pk']);
684 $resourceLink->primaryResourceLinkId =
null;
686 $resourceLink->shareApproved = (is_null($row[
'share_approved'])) ?
null : (intval($row[
'share_approved']) === 1);
687 $resourceLink->created = strtotime($row[
'created']);
688 $resourceLink->updated = strtotime($row[
'updated']);
703 if (is_null($resourceLink->shareApproved)) {
705 } elseif ($resourceLink->shareApproved) {
711 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
712 $settingsValue = json_encode($resourceLink->getSettings());
713 if (!is_null($resourceLink->getContext())) {
715 $contextId = $resourceLink->getContext()->getRecordId();
716 } elseif (!is_null($resourceLink->getContextId())) {
718 $contextId = $resourceLink->getContextId();
720 $consumerId = $resourceLink->getPlatform()->getRecordId();
723 if (empty($resourceLink->primaryResourceLinkId)) {
724 $primaryResourceLinkId =
null;
726 $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
728 $id = $resourceLink->getRecordId();
730 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' (consumer_pk, context_pk, ' .
731 'title, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
732 'VALUES (:cid, :ctx, :title, :rlid, :settings, :prlid, :share_approved, :created, :updated)';
733 $query = $this->db->prepare($sql);
734 $query->bindValue(
'cid', $consumerId, \PDO::PARAM_INT);
735 $query->bindValue(
'ctx', $contextId, \PDO::PARAM_INT);
736 $query->bindValue(
'title', $resourceLink->title, \PDO::PARAM_STR);
737 $query->bindValue(
'rlid', $resourceLink->getId(), \PDO::PARAM_STR);
738 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
739 $query->bindValue(
'prlid', $primaryResourceLinkId, \PDO::PARAM_INT);
740 $query->bindValue(
'share_approved', $approved, \PDO::PARAM_INT);
741 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
742 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
743 } elseif (!is_null($contextId)) {
744 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
745 'consumer_pk = NULL, context_pk = :ctx, title = :title, lti_resource_link_id = :rlid, settings = :settings, ' .
746 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
747 'WHERE (resource_link_pk = :id)';
748 $query = $this->db->prepare($sql);
749 $query->bindValue(
'ctx', $contextId, \PDO::PARAM_INT);
750 $query->bindValue(
'title', $resourceLink->title, \PDO::PARAM_STR);
751 $query->bindValue(
'rlid', $resourceLink->getId(), \PDO::PARAM_STR);
752 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
753 $query->bindValue(
'prlid', $primaryResourceLinkId, \PDO::PARAM_INT);
754 $query->bindValue(
'share_approved', $approved, \PDO::PARAM_INT);
755 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
756 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
758 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' SET ' .
759 'context_pk = NULL, title = :title, lti_resource_link_id = :rlid, settings = :settings, ' .
760 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
761 'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
762 $query = $this->db->prepare($sql);
763 $query->bindValue(
'title', $resourceLink->title, \PDO::PARAM_STR);
764 $query->bindValue(
'rlid', $resourceLink->getId(), \PDO::PARAM_STR);
765 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
766 $query->bindValue(
'prlid', $primaryResourceLinkId, \PDO::PARAM_INT);
767 $query->bindValue(
'share_approved', $approved, \PDO::PARAM_INT);
768 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
769 $query->bindValue(
'cid', $consumerId, \PDO::PARAM_INT);
770 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
775 $resourceLink->setRecordId($this->
getLastInsertId(static::RESOURCE_LINK_TABLE_NAME));
776 $resourceLink->created = $time;
778 $resourceLink->updated = $time;
793 $id = $resourceLink->getRecordId();
796 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
797 'WHERE (resource_link_pk = :id)';
798 $query = $this->db->prepare($sql);
799 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
804 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
805 'WHERE (resource_link_pk = :id)';
806 $query = $this->db->prepare($sql);
807 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
813 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
814 'SET primary_resource_link_pk = NULL ' .
815 'WHERE (primary_resource_link_pk = :id)';
816 $query = $this->db->prepare($sql);
817 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
823 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' ' .
824 'WHERE (resource_link_pk = :id)';
825 $query = $this->db->prepare($sql);
826 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
831 $resourceLink->initialize();
851 $id = $resourceLink->getRecordId();
852 $userResults = array();
855 $sql =
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
856 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
857 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
858 'ON u.resource_link_pk = rl.resource_link_pk ' .
859 'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
860 $query = $this->db->prepare($sql);
861 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
863 $sql =
'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
864 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' u ' .
865 "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' rl ' .
866 'ON u.resource_link_pk = rl.resource_link_pk ' .
867 'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
868 '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))';
869 $query = $this->db->prepare($sql);
870 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
871 $query->bindValue(
'pid', $id, \PDO::PARAM_INT);
874 while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
875 $row = array_change_key_case($row);
876 $userresult = LTI\UserResult::fromRecordId($row[
'user_result_pk'], $resourceLink->getDataConnector());
877 $userresult->setRecordId(intval($row[
'user_result_pk']));
878 $userresult->ltiResultSourcedId = $row[
'lti_result_sourcedid'];
879 $userresult->created = strtotime($row[
'created']);
880 $userresult->updated = strtotime($row[
'updated']);
881 if (is_null($idScope)) {
882 $userResults[] = $userresult;
884 $userResults[$userresult->getId($idScope)] = $userresult;
901 $id = $resourceLink->getRecordId();
905 $sql =
'SELECT c.consumer_name consumer_name, r.resource_link_pk resource_link_pk, r.title title, r.share_approved share_approved ' .
906 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r ' .
907 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' c ON r.consumer_pk = c.consumer_pk ' .
908 'WHERE (r.primary_resource_link_pk = :id1) ' .
910 'SELECT c2.consumer_name consumer_name, r2.resource_link_pk resource_link_pk, r2.title title, r2.share_approved share_approved ' .
911 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME .
' r2 ' .
912 "INNER JOIN {$this->dbTableNamePrefix}" . static::CONTEXT_TABLE_NAME .
' x ON r2.context_pk = x.context_pk ' .
913 "INNER JOIN {$this->dbTableNamePrefix}" . static::PLATFORM_TABLE_NAME .
' c2 ON x.consumer_pk = c2.consumer_pk ' .
914 'WHERE (r2.primary_resource_link_pk = :id2) ' .
915 'ORDER BY consumer_name, title';
916 $query = $this->db->prepare($sql);
917 $query->bindValue(
'id1', $id, \PDO::PARAM_INT);
918 $query->bindValue(
'id2', $id, \PDO::PARAM_INT);
920 while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
921 $row = array_change_key_case($row);
923 $share->consumerName = $row[
'consumer_name'];
924 $share->resourceLinkId = intval($row[
'resource_link_pk']);
925 $share->title = $row[
'title'];
926 $share->approved = (intval($row[
'share_approved']) === 1);
935### PlatformNonce methods
947 if (parent::useMemcache()) {
948 $ok = parent::loadPlatformNonce($nonce);
951 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
952 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE expires <= :now';
953 $query = $this->db->prepare($sql);
954 $query->bindValue(
'now', $now, \PDO::PARAM_STR);
958 $id = $nonce->getPlatform()->getRecordId();
959 $value = $nonce->getValue();
960 $sql =
"SELECT value T FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' WHERE (consumer_pk = :id) AND (value = :value)';
961 $query = $this->db->prepare($sql);
962 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
963 $query->bindValue(
'value', $value, \PDO::PARAM_STR);
966 $row = $query->fetch(\PDO::FETCH_ASSOC);
967 if ($row ===
false) {
985 if (parent::useMemcache()) {
986 $ok = parent::savePlatformNonce($nonce);
988 $id = $nonce->getPlatform()->getRecordId();
989 $value = $nonce->getValue();
990 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
991 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' (consumer_pk, value, expires) VALUES (:id, :value, :expires)';
992 $query = $this->db->prepare($sql);
993 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
994 $query->bindValue(
'value', $value, \PDO::PARAM_STR);
995 $query->bindValue(
'expires', $expires, \PDO::PARAM_STR);
1011 if (parent::useMemcache()) {
1012 $ok = parent::deletePlatformNonce($nonce);
1014 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::NONCE_TABLE_NAME .
' ' .
1015 'WHERE (consumer_pk = :id) AND (value = :value)';
1016 $query = $this->db->prepare($sql);
1017 $id = $nonce->getPlatform()->getRecordId();
1018 $query->bindValue(
'id', $id, \PDO::PARAM_STR);
1019 $value = $nonce->getValue();
1020 $query->bindValue(
'value', $value, \PDO::PARAM_STR);
1028### AccessToken methods
1040 if (parent::useMemcache()) {
1041 $ok = parent::loadAccessToken($accessToken);
1044 $consumer_pk = $accessToken->getPlatform()->getRecordId();
1045 $sql =
"SELECT scopes, token, expires, created, updated FROM {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
1046 'WHERE (consumer_pk = :consumer_pk)';
1047 $query = $this->db->prepare($sql);
1048 $query->bindValue(
'consumer_pk', $consumer_pk, \PDO::PARAM_INT);
1050 $row = $query->fetch(\PDO::FETCH_ASSOC);
1051 if ($row !==
false) {
1052 $row = array_change_key_case($row);
1054 if (!is_array($scopes)) {
1057 $accessToken->scopes = $scopes;
1058 $accessToken->token = $row[
'token'];
1059 $accessToken->expires = strtotime($row[
'expires']);
1060 $accessToken->created = strtotime($row[
'created']);
1061 $accessToken->updated = strtotime($row[
'updated']);
1079 if (parent::useMemcache()) {
1080 $ok = parent::saveAccessToken($accessToken);
1082 $consumer_pk = $accessToken->getPlatform()->getRecordId();
1083 $scopes = json_encode($accessToken->scopes, JSON_UNESCAPED_SLASHES);
1084 $token = $accessToken->token;
1085 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $accessToken->expires);
1087 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1088 if (empty($accessToken->created)) {
1089 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
1090 '(consumer_pk, scopes, token, expires, created, updated) ' .
1091 'VALUES (:consumer_pk, :scopes, :token, :expires, :created, :updated)';
1092 $query = $this->db->prepare($sql);
1093 $query->bindValue(
'consumer_pk', $consumer_pk, \PDO::PARAM_INT);
1094 $query->bindValue(
'scopes', $scopes, \PDO::PARAM_STR);
1095 $query->bindValue(
'token', $token, \PDO::PARAM_STR);
1096 $query->bindValue(
'expires', $expires, \PDO::PARAM_STR);
1097 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
1098 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1100 $sql =
'UPDATE ' . $this->dbTableNamePrefix . static::ACCESS_TOKEN_TABLE_NAME .
' ' .
1101 'SET scopes = :scopes, token = :token, expires = :expires, updated = :updated ' .
1102 'WHERE consumer_pk = :consumer_pk';
1103 $query = $this->db->prepare($sql);
1104 $query->bindValue(
'scopes', $scopes, \PDO::PARAM_STR);
1105 $query->bindValue(
'token', $token, \PDO::PARAM_STR);
1106 $query->bindValue(
'expires', $expires, \PDO::PARAM_STR);
1107 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1108 $query->bindValue(
'consumer_pk', $consumer_pk, \PDO::PARAM_INT);
1117### ResourceLinkShareKey methods
1132 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
1133 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' WHERE expires <= :now';
1134 $query = $this->db->prepare($sql);
1135 $query->bindValue(
'now', $now, \PDO::PARAM_STR);
1139 $id = $shareKey->getId();
1140 $sql =
'SELECT resource_link_pk, auto_approve, expires ' .
1141 "FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1142 'WHERE share_key_id = :id';
1143 $query = $this->db->prepare($sql);
1144 $query->bindValue(
'id', $id, \PDO::PARAM_STR);
1146 $row = $query->fetch(\PDO::FETCH_ASSOC);
1147 if ($row !==
false) {
1148 $row = array_change_key_case($row);
1149 $shareKey->resourceLinkId = intval($row[
'resource_link_pk']);
1150 $shareKey->autoApprove = (intval($row[
'auto_approve']) === 1);
1151 $shareKey->expires = strtotime($row[
'expires']);
1168 $id = $shareKey->getId();
1169 $autoApprove = ($shareKey->autoApprove) ? 1 : 0;
1170 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
1171 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1172 '(share_key_id, resource_link_pk, auto_approve, expires) ' .
1173 'VALUES (:id, :prlid, :approve, :expires)';
1174 $query = $this->db->prepare($sql);
1175 $query->bindValue(
'id', $id, \PDO::PARAM_STR);
1176 $query->bindValue(
'prlid', $shareKey->resourceLinkId, \PDO::PARAM_INT);
1177 $query->bindValue(
'approve', $autoApprove, \PDO::PARAM_INT);
1178 $query->bindValue(
'expires', $expires, \PDO::PARAM_STR);
1193 $id = $shareKey->getId();
1194 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' WHERE share_key_id = :id';
1195 $query = $this->db->prepare($sql);
1196 $query->bindValue(
'id', $id, \PDO::PARAM_STR);
1200 $shareKey->initialize();
1207### UserResult Result methods
1220 if (!is_null($userresult->getRecordId())) {
1221 $id = $userresult->getRecordId();
1222 $sql =
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1223 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1224 'WHERE (user_result_pk = :id)';
1225 $query = $this->db->prepare($sql);
1226 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
1228 $id = $userresult->getResourceLink()->getRecordId();
1230 $sql =
'SELECT user_result_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1231 "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1232 'WHERE (resource_link_pk = :id) AND (lti_user_id = :u_id)';
1233 $query = $this->db->prepare($sql);
1234 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
1235 $query->bindValue(
'u_id', $uid, \PDO::PARAM_STR);
1238 $row = $query->fetch(\PDO::FETCH_ASSOC);
1239 if ($row !==
false) {
1240 $row = array_change_key_case($row);
1241 $userresult->setRecordId(intval($row[
'user_result_pk']));
1242 $userresult->setResourceLinkId(intval($row[
'resource_link_pk']));
1243 $userresult->ltiUserId = $row[
'lti_user_id'];
1244 $userresult->ltiResultSourcedId = $row[
'lti_result_sourcedid'];
1245 $userresult->created = strtotime($row[
'created']);
1246 $userresult->updated = strtotime($row[
'updated']);
1264 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1265 if (is_null($userresult->created)) {
1266 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' (resource_link_pk, ' .
1267 'lti_user_id, lti_result_sourcedid, created, updated) ' .
1268 'VALUES (:rlid, :u_id, :sourcedid, :created, :updated)';
1269 $query = $this->db->prepare($sql);
1270 $query->bindValue(
'rlid', $userresult->getResourceLink()->getRecordId(), \PDO::PARAM_INT);
1272 $query->bindValue(
'sourcedid', $userresult->ltiResultSourcedId, \PDO::PARAM_STR);
1273 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
1274 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1276 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1277 'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
1278 'WHERE (user_result_pk = :id)';
1279 $query = $this->db->prepare($sql);
1280 $query->bindValue(
'sourcedid', $userresult->ltiResultSourcedId, \PDO::PARAM_STR);
1281 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1282 $query->bindValue(
'id', $userresult->getRecordId(), \PDO::PARAM_INT);
1286 if (is_null($userresult->created)) {
1287 $userresult->setRecordId($this->
getLastInsertId(static::USER_RESULT_TABLE_NAME));
1288 $userresult->created = $time;
1290 $userresult->updated = $time;
1305 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME .
' ' .
1306 'WHERE (user_result_pk = :id)';
1307 $query = $this->db->prepare($sql);
1308 $query->bindValue(
'id', $userresult->getRecordId(), \PDO::PARAM_INT);
1312 $userresult->initialize();
1332 if (!is_null($tool->getRecordId())) {
1333 $sql =
'SELECT tool_pk, name, consumer_key, secret, ' .
1334 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1335 'lti_version, signature_method, settings, enabled, ' .
1336 'enable_from, enable_until, last_access, created, updated ' .
1337 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1338 'WHERE tool_pk = :id';
1339 $query = $this->db->prepare($sql);
1340 $id = $tool->getRecordId();
1341 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
1342 } elseif (!empty($tool->initiateLoginUrl)) {
1343 $sql =
'SELECT tool_pk, name, consumer_key, secret, ' .
1344 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1345 'lti_version, signature_method, settings, enabled, ' .
1346 'enable_from, enable_until, last_access, created, updated ' .
1347 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1348 'WHERE initiate_login_url = :initiate_login_url';
1349 $query = $this->db->prepare($sql);
1350 $query->bindValue(
'initiate_login_url', $tool->initiateLoginUrl, \PDO::PARAM_STR);
1352 $sql =
'SELECT tool_pk, name, consumer_key, secret, ' .
1353 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1354 'lti_version, signature_method, settings, enabled, ' .
1355 'enable_from, enable_until, last_access, created, updated ' .
1356 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1357 'WHERE consumer_key = :key';
1358 $query = $this->db->prepare($sql);
1359 $consumer_key = $tool->getKey();
1360 $query->bindValue(
'key', $consumer_key, \PDO::PARAM_STR);
1364 $row = $query->fetch(\PDO::FETCH_ASSOC);
1365 $ok = ($row !==
false);
1368 $row = array_change_key_case($row);
1369 $tool->setRecordId(intval($row[
'tool_pk']));
1370 $tool->name = $row[
'name'];
1371 $tool->setkey($row[
'consumer_key']);
1372 $tool->secret = $row[
'secret'];
1373 $tool->messageUrl = $row[
'message_url'];
1374 $tool->initiateLoginUrl = $row[
'initiate_login_url'];
1376 if (!is_array($tool->redirectionUris)) {
1377 $tool->redirectionUris = array();
1379 $tool->rsaKey = $row[
'public_key'];
1380 $tool->ltiVersion = $row[
'lti_version'];
1381 $tool->signatureMethod = $row[
'signature_method'];
1383 if (!is_array($settings)) {
1384 $settings = array();
1386 $tool->setSettings($settings);
1387 $tool->enabled = (intval($row[
'enabled']) === 1);
1388 $tool->enableFrom =
null;
1389 if (!is_null($row[
'enable_from'])) {
1390 $tool->enableFrom = strtotime($row[
'enable_from']);
1392 $tool->enableUntil =
null;
1393 if (!is_null($row[
'enable_until'])) {
1394 $tool->enableUntil = strtotime($row[
'enable_until']);
1396 $tool->lastAccess =
null;
1397 if (!is_null($row[
'last_access'])) {
1398 $tool->lastAccess = strtotime($row[
'last_access']);
1400 $tool->created = strtotime($row[
'created']);
1401 $tool->updated = strtotime($row[
'updated']);
1418 $id = $tool->getRecordId();
1419 $consumer_key = $tool->getKey();
1420 $enabled = ($tool->enabled) ? 1 : 0;
1421 $redirectionUrisValue = json_encode($tool->redirectionUris);
1423 $settingsValue = json_encode($tool->getSettings());
1426 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1428 if (!is_null($tool->enableFrom)) {
1429 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableFrom);
1432 if (!is_null($tool->enableUntil)) {
1433 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $tool->enableUntil);
1436 if (!is_null($tool->lastAccess)) {
1437 $last = date($this->dateFormat, $tool->lastAccess);
1440 $sql =
"INSERT INTO {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' (name, consumer_key, secret, ' .
1441 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1442 'lti_version, signature_method, settings, enabled, enable_from, enable_until, ' .
1443 'last_access, created, updated) ' .
1444 'VALUES (:name, :key, :secret, ' .
1445 ':message_url, :initiate_login_url, :redirection_uris, :public_key, ' .
1446 ':lti_version, :signature_method, :settings, :enabled, :enable_from, :enable_until, ' .
1447 ':last_access, :created, :updated)';
1448 $query = $this->db->prepare($sql);
1449 $query->bindValue(
'name', $tool->name, \PDO::PARAM_STR);
1450 $query->bindValue(
'key', $consumer_key, \PDO::PARAM_STR);
1451 $query->bindValue(
'secret', $tool->secret, \PDO::PARAM_STR);
1452 $query->bindValue(
'message_url', $tool->messageUrl, \PDO::PARAM_STR);
1453 $query->bindValue(
'initiate_login_url', $tool->initiateLoginUrl, \PDO::PARAM_STR);
1454 $query->bindValue(
'redirection_uris', $redirectionUrisValue, \PDO::PARAM_STR);
1455 $query->bindValue(
'public_key', $tool->rsaKey, \PDO::PARAM_STR);
1456 $query->bindValue(
'lti_version', $tool->ltiVersion, \PDO::PARAM_STR);
1457 $query->bindValue(
'signature_method', $tool->signatureMethod, \PDO::PARAM_STR);
1458 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
1459 $query->bindValue(
'enabled', $enabled, \PDO::PARAM_INT);
1460 $query->bindValue(
'enable_from', $from, \PDO::PARAM_STR);
1461 $query->bindValue(
'enable_until', $until, \PDO::PARAM_STR);
1462 $query->bindValue(
'last_access', $last, \PDO::PARAM_STR);
1463 $query->bindValue(
'created', $now, \PDO::PARAM_STR);
1464 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1466 $sql =
"UPDATE {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' SET ' .
1467 'name = :name, consumer_key = :key, secret= :secret, ' .
1468 'message_url = :message_url, initiate_login_url = :initiate_login_url, redirection_uris = :redirection_uris, public_key = :public_key, ' .
1469 'lti_version = :lti_version, signature_method = :signature_method, settings = :settings, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, ' .
1470 'last_access = :last_access, updated = :updated ' .
1471 'WHERE tool_pk = :id';
1472 $query = $this->db->prepare($sql);
1473 $query->bindValue(
'name', $tool->name, \PDO::PARAM_STR);
1474 $query->bindValue(
'key', $consumer_key, \PDO::PARAM_STR);
1475 $query->bindValue(
'secret', $tool->secret, \PDO::PARAM_STR);
1476 $query->bindValue(
'message_url', $tool->messageUrl, \PDO::PARAM_STR);
1477 $query->bindValue(
'initiate_login_url', $tool->initiateLoginUrl, \PDO::PARAM_STR);
1478 $query->bindValue(
'redirection_uris', $redirectionUrisValue, \PDO::PARAM_STR);
1479 $query->bindValue(
'public_key', $tool->rsaKey, \PDO::PARAM_STR);
1480 $query->bindValue(
'lti_version', $tool->ltiVersion, \PDO::PARAM_STR);
1481 $query->bindValue(
'signature_method', $tool->signatureMethod, \PDO::PARAM_STR);
1482 $query->bindValue(
'settings', $settingsValue, \PDO::PARAM_STR);
1483 $query->bindValue(
'enabled', $enabled, \PDO::PARAM_INT);
1484 $query->bindValue(
'enable_from', $from, \PDO::PARAM_STR);
1485 $query->bindValue(
'enable_until', $until, \PDO::PARAM_STR);
1486 $query->bindValue(
'last_access', $last, \PDO::PARAM_STR);
1487 $query->bindValue(
'updated', $now, \PDO::PARAM_STR);
1488 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
1494 $tool->created = $time;
1496 $tool->updated = $time;
1511 $id = $tool->getRecordId();
1513 $sql =
"DELETE FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1514 'WHERE tool_pk = :id';
1515 $query = $this->db->prepare($sql);
1516 $query->bindValue(
'id', $id, \PDO::PARAM_INT);
1520 $tool->initialize();
1535 $sql =
'SELECT tool_pk, name, consumer_key, secret, ' .
1536 'message_url, initiate_login_url, redirection_uris, public_key, ' .
1537 'lti_version, signature_method, settings, enabled, ' .
1538 'enable_from, enable_until, last_access, created, updated ' .
1539 "FROM {$this->dbTableNamePrefix}" . static::TOOL_TABLE_NAME .
' ' .
1541 $query = $this->db->prepare($sql);
1542 $ok = ($query !==
false);
1549 while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
1550 $row = array_change_key_case($row);
1551 $tool =
new Tool($this);
1552 $tool->setRecordId(intval($row[
'tool_pk']));
1553 $tool->name = $row[
'name'];
1554 $tool->setkey($row[
'consumer_key']);
1555 $tool->secret = $row[
'secret'];
1556 $tool->messageUrl = $row[
'message_url'];
1557 $tool->initiateLoginUrl = $row[
'initiate_login_url'];
1559 if (!is_array($tool->redirectionUris)) {
1560 $tool->redirectionUris = array();
1562 $tool->rsaKey = $row[
'public_key'];
1563 $tool->ltiVersion = $row[
'lti_version'];
1564 $tool->signatureMethod = $row[
'signature_method'];
1566 if (!is_array($settings)) {
1567 $settings = array();
1569 $tool->setSettings($settings);
1570 $tool->enabled = (intval($row[
'enabled']) === 1);
1571 $tool->enableFrom =
null;
1572 if (!is_null($row[
'enable_from'])) {
1573 $tool->enableFrom = strtotime($row[
'enable_from']);
1575 $tool->enableUntil =
null;
1576 if (!is_null($row[
'enable_until'])) {
1577 $tool->enableUntil = strtotime($row[
'enable_until']);
1579 $tool->lastAccess =
null;
1580 if (!is_null($row[
'last_access'])) {
1581 $tool->lastAccess = strtotime($row[
'last_access']);
1583 $tool->created = strtotime($row[
'created']);
1584 $tool->updated = strtotime($row[
'updated']);
1606 return intval($this->db->lastInsertId());
1623 $ok = $query->execute();
1624 }
catch (\PDOException $e) {
1629 $query->debugDumpParams();
1630 $debug = ob_get_contents();
1632 $pos = strpos($debug,
'Sent SQL: [');
1633 if ($pos !==
false) {
1634 $debug = substr($debug, $pos + 11);
1635 $pos = strpos($debug,
'] ');
1636 if ($pos !==
false) {
1637 $n = substr($debug, 0, $pos);
1638 if (is_numeric($n)) {
1639 $sql = substr($debug, $pos + 2, intval($n));
1643 if (!$ok && $reportError) {
1644 Util::logError($sql . $this->errorInfoToString($query->errorInfo()));
1660 private function errorInfoToString($errorInfo)
1662 if (is_array($errorInfo) && (count($errorInfo) === 3)) {
1663 $errors = PHP_EOL .
"Error {$errorInfo[0]}/{$errorInfo[1]}: {$errorInfo[2]}";
Class to represent an HTTP message.
Class to represent a platform context.
Class to represent an LTI Data Connector for PDO connections.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
getLastInsertId($tableName)
Get the ID for the last record inserted into a table.
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 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.
executeQuery($sql, $query, $reportError=true)
Execute a database query.
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 $logLevel
Current logging level.
static logError($message, $showSource=true)
Log an error message.
const LOGLEVEL_DEBUG
Log all messages.
static jsonDecode($str, $associative=false)
Decode a JSON string.
const LOGLEVEL_ERROR
Log errors only.
static logDebug($message, $showSource=false)
Log a debug message.