Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(no description)

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

Defines 1 class

ToolConsumer:: (24 methods):
  __construct()
  initialize()
  initialise()
  save()
  delete()
  getRecordId()
  setRecordId()
  getKey()
  setKey()
  getDataConnector()
  getIsAvailable()
  getSetting()
  setSetting()
  getSettings()
  setSettings()
  saveSettings()
  hasToolSettingsService()
  getToolSettings()
  setToolSettings()
  signParameters()
  addSignature()
  doServiceRequest()
  fromRecordId()
  load()


Class: ToolConsumer  - X-Ref

Class to represent a tool consumer

__construct($key = null, $dataConnector = null, $autoEnable = false)   X-Ref
Class constructor.

param: string  $key             Consumer key
param: DataConnector   $dataConnector   A data connector object
param: boolean $autoEnable      true if the tool consumers is to be enabled automatically (optional, default is false)

initialize()   X-Ref
Initialise the tool consumer.


initialise()   X-Ref
Initialise the tool consumer.

Pseudonym for initialize().

save()   X-Ref
Save the tool consumer to the database.

return: boolean True if the object was successfully saved

delete()   X-Ref
Delete the tool consumer from the database.

return: boolean True if the object was successfully deleted

getRecordId()   X-Ref
Get the tool consumer record ID.

return: int Consumer record ID value

setRecordId($id)   X-Ref
Sets the tool consumer record ID.

param: int $id  Consumer record ID value

getKey()   X-Ref
Get the tool consumer key.

return: string Consumer key value

setKey($key)   X-Ref
Set the tool consumer key.

param: string $key  Consumer key value

getDataConnector()   X-Ref
Get the data connector.

return: mixed Data connector object or string

getIsAvailable()   X-Ref
Is the consumer key available to accept launch requests?

return: boolean True if the consumer key is enabled and within any date constraints

getSetting($name, $default = '')   X-Ref
Get a setting value.

param: string $name    Name of setting
param: string $default Value to return if the setting does not exist (optional, default is an empty string)
return: string Setting value

setSetting($name, $value = null)   X-Ref
Set a setting value.

param: string $name  Name of setting
param: string $value Value to set, use an empty value to delete a setting (optional, default is null)

getSettings()   X-Ref
Get an array of all setting values.

return: array Associative array of setting values

setSettings($settings)   X-Ref
Set an array of all setting values.

param: array $settings  Associative array of setting values

saveSettings()   X-Ref
Save setting values.

return: boolean True if the settings were successfully saved

hasToolSettingsService()   X-Ref
Check if the Tool Settings service is supported.

return: boolean True if this tool consumer supports the Tool Settings service

getToolSettings($simple = true)   X-Ref
Get Tool Settings.

param: boolean  $simple     True if all the simple media type is to be used (optional, default is true)
return: mixed The array of settings if successful, otherwise false

setToolSettings($settings = array()   X-Ref
Perform a Tool Settings service request.

param: array    $settings   An associative array of settings (optional, default is none)
return: boolean True if action was successful, otherwise false

signParameters($url, $type, $version, $params)   X-Ref
Add the OAuth signature to an LTI message.

param: string  $url         URL for message request
param: string  $type        LTI message type
param: string  $version     LTI version
param: array   $params      Message parameters
return: array Array of signed message parameters

addSignature($endpoint, $consumerKey, $consumerSecret, $data, $method = 'POST', $type = null)   X-Ref
Add the OAuth signature to an array of message parameters or to a header string.

return: mixed Array of signed message parameters or header string

doServiceRequest($service, $method, $format, $data)   X-Ref
Perform a service request

param: object $service  Service object to be executed
param: string $method   HTTP action
param: string $format   Media type
param: mixed  $data     Array of parameters or body string
return: HTTPMessage HTTP object containing request and response details

fromRecordId($id, $dataConnector)   X-Ref
Load the tool consumer from the database by its record ID.

param: string          $id                The consumer key record ID
param: DataConnector   $dataConnector    Database connection object
return: object ToolConsumer       The tool consumer object

load($key, $autoEnable = false)   X-Ref
Load the tool consumer from the database.

param: string  $key        The consumer key value
param: boolean $autoEnable True if the consumer should be enabled (optional, default if false)
return: boolean True if the consumer was successfully loaded