I've created an LTI enabled tool and am having some trouble with sending data back to an LMS such as Desire2Learn. Based on my understanding alone, you generate an XML payload containing the grade item itself and send this via POST back to the LMS using cURL. The problem I'm running into is that my $result variable is returning false and I can't figure it out right now. Here is my code:
session_start();
require_once 'blti/blti.php';
require_once 'blti/blti_util.php';
define('OAUTH_CONSUMER_KEY', 'key');
define('OAUTH_CONSUMER_SECRET', 'secret');
$blti = new BLTI(OAUTH_CONSUMER_SECRET, true, false);
if ($blti->valid) {
$_SESSION['lis_outcome_service_url'] = $_REQUEST['lis_outcome_service_url'];
$_SESSION['lis_result_sourcedid'] = $_REQUEST['lis_result_sourcedid'];
$_SESSION['lis_person_name_given'] = $_REQUEST['lis_person_name_given'];
$_SESSION['oauth_consumer_key'] = $_REQUEST['oauth_consumer_key'];
$_SESSION['oauth_consumer_secret'] = OAUTH_CONSUMER_SECRET;
sendGradeBackToLMS();
}else {
exit($blti->message);
}
function sendGradeBackToLMS() {
$ch = curl_init();
if (!$ch) { exit('curl is not supported!'); }
$url = 'http://localhost/endpoint.php';
$xmldata = getPOXRequest();
$xml = str_replace(
array('MESSAGE_IDENTIFIER', 'SOURCEDID', 'GRADE'),
array(uniqid(), $_SESSION['lis_result_sourcedid'], 0.75),
$xmldata);
$request_headers = array();
$request_headers[] = 'User-Agent: '. $_SERVER['HTTP_USER_AGENT'];
$request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $xml
));
$results = curl_exec($ch);
curl_close($ch);
echo $results;
}
function getPOXRequest() {
return <<<XML
<?xml version = "1.0" encoding = "UTF-8"?>
<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<imsx_POXHeader>
<imsx_POXRequestHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>MESSAGE_IDENTIFIER</imsx_messageIdentifier>
</imsx_POXRequestHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>
<replaceResultRequest>
<resultRecord>
<sourcedGUID>
<sourcedId>SOURCEDID</sourcedId>
</sourcedGUID>
<result>
<resultScore>
<language>en</language>
<textString>GRADE</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>
XML;
}
Just to summarize it up, $blti is an instance that checks if it is a valid Basic LTI launch or not. If that is true, I initialize the SESSION by storing LTI request variables into SESSION variables. Next in the sendGradeBackToLMS() function I send a block of XML data containing the grade item to the path given in $url.
Any kind of input would be helpful! Thanks!