19 declare(strict_types=1);
43 $this->database = $DIC->database();
47 $this->dbTableNamePrefix =
"";
61 $allowMultiple =
false;
62 $id = $platform->getRecordId();
63 $query =
'SELECT consumer_pk, name, consumer_key, secret, ' .
64 'platform_id, client_id, deployment_id, public_key, ' .
65 'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
66 'profile, tool_proxy, settings, protected, enabled, ' .
67 'enable_from, enable_until, last_access, created, updated, ext_consumer_id, ref_id ' .
68 'FROM lti2_consumer WHERE ';
70 $query .=
'consumer_pk = %s';
71 $types = array(
'integer');
73 } elseif (!empty($platform->platformId)) {
74 if (empty($platform->clientId)) {
75 $allowMultiple =
true;
76 $query .=
'(platform_id = %s)';
77 $types = array(
'text');
78 $values = array($platform->platformId);
79 } elseif (empty($platform->deploymentId)) {
80 $allowMultiple =
true;
81 $query .=
'(platform_id = %s) AND (client_id = %s)';
82 $types = array(
'text',
'text');
83 $values = array($platform->platformId, $platform->clientId);
85 $query .=
'(platform_id = %s) AND (client_id = %s) AND (deployment_id = %s)';
86 $types = array(
'text',
'text',
'text');
87 $values = array($platform->platformId, $platform->clientId, $platform->deploymentId);
89 } elseif (!empty($platform->getKey())) {
90 $key = $platform->getKey();
91 $query .=
'consumer_key = %s';
92 $types = array(
'text');
93 $values = array($key);
107 $res = $this->database->queryF($query, $types, $values);
108 while ($row = $this->database->fetchObject(
$res)) {
109 $platform->setRecordId(intval($row->consumer_pk));
110 $platform->name = $row->name;
111 $platform->setkey((
string) $row->consumer_key);
112 $platform->secret = $row->secret;
113 $platform->platformId = $row->platform_id;
114 $platform->clientId = $row->client_id;
115 $platform->deploymentId = $row->deployment_id;
116 $platform->rsaKey = $row->public_key;
117 $platform->ltiVersion = isset($row->lti_version) ?
LtiVersion::from($row->lti_version) : LtiVersion::V1;
118 $platform->signatureMethod = $row->signature_method;
119 $platform->consumerName = $row->consumer_name;
120 $platform->consumerVersion = $row->consumer_version;
121 $platform->consumerGuid = $row->consumer_guid;
122 $platform->profile = json_decode((
string) $row->profile);
123 $platform->toolProxy = $row->tool_proxy;
124 $settings = json_decode($row->settings,
true);
125 if (!is_array($settings)) {
126 $settings = @unserialize($row->settings);
128 if (!is_array($settings)) {
131 $platform->setSettings($settings);
132 $platform->protected = (intval($row->protected) === 1);
133 $platform->enabled = (intval($row->enabled) === 1);
134 $platform->enableFrom =
null;
135 if (!is_null($row->enable_from)) {
136 $platform->enableFrom = strtotime($row->enable_from);
138 $platform->enableUntil =
null;
139 if (!is_null($row->enable_until)) {
140 $platform->enableUntil = strtotime($row->enable_until);
142 $platform->lastAccess =
null;
143 if (!is_null($row->last_access)) {
144 $platform->lastAccess = strtotime($row->last_access);
146 $platform->created = strtotime($row->created);
147 $platform->updated = strtotime($row->updated);
149 $platform->setExtConsumerId(intval($row->ext_consumer_id));
150 $platform->setRefId((
int) $row->ref_id);
158 $this->fixPlatformSettings($platform,
false);
198 $query =
'SELECT * from lti_ext_consumer where id = ' .
$ilDB->quote($platform->
getExtConsumerId(),
'integer');
205 $platform->
setRole((
int) $row->role);
206 $platform->
setActive((
bool) $row->active);
312 $query =
'SELECT consumer_pk from lti2_consumer ' .
314 'AND ref_id = ' . $db->quote($platform->
getRefId(),
'integer');
315 $res = $db->query($query);
317 return (
int) $row->consumer_pk;
474 $new_id =
$ilDB->nextId(
'lti_ext_consumer');
475 $query =
'INSERT INTO lti_ext_consumer (title, description, prefix, user_language, role, id, active) ' .
476 'VALUES (%s, %s, %s, %s, %s, %s, %s)';
477 $types = [
"text",
"text",
"text",
"text",
"integer",
"integer",
'integer'];
487 $ilDB->manipulateF($query, $types, $values);
492 $query =
'update lti_ext_consumer set ' .
493 'title = ' .
$ilDB->quote($platform->
getTitle(),
'text') .
', ' .
495 'prefix = ' .
$ilDB->quote($platform->
getPrefix(),
'text') .
', ' .
496 'user_language = ' .
$ilDB->quote($platform->
getLanguage(),
'text') .
', ' .
497 'role = ' .
$ilDB->quote($platform->
getRole(),
'integer') .
', ' .
498 'active = ' .
$ilDB->quote((
int) $platform->
getActive(),
'integer') .
' ' .
500 $ilDB->manipulate($query);
514 $id = $platform->getRecordId();
515 $key = $platform->getKey();
516 $protected = ($platform->protected) ? 1 : 0;
517 $enabled = ($platform->enabled) ? 1 : 0;
518 $profile = (!empty($platform->profile)) ? json_encode($platform->profile) :
null;
520 $this->fixPlatformSettings($platform,
true);
521 $settingsValue = json_encode($platform->getSettings());
522 $this->fixPlatformSettings($platform,
false);
524 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
526 if (!is_null($platform->enableFrom)) {
527 $from = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
530 if (!is_null($platform->enableUntil)) {
531 $until = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
534 if (!is_null($platform->lastAccess)) {
535 $last = date($this->dateFormat, $platform->lastAccess);
538 $platform->name = $platform->
getTitle();
540 $platform->setRecordId(
$ilDB->nextId(
'lti2_consumer'));
541 $id = $platform->getRecordId();
542 $platform->created = $time;
543 $platform->updated = $time;
546 $query =
'INSERT INTO lti2_consumer (consumer_key, name, ' .
547 'secret, lti_version, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' .
548 'enable_from, enable_until, last_access, created, updated, consumer_pk, ext_consumer_id, ref_id, platform_id, client_id, deployment_id, public_key) ' .
549 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)';
550 $types = array(
"text",
575 $values = array($key,
578 $platform->ltiVersion->value,
579 $platform->consumerName,
580 $platform->consumerVersion,
581 $platform->consumerGuid,
583 $platform->toolProxy,
595 (string) $platform->platformId,
597 $platform->deploymentId,
600 $ilDB->manipulateF($query, $types, $values);
602 $platform->updated = $time;
604 $query =
'UPDATE lti2_consumer SET ' .
605 'consumer_key = %s, name = %s, ' .
606 'secret= %s, lti_version = %s, consumer_name = %s, consumer_version = %s, consumer_guid = %s, ' .
607 'profile = %s, tool_proxy = %s, settings = %s, protected = %s, enabled = %s, ' .
608 'enable_from = %s, enable_until = %s, last_access = %s, updated = %s, ' .
609 'platform_id = %s, client_id = %s, deployment_id = %s, public_key = %s ' .
610 'WHERE consumer_pk = %s';
611 $types = array(
"text",
633 $values = array($key,
636 $platform->ltiVersion->value,
637 $platform->consumerName,
638 $platform->consumerVersion,
639 $platform->consumerGuid,
641 $platform->toolProxy,
649 $platform->platformId,
651 $platform->deploymentId,
655 $ilDB->manipulateF($query, $types, $values);
668 $query =
'DELETE FROM lti_ext_consumer WHERE id = %s';
669 $types = array(
"integer");
671 $ilDB->manipulateF($query, $types, $values);
673 $query =
'DELETE FROM lti_ext_consumer_otype WHERE consumer_id = %s';
674 $types = array(
"integer");
676 $ilDB->manipulateF($query, $types, $values);
678 $query =
'DELETE FROM lti2_consumer WHERE ext_consumer_id = %s';
679 $types = array(
"integer");
681 $ilDB->manipulateF($query, $types, $values);
698 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME .
' WHERE consumer_pk = %s';
699 $types = array(
"integer");
700 $values = array($platform->getRecordId());
701 $ilDB->manipulateF($query, $types, $values);
704 $query =
'DELETE sk ' .
705 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
706 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
707 'WHERE rl.consumer_pk = %s';
708 $types = array(
"integer");
709 $values = array($platform->getRecordId());
710 $ilDB->manipulateF($query, $types, $values);
713 $query =
'DELETE sk ' .
714 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
715 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
716 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
717 'WHERE c.consumer_pk = %s';
718 $types = array(
"integer");
719 $values = array($platform->getRecordId());
720 $ilDB->manipulateF($query, $types, $values);
723 $query =
'DELETE u ' .
724 "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME .
' u ' .
725 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
726 'WHERE rl.consumer_pk = %s';
727 $types = array(
"integer");
728 $values = array($platform->getRecordId());
729 $ilDB->manipulateF($query, $types, $values);
732 $query =
'DELETE u ' .
733 "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME .
' u ' .
734 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
735 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
736 'WHERE c.consumer_pk = %s';
737 $types = array(
"integer");
738 $values = array($platform->getRecordId());
739 $ilDB->manipulateF($query, $types, $values);
742 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' prl ' .
743 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
744 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
745 'WHERE rl.consumer_pk = %s';
746 $types = array(
"integer");
747 $values = array($platform->getRecordId());
748 $ilDB->manipulateF($query, $types, $values);
751 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' prl ' .
752 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
753 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
754 'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
755 'WHERE c.consumer_pk = %s';
756 $types = array(
"integer");
757 $values = array($platform->getRecordId());
758 $ilDB->manipulateF($query, $types, $values);
761 $query =
'DELETE rl ' .
762 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ' .
763 'WHERE rl.consumer_pk = %s';
764 $types = array(
"integer");
765 $values = array($platform->getRecordId());
766 $ilDB->manipulateF($query, $types, $values);
769 $query =
'DELETE rl ' .
770 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ' .
771 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ON rl.context_pk = c.context_pk ' .
772 'WHERE c.consumer_pk = %s';
773 $types = array(
"integer");
774 $values = array($platform->getRecordId());
775 $ilDB->manipulateF($query, $types, $values);
778 $query =
'DELETE c ' .
779 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ' .
780 'WHERE c.consumer_pk = %s';
781 $types = array(
"integer");
782 $values = array($platform->getRecordId());
783 $ilDB->manipulateF($query, $types, $values);
786 $query =
'DELETE c ' .
787 "FROM {$this->dbTableNamePrefix}" . DataConnector::PLATFORM_TABLE_NAME .
' c ' .
788 'WHERE c.consumer_pk = %s';
789 $types = array(
"integer");
790 $values = array($platform->getRecordId());
791 $ilDB->manipulateF($query, $types, $values);
794 $platform->initialize();
808 $platforms = array();
809 $query =
'SELECT * from lti_ext_consumer ';
813 $platform->setExtConsumerId((
int) $row->id);
814 $platform->setTitle($row->title);
815 $platform->setDescription($row->description);
816 $platform->setPrefix($row->prefix);
817 $platform->setLanguage($row->user_language);
818 $platform->setRole((
int) $row->role);
819 $platform->setActive((
bool) $row->active);
820 $platforms[] = $platform;
828 # Load all tool consumers from the database 836 $platforms = array();
837 $query =
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
838 'consumer_name, consumer_version, consumer_guid, ' .
839 'profile, tool_proxy, settings, protected, enabled, ' .
840 'enable_from, enable_until, last_access, created, updated, ' .
841 'title, description, prefix, user_language, role, local_role_always_member, default_skin ' .
842 'FROM lti2_consumer, lti_ext_consumer ' .
843 'WHERE lti_ext_consumer.id = consumer_pk';
855 while ($row =
$ilDB->fetchObject(
$res)) {
858 $platform->setRecordId(intval($row->consumer_pk));
859 $platform->name = $row->name;
860 $platform->secret = $row->secret;
861 $platform->ltiVersion = $row->lti_version;
862 $platform->consumerName = $row->consumer_name;
863 $platform->consumerVersion = $row->consumer_version;
864 $platform->consumerGuid = $row->consumer_guid;
865 $platform->profile = json_decode($row->profile);
866 $platform->toolProxy = $row->tool_proxy;
867 $settings = unserialize($row->settings);
868 if (!is_array($settings)) {
871 $platform->setSettings($settings);
872 $platform->protected = (intval($row->protected) === 1);
873 $platform->enabled = (intval($row->enabled) === 1);
874 $platform->enableFrom =
null;
875 if (!is_null($row->enable_from)) {
876 $platform->enableFrom = strtotime($row->enable_from);
878 $platform->enableUntil =
null;
879 if (!is_null($row->enable_until)) {
880 $platform->enableUntil = strtotime($row->enable_until);
882 $platform->lastAccess =
null;
883 if (!is_null($row->last_access)) {
884 $platform->lastAccess = strtotime($row->last_access);
886 $platform->created = strtotime($row->created);
887 $platform->updated = strtotime($row->updated);
889 $platform->setTitle($row->title);
890 $platform->setDescription($row->description);
891 $platform->setPrefix($row->prefix);
892 $platform->setLanguage($row->user_language);
893 $platform->setRole($row->role);
896 $platform->setKey($row->consumer_key256);
897 $platforms[] = $platform;
905 ### ToolProxy methods 945 if (!empty($context->getRecordId())) {
946 $query =
'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
947 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' ' .
948 'WHERE (context_pk = %s)';
949 $types = array(
"integer");
950 $values = array($context->getRecordId());
952 $query =
'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
953 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' ' .
954 'WHERE (consumer_pk = %s) AND (lti_context_id = %s)';
955 $types = array(
"integer",
"text");
956 $values = array($context->getPlatform()->getRecordId(), $context->ltiContextId);
958 $rs_context =
$ilDB->queryF($query, $types, $values);
960 $row =
$ilDB->fetchObject($rs_context);
962 $context->setRecordId(intval($row->context_pk));
963 $context->setPlatformId(intval($row->consumer_pk));
964 $context->ltiContextId = $row->lti_context_id;
965 $settings = json_decode($row->settings);
966 if (!is_array($settings)) {
969 $context->setSettings($settings);
970 $context->created = strtotime($row->created);
971 $context->updated = strtotime($row->updated);
989 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
991 $settingsValue = json_encode($context->getSettings());
992 $id = $context->getRecordId();
993 $platform_pk = $context->getPlatform()->getRecordId();
995 $context->setRecordId(
$ilDB->nextId(DataConnector::CONTEXT_TABLE_NAME));
996 $id = $context->getRecordId();
997 $context->created = $time;
999 $query =
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
1000 ' (context_pk, consumer_pk, lti_context_id, settings, created, updated) ' .
1001 'VALUES (%s, %s, %s, %s, %s, %s)';
1002 $types = array(
"integer",
"integer",
"text",
"text",
"timestamp",
"timestamp");
1003 $values = array($id, $platform_pk, $context->ltiContextId, $settingsValue, $now, $now);
1005 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' SET ' .
1006 'lti_context_id = %s, settings = %s, ' .
1008 'WHERE (consumer_pk = %s) AND (context_pk = %s)';
1009 $types = array(
"text",
"text",
"timestamp",
"integer",
"integer");
1010 $values = array($context->ltiContextId, $settingsValue, $now, $platform_pk, $id);
1012 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1014 $context->updated = $time;
1030 $query =
'DELETE sk ' .
1031 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' sk ' .
1032 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
1033 'WHERE rl.context_pk = %s';
1034 $types = array(
"integer");
1035 $values = array($context->getRecordId());
1036 $ilDB->manipulateF($query, $types, $values);
1039 $query =
'DELETE u ' .
1040 "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME .
' u ' .
1041 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
1042 'WHERE rl.context_pk = %s';
1043 $types = array(
"integer");
1044 $values = array($context->getRecordId());
1045 $ilDB->manipulateF($query, $types, $values);
1048 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' prl ' .
1049 "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
1050 'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' .
1051 'WHERE rl.context_pk = %s';
1052 $types = array(
"integer");
1053 $values = array($context->getRecordId());
1054 $ilDB->manipulateF($query, $types, $values);
1057 $query =
'DELETE rl ' .
1058 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' rl ' .
1059 'WHERE rl.context_pk = %s';
1060 $types = array(
"integer");
1061 $values = array($context->getRecordId());
1062 $ilDB->manipulateF($query, $types, $values);
1065 $query =
'DELETE c ' .
1066 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ' .
1067 'WHERE c.context_pk = %s';
1068 $types = array(
"integer");
1069 $values = array($context->getRecordId());
1070 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1072 $context->initialize();
1079 ### ResourceLink methods 1092 $id = $resourceLink->getRecordId();
1095 if (!is_null(
$id)) {
1096 $query =
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
1097 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' ' .
1098 'WHERE (resource_link_pk = %s)';
1099 $types = array(
"integer");
1100 $values = array(
$id);
1101 } elseif (!is_null($resourceLink->getContext())) {
1102 $rid = $resourceLink->getId();
1103 $cid = $resourceLink->getContext()->getRecordId();
1104 $query =
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
1105 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' r ' .
1106 'WHERE (r.lti_resource_link_id = %s) AND ((r.context_pk = %s) OR (r.consumer_pk IN (' .
1107 'SELECT c.consumer_pk ' .
1108 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
' c ' .
1109 'WHERE (c.context_pk = %s))))';
1110 $types = array(
"text",
"integer",
"integer");
1111 $values = array($rid, $cid, $cid);
1113 $id = $resourceLink->getPlatform()->getRecordId();
1114 $rid = $resourceLink->getId();
1115 $query =
'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
1116 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' r LEFT OUTER JOIN ' .
1117 $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME .
' c ON r.context_pk = c.context_pk ' .
1118 ' WHERE ((r.consumer_pk = %s) OR (c.consumer_pk = %s)) AND (lti_resource_link_id = %s)';
1119 $types = array(
"integer",
"integer",
"text");
1120 $values = array(
$id,
$id, $rid);
1122 $this->
logger->debug(
"loadResourceLink id = " .
$id .
" rid =" . $rid .
" cid =" . $cid .
" query = " . $query);
1123 $rsContext =
$ilDB->queryF($query, $types, $values);
1125 $row =
$ilDB->fetchObject($rsContext);
1127 $resourceLink->setRecordId(intval($row->resource_link_pk));
1128 if (!is_null($row->context_pk)) {
1129 $resourceLink->setContextId(intval($row->context_pk));
1131 $resourceLink->setContextId(
null);
1133 if (!is_null($row->consumer_pk)) {
1134 $resourceLink->setPlatformId(intval($row->consumer_pk));
1136 $resourceLink->setPlatformId(
null);
1139 $resourceLink->ltiResourceLinkId = $row->lti_resource_link_id;
1140 $settings = json_decode($row->settings,
true);
1141 if (!is_array($settings)) {
1142 $settings = @unserialize($row->settings);
1144 if (!is_array($settings)) {
1145 $settings = array();
1147 $resourceLink->setSettings($settings);
1148 if (!is_null($row->primary_resource_link_pk)) {
1149 $resourceLink->primaryResourceLinkId = intval($row->primary_resource_link_pk);
1151 $resourceLink->primaryResourceLinkId =
null;
1153 $resourceLink->shareApproved = (is_null($row->share_approved)) ?
null : (intval($row->share_approved) === 1);
1154 $resourceLink->created = strtotime($row->created);
1155 $resourceLink->updated = strtotime($row->updated);
1174 if (is_null($resourceLink->shareApproved)) {
1176 } elseif ($resourceLink->shareApproved) {
1181 if (empty($resourceLink->primaryResourceLinkId) || $resourceLink->primaryResourceLinkId ==
'0') {
1182 $primaryResourceLinkId =
null;
1183 $resourceLink->primaryResourceLinkId =
null;
1185 $primaryResourceLinkId = strval($resourceLink->primaryResourceLinkId);
1188 $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
1189 $settingsValue = serialize($resourceLink->getSettings());
1190 if (!is_null($resourceLink->getContext())) {
1192 $platformId = strval($resourceLink->getPlatform()->getRecordId());
1193 $contextId = strval($resourceLink->getContext()->getRecordId());
1194 } elseif (!is_null($resourceLink->getContextId())) {
1196 $platformId = strval($resourceLink->getPlatform()->getRecordId());
1197 $contextId = strval($resourceLink->getContextId());
1199 $platformId = strval($resourceLink->getPlatform()->getRecordId());
1202 $id = $resourceLink->getRecordId();
1204 $resourceLink->setRecordId(
$ilDB->nextId(DataConnector::RESOURCE_LINK_TABLE_NAME));
1205 $id = $resourceLink->getRecordId();
1206 $resourceLink->created = $time;
1207 $query =
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' (resource_link_pk, consumer_pk, context_pk, ' .
1208 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
1209 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)';
1210 $types = array(
"integer",
1220 $values = array(
$id,
1223 $resourceLink->getId(),
1225 $primaryResourceLinkId,
1230 } elseif (!is_null($contextId)) {
1231 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' SET ' .
1232 'consumer_pk = %s, lti_resource_link_id = %s, settings = %s, ' .
1233 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
1234 'WHERE (context_pk = %s) AND (resource_link_pk = %s)';
1235 $types = array(
"integer",
"text",
"text",
"integer",
"integer",
"timestamp",
"integer",
"integer");
1236 $values = array($platformId,
1237 $resourceLink->getId(),
1239 $primaryResourceLinkId,
1246 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' SET ' .
1247 'context_pk = %s, lti_resource_link_id = %s, settings = %s, ' .
1248 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
1249 'WHERE (consumer_pk = %s) AND (resource_link_pk = %s)';
1250 $types = array(
"integer",
"text",
"text",
"integer",
"integer",
"timestamp",
"integer",
"integer");
1251 $values = array($contextId,
1252 $resourceLink->getId(),
1254 $primaryResourceLinkId,
1261 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1262 $this->
logger->debug(
'Update resource link with query: ' . $query);
1268 $resourceLink->updated = $time;
1284 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1285 'WHERE (resource_link_pk = %s)';
1286 $types = array(
"integer");
1287 $values = array($resourceLink->getRecordId());
1288 $ok =
$ilDB->manipulateF($query, $types, $values);
1292 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1293 'WHERE (resource_link_pk = %s)';
1294 $types = array(
"integer");
1295 $values = array($resourceLink->getRecordId());
1296 $ok =
$ilDB->manipulateF($query, $types, $values);
1301 $query =
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' ' .
1302 'SET primary_resource_link_pk = NULL ' .
1303 'WHERE (primary_resource_link_pk = %s)';
1304 $types = array(
"integer");
1305 $values = array($resourceLink->getRecordId());
1306 $ok =
$ilDB->manipulateF($query, $types, $values);
1311 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME .
' ' .
1312 'WHERE (resource_link_pk = %s)';
1313 $types = array(
"integer");
1314 $values = array($resourceLink->getRecordId());
1315 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1319 $resourceLink->initialize();
1335 ResourceLink $resourceLink,
1411 ### PlatformNonce methods 1426 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
1427 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME .
" WHERE expires <= %s";
1428 $types = array(
"timestamp");
1429 $values = array($now);
1430 $ilDB->manipulateF($query, $types, $values);
1432 $query =
"SELECT value AS T FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME .
' WHERE (consumer_pk = %s) AND (value = %s)';
1433 $types = array(
"integer",
"text");
1434 $values = array($nonce->getPlatform()->getRecordId(), $nonce->getValue());
1435 $rs_nonce =
$ilDB->queryF($query, $types, $values);
1437 $row =
$ilDB->fetchObject($rs_nonce);
1455 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
1456 $query =
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME .
" (consumer_pk, value, expires) VALUES (%s, %s, %s)";
1457 $types = array(
"integer",
"text",
"timestamp");
1458 $values = array($nonce->getPlatform()->getRecordId(), $nonce->getValue(), $expires);
1459 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1466 ### ResourceLinkShareKey methods 1482 $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
1483 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
" WHERE expires <= '%s'";
1484 $types = array(
"timestamp");
1485 $values = array($now);
1486 $ilDB->manipulateF($query, $types, $values);
1490 $id = $shareKey->getId();
1491 $query =
'SELECT resource_link_pk, auto_approve, expires ' .
1492 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1493 "WHERE share_key_id = %s";
1494 $types = array(
"text");
1495 $values = array(
$id);
1496 $rsShareKey =
$ilDB->queryF($query, $types, $values);
1498 $row =
$ilDB->fetchObject($rsShareKey);
1499 if ($row && (intval($row->resource_link_pk) === $shareKey->resourceLinkId)) {
1500 $shareKey->autoApprove = (intval($row->auto_approve) === 1);
1501 $shareKey->expires = strtotime($row->expires);
1519 if ($shareKey->autoApprove) {
1524 $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
1525 $query =
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
' ' .
1526 '(share_key_id, resource_link_pk, auto_approve, expires) ' .
1527 "VALUES (%s, %s, %s, %s)";
1528 $types = array(
"text",
"integer",
"integer",
"timestamp");
1529 $values = array($shareKey->getId(), $shareKey->resourceLinkId, $approve, $expires);
1530 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1544 $query =
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME .
" WHERE share_key_id = %s";
1545 $types = array(
"text");
1546 $values = array($shareKey->getId());
1547 $ok = (bool)
$ilDB->manipulateF($query, $types, $values);
1550 $shareKey->initialize();
1569 $id = $userresult->getRecordId();
1570 if (!is_null(
$id)) {
1571 $query =
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1572 'FROM ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1573 'WHERE user_pk = ' .
$ilDB->quote(
$id,
'integer');
1575 $rid = $userresult->getResourceLink()->getRecordId();
1576 $uid = $userresult->getId(ToolProvider\Tool::ID_SCOPE_ID_ONLY);
1578 $query =
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
1579 'FROM ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1580 'WHERE resource_link_pk = ' .
$ilDB->quote($rid,
'integer') .
' ' .
1581 'AND lti_user_id = ' .
$ilDB->quote($uid,
'text');
1584 $this->
logger->debug(
'Loading user with query: ' . $query);
1590 $userresult->setRecordId((
int) $row->user_pk);
1591 $userresult->setResourceLinkId((
int) $row->resource_link_pk);
1592 $userresult->ltiUserId = (string) $row->lti_user_id;
1593 $userresult->ltiResultSourcedId = (
string) $row->lti_result_sourcedid;
1594 $userresult->created = strtotime($row->created);
1595 $userresult->updated = strtotime($row->updated);
1599 $this->
logger->error((
string) $e);
1613 $this->
logger->info(
'Save user called with ' . $userresult->created);
1616 $now = date($this->dateFormat .
' ' . $this->timeFormat, $time);
1617 if (is_null($userresult->created)) {
1619 $userresult->setRecordId(
$ilDB->nextId($this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME));
1620 $userresult->created = $time;
1621 $rid = $userresult->getResourceLink()->getRecordId();
1622 $uid = $userresult->getId(ToolProvider\Tool::ID_SCOPE_ID_ONLY);
1623 $query =
'INSERT INTO ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1624 '(user_pk,resource_link_pk,lti_user_id, lti_result_sourcedid, created, updated) ' .
1626 $ilDB->quote($userresult->getRecordId(),
'integer') .
', ' .
1627 $ilDB->quote($rid,
'integer') .
', ' .
1628 $ilDB->quote($uid,
'text') .
', ' .
1629 $ilDB->quote($userresult->ltiResultSourcedId,
'text') .
', ' .
1630 $ilDB->quote($now,
'text') .
', ' .
1631 $ilDB->quote($now,
'text') .
1634 $query =
'UPDATE ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1635 'SET lti_result_sourcedid = ' .
$ilDB->quote($userresult->ltiResultSourcedId,
'text') .
', ' .
1636 'updated = ' .
$ilDB->quote($now,
'text') .
' ' .
1637 'WHERE user_pk = ' .
$ilDB->quote($userresult->getRecordId(),
'integer');
1640 $this->
logger->debug(
'Saving user data with query: ' . $query);
1644 $ilDB->manipulate($query);
1645 $userresult->updated = $time;
1648 $this->
logger->error($e->getMessage());
1663 $query =
'DELETE from ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME .
' ' .
1664 'WHERE user_pk = ' .
$ilDB->quote($user->getRecordId(),
'integer');
1668 $ilDB->manipulate($query);
1669 $user->initialize();
1672 $this->
logger->error((
string) $e);
1688 int $a_ext_consumer,
1695 $query =
'select rl.resource_link_pk ' .
1696 'from lti2_user_result ur join lti2_resource_link rl on rl.resource_link_pk = ur.resource_link_pk ' .
1697 'join lti2_consumer c on rl.consumer_pk = c.consumer_pk ' .
1698 'join lti_ext_consumer ec on c.ext_consumer_id = ec.id ' .
1699 'where c.enabled = ' . $db->quote(1,
'integer') .
' ' .
1700 'and ref_id = ' . $db->quote($a_ref_id,
'integer') .
' ' .
1701 'and ur.lti_user_id = ' . $db->quote($a_lti_user,
'text') .
' ' .
1702 'and ec.id = ' . $db->quote($a_ext_consumer,
'integer');
1703 $logger->debug($query);
1704 $resource_links = [];
1706 $res = $db->query($query);
1708 $resource_links[] = $row->resource_link_pk;
1711 $logger->error(
'Query execution failed with message: ' . $e->getMessage());
1713 return $resource_links;
1725 $query =
'select lti_user_id, rl.resource_link_pk, ec.id, ref_id ' .
1726 'from lti2_resource_link rl join lti2_user_result ur on rl.resource_link_pk = ur.resource_link_pk ' .
1727 'join lti2_consumer c on rl.consumer_pk = c.consumer_pk ' .
1728 'join lti_ext_consumer ec on ext_consumer_id = ec.id ' .
1729 'where c.enabled = ' . $db->quote(1,
'integer') .
' ' .
1731 $res = $db->query($query);
1735 $results[$row->id .
'__' . $row->lti_user_id][] = $row->resource_link_pk .
'__' . $row->ref_id;
1743 return $dataConnector;
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
deleteContext(Context $context)
Delete context object.
getUserResultSourcedIDsResourceLink(ResourceLink $resourceLink, bool $localOnly, ?IdScope $idScope)
Get array of user objects.
saveResourceLink(ResourceLink $resourceLink)
Save resource link object.
static getLogger(string $a_component_id)
Get component logger.
deleteResourceLinkShareKey(ResourceLinkShareKey $shareKey)
Delete resource link share key object.
deleteToolConsumer(DataConnectorPlatform $platform)
Delete tool consumer object.
quote($value, string $type)
saveUserResult(User $userresult)
Save user object.
loadPlatform(Platform $platform)
Load platform object.
loadUserResult(User $userresult)
Load user object.
static getDataConnector(mixed $db=null, string $dbTableNamePrefix='', string $type='')
lookupRecordIdByGlobalSettingsAndRefId(ilLTIPlatform $platform)
Load extended tool consumer object with ILIAS extension.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
lookupResourcesForAllUsersSinceDate(ilDateTime $since)
loadResourceLinkShareKey(ResourceLinkShareKey $shareKey)
Load resource link share key object.
savePlatformNonce(PlatformNonce $nonce)
Save nonce object.
loadResourceLink(ResourceLink $resourceLink)
Load resource link object.
getGlobalToolConsumerSettings()
Get global consumer settings.
lookupResourcesForUserObjectRelation(int $a_ref_id, string $a_lti_user, int $a_ext_consumer, ?ilDateTime $since=null)
Lookup resources for user object relation.
loadPlatformNonce(PlatformNonce $nonce)
Get array of shares defined for this resource link.
loadContext(Context $context)
Load context object.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
saveToolConsumerILIAS(ilLTIPlatform $platform)
Save extended tool consumer object with ILIAS extensions.
saveContext(Context $context)
Save context object.
saveResourceLinkShareKey(ResourceLinkShareKey $shareKey)
Save resource link share key object.
saveGlobalToolConsumerSettings(ilLTIPlatform $platform)
Save platform object.
Component logger with individual log levels by component id.
deleteResourceLink(ResourceLink $resourceLink)
Delete resource link object.
deleteUser(DataConnectorUser $user)
Delete user object.
loadGlobalToolConsumerSettings(ilLTIPlatform $platform)
Load tool consumer settings.
__construct()
ilLTIDataConnector constructor.
deleteGlobalToolConsumerSettings(ilLTIPlatform $platform)
Delete global tool consumer settings.