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

Class to represent a platform context. More...

Inheritance diagram for Context:
ApiHook

Public Member Functions

 __construct ()
 Class constructor.
 
 initialize ()
 Initialise the context.
 
 initialise ()
 Initialise the context.
 
 save ()
 Save the context to the database.
 
 delete ()
 Delete the context from the database.
 
 getConsumer ()
 Get tool consumer.
 
 setConsumerId ($consumerId)
 Set tool consumer ID.
 
 getPlatform ()
 Get platform.
 
 setPlatformId ($platformId)
 Set platform ID.
 
 getKey ()
 Get consumer key.
 
 getId ()
 Get context ID.
 
 getRecordId ()
 Get the context record ID.
 
 setRecordId ($id)
 Sets the context record ID.
 
 getDataConnector ()
 Get the data connector.
 
 getSetting ($name, $default='')
 Get a setting value.
 
 setSetting ($name, $value=null)
 Set a setting value.
 
 getSettings ()
 Get an array of all setting values.
 
 setSettings ($settings)
 Set an array of all setting values.
 
 saveSettings ()
 Save setting values.
 
 hasToolSettingsService ()
 Check if the Tool Settings service is available.
 
 getToolSettings ($mode=Service\ToolSettings::MODE_CURRENT_LEVEL, $simple=true)
 Get Tool Settings.
 
 setToolSettings ($settings=array())
 Set Tool Settings.
 
 hasGroupService ()
 Check if a Course Group service is available.
 
 getGroups ()
 Get course group sets and groups.
 
 hasMembershipService ()
 Check if the Membership service is supported.
 
 hasMembershipsService ()
 Check if a Membership service is available.
 
 getMembership ()
 Get Membership.
 
 getMemberships ($withGroups=false)
 Get Memberships.
 
 hasLineItemService ()
 Check if the Line-item service is available.
 
 hasScoreService ()
 Check if the Score service is available.
 
 hasResultService ()
 Check if the Result service is available.
 
 getLineItems ($resourceId=null, $tag=null, $limit=null)
 Get line-items.
 
 createLineItem ($lineItem)
 Create a new line-item.
 

Static Public Member Functions

static fromRecordId ($id, $dataConnector)
 Load the context from the database.
 
static fromConsumer ($consumer, $ltiContextId)
 Class constructor from consumer.
 
static fromPlatform ($platform, $ltiContextId)
 Class constructor from platform.
 
- Static Public Member Functions inherited from ApiHook
static registerApiHook ($hookName, $familyCode, $className)
 Register the availability of an API hook.
 

Data Fields

 $ltiContextId = null
 Context ID as supplied in the last connection request.
 
 $title = null
 Context title.
 
 $type = null
 Context type.
 
 $groupSets = null
 User group sets (null if the platform does not support the groups enhancement)
 
 $groups = null
 User groups (null if the platform does not support the groups enhancement)
 
 $lastServiceRequest = null
 HttpMessage object for last service request.
 
 $created = null
 Timestamp for when the object was created.
 
 $updated = null
 Timestamp for when the object was last updated.
 

Additional Inherited Members

- Static Public Attributes inherited from ApiHook
static $USER_ID_HOOK = "UserId"
 User Id hook name.
 
static $CONTEXT_ID_HOOK = "ContextId"
 Context Id hook name.
 
static $GROUPS_SERVICE_HOOK = "Groups"
 Course Groups service hook name.
 
static $MEMBERSHIPS_SERVICE_HOOK = "Memberships"
 Memberships service hook name.
 
static $OUTCOMES_SERVICE_HOOK = "Outcomes"
 Outcomes service hook name.
 
static $TOOL_SETTINGS_SERVICE_HOOK = "ToolSettings"
 Tool Settings service hook name.
 
static $ACCESS_TOKEN_SERVICE_HOOK = "AccessToken"
 Access Token service hook name.
 

Detailed Description

Class to represent a platform context.

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

Definition at line 17 of file Context.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Class constructor.

Definition at line 134 of file Context.php.

References Context\initialize().

Member Function Documentation

◆ createLineItem()

createLineItem (   $lineItem)

Create a new line-item.

Parameters
LineItem$lineItemLine-item object
Returns
bool True if successful

Definition at line 642 of file Context.php.

◆ delete()

delete ( )

Delete the context from the database.

Returns
bool True if the context was successfully deleted.

Definition at line 182 of file Context.php.

References Context\getDataConnector().

◆ fromConsumer()

static fromConsumer (   $consumer,
  $ltiContextId 
)
static

Class constructor from consumer.

