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

Public Member Functions

 __construct ($client, $token, $plugin=false)
 
 setRequestParams ($request)
 
 token ()
 
 client ()
 
 lrsType ()
 
 replacedValues ()
 
 specificAllowedStatements ()
 
 blockSubStatements ()
 
 cmdParts ()
 
 method ()
 
 getDefaultLrsEndpoint ()
 
 getDefaultLrsKey ()
 
 getDefaultLrsSecret ()
 
 getFallbackLrsEndpoint ()
 
 getFallbackLrsKey ()
 
 getFallbackLrsSecret ()
 
 setXapiProxyRequest ($xapiProxyRequest)
 
 getXapiProxyRequest ()
 
 setXapiProxyResponse ($xapiProxyResponse)
 
 getXapiProxyResponse ()
 
 processStatements ($request, $body)
 
 modifyBody ($body)
 
- Public Member Functions inherited from XapiProxy\XapiProxyPolyFill
 __construct ($client, $token, $plugin=false)
 
 log ()
 
 msg ($msg)
 
 initLrs ()
 

Private Member Functions

 handleStatementEvaluation ($xapiStatement)
 
 setValue (&$obj, $path, $value)
 
 setStatus ($obj)
 
 isSubStatementCheck ($obj)
 

Private Attributes

 $xapiProxyRequest
 
 $xapiProxyResponse
 

Additional Inherited Members

- Data Fields inherited from XapiProxy\XapiProxyPolyFill
const PARTS_REG = '/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/'
 
const TERMINATED_VERB = "http://adlnet.gov/expapi/verbs/terminated"
 
- Protected Attributes inherited from XapiProxy\XapiProxyPolyFill
 $client
 
 $token
 
 $plugin
 
 $table_prefix
 
 $lrsType
 
 $authToken = null
 
 $objId = null
 
 $specificAllowedStatements = null
 
 $replacedValues = null
 
 $blockSubStatements = false
 
 $cmdParts
 
 $method
 
 $defaultLrsEndpoint = ''
 
 $defaultLrsKey = ''
 
 $defaultLrsSecret = ''
 
 $fallbackLrsEndpoint = ''
 
 $fallbackLrsKey = ''
 
 $fallbackLrsSecret = ''
 
 $sniffVerbs
 

Detailed Description

Definition at line 6 of file XapiProxy.php.

Constructor & Destructor Documentation

◆ __construct()

XapiProxy\XapiProxy::__construct (   $client,
  $token,
  $plugin = false 
)

Definition at line 11 of file XapiProxy.php.

References $client, XapiProxy\$plugin, $token, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ blockSubStatements()

XapiProxy\XapiProxy::blockSubStatements ( )

Definition at line 47 of file XapiProxy.php.

◆ client()

XapiProxy\XapiProxy::client ( )

Definition at line 27 of file XapiProxy.php.

References $client.

28  {
29  return $this->client;
30  }

◆ cmdParts()

XapiProxy\XapiProxy::cmdParts ( )

Definition at line 52 of file XapiProxy.php.

◆ getDefaultLrsEndpoint()

XapiProxy\XapiProxy::getDefaultLrsEndpoint ( )

Definition at line 62 of file XapiProxy.php.

◆ getDefaultLrsKey()

XapiProxy\XapiProxy::getDefaultLrsKey ( )

Definition at line 67 of file XapiProxy.php.

◆ getDefaultLrsSecret()

XapiProxy\XapiProxy::getDefaultLrsSecret ( )

Definition at line 72 of file XapiProxy.php.

◆ getFallbackLrsEndpoint()

XapiProxy\XapiProxy::getFallbackLrsEndpoint ( )

Definition at line 77 of file XapiProxy.php.

◆ getFallbackLrsKey()

XapiProxy\XapiProxy::getFallbackLrsKey ( )

Definition at line 82 of file XapiProxy.php.

◆ getFallbackLrsSecret()

XapiProxy\XapiProxy::getFallbackLrsSecret ( )

Definition at line 87 of file XapiProxy.php.

◆ getXapiProxyRequest()

XapiProxy\XapiProxy::getXapiProxyRequest ( )

Definition at line 97 of file XapiProxy.php.

98  {
100  }

◆ getXapiProxyResponse()

XapiProxy\XapiProxy::getXapiProxyResponse ( )

Definition at line 107 of file XapiProxy.php.

108  {
110  }

◆ handleStatementEvaluation()

XapiProxy\XapiProxy::handleStatementEvaluation (   $xapiStatement)
private

Definition at line 206 of file XapiProxy.php.

References $DIC, ilLPStatusWrapper\_updateStatus(), ANONYMOUS_USER_ID, ilObjectFactory\getInstanceByObjId(), and ilObjCmiXapi\LAUNCH_MODE_NORMAL.

