3 declare(strict_types=1);
79 if ($this->availability == 0) {
92 $xml = simplexml_load_file(
'php://input');
93 $this->message_ref_id = (string) $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
95 $request = $xml->imsx_POXBody->children()[0];
96 $this->operation = str_replace(
'Request',
'', $request->getName());
101 if (empty($this->result)) {
117 $result = $this->
checkSignature($this->fields[
'KEY'], $this->fields[
'SECRET']);
124 switch ($this->operation) {
129 case 'replaceResult':
151 protected function readResult(\SimpleXMLElement $request): void
154 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
159 header(
'Content-type: application/xml');
168 $result = (string) $request->resultRecord->result->resultScore->textString;
169 if (!is_numeric($result)) {
171 $severity =
"status";
172 $description =
"The result is not a number.";
173 } elseif ($result < 0 or $result > 1) {
175 $severity =
"status";
176 $description =
"The result is out of range from 0 to 1.";
178 $this->result->result = (float) $result;
179 $this->result->
save();
186 $lp_percentage = (
int) round(100 * $result);
192 $severity =
"status";
193 $description = sprintf(
"Score for %s is now %s", $this->result->id, $this->result->result);
197 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
204 header(
'Content-type: application/xml');
213 $this->result->result = null;
214 $this->result->save();
221 $severity =
"status";
224 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
230 header(
'Content-type: application/xml');
242 return file_get_contents(
'./Modules/LTIConsumer/responses/' . $a_name);
253 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
257 header(
'Content-type: application/xml');
267 $response = str_replace(
'{message_id}', md5((
string) rand(0, 999_999_999)),
$response);
271 header(
'Content-type: application/xml');
280 header(
'HTTP/1.1 400 Bad Request');
281 header(
'Content-type: text/plain');
285 echo
'This is not a well-formed LTI Basic Outcomes Service request.';
295 header(
'HTTP/1.1 401 Unauthorized');
296 header(
'Content-type: text/plain');
300 echo
'This request could not be authorized.';
312 SELECT lti_ext_provider.availability, lti_consumer_settings.mastery_score 313 FROM lti_ext_provider, lti_consumer_settings 314 WHERE lti_ext_provider.id = lti_consumer_settings.provider_id 315 AND lti_consumer_settings.obj_id = %s 318 $res = $DIC->database()->queryF($query, array(
'integer'), array($a_obj_id));
320 if ($row = $DIC->database()->fetchAssoc(
$res)) {
335 SELECT lti_ext_provider.provider_key, lti_ext_provider.provider_secret, lti_consumer_settings.launch_key, lti_consumer_settings.launch_secret 336 FROM lti_ext_provider, lti_consumer_settings 337 WHERE lti_ext_provider.id = lti_consumer_settings.provider_id 338 AND lti_consumer_settings.obj_id = %s 341 $res = $DIC->database()->queryF($query, array(
'integer'), array($a_obj_id));
343 while ($row = $DIC->database()->fetchAssoc(
$res)) {
344 if (strlen($row[
"launch_key"]) > 0) {
345 $this->fields[
"KEY"] = $row[
"launch_key"];
347 $this->fields[
"KEY"] = $row[
"provider_key"];
349 if (strlen($row[
"launch_key"]) > 0) {
350 $this->fields[
"SECRET"] = $row[
"launch_secret"];
352 $this->fields[
"SECRET"] = $row[
"provider_secret"];
364 $store->add_consumer($a_key, $a_secret);
366 $server = new \ILIAS\LTIOAuth\OAuthServer($store);
367 $method = new \ILIAS\LTIOAuth\OAuthSignatureMethod_HMAC_SHA1();
368 $server->add_signature_method($method);
370 $request = \ILIAS\LTIOAuth\OAuthRequest::from_request();
372 $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.
if(!file_exists(getcwd() . '/ilias.ini.php'))
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.
A Trivial memory-based store - no support for tokens.
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.