LTI Integration Library 5.1.4
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
DataConnector Class Reference

Class to provide a connection to a persistent store for LTI objects. More...

+ Inheritance diagram for DataConnector:

Public Member Functions

bool loadPlatform (Platform $platform)
 Load platform object.
 
bool savePlatform (Platform $platform)
 Save platform object.
 
bool deletePlatform (Platform $platform)
 Delete platform object.
 
Platform[] getPlatforms ()
 Load platform objects.
 
bool loadContext (Context $context)
 Load context object.
 
bool saveContext (Context $context)
 Save context object.
 
bool deleteContext (Context $context)
 Delete context object.
 
bool loadResourceLink (ResourceLink $resourceLink)
 Load resource link object.
 
bool saveResourceLink (ResourceLink $resourceLink)
 Save resource link object.
 
bool deleteResourceLink (ResourceLink $resourceLink)
 Delete resource link object.
 
UserResult[] getUserResultSourcedIDsResourceLink (ResourceLink $resourceLink, bool $localOnly, ?IdScope $idScope)
 Get array of user objects.
 
ResourceLinkShare[] getSharesResourceLink (ResourceLink $resourceLink)
 Get array of shares defined for this resource link.
 
bool loadPlatformNonce (PlatformNonce $nonce)
 Load nonce object.
 
bool savePlatformNonce (PlatformNonce $nonce)
 Save nonce object.
 
bool deletePlatformNonce (PlatformNonce $nonce)
 Delete nonce object.
 
bool loadAccessToken (AccessToken $accessToken)
 Load access token object.
 
bool saveAccessToken (AccessToken $accessToken)
 Save access token object.
 
bool loadResourceLinkShareKey (ResourceLinkShareKey $shareKey)
 Load resource link share key object.
 
bool saveResourceLinkShareKey (ResourceLinkShareKey $shareKey)
 Save resource link share key object.
 
bool deleteResourceLinkShareKey (ResourceLinkShareKey $shareKey)
 Delete resource link share key object.
 
bool loadUserResult (UserResult $userResult)
 Load user object.
 
bool saveUserResult (UserResult $userResult)
 Save user object.
 
bool deleteUserResult (UserResult $userResult)
 Delete user object.
 
bool loadTool (Tool $tool)
 Load tool object.
 
bool saveTool (Tool $tool)
 Save tool object.
 
bool deleteTool (Tool $tool)
 Delete tool object.
 
Tool[] getTools ()
 Load tool objects.
 

Static Public Member Functions

static bool useMemcache (string $host=null, int $port=-1)
 Set/check whether memcached should be used when available.
 
static DataConnector getDataConnector (mixed $db=null, string $dbTableNamePrefix='', string $type='')
 Create data connector object.
 

Public Attributes

const PLATFORM_TABLE_NAME = 'lti2_consumer'
 Default name for database table used to store platforms.
 
const CONTEXT_TABLE_NAME = 'lti2_context'
 Default name for database table used to store contexts.
 
const RESOURCE_LINK_TABLE_NAME = 'lti2_resource_link'
 Default name for database table used to store resource links.
 
const USER_RESULT_TABLE_NAME = 'lti2_user_result'
 Default name for database table used to store users.
 
const RESOURCE_LINK_SHARE_KEY_TABLE_NAME = 'lti2_share_key'
 Default name for database table used to store resource link share keys.
 
const NONCE_TABLE_NAME = 'lti2_nonce'
 Default name for database table used to store nonce values.
 
const ACCESS_TOKEN_TABLE_NAME = 'lti2_access_token'
 Default name for database table used to store access token values.
 
const TOOL_TABLE_NAME = 'lti2_tool'
 Default name for database table used to store tools.
 

Protected Member Functions

 __construct (mixed $db, string $dbTableNamePrefix='')
 Class constructor.
 
void fixPlatformSettings (Platform $platform, bool $isSave)
 Adjust the settings for any platform properties being stored as a setting value.
 
void fixToolSettings (Tool $tool, bool $isSave)
 Adjust the settings for any tool properties being stored as a setting value.
 
string dbTableName (string $table)
 Add the prefix to the name for a database table.
 

Protected Attributes

mixed $db = null
 Database connection.
 
string $dbTableNamePrefix = ''
 Prefix for database table names.
 
string $dateFormat = 'Y-m-d'
 SQL date format (default = 'Y-m-d')
 
string $timeFormat = 'H:i:s'
 SQL time format (default = 'H:i:s')
 