207  {
208  global $DIC;
209  if ($this->plugin) {
210  require_once __DIR__ . '/../class.ilObjXapiCmi5.php';
211  // ToDo: handle terminate -> delete session
212  $this->setStatus($xapiStatement);
213  } else {
214  /* @var $object */
215  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId());
216  if ((string) $object->getLaunchMode() === (string) \ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
217  // ToDo: check function hasContextActivitiesParentNotEqualToObject!
218  $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
219  $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
220 
221  if ($this->authToken->getUsrId() != ANONYMOUS_USER_ID) {
223  $this->authToken->getObjId(),
224  $this->authToken->getUsrId()
225  );
226  }
227  }
228  if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
229  // ToDo : only cmi5 or also xapi? authToken object still used after that?
230  $this->authToken->delete();
231  }
232  }
233  }
const ANONYMOUS_USER_ID
Definition: constants.php:25
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
global $DIC
Definition: goto.php:24
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

◆ isSubStatementCheck()

XapiProxy\XapiProxy::isSubStatementCheck (   $obj)
private

Definition at line 269 of file XapiProxy.php.

References ilObjectFactory\getInstanceByObjId().

270  {
271  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId()); // get ActivityId in Constructor for better performance, is also used in handleEvaluationStatement
272  $objActivityId = $object->getActivityId();
273  $statementActivityId = $obj->object->id;
274  if ($statementActivityId != $objActivityId) {
275  $this->log()->debug($this->msg("statement object id " . $statementActivityId . " != activityId " . $objActivityId));
276  $this->log()->debug($this->msg("is Substatement"));
277  return true;
278  } else {
279  $this->log()->debug($this->msg("is not Substatement"));
280  return false;
281  }
282  }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

◆ lrsType()

XapiProxy\XapiProxy::lrsType ( )

Definition at line 32 of file XapiProxy.php.

◆ method()

XapiProxy\XapiProxy::method ( )

Definition at line 57 of file XapiProxy.php.

58  {
59  return $this->method;
60  }

◆ modifyBody()

XapiProxy\XapiProxy::modifyBody (   $body)

Definition at line 173 of file XapiProxy.php.

References $i.

174  {
175  $obj = json_decode($body, false);
176 
177  if (json_last_error() != JSON_ERROR_NONE) {
178  // JSON is not valid
179  $this->log()->error($this->msg(json_last_error_msg()));
180  return $body;
181  }
182 
183  // $log->debug(json_encode($obj, JSON_PRETTY_PRINT)); // only in DEBUG mode for better performance
184  if (is_object($obj)) {
185  if (is_array($this->replacedValues)) {
186  foreach ($this->replacedValues as $key => $value) {
187  $this->setValue($obj, $key, $value);
188  }
189  }
190  $this->handleStatementEvaluation($obj); // ToDo
191  }
192 
193  if (is_array($obj)) {
194  for ($i = 0; $i < count($obj); $i++) {
195  if (is_array($this->replacedValues)) {
196  foreach ($this->replacedValues as $key => $value) {
197  $this->setValue($obj[$i], $key, $value);
198  }
199  }
200  $this->handleStatementEvaluation($obj[$i]); // ToDo
201  }
202  }
203  return json_encode($obj);
204  }
setValue(&$obj, $path, $value)
Definition: XapiProxy.php:235
handleStatementEvaluation($xapiStatement)
Definition: XapiProxy.php:206
$i
Definition: metadata.php:24

◆ processStatements()

XapiProxy\XapiProxy::processStatements (   $request,
  $body 
)

Definition at line 112 of file XapiProxy.php.

References $i, and $ret.

