LTI Integration Library 5.0.0-rc2
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:
DataConnector_mysql DataConnector_mysqli DataConnector_oci DataConnector_pdo DataConnector_pg DataConnector_sqlsrv DataConnector_pdo_oci DataConnector_pdo_pgsql

Public Member Functions

bool loadToolConsumer ($consumer)
 Load tool consumer object.
 
bool saveToolConsumer ($consumer)
 Save tool consumer object.
 
bool deleteToolConsumer ($consumer)
 Delete tool consumer object.
 
ToolConsumer[] getToolConsumers ()
 Load tool consumer objects.
 
bool loadPlatform ($platform)
 Load platform object.
 
bool savePlatform ($platform)
 Save platform object.
 
bool deletePlatform ($platform)
 Delete platform object.
 
Platform[] getPlatforms ()
 Load platform objects.
 
bool loadContext ($context)
 Load context object.
 
bool saveContext ($context)
 Save context object.
 
bool deleteContext ($context)
 Delete context object.
 
bool loadResourceLink ($resourceLink)
 Load resource link object.
 
bool saveResourceLink ($resourceLink)
 Save resource link object.
 
bool deleteResourceLink ($resourceLink)
 Delete resource link object.
 
UserResult[] getUserResultSourcedIDsResourceLink ($resourceLink, $localOnly, $idScope)
 Get array of user objects.
 
ResourceLinkShare[] getSharesResourceLink ($resourceLink)
 Get array of shares defined for this resource link.
 
bool loadConsumerNonce ($nonce)
 Load nonce object.
 
bool saveConsumerNonce ($nonce)
 Save nonce object.
 
bool deleteConsumerNonce ($nonce)
 Delete nonce object.
 
bool loadPlatformNonce ($nonce)
 Load nonce object.
 
bool savePlatformNonce ($nonce)
 Save nonce object.
 
bool deletePlatformNonce ($nonce)
 Delete nonce object.
 
bool loadAccessToken ($accessToken)
 Load access token object.
 
bool saveAccessToken ($accessToken)
 Save access token object.
 
bool loadResourceLinkShareKey ($shareKey)
 Load resource link share key object.
 
bool saveResourceLinkShareKey ($shareKey)
 Save resource link share key object.
 
bool deleteResourceLinkShareKey ($shareKey)
 Delete resource link share key object.
 
bool loadUserResult ($userresult)
 Load user object.
 
bool saveUserResult ($userresult)
 Save user object.
 
bool deleteUserResult ($userresult)
 Delete user object.
 
bool loadTool ($tool)
 Load tool object.
 
bool saveTool ($tool)
 Save tool object.
 
bool deleteTool ($tool)
 Delete tool object.
 
Tool[] getTools ()
 Load platform objects.
 
string escape ($value, $addQuotes=true)
 Escape a string for use in a database query.
 

Static Public Member Functions

static bool useMemcache ($host=null, $port=-1)
 Set/check whether memcached should be used when available.
 
static DataConnector getDataConnector ($db=null, $dbTableNamePrefix='', $type='')
 Create data connector object.
 
static string getRandomString ($length=8)
 Generate a random string.
 
static string quoted ($value, $addQuotes=true)
 Quote a string for use in a database query.
 

Public Attributes

const PLATFORM_TABLE_NAME = 'lti2_consumer'
 Default name for database table used to store platforms.
 
const CONSUMER_TABLE_NAME = self::PLATFORM_TABLE_NAME
 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 ($db, $dbTableNamePrefix='')
 Class constructor.
 
 fixPlatformSettings ($platform, $isSave)
 Adjust the settings for any platform properties being stored as a setting value.
 
 fixToolSettings ($tool, $isSave)
 Adjust the settings for any tool properties being stored as a setting value.
 

Protected Attributes

object resource $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 (   $db,
  $dbTableNamePrefix = '' 
)
protected

Class constructor.

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