Detailed Description

Class to provide a connection to a persistent store for LTI objects.

This class assumes no data persistence - it should be extended for specific database connections.

Author
Stephen P Vickers steph.nosp@m.en@s.nosp@m.pvsof.nosp@m.twar.nosp@m.eprod.nosp@m.ucts.nosp@m..com
Licence: http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3

Constructor & Destructor Documentation

◆ __construct()

__construct ( mixed $db,
string $dbTableNamePrefix = '' )
protected

Class constructor.

Parameters
object | resource$dbDatabase connection object
string$dbTableNamePrefixPrefix for database table names (optional, default is none)

Reimplemented in DataConnector_oci8.

Member Function Documentation

◆ dbTableName()

string dbTableName ( string $table)
protected

◆ deleteContext()

bool deleteContext ( Context $context)

Delete context object.

Parameters
Context$contextContext object
Returns
bool True if the Context object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\deleteResourceLink(), and ResourceLink\initialize().

◆ deletePlatform()

bool deletePlatform ( Platform $platform)

Delete platform object.

Parameters
Platform$platformPlatform object
Returns
bool True if the platform object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ deletePlatformNonce()

bool deletePlatformNonce ( PlatformNonce $nonce)

Delete nonce object.

Parameters
PlatformNonce$nonceNonce object
Returns
bool True if the nonce object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ deleteResourceLink()

bool deleteResourceLink ( ResourceLink $resourceLink)

Delete resource link object.

Parameters
ResourceLink$resourceLinkResourceLink object
Returns
bool True if the resource link object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\deleteContext().

◆ deleteResourceLinkShareKey()

bool deleteResourceLinkShareKey ( ResourceLinkShareKey $shareKey)

Delete resource link share key object.

Parameters
ResourceLinkShareKey$shareKeyResource link share key object
Returns
bool True if the resource link share key object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ deleteTool()

bool deleteTool ( Tool $tool)

Delete tool object.

Parameters
Tool$toolTool object
Returns
bool True if the tool object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ deleteUserResult()

bool deleteUserResult ( UserResult $userResult)

Delete user object.

Parameters
UserResult$userResultUserResult object
Returns
bool True if the user object was successfully deleted

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ fixPlatformSettings()

void fixPlatformSettings ( Platform $platform,
bool $isSave )
protected

Adjust the settings for any platform properties being stored as a setting value.

Parameters
Platform$platformPlatform object
bool$isSaveTrue if the settings are being saved

References Util\$logLevel.

◆ fixToolSettings()

void fixToolSettings ( Tool $tool,
bool $isSave )
protected

Adjust the settings for any tool properties being stored as a setting value.

Parameters
Tool$toolTool object
bool$isSaveTrue if the settings are being saved

◆ getDataConnector()

static DataConnector getDataConnector ( mixed $db = null,
string $dbTableNamePrefix = '',
string $type = '' )
static

Create data connector object.

A data connector provides access to persistent storage for the different objects.

Names of tables may be given a prefix to allow multiple versions to share the same schema. A separate sub-class is defined for each different database connection - the class to use is determined by inspecting the database object passed, but this can be overridden (for example, to use a bespoke connector) by specifying a type. If no database is passed then this class is used which acts as a dummy connector with no persistence.

Parameters
object | resource$dbA database connection object or string (optional, default is no persistence)
string$dbTableNamePrefixPrefix for database table names (optional, default is none)
string$typeThe type of data connector (optional, default is based on $db parameter)
Returns
DataConnector Data connector object

References Util\$logLevel.

◆ getPlatforms()

Platform[] getPlatforms ( )

Load platform objects.

Returns
Platform[] Array of all defined Platform objects

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ getSharesResourceLink()

ResourceLinkShare[] getSharesResourceLink ( ResourceLink $resourceLink)

Get array of shares defined for this resource link.

Parameters
ResourceLink$resourceLinkResourceLink object
Returns
ResourceLinkShare[] Array of ResourceLinkShare objects

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ getTools()

Tool[] getTools ( )

Load tool objects.

Returns
Tool[] Array of all defined Tool objects

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ getUserResultSourcedIDsResourceLink()

UserResult[] getUserResultSourcedIDsResourceLink ( ResourceLink $resourceLink,
bool $localOnly,
?IdScope $idScope )

Get array of user objects.

Obtain an array of UserResult objects for users with a result sourcedId. The array may include users from other resource links which are sharing this resource link. It may also be optionally indexed by the user ID of a specified scope.

