Skip to content

Commit 3460089

Browse files
committed
Enhance support for platforms
Added new functionality when used by a platform
1 parent c8a5a67 commit 3460089

14 files changed

+2215
-172
lines changed

sql/lti4-platform-mssql.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE lti2_tool (
2+
tool_pk int IDENTITY NOT NULL,
3+
name varchar(50) NOT NULL,
4+
consumer_key varchar(255) DEFAULT NULL,
5+
secret varchar(1024) DEFAULT NULL,
6+
message_url varchar(255) DEFAULT NULL,
7+
initiate_login_url varchar(255) DEFAULT NULL,
8+
redirection_uris text DEFAULT NULL,
9+
public_key text DEFAULT NULL,
10+
lti_version varchar(10) DEFAULT NULL,
11+
signature_method varchar(15) NOT NULL DEFAULT 'HMAC-SHA1',
12+
settings text DEFAULT NULL,
13+
enabled bit NOT NULL,
14+
enable_from datetime2 DEFAULT NULL,
15+
enable_until datetime2 DEFAULT NULL,
16+
last_access date DEFAULT NULL,
17+
created datetime2 NOT NULL,
18+
updated datetime2 NOT NULL,
19+
PRIMARY KEY (tool_pk),
20+
CONSTRAINT UC_lti2_tool_initiate_login_url UNIQUE (initiate_login_url ASC)
21+
);