113  {
114  // everything is allowed
115  if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
116  $this->log()->debug($this->msg("all statement are allowed"));
117  return null;
118  }
119  $obj = json_decode($body, false);
120  // single statement object
121  if (is_object($obj) && isset($obj->verb)) {
122  $this->log()->debug($this->msg("json is object and statement"));
123  $isSubStatement = $this->isSubStatementCheck($obj);
124  $verb = $obj->verb->id;
125  if ($this->blockSubStatements && $isSubStatement) {
126  $this->log()->debug($this->msg("sub-statement is NOT allowed, fake response - " . $verb));
127  $this->xapiProxyResponse->fakeResponseBlocked(null);
128  }
129  // $specificAllowedStatements
130  if (!is_array($this->specificAllowedStatements)) {
131  return null;
132  }
133  if (in_array($verb, $this->specificAllowedStatements)) {
134  $this->log()->debug($this->msg("statement is allowed, do nothing - " . $verb));
135  return null;
136  } else {
137  $this->log()->debug($this->msg("statement is NOT allowed, fake response - " . $verb));
138  $this->xapiProxyResponse->fakeResponseBlocked(null);
139  }
140  }
141  // array of statement objects
142  if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
143  $this->log()->debug($this->msg("json is array of statements"));
144  $ret = array();
145  $up = array();
146  for ($i = 0; $i < count($obj); $i++) {
147  array_push($ret, $obj[$i]->id); // push every statementid for fakePostResponse
148  $isSubStatement = $this->isSubStatementCheck($obj[$i]);
149  $verb = $obj[$i]->verb->id;
150  if ($this->blockSubStatements && $isSubStatement) {
151  $this->log()->debug($this->msg("sub-statement is NOT allowed - " . $verb));
152  } else {
153  if (!is_array($this->specificAllowedStatements) || (is_array($this->specificAllowedStatements) && in_array($verb, $this->specificAllowedStatements))) {
154  $this->log()->debug($this->msg("statement is allowed - " . $verb));
155  array_push($up, $obj[$i]);
156  }
157  }
158  }
159  if (count($up) === 0) { // nothing allowed
160  $this->log()->debug($this->msg("no allowed statements in array - fake response..."));
161  $this->xapiProxyResponse->fakeResponseBlocked($ret);
162  } elseif (count($up) !== count($ret)) { // mixed request with allowed and not allowed statements
163  $this->log()->debug($this->msg("mixed with allowed and unallowed statements"));
164  return array($up,$ret);
165  } else {
166  // just return nothing
167  return null;
168  }
169  }
170  return null;
171  }
$ret
Definition: parser.php:6
$i
Definition: metadata.php:24

◆ replacedValues()

XapiProxy\XapiProxy::replacedValues ( )

Definition at line 37 of file XapiProxy.php.

◆ setRequestParams()

XapiProxy\XapiProxy::setRequestParams (   $request)

Definition at line 17 of file XapiProxy.php.

18  {
19  preg_match(self::PARTS_REG, $request->getUri(), $this->cmdParts);
20  }

◆ setStatus()

XapiProxy\XapiProxy::setStatus (   $obj)
private

Definition at line 249 of file XapiProxy.php.

250  {
251  if (isset($obj->verb) && isset($obj->actor) && isset($obj->object)) {
252  $verb = $obj->verb->id;
253  $score = 'NOT_SET';
254  if (array_key_exists($verb, $this->sniffVerbs)) {
255  // check context
256  if ($this->isSubStatementCheck($obj)) {
257  $this->log()->debug($this->msg("statement is sub-statement, ignore status verb " . $verb));
258  return;
259  }
260  if (isset($obj->result) && isset($obj->result->score) && isset($obj->result->score->scaled)) {
261  $score = $obj->result->score->scaled;
262  }
263  $this->log()->debug($this->msg("handleLPStatus: " . $this->sniffVerbs[$verb] . " : " . $score));
264  \ilObjXapiCmi5::handleLPStatusFromProxy($this->client, $this->token, $this->sniffVerbs[$verb], $score);//UK check
265  }
266  }
267  }

◆ setValue()

XapiProxy\XapiProxy::setValue ( $obj,
  $path,
  $value 
)
private

Definition at line 235 of file XapiProxy.php.

236  {
237  $path_components = explode('.', $path);
238  if (count($path_components) == 1) {
239  if (property_exists($obj, $path_components[0])) {
240  $obj->{$path_components[0]} = $value;
241  }
242  } else {
243  if (property_exists($obj, $path_components[0])) {
244  $this->setValue($obj->{array_shift($path_components)}, implode('.', $path_components), $value);
245  }
246  }
247  }
setValue(&$obj, $path, $value)
Definition: XapiProxy.php:235

◆ setXapiProxyRequest()

XapiProxy\XapiProxy::setXapiProxyRequest (   $xapiProxyRequest)

Definition at line 92 of file XapiProxy.php.

93  {
94  $this->xapiProxyRequest = $xapiProxyRequest;
95  }

◆ setXapiProxyResponse()

XapiProxy\XapiProxy::setXapiProxyResponse (   $xapiProxyResponse)

Definition at line 102 of file XapiProxy.php.

103  {
104  $this->xapiProxyResponse = $xapiProxyResponse;
105  }

◆ specificAllowedStatements()

XapiProxy\XapiProxy::specificAllowedStatements ( )

Definition at line 42 of file XapiProxy.php.

◆ token()

XapiProxy\XapiProxy::token ( )

Definition at line 22 of file XapiProxy.php.

References $token.

23  {
24  return $this->token;
25  }

Field Documentation

◆ $xapiProxyRequest

XapiProxy\XapiProxy::$xapiProxyRequest
private

Definition at line 8 of file XapiProxy.php.

◆ $xapiProxyResponse

XapiProxy\XapiProxy::$xapiProxyResponse
private

Definition at line 9 of file XapiProxy.php.


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