Parameters
ResourceLink$resourceLinkResource link object
bool$localOnlyTrue if only users within the resource link are to be returned (excluding users sharing this resource link)
IdScope | null$idScopeScope value to use for user IDs
Returns
UserResult[] Array of UserResult objects

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pdo_pgsql, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\savePlatformNonce().

◆ loadAccessToken()

bool loadAccessToken ( AccessToken $accessToken)

Load access token object.

Parameters
AccessToken$accessTokenAccess token object
Returns
bool True if the nonce object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\savePlatformNonce().

◆ loadContext()

bool loadContext ( Context $context)

Load context object.

Parameters
Context$contextContext object
Returns
bool True if the context object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\loadResourceLink().

◆ loadPlatform()

bool loadPlatform ( Platform $platform)

Load platform object.

Parameters
Platform$platformPlatform object
Returns
bool True if the platform object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\useMemcache().

◆ loadPlatformNonce()

bool loadPlatformNonce ( PlatformNonce $nonce)

Load nonce object.

Parameters
PlatformNonce$nonceNonce object
Returns
bool True if the nonce object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ loadResourceLink()

bool loadResourceLink ( ResourceLink $resourceLink)

Load resource link object.

Parameters
ResourceLink$resourceLinkResourceLink object
Returns
bool True if the resource link object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\loadContext().

◆ loadResourceLinkShareKey()

bool loadResourceLinkShareKey ( ResourceLinkShareKey $shareKey)

Load resource link share key object.

Parameters
ResourceLinkShareKey$shareKeyResourceLink share key object
Returns
bool True if the resource link share key object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\loadUserResult().

◆ loadTool()

bool loadTool ( Tool $tool)

Load tool object.

Parameters
Tool$toolTool object
Returns
bool True if the tool object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\loadUserResult().

◆ loadUserResult()

bool loadUserResult ( UserResult $userResult)

Load user object.

Parameters
UserResult$userResultUserResult object
Returns
bool True if the user object was successfully loaded

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\loadTool().

Referenced by DataConnector\loadResourceLinkShareKey().

◆ saveAccessToken()

bool saveAccessToken ( AccessToken $accessToken)

Save access token object.

Parameters
AccessToken$accessTokenAccess token object
Returns
bool True if the access token object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\saveResourceLinkShareKey().

◆ saveContext()

bool saveContext ( Context $context)

Save context object.

Parameters
Context$contextContext object
Returns
bool True if the context object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References DataConnector\saveResourceLink().

◆ savePlatform()

bool savePlatform ( Platform $platform)

Save platform object.

Parameters
Platform$platformPlatform object
Returns
bool True if the platform object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ savePlatformNonce()

bool savePlatformNonce ( PlatformNonce $nonce)

Save nonce object.

Parameters
PlatformNonce$nonceNonce object
Returns
bool True if the nonce object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

References AccessToken\get(), AccessToken\getPlatform(), System\getRecordId(), and DataConnector\loadAccessToken().

Referenced by DataConnector\getUserResultSourcedIDsResourceLink().

◆ saveResourceLink()

bool saveResourceLink ( ResourceLink $resourceLink)

Save resource link object.

Parameters
ResourceLink$resourceLinkResourceLink object
Returns
bool True if the resource link object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\saveContext().

◆ saveResourceLinkShareKey()

bool saveResourceLinkShareKey ( ResourceLinkShareKey $shareKey)

Save resource link share key object.

Parameters
ResourceLinkShareKey$shareKeyResource link share key object
Returns
bool True if the resource link share key object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pdo_pgsql, DataConnector_pgsql, and DataConnector_sql.

Referenced by DataConnector\saveAccessToken().

◆ saveTool()

bool saveTool ( Tool $tool)

Save tool object.

Parameters
Tool$toolTool object
Returns
bool True if the tool object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ saveUserResult()

bool saveUserResult ( UserResult $userResult)

Save user object.

Parameters
UserResult$userResultUserResult object
Returns
bool True if the user object was successfully saved

Reimplemented in DataConnector_mysqli, DataConnector_oci8, DataConnector_pdo, DataConnector_pgsql, and DataConnector_sql.

◆ useMemcache()

static bool useMemcache ( string $host = null,
int $port = -1 )
static

Set/check whether memcached should be used when available.

Parameters
string$hostName or IP address of host running memcache server (use an empty string to disable)
int$portPort number used by memcache server (use -1 for default)
Returns
bool True if memcache is enabled

References DataConnector\loadPlatform().