Skip to content

Memberships service

Stephen Vickers edited this page Apr 3, 2022 · 5 revisions

The Memberships service and Name and the Roles Provisioning service both allow a tool to obtain a list of users enrolled in a context. The latter service may be extended by support of the Course Groups service which allows group membership data to be included in the response.

The getMemberships methods provided return an array of UserResult objects. The context may be obtained by using its primary key, its context ID or via a resource link ID which is known to belong to that context:

$context = LTI\Context::fromRecordId($contextPk);
$platform = LTI\Platform::fromConsumerKey($consumerKey, $dataConnector);
$context = LTI\Context::fromConsumer($platform, $contextId);
$platform = LTI\Platform::fromConsumerKey($consumerKey, $dataConnector);
$resourceLink = LTI\ResourceLink::fromPlatform($platform, $resourceLinkId);
$context = $resourceLink->getContext();

The memberships for the context can then be obtained by a simple call to the getMemberships method.

$users = $context->getMemberships();

Similarly, use the resource link instance to get a list of users with access to the resource link:

$users = $resourceLink->getMemberships();

Note that the role and limit options of this service are not supported by these methods, but the default limit for this service may be changed by setting the $defaultLimit static property; for example:

Service\Membership::$defaultLimit = 50;
$users = $resourceLink->getMemberships();

Alternatively, it can be applied when calling the get method of the Service\Membership service directly; for example, this requests learners from the platform with the response split into pages of up to 50 users at a time:

use ceLTIc\LTI\Service;

$url = $context->getSetting('custom_context_memberships_v2_url');
$format = Service\Membership::MEDIA_TYPE_MEMBERSHIPS_NRPS;
$limit = 50;

$membershipService = new Service\Membership($context, $url, $format, $limit);
$users = $membershipService->get('http://purl.imsglobal.org/vocab/lis/v2/membership#Learner');

The limit may be set by passing it in the call to the get method:

$membershipService = new Service\Membership($context, $url, $format);
$users = $membershipService->get('http://purl.imsglobal.org/vocab/lis/v2/membership#Learner', $limit);

The value passed here will override the default limit (initialised to 100) and any value set when the service object was constructed. Use a value of 0 for unlimited.

Memberships extension service

The above methods will use the Memberships extension service if none of the official Memberships services were not offered by the platform.

Group membership information

If both the Name and Roles Provisioning and Course Groups services, or the Memberships extension service, are supported by the platform, group membership can be included in the response. For example, this request:

$users = $resourceLink->getMemberships(true);

will populate the groupSets and groups properties of the ResourceLink object (as well as any Context object associated with the resource link). A group set is a collection of groups into which users have been assigned. Usually each user is restricted to being a member of only a single group in the collection, but this is a platform specific issue. Furthermore, usually each group may only belong to a single group set, but some platforms (such as Moodle) allow groups to be part of more than one, in which case the set element of a group array is an array of group set IDs, rather than a string. The Api Hooks functionality included in this library also natively supports the obtaining of group information from Moodle and Canvas platforms via their APIs. API hooks can be added for other platforms as needed.

Clone this wiki locally