Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 607 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: DataConnector  - X-Ref

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.

__construct($db, $dbTableNamePrefix = '')   X-Ref
Class constructor

param: object $db                 Database connection object
param: string $dbTableNamePrefix  Prefix for database table names (optional, default is none)

loadToolConsumer($consumer)   X-Ref
Load tool consumer object.

return: boolean True if the tool consumer object was successfully loaded
param: ToolConsumer $consumer ToolConsumer object

saveToolConsumer($consumer)   X-Ref
Save tool consumer object.

return: boolean True if the tool consumer object was successfully saved
param: ToolConsumer $consumer Consumer object

deleteToolConsumer($consumer)   X-Ref
Delete tool consumer object.

return: boolean True if the tool consumer object was successfully deleted
param: ToolConsumer $consumer Consumer object

getToolConsumers()   X-Ref
Load tool consumer objects.

return: array Array of all defined ToolConsumer objects

loadToolProxy($toolProxy)   X-Ref
Load tool proxy object.

return: boolean True if the tool proxy object was successfully loaded
param: ToolProxy $toolProxy ToolProxy object

saveToolProxy($toolProxy)   X-Ref
Save tool proxy object.

return: boolean True if the tool proxy object was successfully saved
param: ToolProxy $toolProxy ToolProxy object

deleteToolProxy($toolProxy)   X-Ref
Delete tool proxy object.

return: boolean True if the tool proxy object was successfully deleted
param: ToolProxy $toolProxy ToolProxy object

loadContext($context)   X-Ref
Load context object.

return: boolean True if the context object was successfully loaded
param: Context $context Context object

saveContext($context)   X-Ref
Save context object.

return: boolean True if the context object was successfully saved
param: Context $context Context object

deleteContext($context)   X-Ref
Delete context object.

return: boolean True if the Context object was successfully deleted
param: Context $context Context object

loadResourceLink($resourceLink)   X-Ref
Load resource link object.

return: boolean True if the resource link object was successfully loaded
param: ResourceLink $resourceLink Resource_Link object

saveResourceLink($resourceLink)   X-Ref
Save resource link object.

return: boolean True if the resource link object was successfully saved
param: ResourceLink $resourceLink Resource_Link object

deleteResourceLink($resourceLink)   X-Ref
Delete resource link object.

return: boolean True if the resource link object was successfully deleted
param: ResourceLink $resourceLink Resource_Link object

getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)   X-Ref
Get array of user objects.

Obtain an array of User 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.

return: array Array of User objects
param: ResourceLink $resourceLink      Resource link object
param: boolean     $localOnly True if only users within the resource link are to be returned (excluding users sharing this resource link)
param: int         $idScope     Scope value to use for user IDs

getSharesResourceLink($resourceLink)   X-Ref
Get array of shares defined for this resource link.

return: array Array of ResourceLinkShare objects
param: ResourceLink $resourceLink Resource_Link object

loadConsumerNonce($nonce)   X-Ref
Load nonce object.

return: boolean True if the nonce object was successfully loaded
param: ConsumerNonce $nonce Nonce object

saveConsumerNonce($nonce)   X-Ref
Save nonce object.

return: boolean True if the nonce object was successfully saved
param: ConsumerNonce $nonce Nonce object

loadResourceLinkShareKey($shareKey)   X-Ref
Load resource link share key object.

return: boolean True if the resource link share key object was successfully loaded
param: ResourceLinkShareKey $shareKey Resource_Link share key object

saveResourceLinkShareKey($shareKey)   X-Ref
Save resource link share key object.

return: boolean True if the resource link share key object was successfully saved
param: ResourceLinkShareKey $shareKey Resource link share key object

deleteResourceLinkShareKey($shareKey)   X-Ref
Delete resource link share key object.

return: boolean True if the resource link share key object was successfully deleted
param: ResourceLinkShareKey $shareKey Resource link share key object

loadUser($user)   X-Ref
Load user object.

return: boolean True if the user object was successfully loaded
param: User $user User object

saveUser($user)   X-Ref
Save user object.

return: boolean True if the user object was successfully saved
param: User $user User object

deleteUser($user)   X-Ref
Delete user object.

return: boolean True if the user object was successfully deleted
param: User $user User object

getConsumerKey($key)   X-Ref
Return a hash of a consumer key for values longer than 255 characters.

return: string
param: string $key

getDataConnector($dbTableNamePrefix = '', $db = null, $type = '')   X-Ref
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.

return: DataConnector Data connector object
param: string  $dbTableNamePrefix  Prefix for database table names (optional, default is none)
param: object  $db                 A database connection object or string (optional, default is no persistence)
param: string  $type               The type of data connector (optional, default is based on $db parameter)

getRandomString($length = 8)   X-Ref
Generate a random string.

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

return: string Random string
param: int $length Length of string to be generated (optional, default is 8 characters)

quoted($value, $addQuotes = true)   X-Ref
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.

return: string The quoted string.
param: string $value Value to be quoted
param: bool $addQuotes If true the returned string will be enclosed in single quotes (optional, default is true)