Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Communicate with backpacks.

Author: Yuliya Bozhko <yuliya.bozhko@totaralms.com>
Copyright: 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 673 lines (28 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: backpack_api  - X-Ref

Class for communicating with backpacks.

__construct($sitebackpack, $userbackpack = false)   X-Ref
Create a wrapper to communicate with the backpack.

The resulting class can only do either site backpack communication or
user backpack communication.

param: stdClass $sitebackpack The site backpack record
param: mixed $userbackpack Optional - if passed it represents the users backpack.

define_mappings()   X-Ref
Define the mappings supported by this usage and api version.


curl_request($action, $collection = null, $entityid = null, $postdata = null)   X-Ref
Make an api request

param: string $action The api function.
param: string $collection An api parameter
param: string $entityid An api parameter
param: string $postdata The body of the api request.
return: mixed

get_auth_user_id()   X-Ref
Get the id to use for requests with this api.

return: integer

get_token_key($type)   X-Ref
Get the name of the key to store this access token type.

param: string $type
return: string

check_status($status)   X-Ref
Normalise the return from a missing user request.

param: string $status
return: mixed

get_assertion($entityid)   X-Ref
Make an api request to get an assertion

param: string $entityid The id of the assertion.
return: mixed

put_badgeclass_assertion($entityid, $data)   X-Ref
Create a badgeclass assertion.

param: string $entityid The id of the badge class.
param: string $data The structure of the badge class assertion.
return: mixed

set_backpack_collections($backpackid, $collections)   X-Ref
Select collections from a backpack.

param: string $backpackid The id of the backpack
param: stdClass[] $collections List of collections with collectionid or entityid.
return: boolean

put_badgeclass($entityid, $data)   X-Ref
Create a badgeclass

param: string $entityid The id of the entity.
param: string $data The structure of the badge class.
return: mixed

put_issuer($data)   X-Ref
Create an issuer

param: string $data The structure of the issuer.
return: mixed

clear_system_user_session()   X-Ref
Delete any user access tokens in the session so we will attempt to get new ones.

return: void

authenticate()   X-Ref
Authenticate using the stored email and password and save the valid access tokens.

return: integer The id of the authenticated user.

get_collections()   X-Ref
Get all collections in this backpack.

return: stdClass[] The collections.

get_collection_record($collectionid)   X-Ref
Get one collection by id.

param: integer $collectionid
return: stdClass The collection.

disconnect_backpack($userid, $backpackid)   X-Ref
Disconnect the backpack from this user.

param: integer $userid The user in Moodle
param: integer $backpackid The backpack to disconnect
return: boolean

get_collection_id_from_response($data)   X-Ref
Handle the response from getting a collection to map to an id.

param: stdClass $data The response data.
return: string The collection id.

get_authentication_error()   X-Ref
Get the last error message returned during an authentication request.

return: string

get_badges($collection, $expanded = false)   X-Ref
Get the list of badges in a collection.

param: stdClass $collection The collection to deal with.
param: boolean $expanded Fetch all the sub entities.
return: stdClass[]