ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilLTIConsumerResultService Class Reference
+ Collaboration diagram for ilLTIConsumerResultService:

Public Member Functions

 getMasteryScore ()
 
 setMasteryScore (float $mastery_score)
 
 getAvailability ()
 
 setAvailability (int $availability)
 
 isAvailable ()
 
 __construct ()
 Constructor: general initialisations. More...
 
 handleRequest ()
 Handle an incoming request from the LTI tool provider. More...
 

Protected Member Functions

 readResult ($request)
 Read a stored result. More...
 
 replaceResult ($request)
 Replace a stored result. More...
 
 deleteResult ($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 ($message=null)
 Send a "bad request" response. More...
 
 respondUnauthorized ($message=null)
 Send an "unauthorized" response. More...
 
 updateLP ()
 

Protected Attributes

 $result = null
 
 $availability = 0
 
 $mastery_score = 1
 
 $fields = array()
 
 $message_ref_id = ''
 
 $operation = ''
 

Private Member Functions

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

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilLTIConsumerResultService::__construct ( )

Constructor: general initialisations.

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

101  {
102  }

Member Function Documentation

◆ checkSignature()

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

Check the reqest signature.

Returns
mixed Exception or true

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

References Vendor\Package\$e, $server, $store, fields, and OAuthRequest\from_request().

Referenced by handleRequest().

393  {
394  require_once('./Modules/LTIConsumer/lib/OAuth.php');
395  require_once('./Modules/LTIConsumer/lib/TrivialOAuthDataStore.php');
396 
398  $store->add_consumer($this->fields['KEY'], $this->fields['SECRET']);
399 
400  $server = new OAuthServer($store);
401  $method = new OAuthSignatureMethod_HMAC_SHA1();
402  $server->add_signature_method($method);
403 
405  try {
406  $server->verify_request($request);
407  } catch (Exception $e) {
408  return $e;
409  }
410  return true;
411  }
$store
Definition: metadata.php:90
static from_request($http_method=null, $http_url=null, $parameters=null)
attempt to build up a request from what was passed to the server
Definition: OAuth.php:228
$errors fields
Definition: imgupload.php:51
A Trivial memory-based store - no support for tokens.
$server
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteResult()

ilLTIConsumerResultService::deleteResult (   $request)
protected

Delete a stored result.

Parameters
SimpleXMLElement$request

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

References $response, and loadResponse().

Referenced by handleRequest().

234  {
235  $this->result->result = null;
236  $this->result->save();
237 
238  #$lp_status = ilLTIConsumerLPStatus::LP_STATUS_IN_PROGRESS_NUM;
239  #$lp_percentage = 0;
240  #ilLTIConsumerLPStatus::trackResult($this->result->usr_id, $this->result->obj_id, $lp_status, $lp_percentage);
241 
242  $code = "success";
243  $severity = "status";
244 
245  $response = $this->loadResponse('deleteResult.xml');
246  $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
247  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
248  $response = str_replace('{operation}', $this->operation, $response);
249  $response = str_replace('{code}', $code, $response);
250  $response = str_replace('{severity}', $severity, $response);
251 
252  header('Content-type: application/xml');
253  echo $response;
254  }
loadResponse($a_name)
Load the XML template for the response.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailability()

ilLTIConsumerResultService::getAvailability ( )
Returns
int

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

References $availability.

◆ getMasteryScore()

ilLTIConsumerResultService::getMasteryScore ( )
Returns
float

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

References $mastery_score.

55  : float
56  {
57  return $this->mastery_score;
58  }

◆ handleRequest()

ilLTIConsumerResultService::handleRequest ( )

Handle an incoming request from the LTI tool provider.

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

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

108  {
109  try {
110  // get the request as xml
111  $xml = simplexml_load_file('php://input');
112  $this->message_ref_id = (string) $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
113  $request = current($xml->imsx_POXBody->children());
114  $this->operation = str_replace('Request', '', $request->getName());
115 
116  $token = ilCmiXapiAuthToken::getInstanceByToken($request->resultRecord->sourcedGUID->sourcedId);
117 
118  $this->result = ilLTIConsumerResult::getByKeys($token->getObjId(), $token->getUsrId(), false);
119  if (empty($this->result)) {
120  $this->respondUnauthorized("lti_consumer_results_id not found!");
121  return;
122  }
123 
124 
125  // check the object status
126  $this->readProperties($this->result->obj_id);
127 
128  if (!$this->isAvailable()) {
129  $this->respondUnsupported();
130  return;
131  }
132 
133  // Verify the signature
134  $this->readFields($this->result->obj_id);
135  $result = $this->checkSignature($this->fields['KEY'], $this->fields['SECRET']);
136  if ($result instanceof Exception) {
137  $this->respondUnauthorized($result->getMessage());
138  return;
139  }
140 
141  // Dispatch the operation
142  switch ($this->operation) {
143  case 'readResult':
144  $this->readResult($request);
145  break;
146 
147  case 'replaceResult':
148  $this->replaceResult($request);
149  $this->updateLP();
150  break;
151 
152  case 'deleteResult':
153  $this->deleteResult($request);
154  $this->updateLP();
155  break;
156 
157  default:
158  $this->respondUnknown();
159  break;
160  }
161  } catch (Exception $exception) {
162  $this->respondBadRequest($exception->getMessage());
163  }
164  }
respondUnknown()
Send a "unknown operation" response.
static getByKeys($a_obj_id, $a_usr_id, $a_create=false)
Get a result by object and user key.
readFields($a_obj_id)
Read the LTI Consumer object fields.
deleteResult($request)
Delete a stored result.
respondUnauthorized($message=null)
Send an "unauthorized" response.
$token
Definition: xapitoken.php:52
replaceResult($request)
Replace a stored result.
respondUnsupported()
Send a response that the operation is not supported This depends on the status of the object...
$errors fields
Definition: imgupload.php:51
checkSignature($a_key, $a_secret)
Check the reqest signature.
respondBadRequest($message=null)
Send a "bad request" response.
$xml
Definition: metadata.php:332
readResult($request)
Read a stored result.
readProperties($a_obj_id)
Read the LTI Consumer object properties.
+ Here is the call graph for this function:

◆ isAvailable()

ilLTIConsumerResultService::isAvailable ( )
Returns
bool

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

Referenced by handleRequest().

87  : bool
88  {
89  if ($this->availability == 0) {
90  return false;
91  }
92  return true;
93  }
+ 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 262 of file class.ilLTIConsumerResultService.php.

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

263  {
264  return file_get_contents('./Modules/LTIConsumer/responses/' . $a_name);
265  }
+ Here is the caller graph for this function:

◆ readFields()

ilLTIConsumerResultService::readFields (   $a_obj_id)
private

Read the LTI Consumer object fields.

Parameters
integer$a_obj_id

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

References $DIC, $query, $res, and fields.

Referenced by handleRequest().

362  {
363  global $DIC;
364 
365  $query = "
366  SELECT lti_ext_provider.provider_key, lti_ext_provider.provider_secret, lti_consumer_settings.launch_key, lti_consumer_settings.launch_secret
367  FROM lti_ext_provider, lti_consumer_settings
368  WHERE lti_ext_provider.id = lti_consumer_settings.provider_id
369  AND lti_consumer_settings.obj_id = %s
370  ";
371 
372  $res = $DIC->database()->queryF($query, array('integer'), array($a_obj_id));
373 
374  while ($row = $DIC->database()->fetchAssoc($res)) {
375  if (strlen($row["launch_key"] > 0)) {
376  $this->fields["KEY"] = $row["launch_key"];
377  } else {
378  $this->fields["KEY"] = $row["provider_key"];
379  }
380  if (strlen($row["launch_key"] > 0)) {
381  $this->fields["SECRET"] = $row["launch_secret"];
382  } else {
383  $this->fields["SECRET"] = $row["provider_secret"];
384  }
385  }
386  }
foreach($_POST as $key=> $value) $res
$errors fields
Definition: imgupload.php:51
global $DIC
Definition: goto.php:24
$query
+ Here is the caller graph for this function:

◆ readProperties()

ilLTIConsumerResultService::readProperties (   $a_obj_id)
private

Read the LTI Consumer object properties.

Parameters
integer$a_obj_id

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

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

Referenced by handleRequest().

337  {
338  global $DIC;
339 
340  $query = "
341  SELECT lti_ext_provider.availability, lti_consumer_settings.mastery_score
342  FROM lti_ext_provider, lti_consumer_settings
343  WHERE lti_ext_provider.id = lti_consumer_settings.provider_id
344  AND lti_consumer_settings.obj_id = %s
345  ";
346 
347  $res = $DIC->database()->queryF($query, array('integer'), array($a_obj_id));
348 
349  if ($row = $DIC->database()->fetchAssoc($res)) {
350  //$this->properties = $row;
351  $this->setAvailability((int) $row['availability']);
352  $this->setMasteryScore((float) $row['mastery_score']);
353  }
354  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readResult()

ilLTIConsumerResultService::readResult (   $request)
protected

Read a stored result.

Parameters
SimpleXMLElement$request

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

References $response, and loadResponse().

Referenced by handleRequest().

171  {
172  $response = $this->loadResponse('readResult.xml');
173  $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
174  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
175  $response = str_replace('{operation}', $this->operation, $response);
176  $response = str_replace('{result}', $this->result->result, $response);
177 
178  header('Content-type: application/xml');
179  echo $response;
180  }
loadResponse($a_name)
Load the XML template for the response.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceResult()

ilLTIConsumerResultService::replaceResult (   $request)
protected

Replace a stored result.

Parameters
SimpleXMLElement$request

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

References $response, $result, if, and loadResponse().

Referenced by handleRequest().

187  {
188  $result = (string) $request->resultRecord->result->resultScore->textString;
189  if (!is_numeric($result)) {
190  $code = "failure";
191  $severity = "status";
192  $description = "The result is not a number.";
193  } elseif ($result < 0 or $result > 1) {
194  $code = "failure";
195  $severity = "status";
196  $description = "The result is out of range from 0 to 1.";
197  } else {
198  $this->result->result = (float) $result;
199  $this->result->save();
200 
201  #if ($result >= $this->getMasteryScore())
202  #{
203  # $lp_status = ilLTIConsumerLPStatus::LP_STATUS_COMPLETED_NUM;
204  #}
205  #else
206  #{
207  # $lp_status = ilLTIConsumerLPStatus::LP_STATUS_FAILED_NUM;
208  #}
209  #$lp_percentage = 100 * $result;
210  #ilLTIConsumerLPStatus::trackResult($this->result->usr_id, $this->result->obj_id, $lp_status, $lp_percentage);
211 
212  $code = "success";
213  $severity = "status";
214  $description = sprintf("Score for %s is now %s", $this->result->id, $this->result->result);
215  }
216 
217  $response = $this->loadResponse('replaceResult.xml');
218  $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
219  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
220  $response = str_replace('{operation}', $this->operation, $response);
221  $response = str_replace('{code}', $code, $response);
222  $response = str_replace('{severity}', $severity, $response);
223  $response = str_replace('{description}', $description, $response);
224 
225  header('Content-type: application/xml');
226  echo $response;
227  }
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
loadResponse($a_name)
Load the XML template for the response.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondBadRequest()

ilLTIConsumerResultService::respondBadRequest (   $message = null)
protected

Send a "bad request" response.

Parameters
stringresponse message

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

References $message.

Referenced by handleRequest().

303  {
304  header('HTTP/1.1 400 Bad Request');
305  header('Content-type: text/plain');
306  if (isset($message)) {
307  echo $message;
308  } else {
309  echo 'This is not a well-formed LTI Basic Outcomes Service request.';
310  }
311  }
$message
Definition: xapiexit.php:14
+ Here is the caller graph for this function:

◆ respondUnauthorized()

ilLTIConsumerResultService::respondUnauthorized (   $message = null)
protected

Send an "unauthorized" response.

Parameters
stringresponse message

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

References $message.

Referenced by handleRequest().

320  {
321  header('HTTP/1.1 401 Unauthorized');
322  header('Content-type: text/plain');
323  if (isset($message)) {
324  echo $message;
325  } else {
326  echo 'This request could not be authorized.';
327  }
328  }
$message
Definition: xapiexit.php:14
+ Here is the caller graph for this function:

◆ respondUnknown()

ilLTIConsumerResultService::respondUnknown ( )
protected

Send a "unknown operation" response.

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

References $response, and loadResponse().

Referenced by handleRequest().

287  {
288  $response = $this->loadResponse('unknown.xml');
289  $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
290  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
291  $response = str_replace('{operation}', $this->operation, $response);
292 
293  header('Content-type: application/xml');
294  echo $response;
295  }
loadResponse($a_name)
Load the XML template for the response.
$response
+ 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 272 of file class.ilLTIConsumerResultService.php.

References $response, and loadResponse().

Referenced by handleRequest().

273  {
274  $response = $this->loadResponse('unsupported.xml');
275  $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
276  $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
277  $response = str_replace('{operation}', $this->operation, $response);
278 
279  header('Content-type: application/xml');
280  echo $response;
281  }
loadResponse($a_name)
Load the XML template for the response.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAvailability()

ilLTIConsumerResultService::setAvailability ( int  $availability)
Parameters
int$availability

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

References $availability.

Referenced by readProperties().

80  {
81  $this->availability = $availability;
82  }
+ Here is the caller graph for this function:

◆ setMasteryScore()

ilLTIConsumerResultService::setMasteryScore ( float  $mastery_score)
Parameters
float$mastery_score

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

References $mastery_score.

Referenced by readProperties().

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

◆ updateLP()

ilLTIConsumerResultService::updateLP ( )
protected

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

References ilLPStatusWrapper\_updateStatus().

Referenced by handleRequest().

414  {
415  if (!($this->result instanceof ilLTIConsumerResult)) {
416  return;
417  }
418 
419  ilLPStatusWrapper::_updateStatus($this->result->getObjId(), $this->result->getUsrId());
420  }
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $availability

ilLTIConsumerResultService::$availability = 0
protected

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

Referenced by getAvailability(), and setAvailability().

◆ $fields

ilLTIConsumerResultService::$fields = array()
protected

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

◆ $mastery_score

ilLTIConsumerResultService::$mastery_score = 1
protected

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

Referenced by getMasteryScore(), and setMasteryScore().

◆ $message_ref_id

ilLTIConsumerResultService::$message_ref_id = ''
protected

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

◆ $operation

ilLTIConsumerResultService::$operation = ''
protected

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

◆ $result

ilLTIConsumerResultService::$result = null
protected

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

Referenced by handleRequest(), and replaceResult().


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