Using the Memberships service

The Memberships service is an unofficial extension to LTI which allows a tool provider to obtain from a tool consumer a list of users who have access to a specified resource link. The PHP classes make this service easy to access. The location of the service and ID to use to identify the resource link are retained by the PHP classes when a launch request is received.

Sample code

Open the memberships.php file in a text editor and replace the "[RESOURCE_LINK_ID]" text with the resource link ID displayed in the previous exercise. Open the page in a browser and see the number of users and the details returned by the tool consumer. The data is extracted into an array of LTI_User objects for processing by your application - no need to worry about parsing the XML!

memberships.php

<?php

// Load LTI classes
require_once('LTI_Tool_Provider.php');

$db = new PDO('sqlite:lti-workshop.sqlitedb');

$consumer = new LTI_Tool_Consumer('jisc.ac.uk', $db);

$resource_link = new LTI_Resource_Link($consumer, '[RESOURCE_LINK_ID]');

$users = $resource_link->doMembershipsService();

if ($users !== FALSE) {
  echo 'User count = ' . count($users) . "\n\n";
  echo $resource_link->ext_response;
} else {
  echo 'Service request failed';
}

?>