Reimplemented in DataConnector_mysql, DataConnector_oci, and DataConnector_pdo_oci.

Member Function Documentation

◆ deleteConsumerNonce()

bool deleteConsumerNonce (   $nonce)

Delete nonce object.

Deprecated:
Use deletePlatformNonce() instead
See also
DataConnector::deletePlatformNonce()
Parameters
ConsumerNonce$nonceNonce object
Returns
bool True if the nonce object was successfully deleted

◆ deleteContext()

bool deleteContext (   $context)

Delete context object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deletePlatform()

bool deletePlatform (   $platform)

Delete platform object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deletePlatformNonce()

bool deletePlatformNonce (   $nonce)

Delete nonce object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deleteResourceLink()

bool deleteResourceLink (   $resourceLink)

Delete resource link object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deleteResourceLinkShareKey()

bool deleteResourceLinkShareKey (   $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_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deleteTool()

bool deleteTool (   $tool)

Delete tool object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ deleteToolConsumer()

bool deleteToolConsumer (   $consumer)

Delete tool consumer object.

Deprecated:
Use deletePlatform() instead
See also
DataConnector::deletePlatform()
Parameters
ToolConsumer$consumerTool consumer object
Returns
bool True if the tool consumer object was successfully deleted

◆ deleteUserResult()

bool deleteUserResult (   $userresult)

Delete user object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ escape()

string escape (   $value,
  $addQuotes = true 
)

Escape a string for use in a database query.

Any single quotes in the value passed will be replaced with two single quotes. If a null value is passed, a string of 'null' is returned (which will never be enclosed in quotes irrespective of the value of the $addQuotes parameter.

Parameters
string$valueValue to be escaped
bool$addQuotesIf true the returned string will be enclosed in single quotes (optional, default is true)
Returns
string The escaped string.

Reimplemented in DataConnector_mysql, DataConnector_pg, and DataConnector_sqlsrv.

◆ fixPlatformSettings()

◆ fixToolSettings()

◆ getDataConnector()

static DataConnector getDataConnector (   $db = null,
  $dbTableNamePrefix = '',
  $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

◆ getPlatforms()

Platform[] getPlatforms ( )

Load platform objects.

Returns
Platform[] Array of all defined Platform objects

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ getRandomString()

static string getRandomString (   $length = 8)
static

Generate a random string.

The generated string will only comprise letters (upper- and lower-case) and digits.

Deprecated:
Use Util::getRandomString() instead
See also
Util::getRandomString()
Parameters
int$lengthLength of string to be generated (optional, default is 8 characters)
Returns
string Random string

◆ getSharesResourceLink()

ResourceLinkShare[] getSharesResourceLink (   $resourceLink)

Get array of shares defined for this resource link.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ getToolConsumers()

ToolConsumer[] getToolConsumers ( )

Load tool consumer objects.

Deprecated:
Use getPlatforms() instead
See also
DataConnector::getPlatforms()
Returns
ToolConsumer[] Array of all defined tool consumer objects

◆ getTools()

Tool[] getTools ( )

Load platform objects.

Returns
Tool[] Array of all defined Tool objects

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ getUserResultSourcedIDsResourceLink()

UserResult[] getUserResultSourcedIDsResourceLink (   $resourceLink,
  $localOnly,
  $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)
int$idScopeScope value to use for user IDs
Returns
UserResult[] Array of UserResult objects

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pdo_pgsql, DataConnector_pg, and DataConnector_sqlsrv.

Referenced by ResourceLink\getLineItems().

◆ loadAccessToken()

bool loadAccessToken (   $accessToken)

Load access token object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadConsumerNonce()

bool loadConsumerNonce (   $nonce)

Load nonce object.

Deprecated:
Use loadPlatformNonce() instead
See also
DataConnector::loadPlatformNonce()
Parameters
ConsumerNonce$nonceNonce object
Returns
bool True if the nonce object was successfully loaded

◆ loadContext()

bool loadContext (   $context)

Load context object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadPlatform()

bool loadPlatform (   $platform)

Load platform object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

Referenced by Platform\fromPlatformId().

◆ loadPlatformNonce()

bool loadPlatformNonce (   $nonce)

Load nonce object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadResourceLink()

bool loadResourceLink (   $resourceLink)

Load resource link object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadResourceLinkShareKey()

bool loadResourceLinkShareKey (   $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_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadTool()

bool loadTool (   $tool)

Load tool object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ loadToolConsumer()

bool loadToolConsumer (   $consumer)

Load tool consumer object.

Deprecated:
Use loadPlatform() instead
See also
DataConnector::loadPlatform()
Parameters
ToolConsumer$consumerTool consumer object
Returns
bool True if the tool consumer object was successfully loaded

◆ loadUserResult()

bool loadUserResult (   $userresult)

Load user object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ quoted()

static string quoted (   $value,
  $addQuotes = true 
)
static

Quote a string for use in a database query.

Any single quotes in the value passed will be replaced with two single quotes. If a null value is passed, a string of 'null' is returned (which will never be enclosed in quotes irrespective of the value of the $addQuotes parameter.

Parameters
string$valueValue to be quoted
bool$addQuotesIf true the returned string will be enclosed in single quotes (optional, default is true)
Returns
string The quoted string.

◆ saveAccessToken()

bool saveAccessToken (   $accessToken)

Save access token object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ saveConsumerNonce()

bool saveConsumerNonce (   $nonce)

Save nonce object.

Deprecated:
Use savePlatformNonce() instead
See also
DataConnector::savePlatformNonce()
Parameters
ConsumerNonce$nonceNonce object
Returns
bool True if the nonce object was successfully saved

◆ saveContext()

bool saveContext (   $context)

Save context object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ savePlatform()

bool savePlatform (   $platform)

Save platform object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ savePlatformNonce()

bool savePlatformNonce (   $nonce)

Save nonce object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ saveResourceLink()

bool saveResourceLink (   $resourceLink)

Save resource link object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ saveResourceLinkShareKey()

bool saveResourceLinkShareKey (   $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_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pdo_pgsql, DataConnector_pg, and DataConnector_sqlsrv.

◆ saveTool()

bool saveTool (   $tool)

Save tool object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ saveToolConsumer()

bool saveToolConsumer (   $consumer)

Save tool consumer object.

Deprecated:
Use savePlatform() instead
See also
DataConnector::savePlatform()
Parameters
ToolConsumer$consumerTool consumer object
Returns
bool True if the tool consumer object was successfully saved

◆ saveUserResult()

bool saveUserResult (   $userresult)

Save user object.

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

Reimplemented in DataConnector_mysql, DataConnector_mysqli, DataConnector_oci, DataConnector_pdo, DataConnector_pg, and DataConnector_sqlsrv.

◆ useMemcache()

static bool useMemcache (   $host = null,
  $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

Member Data Documentation

◆ $dateFormat

string $dateFormat = 'Y-m-d'
protected

SQL date format (default = 'Y-m-d')

$dateFormat

◆ $db

object resource $db = null
protected

Database connection.

$db

Referenced by DataConnector_mysql\__construct(), and DataConnector_oci\__construct().

◆ $dbTableNamePrefix

string $dbTableNamePrefix = ''
protected

Prefix for database table names.

$dbTableNamePrefix

Referenced by DataConnector_mysql\__construct(), and DataConnector_oci\__construct().

◆ $timeFormat

string $timeFormat = 'H:i:s'
protected

SQL time format (default = 'H:i:s')

$timeFormat

◆ CONSUMER_TABLE_NAME

const CONSUMER_TABLE_NAME = self::PLATFORM_TABLE_NAME

Default name for database table used to store platforms.

Deprecated:
Use DataConnector::PLATFORM_TABLE_NAME instead
See also
DataConnector::PLATFORM_TABLE_NAME

The documentation for this class was generated from the following file: