ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLTIConsumerResultService Class Reference
+ Collaboration diagram for ilLTIConsumerResultService:

Public Member Functions

 getMasteryScore ()
 
 setMasteryScore (float $mastery_score)
 
 getAvailability ()
 
 setAvailability (int $availability)
 
 isAvailable ()
 
 handleRequest ()
 Handle an incoming request from the LTI tool provider. More...
 
 readProperties (int $a_obj_id)
 Read the LTI Consumer object properties. More...
 

Protected Member Functions

 readResult (\SimpleXMLElement $request)
 Read a stored result. More...
 
 replaceResult (\SimpleXMLElement $request)
 Replace a stored result. More...
 
 deleteResult (\SimpleXMLElement $request)
 Delete a stored result. More...
 
 loadResponse ($a_name)
 Load the XML template for the response. More...
 
 respondUnsupported ()
 Send a response that the operation is not supported This depends on the status of the object. More...
 
 respondUnknown ()
 Send a "unknown operation" response. More...
 
 respondBadRequest (?string $message=null)
 Send a "bad request" response. More...
 
 respondUnauthorized (?string $message=null)
 Send an "unauthorized" response. More...
 
 updateLP ()
 

Protected Attributes

ilLTIConsumerResult $result = null
 
int $availability = 0
 
float $mastery_score = 1
 
array $fields = array()
 
string $message_ref_id = ''
 
string $operation = ''
 

Private Member Functions

 readFields (int $a_obj_id)
 Read the LTI Consumer object fields. More...
 
 checkSignature (string $a_key, string $a_secret)
 Check the reqest signature. More...
 

Detailed Description

Definition at line 28 of file class.ilLTIConsumerResultService.php.

Member Function Documentation

◆ checkSignature()

ilLTIConsumerResultService::checkSignature ( string  $a_key,
string  $a_secret 
)
private

Check the reqest signature.

Returns
bool|Exception Exception or true

Definition at line 363 of file class.ilLTIConsumerResultService.php.

References Vendor\Package\$e, and $server.

Referenced by handleRequest().

364  {
365  $store = new TrivialOAuthDataStore();
366  $store->add_consumer($a_key, $a_secret);
367 
368  $server = new \ILIAS\LTIOAuth\OAuthServer($store);
369  $method = new \ILIAS\LTIOAuth\OAuthSignatureMethod_HMAC_SHA1();
370  $server->add_signature_method($method);
371 
372  $request = \ILIAS\LTIOAuth\OAuthRequest::from_request();
373  try {
374  $server->verify_request($request);
375  } catch (Exception $e) {
376  return $e;
377  }
378  return true;
379  }
A Trivial memory-based store - no support for tokens.
$server
Definition: shib_login.php:24
+ Here is the caller graph for this function:

◆ deleteResult()

ilLTIConsumerResultService::deleteResult ( \SimpleXMLElement  $request)
protected

Delete a stored result.

Definition at line 213 of file class.ilLTIConsumerResultService.php.

References $response, ILIAS\UI\examples\Symbol\Glyph\Header\header(), loadResponse(), ilLPStatus\LP_STATUS_IN_PROGRESS_NUM, null, and ilLPStatus\writeStatus().

Referenced by handleRequest().

213  : void
214  {
215  $this->result->result = null;
216  $this->result->save();
217 
219  $lp_percentage = 0;
220  ilLPStatus::writeStatus($this->result->obj_id, $this->result->usr_id, $lp_status, $lp_percentage, true);
221 
222  $code = "success";
223  $severity = "status";
224 
225  $response = $this->loadResponse('deleteResult.xml');
226  $response = str_replace('{message_id}', md5((string) rand(0, 999_999_999)), $response);
227  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
228  $response = str_replace('{operation}', $this->operation, $response);
229  $response = str_replace('{code}', $code, $response);
230  $response = str_replace('{severity}', $severity, $response);
231 
232  header('Content-type: application/xml');
233  echo $response;
234  }
const LP_STATUS_IN_PROGRESS_NUM
$response
Definition: xapitoken.php:93
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailability()

ilLTIConsumerResultService::getAvailability ( )

Definition at line 70 of file class.ilLTIConsumerResultService.php.

References $availability.

70  : int
71  {
72  return $this->availability;
73  }

◆ getMasteryScore()

ilLTIConsumerResultService::getMasteryScore ( )

Definition at line 60 of file class.ilLTIConsumerResultService.php.

References $mastery_score.

Referenced by replaceResult().

60  : float
61  {
62  return $this->mastery_score;
63  }
+ Here is the caller graph for this function:

◆ handleRequest()

ilLTIConsumerResultService::handleRequest ( )

Handle an incoming request from the LTI tool provider.

Definition at line 91 of file class.ilLTIConsumerResultService.php.

References $token, checkSignature(), deleteResult(), ilLTIConsumerResult\getByKeys(), ilCmiXapiAuthToken\getInstanceByToken(), isAvailable(), readFields(), readProperties(), readResult(), replaceResult(), respondBadRequest(), respondUnauthorized(), respondUnknown(), respondUnsupported(), and updateLP().

91  : void
92  {
93  try {
94  // get the request as xml
95  $xml = simplexml_load_file('php://input');
96  $this->message_ref_id = (string) $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
97  $request = current($xml->imsx_POXBody->children());
98  $this->operation = str_replace('Request', '', $request->getName());
99 
100  $token = ilCmiXapiAuthToken::getInstanceByToken((string) $request->resultRecord->sourcedGUID->sourcedId);
101 
102  $this->result = ilLTIConsumerResult::getByKeys($token->getObjId(), $token->getUsrId(), false);
103  if (empty($this->result)) {
104  $this->respondUnauthorized("lti_consumer_results_id not found!");
105  return;
106  }
107 
108 
109  // check the object status
110  $this->readProperties($this->result->obj_id);
111 
112  if (!$this->isAvailable()) {
113  $this->respondUnsupported();
114  return;
115  }
116 
117  // Verify the signature
118  $this->readFields($this->result->obj_id);
119  $result = $this->checkSignature($this->fields['KEY'], $this->fields['SECRET']);
120  if ($result instanceof Exception) {
121  $this->respondUnauthorized($result->getMessage());
122  return;
123  }
124 
125  // Dispatch the operation
126  switch ($this->operation) {
127  case 'readResult':
128  $this->readResult($request);
129  break;
130 
131  case 'replaceResult':
132  $this->replaceResult($request);
133  $this->updateLP();
134  break;
135 
136  case 'deleteResult':
137  $this->deleteResult($request);
138  $this->updateLP();
139  break;
140 
141  default:
142  $this->respondUnknown();
143  break;
144  }
145  } catch (Exception $exception) {
146  $this->respondBadRequest($exception->getMessage());
147  }
148  }
readFields(int $a_obj_id)
Read the LTI Consumer object fields.
respondUnknown()
Send a "unknown operation" response.
respondBadRequest(?string $message=null)
Send a "bad request" response.
checkSignature(string $a_key, string $a_secret)
Check the reqest signature.
static getInstanceByToken(string $token)
deleteResult(\SimpleXMLElement $request)
Delete a stored result.
respondUnauthorized(?string $message=null)
Send an "unauthorized" response.
readProperties(int $a_obj_id)
Read the LTI Consumer object properties.
$token
Definition: xapitoken.php:70
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.
replaceResult(\SimpleXMLElement $request)
Replace a stored result.
readResult(\SimpleXMLElement $request)
Read a stored result.
+ Here is the call graph for this function:

◆ isAvailable()

ilLTIConsumerResultService::isAvailable ( )

Definition at line 80 of file class.ilLTIConsumerResultService.php.

Referenced by handleRequest().

80  : bool
81  {
82  if ($this->availability == 0) {
83  return false;
84  }
85  return true;
86  }
+ Here is the caller graph for this function:

◆ loadResponse()

ilLTIConsumerResultService::loadResponse (   $a_name)
protected

Load the XML template for the response.

Parameters
stringfile name
Returns
string file content

Definition at line 242 of file class.ilLTIConsumerResultService.php.

Referenced by deleteResult(), readResult(), replaceResult(), respondUnknown(), and respondUnsupported().

242  : string
243  {
244  return file_get_contents('./components/ILIAS/LTIConsumer/responses/' . $a_name);
245  }
+ Here is the caller graph for this function:

◆ readFields()

ilLTIConsumerResultService::readFields ( int  $a_obj_id)
private

Read the LTI Consumer object fields.

Definition at line 332 of file class.ilLTIConsumerResultService.php.

References $DIC, and $res.

Referenced by handleRequest().

