19 declare(strict_types=1);
88 if ($this->availability == 0) {
102 $logger = $DIC->logger()->root();
103 $logger->info(
'LTI Consumer Result Service: Incoming request');
105 $xml = simplexml_load_file(
'php://input');
106 $logger->info(
'LTI Consumer Result Service: xml loaded');
107 $this->message_ref_id = (string) $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
108 $children = (array) $xml->imsx_POXBody->children();
109 $request = current($children);
111 $ns = $xml->getNamespaces(
true);
112 $body = $xml->children($ns[
''])->imsx_POXBody;
114 $logger->info(
'LTI Consumer Result Service: request loaded');
115 $this->operation = str_replace(
'Request',
'', $request->getName());
117 $request = $body->replaceResultRequest;
119 $logger->info(
"LTI Consumer Result Service: operation loaded ($this->operation), user " .
$token->getUsrId() .
" and objId " .
$token->getObjId());
121 $logger->info(
"LTI Consumer Result Service: token loaded");
123 if (empty($this->result)) {
124 $logger->error(
'LTI Consumer Result Service: Incoming request');
140 $result = $this->
checkSignature($this->fields[
'KEY'], $this->fields[
'SECRET']);
142 $logger->error(
'LTI Consumer Result Service: Incoming request');
147 $logger->info(
"LTI Consumer Result Service: Request signature verified, this->operation: $this->operation");
150 switch ($this->operation) {
155 case 'replaceResult':
180 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
185 header(
'Content-type: application/xml');
195 $logger = $DIC->logger()->root();
197 $result = (string) $request->resultRecord->result->resultScore->textString;
198 $logger->info(
'LTI Consumer Result Service: Replace result. Result: ' . $result);
199 if (!is_numeric($result)) {
201 $severity =
"status";
202 $description =
"The result is not a number.";
203 } elseif ($result > 1) {
205 $severity =
"status";
206 $description =
"The result is out of range from 0 to 1.";
208 $this->result->result = (float) $result;
209 $this->result->
save();
216 $lp_percentage = (
int) round(100 * $result);
222 $severity =
"status";
223 $description = sprintf(
"Score for %s is now %s", $this->result->id, $this->result->result);
227 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
234 header(
'Content-type: application/xml');
243 $this->result->result = null;
244 $this->result->save();
251 $severity =
"status";
254 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
260 header(
'Content-type: application/xml');
272 return file_get_contents(__DIR__ .
'/../responses/' . $a_name);
283 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
287 header(
'Content-type: application/xml');
297 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
301 header(
'Content-type: application/xml');
310 header(
'HTTP/1.1 400 Bad Request');
311 header(
'Content-type: text/plain');
312 if (isset($message)) {
315 echo
'This is not a well-formed LTI Basic Outcomes Service request.';
325 header(
'HTTP/1.1 401 Unauthorized');
326 header(
'Content-type: text/plain');
327 if (isset($message)) {
330 echo
'This request could not be authorized.';
342 SELECT lti_ext_provider.availability, lti_consumer_settings.mastery_score 343 FROM lti_ext_provider, lti_consumer_settings 344 WHERE lti_ext_provider.id = lti_consumer_settings.provider_id 345 AND lti_consumer_settings.obj_id = %s 348 $res = $DIC->database()->queryF($query, array(
'integer'), array($a_obj_id));
350 if ($row = $DIC->database()->fetchAssoc(
$res)) {
365 SELECT lti_ext_provider.provider_key, lti_ext_provider.provider_secret, lti_consumer_settings.launch_key, lti_consumer_settings.launch_secret 366 FROM lti_ext_provider, lti_consumer_settings 367 WHERE lti_ext_provider.id = lti_consumer_settings.provider_id 368 AND lti_consumer_settings.obj_id = %s 371 $res = $DIC->database()->queryF($query, array(
'integer'), array($a_obj_id));
373 while ($row = $DIC->database()->fetchAssoc(
$res)) {
374 if (strlen($row[
"launch_key"]) > 0) {
375 $this->fields[
"KEY"] = $row[
"launch_key"];
377 $this->fields[
"KEY"] = $row[
"provider_key"];
379 if (strlen($row[
"launch_key"]) > 0) {
380 $this->fields[
"SECRET"] = $row[
"launch_secret"];
382 $this->fields[
"SECRET"] = $row[
"provider_secret"];
395 $platform->setKey($a_key);
396 $platform->setSecret($a_secret);
398 $store =
new OAuthDataStore($platform);
400 $server =
new OAuthServer($store);
401 $method =
new OAuthSignatureMethod_HMAC_SHA1();
402 $server->add_signature_method($method);
404 $request = OAuthRequest::from_request();
407 $server->verify_request($request);
const LP_STATUS_COMPLETED_NUM
readFields(int $a_obj_id)
Read the LTI Consumer object fields.
respondUnknown()
Send a "unknown operation" response.
setMasteryScore(float $mastery_score)
respondBadRequest(?string $message=null)
Send a "bad request" response.
checkSignature(string $a_key, string $a_secret)
Check the reqest signature.
setAvailability(int $availability)
static getInstanceByToken(string $token)
deleteResult(\SimpleXMLElement $request)
Delete a stored result.
const LP_STATUS_IN_PROGRESS_NUM
respondUnauthorized(?string $message=null)
Send an "unauthorized" response.
readProperties(int $a_obj_id)
Read the LTI Consumer object properties.
save()
Save a result object.
handleRequest()
Handle an incoming request from the LTI tool provider.
respondUnsupported()
Send a response that the operation is not supported This depends on the status of the object...
static getByKeys(int $a_obj_id, int $a_usr_id, ?bool $a_create=false)
Get a result by object and user key.
ilLTIConsumerResult $result
loadResponse($a_name)
Load the XML template for the response.
static writeStatus(int $a_obj_id, int $a_user_id, int $a_status, int $a_percentage=0, bool $a_force_per=false, ?int &$a_old_status=self::LP_STATUS_NOT_ATTEMPTED_NUM)
Write status for user and object.
replaceResult(\SimpleXMLElement $request)
Replace a stored result.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
readResult(\SimpleXMLElement $request)
Read a stored result.