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 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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: 727 lines (31 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

return: mixed
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.

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.

return: string
param: string $type

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

return: mixed
param: string $status

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

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

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

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

update_assertion(string $entityid, array $data)   X-Ref
Update a badgeclass assertion.

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

import_badge_assertion(string $data)   X-Ref
Import a badge assertion into a backpack. This is used to handle cross domain backpacks.

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

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

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

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

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

put_issuer($data)   X-Ref
Create an issuer

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

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.

return: stdClass The collection.
param: integer $collectionid

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

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

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

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

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.

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