-
Notifications
You must be signed in to change notification settings - Fork 24
Calling Services
Before using names and roles you should check that you have access to it.
if (!$launch->hasNrps()) {
throw new Exception("Don't have names and roles!");
}
Once we know we can access it, we can get an instance of the service from the launch.
$nrps = $launch->getNrps();
From the service we can get an array of all the members by calling:
$members = $nrps->getMembers();
Before using assignments and grades you should check that you have access to it.
if (!$launch->hasAgs()) {
throw new Exception("Don't have assignments and grades!");
}
Once we know we can access it, we can get an instance of the service from the launch.
$ags = $launch->getAgs();
To pass a grade back to the platform, you will need to create an Packback\Lti1p3\LtiGrade
object and populate it with the necessary information.
$grade = Packback\Lti1p3\LtiGrade::new()
->setScoreGiven($grade)
->setScoreMaximum(100)
->setTimestamp(date(DateTime::ISO8601))
->setActivityProgress('Completed')
->setGradingProgress('FullyGraded')
->setUserId($external_user_id);
To send the grade to the platform we can call:
$ags->putGrade($grade);
This will put the grade into the default provided lineitem. If no default lineitem exists it will create one.
If you want to send multiple types of grade back, that can be done by specifying an Packback\Lti1p3\LtiLineitem
.
$lineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('grade')
->setScoreMaximum(100)
->setLabel('Grade');
$ags->putGrade($grade, $lineitem);
If a lineitem with the same tag
exists, that lineitem will be used, otherwise a new lineitem will be created.