Deprecated:
Use fromPlatform() instead
See also
Context::fromPlatform()
Parameters
ToolConsumer$consumerConsumer instance
string$ltiContextIdLTI Context ID value
Returns
Context

Definition at line 681 of file Context.php.

References Context\$ltiContextId, and Context\fromPlatform().

◆ fromPlatform()

static fromPlatform (   $platform,
  $ltiContextId 
)
static

Class constructor from platform.

Parameters
Platform$platformPlatform instance
string$ltiContextIdLTI Context ID value
Returns
Context

Definition at line 694 of file Context.php.

References Context\$ltiContextId.

Referenced by Context\fromConsumer().

◆ fromRecordId()

static fromRecordId (   $id,
  $dataConnector 
)
static

Load the context from the database.

Parameters
int$idRecord ID of context
DataConnector$dataConnectorDatabase connection object
Returns
Context Context object

Definition at line 661 of file Context.php.

Referenced by ResourceLink\getContext().

◆ getConsumer()

getConsumer ( )

Get tool consumer.

Deprecated:
Use getPlatform() instead
See also
Context::getPlatform()
Returns
ToolConsumer Tool consumer object for this context.

Definition at line 195 of file Context.php.

References Context\getPlatform(), and Util\logDebug().

◆ getDataConnector()

getDataConnector ( )

Get the data connector.

Returns
mixed Data connector object or string

Definition at line 287 of file Context.php.

Referenced by Platform\__construct(), Tool\__construct(), Context\delete(), Context\getPlatform(), and Context\save().

◆ getGroups()

getGroups ( )

Get course group sets and groups.

Returns
bool True if the request was successful

Definition at line 452 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

◆ getId()

getId ( )

Get context ID.

Returns
string|null ID for this context.

Definition at line 257 of file Context.php.

References Context\$ltiContextId.

◆ getKey()

getKey ( )

Get consumer key.

Returns
string Consumer key value for this context.

Definition at line 247 of file Context.php.

References Context\getPlatform().

◆ getLineItems()

getLineItems (   $resourceId = null,
  $tag = null,
  $limit = null 
)

Get line-items.

Parameters
string | null$resourceIdTool resource ID
string | null$tagTag
int | null$limitLimit of line-items to be returned in each request, null for service default
Returns
LineItem[]|bool Array of LineItem objects or false on error

Definition at line 621 of file Context.php.

◆ getMembership()

getMembership ( )

Get Membership.

Deprecated:
Use getMemberships() instead
See also
Context::getMemberships()
Returns
array|bool The array of UserResult objects if successful, otherwise false

Definition at line 507 of file Context.php.

References Context\getMemberships(), and Util\logDebug().

◆ getMemberships()

getMemberships (   $withGroups = false)

Get Memberships.

Parameters
bool$withGroupsTrue is group information is to be requested as well
Returns
array|bool The array of UserResult objects if successful, otherwise false

Definition at line 521 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

Referenced by Context\getMembership().

◆ getPlatform()

◆ getRecordId()

getRecordId ( )

Get the context record ID.

Returns
int|string|null Context record ID value

Definition at line 267 of file Context.php.

◆ getSetting()

getSetting (   $name,
  $default = '' 
)

Get a setting value.

Parameters
string$nameName of setting
string$defaultValue to return if the setting does not exist (optional, default is an empty string)
Returns
string Setting value

Definition at line 300 of file Context.php.

Referenced by Context\getGroups(), Context\getMemberships(), Context\getToolSettings(), Context\hasGroupService(), Context\hasLineItemService(), Context\hasMembershipsService(), Context\hasResultService(), Context\hasScoreService(), Context\hasToolSettingsService(), Context\setSetting(), and Context\setToolSettings().

◆ getSettings()

getSettings ( )

Get an array of all setting values.

Returns
array Associative array of setting values

Definition at line 335 of file Context.php.

◆ getToolSettings()

getToolSettings (   $mode = Service\ToolSettings::MODE_CURRENT_LEVEL,
  $simple = true 
)

Get Tool Settings.

Parameters
int$modeMode for request (optional, default is current level only)
bool$simpleTrue if all the simple media type is to be used (optional, default is true)
Returns
array|bool The array of settings if successful, otherwise false

Definition at line 388 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

◆ hasGroupService()

hasGroupService ( )

Check if a Course Group service is available.

Returns
bool True if this context supports a Course Group service

Definition at line 438 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

◆ hasLineItemService()

hasLineItemService ( )

Check if the Line-item service is available.

Returns
bool True if this context supports the Line-item service

Definition at line 563 of file Context.php.

References Context\getSetting().

◆ hasMembershipService()

hasMembershipService ( )

Check if the Membership service is supported.

