Skip to content

Outcomes service

Stephen Vickers edited this page Jun 25, 2020 · 5 revisions

A grade book entry for a specific user is identified by their associated result sourcedid; this value is passed when the user launches the tool and is automatically retained by the library for future use. The result sourcedid for the current user could be saved as a session variable as part of the onLaunch method, but the value may be obtained by loading the User record from its user ID:

$user = LTI\User::fromResourceLink($resource_link, $user_id);

The user's grade may be retrieved from the grade book in the tool consumer using a read operation:

$outcome = new LTI\Outcome();
if ($resource_link->doOutcomesService(LTI\ResourceLink::EXT_READ, $outcome, $user)) {
  $score = $outcome->getValue();
}

The user's grade may be saved to the grade book in the tool consumer using a write operation:

$outcome = new LTI\Outcome($score);
$ok = $resource_link->doOutcomesService(LTI\ResourceLink::EXT_WRITE, $outcome, $user);

The score should normally be a decimal value between 0 and 1, but the doOutcomesService method makes every effort to convert the value passed to a format which is accepted by the tool consumer; for example, a percentage of 65% may be converted to a decimal 0.65. If the value cannot be converted to a decimal and the tool consumer supports the Outcomes extension service then an attempt will be made to use this service instead.

The delete operation can be used to remove a grade from the grade book.

Outcomes extension service

If the tool consumer has not given access to the Outcomes service, then the doOutcomesService method will use the unofficial Outcomes extension service if available. This has the same functionality but also supports value types other than decimal (set using the type property of the Outcome object).