19 declare(strict_types=1);
    43         $this->database = $DIC->database();
    47         $this->dbTableNamePrefix = 
"";
    62         $allowMultiple = 
false;
    63         $id = $platform->getRecordId();
    64         $query = 
'SELECT consumer_pk, name, consumer_key, secret, ' .
    65             'platform_id, client_id, deployment_id, public_key, ' .
    66             'lti_version, signature_method, consumer_name, consumer_version, consumer_guid, ' .
    67             'profile, tool_proxy, settings, protected, enabled, ' .
    68             'enable_from, enable_until, last_access, created, updated, ext_consumer_id, ref_id ' .
    69             'FROM lti2_consumer WHERE ';
    71             $query .= 
'consumer_pk = %s';
    72             $types = array(
'integer');
    74         } elseif (!empty($platform->platformId)) {
    75             if (empty($platform->clientId)) {
    76                 $allowMultiple = 
true;
    77                 $query .= 
'(platform_id = %s)';
    78                 $types = array(
'text');
    79                 $values = array($platform->platformId);
    80             } elseif (empty($platform->deploymentId)) {
    81                 $allowMultiple = 
true;
    82                 $query .= 
'(platform_id = %s) AND (client_id = %s)';
    83                 $types = array(
'text',
'text');
    84                 $values = array($platform->platformId, $platform->clientId);
    86                 $query .= 
'(platform_id = %s) AND (client_id = %s) AND (deployment_id = %s)';
    87                 $types = array(
'text',
'text',
'text');
    88                 $values = array($platform->platformId, $platform->clientId, $platform->deploymentId);
    90         } elseif (!empty($platform->getKey())) {
    91             $key = $platform->getKey();
    92             $query .= 
'consumer_key = %s';
    93             $types = array(
'text');
    94             $values = array($key);
   108         $res = $this->database->queryF($query, $types, $values);
   109         while ($row = $this->database->fetchObject(
$res)) {
   110             $platform->setRecordId(intval($row->consumer_pk));
   111             $platform->name = $row->name;
   112             $platform->setkey((
string) $row->consumer_key);
   113             $platform->secret = $row->secret;
   114             $platform->platformId = $row->platform_id;
   115             $platform->clientId = $row->client_id;
   116             $platform->deploymentId = $row->deployment_id;
   117             $platform->rsaKey = $row->public_key;
   118             $platform->ltiVersion = isset($row->lti_version) ? 
LtiVersion::from($row->lti_version) : LtiVersion::V1;
   119             $platform->signatureMethod = $row->signature_method;
   120             $platform->consumerName = $row->consumer_name;
   121             $platform->consumerVersion = $row->consumer_version;
   122             $platform->consumerGuid = $row->consumer_guid;
   123             $platform->profile = json_decode((
string) $row->profile);
   124             $platform->toolProxy = $row->tool_proxy;
   125             $settings = json_decode($row->settings, 
true);
   126             if (!is_array($settings)) {
   127                 $settings = @unserialize($row->settings);  
   129             if (!is_array($settings)) {
   132             $platform->setSettings($settings);
   133             $platform->protected = (intval($row->protected) === 1);
   134             $platform->enabled = (intval($row->enabled) === 1);
   135             $platform->enableFrom = null;
   136             if (!is_null($row->enable_from)) {
   137                 $platform->enableFrom = strtotime($row->enable_from);
   139             $platform->enableUntil = null;
   140             if (!is_null($row->enable_until)) {
   141                 $platform->enableUntil = strtotime($row->enable_until);
   143             $platform->lastAccess = null;
   144             if (!is_null($row->last_access)) {
   145                 $platform->lastAccess = strtotime($row->last_access);
   147             $platform->created = strtotime($row->created);
   148             $platform->updated = strtotime($row->updated);
   154                 $platform->
setRefId((
int) $row->ref_id);
   163             $this->fixPlatformSettings($platform, 
false);
   204         $query = 
'SELECT * from lti_ext_consumer where id = ' . 
$ilDB->quote($platform->
getExtConsumerId(), 
'integer');
   211             $platform->
setRole((
int) $row->role);
   212             $platform->
setActive((
bool) $row->active);
   318         $query = 
'SELECT consumer_pk from lti2_consumer ' .
   320             'AND ref_id = ' . $db->quote($platform->
getRefId(), 
'integer');
   321         $res = $db->query($query);
   323             return (
int) $row->consumer_pk;
   480             $new_id = 
$ilDB->nextId(
'lti_ext_consumer');
   481             $query = 
'INSERT INTO lti_ext_consumer (title, description, prefix, user_language, role, id, active) ' .
   482                 'VALUES (%s, %s, %s, %s, %s, %s, %s)';
   483             $types = [
"text", 
"text", 
"text", 
"text", 
"integer", 
"integer", 
'integer'];
   493             $ilDB->manipulateF($query, $types, $values);
   498             $query = 
'update lti_ext_consumer set ' .
   499                 'title  = ' . 
$ilDB->quote($platform->
getTitle(), 
'text') . 
', ' .
   501                 'prefix = ' . 
$ilDB->quote($platform->
getPrefix(), 
'text') . 
', ' .
   502                 'user_language = ' . 
$ilDB->quote($platform->
getLanguage(), 
'text') . 
', ' .
   503                 'role = ' . 
$ilDB->quote($platform->
getRole(), 
'integer') . 
', ' .
   504                 'active = ' . 
$ilDB->quote((
int) $platform->
getActive(), 
'integer') . 
' ' .
   506             $ilDB->manipulate($query);
   520         $id = $platform->getRecordId();
   521         $key = $platform->getKey();
   522         $protected = ($platform->protected) ? 1 : 0;
   523         $enabled = ($platform->enabled) ? 1 : 0;
   524         $profile = (!empty($platform->profile)) ? json_encode($platform->profile) : null;
   526         $this->fixPlatformSettings($platform, 
true);
   527         $settingsValue = json_encode($platform->getSettings());
   528         $this->fixPlatformSettings($platform, 
false);
   530         $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
   532         if (!is_null($platform->enableFrom)) {
   533             $from = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableFrom);
   536         if (!is_null($platform->enableUntil)) {
   537             $until = date(
"{$this->dateFormat} {$this->timeFormat}", $platform->enableUntil);
   540         if (!is_null($platform->lastAccess)) {
   541             $last = date($this->dateFormat, $platform->lastAccess);
   544         $platform->name = $platform->
getTitle();
   546             $platform->setRecordId(
$ilDB->nextId(
'lti2_consumer'));
   547             $id = $platform->getRecordId();
   548             $platform->created = $time;
   549             $platform->updated = $time;
   552             $query = 
'INSERT INTO lti2_consumer (consumer_key, name, ' .
   553                 'secret, lti_version, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' .
   554                 'enable_from, enable_until, last_access, created, updated, consumer_pk, ext_consumer_id, ref_id, platform_id, client_id, deployment_id, public_key) ' .
   555                 '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)';
   556             $types = array(
"text",
   581             $values = array($key,
   584                             $platform->ltiVersion->value,
   585                             $platform->consumerName,
   586                             $platform->consumerVersion,
   587                             $platform->consumerGuid,
   589                             $platform->toolProxy,
   601                             (string) $platform->platformId,
   603                             $platform->deploymentId,
   606             $ilDB->manipulateF($query, $types, $values);
   608             $platform->updated = $time;
   610             $query = 
'UPDATE lti2_consumer SET ' .
   611                 'consumer_key = %s, name = %s, ' .
   612                 'secret= %s, lti_version = %s, consumer_name = %s, consumer_version = %s, consumer_guid = %s, ' .
   613                 'profile = %s, tool_proxy = %s, settings = %s, protected = %s, enabled = %s, ' .
   614                 'enable_from = %s, enable_until = %s, last_access = %s, updated = %s, ' .
   615                 'platform_id = %s, client_id = %s, deployment_id = %s, public_key = %s ' .
   616                 'WHERE consumer_pk = %s';
   617             $types = array(
"text",
   639             $values = array($key,
   642                             $platform->ltiVersion->value,
   643                             $platform->consumerName,
   644                             $platform->consumerVersion,
   645                             $platform->consumerGuid,
   647                             $platform->toolProxy,
   655                             $platform->platformId,
   657                             $platform->deploymentId,
   661             $ilDB->manipulateF($query, $types, $values);
   674         $query = 
'DELETE FROM lti_ext_consumer WHERE id = %s';
   675         $types = array(
"integer");
   677         $ilDB->manipulateF($query, $types, $values);
   679         $query = 
'DELETE FROM lti_ext_consumer_otype WHERE consumer_id = %s';
   680         $types = array(
"integer");
   682         $ilDB->manipulateF($query, $types, $values);
   684         $query = 
'DELETE FROM lti2_consumer WHERE ext_consumer_id = %s';
   685         $types = array(
"integer");
   687         $ilDB->manipulateF($query, $types, $values);
   704         $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . 
' WHERE consumer_pk = %s';
   705         $types = array(
"integer");
   706         $values = array($platform->getRecordId());
   707         $ilDB->manipulateF($query, $types, $values);
   710         $query = 
'DELETE sk ' .
   711             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' sk ' .
   712             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
   713             'WHERE rl.consumer_pk = %s';
   714         $types = array(
"integer");
   715         $values = array($platform->getRecordId());
   716         $ilDB->manipulateF($query, $types, $values);
   719         $query = 
'DELETE sk ' .
   720             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' sk ' .
   721             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
   722             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ON rl.context_pk = c.context_pk ' .
   723             'WHERE c.consumer_pk = %s';
   724         $types = array(
"integer");
   725         $values = array($platform->getRecordId());
   726         $ilDB->manipulateF($query, $types, $values);
   729         $query = 
'DELETE u ' .
   730             "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . 
' u ' .
   731             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
   732             'WHERE rl.consumer_pk = %s';
   733         $types = array(
"integer");
   734         $values = array($platform->getRecordId());
   735         $ilDB->manipulateF($query, $types, $values);
   738         $query = 
'DELETE u ' .
   739             "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . 
' u ' .
   740             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
   741             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ON rl.context_pk = c.context_pk ' .
   742             'WHERE c.consumer_pk = %s';
   743         $types = array(
"integer");
   744         $values = array($platform->getRecordId());
   745         $ilDB->manipulateF($query, $types, $values);
   748         $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' prl ' .
   749             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
   750             'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
   751             'WHERE rl.consumer_pk = %s';
   752         $types = array(
"integer");
   753         $values = array($platform->getRecordId());
   754         $ilDB->manipulateF($query, $types, $values);
   757         $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' prl ' .
   758             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
   759             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ON rl.context_pk = c.context_pk ' .
   760             'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
   761             'WHERE c.consumer_pk = %s';
   762         $types = array(
"integer");
   763         $values = array($platform->getRecordId());
   764         $ilDB->manipulateF($query, $types, $values);
   767         $query = 
'DELETE rl ' .
   768             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ' .
   769             'WHERE rl.consumer_pk = %s';
   770         $types = array(
"integer");
   771         $values = array($platform->getRecordId());
   772         $ilDB->manipulateF($query, $types, $values);
   775         $query = 
'DELETE rl ' .
   776             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ' .
   777             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ON rl.context_pk = c.context_pk ' .
   778             'WHERE c.consumer_pk = %s';
   779         $types = array(
"integer");
   780         $values = array($platform->getRecordId());
   781         $ilDB->manipulateF($query, $types, $values);
   784         $query = 
'DELETE c ' .
   785             "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ' .
   786             'WHERE c.consumer_pk = %s';
   787         $types = array(
"integer");
   788         $values = array($platform->getRecordId());
   789         $ilDB->manipulateF($query, $types, $values);
   792         $query = 
'DELETE c ' .
   793             "FROM {$this->dbTableNamePrefix}" . DataConnector::PLATFORM_TABLE_NAME . 
' c ' .
   794             'WHERE c.consumer_pk = %s';
   795         $types = array(
"integer");
   796         $values = array($platform->getRecordId());
   797         $ilDB->manipulateF($query, $types, $values);
   800         $platform->initialize();
   814         $platforms = array();
   815         $query = 
'SELECT * from lti_ext_consumer ';
   819             $platform->setExtConsumerId((
int) $row->id);
   820             $platform->setTitle($row->title);
   821             $platform->setDescription($row->description);
   822             $platform->setPrefix($row->prefix);
   823             $platform->setLanguage($row->user_language);
   824             $platform->setRole((
int) $row->role);
   825             $platform->setActive((
bool) $row->active);
   826             $platforms[] = $platform;
   834     #    Load all tool consumers from the database   842         $platforms = array();
   843         $query = 
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
   844             'consumer_name, consumer_version, consumer_guid, ' .
   845             'profile, tool_proxy, settings, protected, enabled, ' .
   846             'enable_from, enable_until, last_access, created, updated, ' .
   847             'title, description, prefix, user_language, role, local_role_always_member, default_skin ' .
   848             'FROM lti2_consumer, lti_ext_consumer ' .
   849             'WHERE lti_ext_consumer.id = consumer_pk';
   861         while ($row = 
$ilDB->fetchObject(
$res)) {
   864             $platform->setRecordId(intval($row->consumer_pk));
   865             $platform->name = $row->name;
   866             $platform->secret = $row->secret;
   867             $platform->ltiVersion = $row->lti_version;
   868             $platform->consumerName = $row->consumer_name;
   869             $platform->consumerVersion = $row->consumer_version;
   870             $platform->consumerGuid = $row->consumer_guid;
   871             $platform->profile = json_decode($row->profile);
   872             $platform->toolProxy = $row->tool_proxy;
   873             $settings = unserialize($row->settings);
   874             if (!is_array($settings)) {
   877             $platform->setSettings($settings);
   878             $platform->protected = (intval($row->protected) === 1);
   879             $platform->enabled = (intval($row->enabled) === 1);
   880             $platform->enableFrom = null;
   881             if (!is_null($row->enable_from)) {
   882                 $platform->enableFrom = strtotime($row->enable_from);
   884             $platform->enableUntil = null;
   885             if (!is_null($row->enable_until)) {
   886                 $platform->enableUntil = strtotime($row->enable_until);
   888             $platform->lastAccess = null;
   889             if (!is_null($row->last_access)) {
   890                 $platform->lastAccess = strtotime($row->last_access);
   892             $platform->created = strtotime($row->created);
   893             $platform->updated = strtotime($row->updated);
   895             $platform->setTitle($row->title);
   896             $platform->setDescription($row->description);
   897             $platform->setPrefix($row->prefix);
   898             $platform->setLanguage($row->user_language);
   899             $platform->setRole($row->role);
   902             $platform->setKey($row->consumer_key256);
   903             $platforms[] = $platform;
   911     ###  ToolProxy methods   951         if (!empty($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 (context_pk = %s)';
   955             $types = array(
"integer");
   956             $values = array($context->getRecordId());
   958             $query = 
'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
   959                 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' ' .
   960                 'WHERE (consumer_pk = %s) AND (lti_context_id = %s)';
   961             $types = array(
"integer", 
"text");
   962             $values = array($context->getPlatform()->getRecordId(), $context->ltiContextId);
   964         $rs_context = 
$ilDB->queryF($query, $types, $values);
   966             $row = 
$ilDB->fetchObject($rs_context);
   968                 $context->setRecordId(intval($row->context_pk));
   969                 $context->setPlatformId(intval($row->consumer_pk));
   970                 $context->ltiContextId = $row->lti_context_id;
   971                 $settings = json_decode($row->settings);
   972                 if (!is_array($settings)) {
   975                 $context->setSettings($settings);
   976                 $context->created = strtotime($row->created);
   977                 $context->updated = strtotime($row->updated);
   995         $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
   997         $settingsValue = json_encode($context->getSettings());
   998         $id = $context->getRecordId();
   999         $platform_pk = $context->getPlatform()->getRecordId();
  1001             $context->setRecordId(
$ilDB->nextId(DataConnector::CONTEXT_TABLE_NAME));
  1002             $id = $context->getRecordId();
  1003             $context->created = $time;
  1005             $query = 
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME .
  1006                 ' (context_pk, consumer_pk, lti_context_id, settings, created, updated) ' .
  1007                 'VALUES (%s, %s, %s, %s, %s, %s)';
  1008             $types = array(
"integer", 
"integer", 
"text", 
"text", 
"timestamp", 
"timestamp");
  1009             $values = array($id, $platform_pk, $context->ltiContextId, $settingsValue, $now, $now);
  1011             $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' SET ' .
  1012                 'lti_context_id = %s, settings = %s, ' .
  1014                 'WHERE (consumer_pk = %s) AND (context_pk = %s)';
  1015             $types = array(
"text", 
"text", 
"timestamp", 
"integer", 
"integer");
  1016             $values = array($context->ltiContextId, $settingsValue, $now, $platform_pk, $id);
  1018         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1020             $context->updated = $time;
  1036         $query = 
'DELETE sk ' .
  1037             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' sk ' .
  1038             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
  1039             'WHERE rl.context_pk = %s';
  1040         $types = array(
"integer");
  1041         $values = array($context->getRecordId());
  1042         $ilDB->manipulateF($query, $types, $values);
  1045         $query = 
'DELETE u ' .
  1046             "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . 
' u ' .
  1047             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON u.resource_link_pk = rl.resource_link_pk ' .
  1048             'WHERE rl.context_pk = %s';
  1049         $types = array(
"integer");
  1050         $values = array($context->getRecordId());
  1051         $ilDB->manipulateF($query, $types, $values);
  1054         $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' prl ' .
  1055             "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
  1056             'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' .
  1057             'WHERE rl.context_pk = %s';
  1058         $types = array(
"integer");
  1059         $values = array($context->getRecordId());
  1060         $ilDB->manipulateF($query, $types, $values);
  1063         $query = 
'DELETE rl ' .
  1064             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' rl ' .
  1065             'WHERE rl.context_pk = %s';
  1066         $types = array(
"integer");
  1067         $values = array($context->getRecordId());
  1068         $ilDB->manipulateF($query, $types, $values);
  1071         $query = 
'DELETE c ' .
  1072             "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ' .
  1073             'WHERE c.context_pk = %s';
  1074         $types = array(
"integer");
  1075         $values = array($context->getRecordId());
  1076         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1078             $context->initialize();
  1085     ###  ResourceLink methods  1098         $id = $resourceLink->getRecordId();
  1101         if (!is_null(
$id)) {
  1102             $query = 
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
  1103                 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' ' .
  1104                 'WHERE (resource_link_pk = %s)';
  1105             $types = array(
"integer");
  1106             $values = array(
$id);
  1107         } elseif (!is_null($resourceLink->getContext())) {
  1108             $rid = $resourceLink->getId();
  1109             $cid = $resourceLink->getContext()->getRecordId();
  1110             $query = 
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
  1111                 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' r ' .
  1112                 'WHERE (r.lti_resource_link_id = %s) AND ((r.context_pk = %s) OR (r.consumer_pk IN (' .
  1113                 'SELECT c.consumer_pk ' .
  1114                 "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . 
' c ' .
  1115                 'WHERE (c.context_pk = %s))))';
  1116             $types = array(
"text", 
"integer", 
"integer");
  1117             $values = array($rid, $cid, $cid);
  1119             $id = $resourceLink->getPlatform()->getRecordId();
  1120             $rid = $resourceLink->getId();
  1121             $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 ' .
  1122                 "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' r LEFT OUTER JOIN ' .
  1123                 $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . 
' c ON r.context_pk = c.context_pk ' .
  1124                 ' WHERE ((r.consumer_pk = %s) OR (c.consumer_pk = %s)) AND (lti_resource_link_id = %s)';
  1125             $types = array(
"integer", 
"integer", 
"text");
  1126             $values = array(
$id, 
$id, $rid);
  1128         $this->
logger->debug(
"loadResourceLink id = " . 
$id . 
" rid =" . $rid . 
" cid =" . $cid . 
" query = " . $query);
  1129         $rsContext = 
$ilDB->queryF($query, $types, $values);
  1131             $row = 
$ilDB->fetchObject($rsContext);
  1133                 $resourceLink->setRecordId(intval($row->resource_link_pk));
  1134                 if (!is_null($row->context_pk)) {
  1135                     $resourceLink->setContextId(intval($row->context_pk));
  1137                     $resourceLink->setContextId(null);
  1139                 if (!is_null($row->consumer_pk)) {
  1140                     $resourceLink->setPlatformId(intval($row->consumer_pk));
  1142                     $resourceLink->setPlatformId(null);
  1145                 $resourceLink->ltiResourceLinkId = $row->lti_resource_link_id;
  1146                 $settings = json_decode($row->settings, 
true);
  1147                 if (!is_array($settings)) {
  1148                     $settings = @unserialize($row->settings);  
  1150                 if (!is_array($settings)) {
  1151                     $settings = array();
  1153                 $resourceLink->setSettings($settings);
  1154                 if (!is_null($row->primary_resource_link_pk)) {
  1155                     $resourceLink->primaryResourceLinkId = intval($row->primary_resource_link_pk);
  1157                     $resourceLink->primaryResourceLinkId = null;
  1159                 $resourceLink->shareApproved = (is_null($row->share_approved)) ? null : (intval($row->share_approved) === 1);
  1160                 $resourceLink->created = strtotime($row->created);
  1161                 $resourceLink->updated = strtotime($row->updated);
  1180         if (is_null($resourceLink->shareApproved)) {
  1182         } elseif ($resourceLink->shareApproved) {
  1187         if (empty($resourceLink->primaryResourceLinkId) || $resourceLink->primaryResourceLinkId == 
'0') {
  1188             $primaryResourceLinkId = null;
  1189             $resourceLink->primaryResourceLinkId = null; 
  1191             $primaryResourceLinkId = strval($resourceLink->primaryResourceLinkId);
  1194         $now = date(
"{$this->dateFormat} {$this->timeFormat}", $time);
  1195         $settingsValue = serialize($resourceLink->getSettings());
  1196         if (!is_null($resourceLink->getContext())) {
  1198             $platformId = strval($resourceLink->getPlatform()->getRecordId());
  1199             $contextId = strval($resourceLink->getContext()->getRecordId());
  1200         } elseif (!is_null($resourceLink->getContextId())) {
  1202             $platformId = strval($resourceLink->getPlatform()->getRecordId());
  1203             $contextId = strval($resourceLink->getContextId());
  1205             $platformId = strval($resourceLink->getPlatform()->getRecordId());
  1208         $id = $resourceLink->getRecordId();
  1210             $resourceLink->setRecordId(
$ilDB->nextId(DataConnector::RESOURCE_LINK_TABLE_NAME));
  1211             $id = $resourceLink->getRecordId();
  1212             $resourceLink->created = $time;
  1213             $query = 
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' (resource_link_pk, consumer_pk, context_pk, ' .
  1214                 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
  1215                 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)';
  1216             $types = array(
"integer",
  1226             $values = array(
$id,
  1229                             $resourceLink->getId(),
  1231                             $primaryResourceLinkId,
  1236         } elseif (!is_null($contextId)) {
  1237             $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' SET ' .
  1238                 'consumer_pk = %s, lti_resource_link_id = %s, settings = %s, ' .
  1239                 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
  1240                 'WHERE (context_pk = %s) AND (resource_link_pk = %s)';
  1241             $types = array(
"integer", 
"text", 
"text", 
"integer", 
"integer", 
"timestamp", 
"integer", 
"integer");
  1242             $values = array($platformId,
  1243                             $resourceLink->getId(),
  1245                             $primaryResourceLinkId,
  1252             $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' SET ' .
  1253                 'context_pk = %s, lti_resource_link_id = %s, settings = %s, ' .
  1254                 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' .
  1255                 'WHERE (consumer_pk = %s) AND (resource_link_pk = %s)';
  1256             $types = array(
"integer", 
"text", 
"text", 
"integer", 
"integer", 
"timestamp", 
"integer", 
"integer");
  1257             $values = array($contextId,
  1258                             $resourceLink->getId(),
  1260                             $primaryResourceLinkId,
  1267         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1268         $this->
logger->debug(
'Update resource link with query: ' . $query);
  1274             $resourceLink->updated = $time;
  1290         $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' ' .
  1291             'WHERE (resource_link_pk = %s)';
  1292         $types = array(
"integer");
  1293         $values = array($resourceLink->getRecordId());
  1294         $ok = 
$ilDB->manipulateF($query, $types, $values);
  1298             $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1299                 'WHERE (resource_link_pk = %s)';
  1300             $types = array(
"integer");
  1301             $values = array($resourceLink->getRecordId());
  1302             $ok = 
$ilDB->manipulateF($query, $types, $values);
  1307             $query = 
"UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' ' .
  1308                 'SET primary_resource_link_pk = NULL ' .
  1309                 'WHERE (primary_resource_link_pk = %s)';
  1310             $types = array(
"integer");
  1311             $values = array($resourceLink->getRecordId());
  1312             $ok = 
$ilDB->manipulateF($query, $types, $values);
  1317             $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . 
' ' .
  1318                 'WHERE (resource_link_pk = %s)';
  1319             $types = array(
"integer");
  1320             $values = array($resourceLink->getRecordId());
  1321             $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1325             $resourceLink->initialize();
  1341         ResourceLink $resourceLink,
  1417     ###  PlatformNonce methods  1432         $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
  1433         $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . 
" WHERE expires <= %s";
  1434         $types = array(
"timestamp");
  1435         $values = array($now);
  1436         $ilDB->manipulateF($query, $types, $values);
  1438         $query = 
"SELECT value AS T FROM {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . 
' WHERE (consumer_pk = %s) AND (value = %s)';
  1439         $types = array(
"integer", 
"text");
  1440         $values = array($nonce->getPlatform()->getRecordId(), $nonce->getValue());
  1441         $rs_nonce = 
$ilDB->queryF($query, $types, $values);
  1443             $row = 
$ilDB->fetchObject($rs_nonce);
  1461         $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
  1462         $query = 
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . 
" (consumer_pk, value, expires) VALUES (%s, %s, %s)";
  1463         $types = array(
"integer", 
"text", 
"timestamp");
  1464         $values = array($nonce->getPlatform()->getRecordId(), $nonce->getValue(), $expires);
  1465         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1472     ###  ResourceLinkShareKey methods  1488         $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
  1489         $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
" WHERE expires <= '%s'";
  1490         $types = array(
"timestamp");
  1491         $values = array($now);
  1492         $ilDB->manipulateF($query, $types, $values);
  1496         $id = $shareKey->getId();
  1497         $query = 
'SELECT resource_link_pk, auto_approve, expires ' .
  1498             "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' ' .
  1499             "WHERE share_key_id = %s";
  1500         $types = array(
"text");
  1501         $values = array(
$id);
  1502         $rsShareKey = 
$ilDB->queryF($query, $types, $values);
  1504             $row = 
$ilDB->fetchObject($rsShareKey);
  1505             if ($row && (intval($row->resource_link_pk) === $shareKey->resourceLinkId)) {
  1506                 $shareKey->autoApprove = (intval($row->auto_approve) === 1);
  1507                 $shareKey->expires = strtotime($row->expires);
  1525         if ($shareKey->autoApprove) {
  1530         $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
  1531         $query = 
"INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
' ' .
  1532             '(share_key_id, resource_link_pk, auto_approve, expires) ' .
  1533             "VALUES (%s, %s, %s, %s)";
  1534         $types = array(
"text", 
"integer", 
"integer", 
"timestamp");
  1535         $values = array($shareKey->getId(), $shareKey->resourceLinkId, $approve, $expires);
  1536         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1550         $query = 
"DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . 
" WHERE share_key_id = %s";
  1551         $types = array(
"text");
  1552         $values = array($shareKey->getId());
  1553         $ok = (bool) 
$ilDB->manipulateF($query, $types, $values);
  1556             $shareKey->initialize();
  1575         $id = $userresult->getRecordId();
  1576         if (!is_null(
$id)) {
  1577             $query = 
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
  1578                 'FROM ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1579                 'WHERE user_pk = ' . 
$ilDB->quote(
$id, 
'integer');
  1581             $rid = $userresult->getResourceLink()->getRecordId();
  1582             $uid = $userresult->getId(IdScope::IdOnly);
  1584             $query = 
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
  1585                 'FROM ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1586                 'WHERE resource_link_pk = ' . 
$ilDB->quote($rid, 
'integer') . 
' ' .
  1587                 'AND lti_user_id = ' . 
$ilDB->quote($uid, 
'text');
  1590         $this->
logger->debug(
'Loading user with query: ' . $query);
  1596                 $userresult->setRecordId((
int) $row->user_pk);
  1597                 $userresult->setResourceLinkId((
int) $row->resource_link_pk);
  1598                 $userresult->ltiUserId = (string) $row->lti_user_id;
  1599                 $userresult->ltiResultSourcedId = (
string) $row->lti_result_sourcedid;
  1600                 $userresult->created = strtotime($row->created);
  1601                 $userresult->updated = strtotime($row->updated);
  1605             $this->
logger->error((
string) $e);
  1619         $this->
logger->info(
'Save user called with ' . $userresult->created);
  1622         $now = date($this->dateFormat . 
' ' . $this->timeFormat, $time);
  1623         if (is_null($userresult->created)) {
  1625             $userresult->setRecordId(
$ilDB->nextId($this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME));
  1626             $userresult->created = $time;
  1627             $rid = $userresult->getResourceLink()->getRecordId();
  1628             $uid = $userresult->getId(IdScope::IdOnly);
  1629             $query = 
'INSERT INTO ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1630                 '(user_pk,resource_link_pk,lti_user_id, lti_result_sourcedid, created, updated) ' .
  1632                 $ilDB->quote($userresult->getRecordId(), 
'integer') . 
', ' .
  1633                 $ilDB->quote($rid, 
'integer') . 
', ' .
  1634                 $ilDB->quote($uid, 
'text') . 
', ' .
  1635                 $ilDB->quote($userresult->ltiResultSourcedId, 
'text') . 
', ' .
  1636                 $ilDB->quote($now, 
'text') . 
', ' .
  1637                 $ilDB->quote($now, 
'text') .
  1640             $query = 
'UPDATE ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1641                 'SET lti_result_sourcedid = ' . 
$ilDB->quote($userresult->ltiResultSourcedId, 
'text') . 
', ' .
  1642                 'updated = ' . 
$ilDB->quote($now, 
'text') . 
' ' .
  1643                 'WHERE user_pk = ' . 
$ilDB->quote($userresult->getRecordId(), 
'integer');
  1646         $this->
logger->debug(
'Saving user data with query: ' . $query);
  1650             $ilDB->manipulate($query);
  1651             $userresult->updated = $time;
  1654             $this->
logger->error($e->getMessage());
  1669         $query = 
'DELETE from ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . 
' ' .
  1670             'WHERE user_pk = ' . 
$ilDB->quote($user->getRecordId(), 
'integer');
  1674             $ilDB->manipulate($query);
  1675             $user->initialize();
  1678             $this->
logger->error((
string) $e);
  1694         int $a_ext_consumer,
  1701         $query = 
'select rl.resource_link_pk ' .
  1702             'from lti2_user_result ur join lti2_resource_link rl on rl.resource_link_pk = ur.resource_link_pk ' .
  1703             'join lti2_consumer c on rl.consumer_pk = c.consumer_pk ' .
  1704             'join lti_ext_consumer ec on c.ext_consumer_id = ec.id ' .
  1705             'where c.enabled = ' . $db->quote(1, 
'integer') . 
' ' .
  1706             'and ref_id = ' . $db->quote($a_ref_id, 
'integer') . 
' ' .
  1707             'and ur.lti_user_id = ' . $db->quote($a_lti_user, 
'text') . 
' ' .
  1708             'and ec.id = ' . $db->quote($a_ext_consumer, 
'integer');
  1709         $logger->debug($query);
  1710         $resource_links = [];
  1712             $res = $db->query($query);
  1714                 $resource_links[] = $row->resource_link_pk;
  1717             $logger->error(
'Query execution failed with message: ' . $e->getMessage());
  1719         return $resource_links;
  1731         $query = 
'select lti_user_id, rl.resource_link_pk, ec.id, ref_id ' .
  1732             'from lti2_resource_link rl join lti2_user_result ur on rl.resource_link_pk = ur.resource_link_pk ' .
  1733             'join lti2_consumer c on rl.consumer_pk = c.consumer_pk ' .
  1734             'join lti_ext_consumer ec on ext_consumer_id = ec.id ' .
  1735             'where c.enabled = ' . $db->quote(1, 
'integer') . 
' ' .
  1737         $res = $db->query($query);
  1741             $results[$row->id . 
'__' . $row->lti_user_id][] = $row->resource_link_pk . 
'__' . $row->ref_id;
  1749         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. 
 
lookupResourcesForUserObjectRelation(int $a_ref_id, string $a_lti_user, int $a_ext_consumer, ilDateTime $since=null)
Lookup resources for user object relation. 
 
deleteToolConsumer(DataConnectorPlatform $platform)
Delete tool consumer object. 
 
quote($value, string $type)
 
saveUserResult(User $userresult)
Save user 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. 
 
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. 
 
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. 
 
loadPlatform(Platform|ilLTIPlatform $platform)
Load platform object.