Deprecated:
Use hasMembershipsService() instead
See also
Context::hasMembershipsService()
Returns
bool True if this context supports the Membership service

Definition at line 478 of file Context.php.

References Context\hasMembershipsService(), and Util\logDebug().

◆ hasMembershipsService()

hasMembershipsService ( )

Check if a Membership service is available.

Returns
bool True if this context supports a Memberships service

Definition at line 490 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

Referenced by Context\hasMembershipService().

◆ hasResultService()

hasResultService ( )

Check if the Result service is available.

Returns
bool True if this context supports the Result service

Definition at line 599 of file Context.php.

References Result\$SCOPE, and Context\getSetting().

◆ hasScoreService()

hasScoreService ( )

Check if the Score service is available.

Returns
bool True if this context supports the Score service

Definition at line 581 of file Context.php.

References Score\$SCOPE, and Context\getSetting().

◆ hasToolSettingsService()

hasToolSettingsService ( )

Check if the Tool Settings service is available.

Returns
bool True if this context supports the Tool Settings service

Definition at line 371 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

◆ initialise()

initialise ( )

Initialise the context.

Synonym for initialize().

Definition at line 157 of file Context.php.

References Context\initialize().

◆ initialize()

initialize ( )

Initialise the context.

Definition at line 142 of file Context.php.

Referenced by Context\__construct(), and Context\initialise().

◆ save()

save ( )

Save the context to the database.

Returns
bool True if the context was successfully saved.

Definition at line 167 of file Context.php.

References Context\getDataConnector().

Referenced by Context\saveSettings().

◆ saveSettings()

saveSettings ( )

Save setting values.

Returns
bool True if the settings were successfully saved

Definition at line 355 of file Context.php.

References Context\save().

◆ setConsumerId()

setConsumerId (   $consumerId)

Set tool consumer ID.

Deprecated:
Use setPlatformId() instead
See also
Context::setPlatformId()
Parameters
int$consumerIdTool Consumer ID for this context.

Definition at line 210 of file Context.php.

References Util\logDebug(), and Context\setPlatformId().

◆ setPlatformId()

setPlatformId (   $platformId)

Set platform ID.

Parameters
int | null$platformIdPlatform ID for this context.

Definition at line 236 of file Context.php.

Referenced by Context\setConsumerId().

◆ setRecordId()

setRecordId (   $id)

Sets the context record ID.

Parameters
int | string | null$idContext record ID value

Definition at line 277 of file Context.php.

◆ setSetting()

setSetting (   $name,
  $value = null 
)

Set a setting value.

Parameters
string$nameName of setting
string | array | null$valueValue to set, use an empty value to delete a setting (optional, default is null)

Definition at line 317 of file Context.php.

References Context\getSetting().

◆ setSettings()

setSettings (   $settings)

Set an array of all setting values.

Parameters
array$settingsAssociative array of setting values

Definition at line 345 of file Context.php.

◆ setToolSettings()

setToolSettings (   $settings = array())

Set Tool Settings.

Parameters
array$settingsAn associative array of settings (optional, default is none)
Returns
bool True if action was successful, otherwise false

Definition at line 415 of file Context.php.

References Context\getPlatform(), and Context\getSetting().

Field Documentation

◆ $created

int null $created = null

Timestamp for when the object was created.

Definition at line 80 of file Context.php.

◆ $groups

array null $groups = null

User groups (null if the platform does not support the groups enhancement)

A group is represented by an associative array with the following elements:

  • title
  • set (ID of group set, array of IDs if the group belongs to more than one set, omitted if the group is not part of a set) The array key value is the group ID.

Definition at line 66 of file Context.php.

◆ $groupSets

array null $groupSets = null

User group sets (null if the platform does not support the groups enhancement)

A group set is represented by an associative array with the following elements:

  • title
  • groups (array of group IDs)
  • num_members
  • num_staff
  • num_learners The array key value is the group set ID.

Definition at line 54 of file Context.php.

◆ $lastServiceRequest

HttpMessage null $lastServiceRequest = null

HttpMessage object for last service request.

Definition at line 73 of file Context.php.

◆ $ltiContextId

string null $ltiContextId = null

Context ID as supplied in the last connection request.

Definition at line 25 of file Context.php.

Referenced by Context\fromConsumer(), Context\fromPlatform(), and Context\getId().

◆ $title

string null $title = null

Context title.

Definition at line 32 of file Context.php.

◆ $type

string null $type = null

Context type.

Definition at line 39 of file Context.php.

◆ $updated

int null $updated = null

Timestamp for when the object was last updated.

Definition at line 87 of file Context.php.


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