sql/lti4-platform-mysql.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE lti2_tool (
2+
tool_pk int(11) NOT NULL AUTO_INCREMENT,
3+
name varchar(50) NOT NULL,
4+
consumer_key varchar(255) DEFAULT NULL,
5+
secret varchar(1024) DEFAULT NULL,
6+
message_url varchar(255) DEFAULT NULL,
7+
initiate_login_url varchar(255) DEFAULT NULL,
8+
redirection_uris text DEFAULT NULL,
9+
public_key text DEFAULT NULL,
10+
lti_version varchar(10) DEFAULT NULL,
11+
signature_method varchar(15) DEFAULT NULL,
12+
settings text DEFAULT NULL,
13+
enabled tinyint(1) NOT NULL,
14+
enable_from datetime DEFAULT NULL,
15+
enable_until datetime DEFAULT NULL,
16+
last_access date DEFAULT NULL,
17+
created datetime NOT NULL,
18+
updated datetime NOT NULL,
19+
PRIMARY KEY (tool_pk)
20+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21+
22+
ALTER TABLE lti2_tool
23+
ADD UNIQUE INDEX lti2_tool_initiate_login_url_UNIQUE (initiate_login_url ASC);

sql/lti4-platform-oracle.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE lti2_tool (
2+
tool_pk number GENERATED ALWAYS AS IDENTITY,
3+
name varchar(50) NOT NULL,
4+
consumer_key varchar(255) DEFAULT NULL,
5+
secret varchar(1024) DEFAULT NULL,
6+
message_url varchar(255) DEFAULT NULL,
7+
initiate_login_url varchar(255) DEFAULT NULL,
8+
redirection_uris clob DEFAULT NULL,
9+
public_key clob DEFAULT NULL,
10+
lti_version varchar(10) DEFAULT NULL,
11+
signature_method varchar(15) DEFAULT NULL,
12+
settings clob DEFAULT NULL,
13+
enabled number(1) NOT NULL,
14+
enable_from timestamp DEFAULT NULL,
15+
enable_until timestamp DEFAULT NULL,
16+
last_access date DEFAULT NULL,
17+
created timestamp NOT NULL,
18+
updated timestamp NOT NULL,
19+
CONSTRAINT lti2_tool_PK PRIMARY KEY (tool_pk)
20+
);
21+
22+
CREATE UNIQUE INDEX lti2_tool_initiate_login_url_UNIQUE
23+
ON lti2_tool (initiate_login_url);

sql/lti4-platform-pgsql.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE lti2_tool (
2+
tool_pk SERIAL,
3+
name varchar(50) NOT NULL,
4+
consumer_key varchar(255) DEFAULT NULL,
5+
secret varchar(1024) DEFAULT NULL,
6+
message_url varchar(255) DEFAULT NULL,
7+
initiate_login_url varchar(255) DEFAULT NULL,
8+
redirection_uris text DEFAULT NULL,
9+
public_key text DEFAULT NULL,
10+
lti_version varchar(10) DEFAULT NULL,
11+
signature_method varchar(15) NOT NULL DEFAULT 'HMAC-SHA1',
12+
settings text DEFAULT NULL,
13+
enabled boolean NOT NULL,
14+
enable_from timestamp DEFAULT NULL,
15+
enable_until timestamp DEFAULT NULL,
16+
last_access date DEFAULT NULL,
17+
created timestamp NOT NULL,
18+
updated timestamp NOT NULL,
19+
PRIMARY KEY (tool_pk),
20+
UNIQUE (initiate_login_url)
21+
);

src/DataConnector/DataConnector.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ceLTIc\LTI\ResourceLinkShareKey;
1010
use ceLTIc\LTI\Platform;
1111
use ceLTIc\LTI\UserResult;
12+
use ceLTIc\LTI\Tool;
1213
use ceLTIc\LTI\Util;
1314

1415
/**
@@ -66,6 +67,11 @@ class DataConnector
6667
*/
6768
const ACCESS_TOKEN_TABLE_NAME = 'lti2_access_token';
6869

70+
/**
71+
* Default name for database table used to store tools.
72+
*/
73+
const TOOL_TABLE_NAME = 'lti2_tool';
74+
6975
/**
7076
* Database connection.
7177
*
@@ -564,6 +570,66 @@ public function deleteUserResult($userresult)
564570
return true;
565571
}
566572

573+
###
574+
### Tool methods
575+
###
576+
577+
/**
578+
* Load tool object.
579+
*
580+
* @param Tool $tool Tool object
581+
*
582+
* @return bool True if the tool object was successfully loaded
583+
*/
584+
public function loadTool($tool)
585+
{
586+
$tool->secret = 'secret';
587+
$tool->enabled = true;
588+
$now = time();
589+
$tool->created = $now;
590+
$tool->updated = $now;
591+
592+
return true;
593+
}
594+
595+
/**
596+
* Save tool object.
597+
*
598+
* @param Tool $tool Tool object
599+
*
600+
* @return bool True if the tool object was successfully saved
601+
*/
602+
public function saveTool($tool)
603+
{
604+
$tool->updated = time();
605+
606+
return true;
607+
}
608+
609+
/**
610+
* Delete tool object.
611+
*
612+
* @param Tool $tool Tool object
613+
*
614+
* @return bool True if the tool object was successfully deleted
615+
*/
616+
public function deleteTool($tool)
617+
{
618+
$tool->initialize();
619+
620+
return true;
621+
}
622+
623+
/**
624+
* Load platform objects.
625+
*
626+
* @return Tool[] Array of all defined Tool objects
627+
*/
628+
public function getTools()
629+
{
630+
return array();
631+
}
632+
567633
###
568634
### Other methods
569635
###
@@ -711,4 +777,26 @@ protected function fixPlatformSettings($platform, $isSave)
711777
}
712778
}
713779

780+
/**
781+
* Adjust the settings for any tool properties being stored as a setting value.
782+
*
783+
* @param Tool $tool Tool object
784+
* @param bool $isSave True if the settings are being saved
785+
*/
786+
protected function fixToolSettings($tool, $isSave)
787+
{
788+
if (!$isSave) {
789+
$tool->encryptionMethod = $tool->getSetting('_encryption_method', $tool->encryptionMethod);
790+
$tool->setSetting('_encryption_method');
791+
$tool->debugMode = $tool->getSetting('_debug', $tool->debugMode ? 'true' : 'false') === 'true';
792+
$tool->setSetting('_debug');
793+
if ($tool->debugMode) {
794+
Util::$logLevel = Util::LOGLEVEL_DEBUG;
795+
}
796+
} else {
797+
$tool->setSetting('_encryption_method', !empty($tool->encryptionMethod) ? $tool->encryptionMethod : null);
798+
$tool->setSetting('_debug', $tool->debugMode ? 'true' : null);
799+
}
800+
}
801+
714802
}

0 commit comments

Comments
 (0)