332  : void
333  {
334  global $DIC;
335 
336  $query = "
337  SELECT lti_ext_provider.provider_key, lti_ext_provider.provider_secret, lti_consumer_settings.launch_key, lti_consumer_settings.launch_secret
338  FROM lti_ext_provider, lti_consumer_settings
339  WHERE lti_ext_provider.id = lti_consumer_settings.provider_id
340  AND lti_consumer_settings.obj_id = %s
341  ";
342 
343  $res = $DIC->database()->queryF($query, array('integer'), array($a_obj_id));
344 
345  while ($row = $DIC->database()->fetchAssoc($res)) {
346  if (strlen($row["launch_key"]) > 0) {
347  $this->fields["KEY"] = $row["launch_key"];
348  } else {
349  $this->fields["KEY"] = $row["provider_key"];
350  }
351  if (strlen($row["launch_key"]) > 0) {
352  $this->fields["SECRET"] = $row["launch_secret"];
353  } else {
354  $this->fields["SECRET"] = $row["provider_secret"];
355  }
356  }
357  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ readProperties()

ilLTIConsumerResultService::readProperties ( int  $a_obj_id)

Read the LTI Consumer object properties.

Definition at line 309 of file class.ilLTIConsumerResultService.php.

References $DIC, $res, setAvailability(), and setMasteryScore().

Referenced by handleRequest().

309  : void
310  {
311  global $DIC;
312 
313  $query = "
314  SELECT lti_ext_provider.availability, lti_consumer_settings.mastery_score
315  FROM lti_ext_provider, lti_consumer_settings
316  WHERE lti_ext_provider.id = lti_consumer_settings.provider_id
317  AND lti_consumer_settings.obj_id = %s
318  ";
319 
320  $res = $DIC->database()->queryF($query, array('integer'), array($a_obj_id));
321 
322  if ($row = $DIC->database()->fetchAssoc($res)) {
323  //$this->properties = $row;
324  $this->setAvailability((int) $row['availability']);
325  $this->setMasteryScore((float) $row['mastery_score']);
326  }
327  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readResult()

ilLTIConsumerResultService::readResult ( \SimpleXMLElement  $request)
protected

Read a stored result.

Definition at line 153 of file class.ilLTIConsumerResultService.php.

References $response, ILIAS\UI\examples\Symbol\Glyph\Header\header(), and loadResponse().

Referenced by handleRequest().

153  : void
154  {
155  $response = $this->loadResponse('readResult.xml');
156  $response = str_replace('{message_id}', md5((string) rand(0, 999_999_999)), $response);
157  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
158  $response = str_replace('{operation}', $this->operation, $response);
159  $response = str_replace('{result}', (string) $this->result->result, $response);
160 
161  header('Content-type: application/xml');
162  echo $response;
163  }
$response
Definition: xapitoken.php:93
loadResponse($a_name)
Load the XML template for the response.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceResult()

ilLTIConsumerResultService::replaceResult ( \SimpleXMLElement  $request)
protected

Replace a stored result.

Definition at line 168 of file class.ilLTIConsumerResultService.php.

References $response, getMasteryScore(), ILIAS\UI\examples\Symbol\Glyph\Header\header(), if, ILIAS\Repository\int(), loadResponse(), ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_IN_PROGRESS_NUM, ilLTIConsumerResult\save(), and ilLPStatus\writeStatus().

Referenced by handleRequest().

168  : void
169  {
170  $result = (string) $request->resultRecord->result->resultScore->textString;
171  if (!is_numeric($result)) {
172  $code = "failure";
173  $severity = "status";
174  $description = "The result is not a number.";
175  } elseif ($result < 0 or $result > 1) {
176  $code = "failure";
177  $severity = "status";
178  $description = "The result is out of range from 0 to 1.";
179  } else {
180  $this->result->result = (float) $result;
181  $this->result->save();
182 
183  if ($result >= $this->getMasteryScore()) {
185  } else {
187  }
188  $lp_percentage = (int) round(100 * $result);
189 
190  // Mantis #37080
191  ilLPStatus::writeStatus($this->result->obj_id, $this->result->usr_id, $lp_status, $lp_percentage, true);
192 
193  $code = "success";
194  $severity = "status";
195  $description = sprintf("Score for %s is now %s", $this->result->id, $this->result->result);
196  }
197 
198  $response = $this->loadResponse('replaceResult.xml');
199  $response = str_replace('{message_id}', md5((string) rand(0, 999_999_999)), $response);
200  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
201  $response = str_replace('{operation}', $this->operation, $response);
202  $response = str_replace('{code}', $code, $response);
203  $response = str_replace('{severity}', $severity, $response);
204  $response = str_replace('{description}', $description, $response);
205 
206  header('Content-type: application/xml');
207  echo $response;
208  }
const LP_STATUS_COMPLETED_NUM
if(!file_exists('../ilias.ini.php'))
const LP_STATUS_IN_PROGRESS_NUM
$response
Definition: xapitoken.php:93
save()
Save a result object.
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.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondBadRequest()

ilLTIConsumerResultService::respondBadRequest ( ?string  $message = null)
protected

Send a "bad request" response.

Definition at line 280 of file class.ilLTIConsumerResultService.php.

References $message, and ILIAS\UI\examples\Symbol\Glyph\Header\header().

Referenced by handleRequest().

280  : void
281  {
282  header('HTTP/1.1 400 Bad Request');
283  header('Content-type: text/plain');
284  if (isset($message)) {
285  echo $message;
286  } else {
287  echo 'This is not a well-formed LTI Basic Outcomes Service request.';
288  }
289  }
$message
Definition: xapiexit.php:31
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondUnauthorized()

ilLTIConsumerResultService::respondUnauthorized ( ?string  $message = null)
protected

Send an "unauthorized" response.

Parameters
string | null$messageresponse message

Definition at line 295 of file class.ilLTIConsumerResultService.php.

References $message, and ILIAS\UI\examples\Symbol\Glyph\Header\header().

Referenced by handleRequest().

295  : void
296  {
297  header('HTTP/1.1 401 Unauthorized');
298  header('Content-type: text/plain');
299  if (isset($message)) {
300  echo $message;
301  } else {
302  echo 'This request could not be authorized.';
303  }
304  }
$message
Definition: xapiexit.php:31
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondUnknown()

ilLTIConsumerResultService::respondUnknown ( )
protected

Send a "unknown operation" response.

Definition at line 266 of file class.ilLTIConsumerResultService.php.

References $response, ILIAS\UI\examples\Symbol\Glyph\Header\header(), and loadResponse().

Referenced by handleRequest().

266  : void
267  {
268  $response = $this->loadResponse('unknown.xml');
269  $response = str_replace('{message_id}', md5((string) rand(0, 999_999_999)), $response);
270  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
271  $response = str_replace('{operation}', $this->operation, $response);
272 
273  header('Content-type: application/xml');
274  echo $response;
275  }
$response
Definition: xapitoken.php:93
loadResponse($a_name)
Load the XML template for the response.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondUnsupported()

ilLTIConsumerResultService::respondUnsupported ( )
protected

Send a response that the operation is not supported This depends on the status of the object.

Definition at line 252 of file class.ilLTIConsumerResultService.php.

References $response, ILIAS\UI\examples\Symbol\Glyph\Header\header(), and loadResponse().

Referenced by handleRequest().

252  : void
253  {
254  $response = $this->loadResponse('unsupported.xml');
255  $response = str_replace('{message_id}', md5((string) rand(0, 999_999_999)), $response);
256  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
257  $response = str_replace('{operation}', $this->operation, $response);
258 
259  header('Content-type: application/xml');
260  echo $response;
261  }
$response
Definition: xapitoken.php:93
loadResponse($a_name)
Load the XML template for the response.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAvailability()

ilLTIConsumerResultService::setAvailability ( int  $availability)

Definition at line 75 of file class.ilLTIConsumerResultService.php.

References $availability.

Referenced by readProperties().

75  : void
76  {
77  $this->availability = $availability;
78  }
+ Here is the caller graph for this function:

◆ setMasteryScore()

ilLTIConsumerResultService::setMasteryScore ( float  $mastery_score)

Definition at line 65 of file class.ilLTIConsumerResultService.php.

References $mastery_score.

Referenced by readProperties().

65  : void
66  {
67  $this->mastery_score = $mastery_score;
68  }
+ Here is the caller graph for this function:

◆ updateLP()

ilLTIConsumerResultService::updateLP ( )
protected

Definition at line 381 of file class.ilLTIConsumerResultService.php.

References ilLPStatusWrapper\_updateStatus().

Referenced by handleRequest().

381  : void
382  {
383  if (!($this->result instanceof ilLTIConsumerResult)) {
384  return;
385  }
386 
387  ilLPStatusWrapper::_updateStatus($this->result->getObjId(), $this->result->getUsrId());
388  }
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $availability

int ilLTIConsumerResultService::$availability = 0
protected

Definition at line 38 of file class.ilLTIConsumerResultService.php.

Referenced by getAvailability(), and setAvailability().

◆ $fields

array ilLTIConsumerResultService::$fields = array()
protected

Definition at line 48 of file class.ilLTIConsumerResultService.php.

◆ $mastery_score

float ilLTIConsumerResultService::$mastery_score = 1
protected

Definition at line 43 of file class.ilLTIConsumerResultService.php.

Referenced by getMasteryScore(), and setMasteryScore().

◆ $message_ref_id

string ilLTIConsumerResultService::$message_ref_id = ''
protected

Definition at line 53 of file class.ilLTIConsumerResultService.php.

◆ $operation

string ilLTIConsumerResultService::$operation = ''
protected

Definition at line 57 of file class.ilLTIConsumerResultService.php.

◆ $result

ilLTIConsumerResult ilLTIConsumerResultService::$result = null
protected

Definition at line 33 of file class.ilLTIConsumerResultService.php.


The documentation for this class was generated from the following file: