ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
XapiProxy\XapiProxy Class Reference
+ Inheritance diagram for XapiProxy\XapiProxy:
+ Collaboration diagram for XapiProxy\XapiProxy:

Public Member Functions

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

Private Member Functions

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

Private Attributes

XapiProxyRequest $xapiProxyRequest
 
XapiProxyResponse $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
string $client
 
string $token
 
bool $plugin = false
 
string $table_prefix
 
ilCmiXapiLrsType $lrsType = null
 
ilCmiXapiAuthToken $authToken = null
 
int $objId = null
 
array $specificAllowedStatements = null
 
array $replacedValues = null
 
bool $blockSubStatements = false
 
array $cmdParts = []
 
string $method
 
string $defaultLrsEndpoint = ''
 
string $defaultLrsKey = ''
 
string $defaultLrsSecret = ''
 
string $fallbackLrsEndpoint = ''
 
string $fallbackLrsKey = ''
 
string $fallbackLrsSecret = ''
 
array $sniffVerbs
 

Detailed Description

Definition at line 25 of file XapiProxy.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 30 of file XapiProxy.php.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ blockSubStatements()

XapiProxy\XapiProxy::blockSubStatements ( )

Definition at line 66 of file XapiProxy.php.

66  : bool
67  {
69  }

◆ client()

XapiProxy\XapiProxy::client ( )

Definition at line 46 of file XapiProxy.php.

References $client.

46  : string
47  {
48  return $this->client;
49  }

◆ cmdParts()

XapiProxy\XapiProxy::cmdParts ( )
Returns
mixed[]

Definition at line 74 of file XapiProxy.php.

74  : array
75  {
76  return $this->cmdParts;
77  }

◆ getDefaultLrsEndpoint()

XapiProxy\XapiProxy::getDefaultLrsEndpoint ( )

Definition at line 84 of file XapiProxy.php.

84  : string
85  {
87  }

◆ getDefaultLrsKey()

XapiProxy\XapiProxy::getDefaultLrsKey ( )

Definition at line 89 of file XapiProxy.php.

89  : string
90  {
91  return $this->defaultLrsKey;
92  }

◆ getDefaultLrsSecret()

XapiProxy\XapiProxy::getDefaultLrsSecret ( )

Definition at line 94 of file XapiProxy.php.

94  : string
95  {
97  }

◆ getFallbackLrsEndpoint()

XapiProxy\XapiProxy::getFallbackLrsEndpoint ( )

Definition at line 99 of file XapiProxy.php.

99  : string
100  {
102  }

◆ getFallbackLrsKey()

XapiProxy\XapiProxy::getFallbackLrsKey ( )

Definition at line 104 of file XapiProxy.php.

104  : string
105  {
106  return $this->fallbackLrsKey;
107  }

◆ getFallbackLrsSecret()

XapiProxy\XapiProxy::getFallbackLrsSecret ( )

Definition at line 109 of file XapiProxy.php.

109  : string
110  {
112  }

◆ getXapiProxyRequest()

XapiProxy\XapiProxy::getXapiProxyRequest ( )

Definition at line 119 of file XapiProxy.php.

119  : XapiProxyRequest
120  {
122  }
XapiProxyRequest $xapiProxyRequest
Definition: XapiProxy.php:27

◆ getXapiProxyResponse()

XapiProxy\XapiProxy::getXapiProxyResponse ( )

Definition at line 129 of file XapiProxy.php.

129  : XapiProxyResponse
130  {
132  }
XapiProxyResponse $xapiProxyResponse
Definition: XapiProxy.php:28

◆ handleStatementEvaluation()

XapiProxy\XapiProxy::handleStatementEvaluation ( object  $xapiStatement)
private

Definition at line 230 of file XapiProxy.php.

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

230  : void
231  {
232  global $DIC;
233  if ($this->plugin) {
234  // ToDo: handle terminate -> delete session
235  $this->setStatus($xapiStatement);
236  } else {
237  /* @var $object */
238  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId());
239  if ((string) $object->getLaunchMode() === (string) \ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
240  // ToDo: check function hasContextActivitiesParentNotEqualToObject!
241  $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
242  $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
243 
244  if ($this->authToken->getUsrId() != ANONYMOUS_USER_ID) {
246  $this->authToken->getObjId(),
247  $this->authToken->getUsrId()
248  );
249  }
250  }
251  if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
252  // ToDo : only cmi5 or also xapi? authToken object still used after that?
253  $this->authToken->delete();
254  }
255  }
256  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
setStatus(object $obj)
Definition: XapiProxy.php:272
global $DIC
Definition: shib_login.php:22
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
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:

◆ isSubStatementCheck()

XapiProxy\XapiProxy::isSubStatementCheck ( object  $obj)
private

Definition at line 293 of file XapiProxy.php.

References ilObjectFactory\getInstanceByObjId().

293  : bool
294  {
295  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId()); // get ActivityId in Constructor for better performance, is also used in handleEvaluationStatement
296  $objActivityId = $object->getActivityId();
297  $statementActivityId = $obj->object->id;
298  if ($statementActivityId != $objActivityId) {
299  $this->log()->debug($this->msg("statement object id " . $statementActivityId . " != activityId " . $objActivityId));
300  $this->log()->debug($this->msg("is Substatement"));
301  return true;
302  } else {
303  $this->log()->debug($this->msg("is not Substatement"));
304  return false;
305  }
306  }
static getInstanceByObjId(?int $obj_id, bool $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 51 of file XapiProxy.php.

◆ method()

XapiProxy\XapiProxy::method ( )

Definition at line 79 of file XapiProxy.php.

79  : string
80  {
81  return $this->method;
82  }

◆ modifyBody()

XapiProxy\XapiProxy::modifyBody ( string  $body)

Definition at line 197 of file XapiProxy.php.

197  : string
198  {
199  $obj = json_decode($body, false);
200 
201  if (json_last_error() != JSON_ERROR_NONE) {
202  // JSON is not valid
203  $this->log()->error($this->msg(json_last_error_msg()));
204  return $body;
205  }
206 
207  // $log->debug(json_encode($obj, JSON_PRETTY_PRINT)); // only in DEBUG mode for better performance
208  if (is_object($obj)) {
209  if (is_array($this->replacedValues)) {
210  foreach ($this->replacedValues as $key => $value) {
211  $this->setValue($obj, (string) $key, (string) $value);
212  }
213  }
214  $this->handleStatementEvaluation($obj); // ToDo
215  }
216 
217  if (is_array($obj)) {
218  for ($i = 0; $i < count($obj); $i++) {
219  if (is_array($this->replacedValues)) {
220  foreach ($this->replacedValues as $key => $value) {
221  $this->setValue($obj[$i], (string) $key, (string) $value);
222  }
223  }
224  $this->handleStatementEvaluation($obj[$i]); // ToDo
225  }
226  }
227  return json_encode($obj);
228  }
setValue(object &$obj, string $path, string $value)
Definition: XapiProxy.php:258
handleStatementEvaluation(object $xapiStatement)
Definition: XapiProxy.php:230

◆ processStatements()

XapiProxy\XapiProxy::processStatements ( \Psr\Http\Message\RequestInterface  $request,
  $body 
)

Definition at line 134 of file XapiProxy.php.

References null.

134  : ?array
135  {
136  // everything is allowed
137  if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
138  $this->log()->debug($this->msg("all statement are allowed"));
139  return null;
140  }
141  $obj = json_decode($body, false);
142  // single statement object
143  if (is_object($obj) && isset($obj->verb)) {
144  $this->log()->debug($this->msg("json is object and statement"));
145  $isSubStatement = $this->isSubStatementCheck($obj);
146  $verb = $obj->verb->id;
147  if ($this->blockSubStatements && $isSubStatement) {
148  $this->log()->debug($this->msg("sub-statement is NOT allowed, fake response - " . $verb));
149  $this->xapiProxyResponse->fakeResponseBlocked(null);
150  }
151  // $specificAllowedStatements
152  if (!is_array($this->specificAllowedStatements)) {
153  return null;
154  }
155  if (in_array($verb, $this->specificAllowedStatements)) {
156  $this->log()->debug($this->msg("statement is allowed, do nothing - " . $verb));
157  return null;
158  } else {
159  $this->log()->debug($this->msg("statement is NOT allowed, fake response - " . $verb));
160  $this->xapiProxyResponse->fakeResponseBlocked(null);
161  }
162  }
163  // array of statement objects
164  if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
165  $this->log()->debug($this->msg("json is array of statements"));
166  $ret = array();
167  $up = array();
168  foreach ($obj as $i => $singleObj) {
169  $ret[] = $singleObj->id;
170  // push every statementid for fakePostResponse
171  $isSubStatement = $this->isSubStatementCheck($singleObj);
172  $verb = $singleObj->verb->id;
173  if ($this->blockSubStatements && $isSubStatement) {
174  $this->log()->debug($this->msg("sub-statement is NOT allowed - " . $verb));
175  } else {
176  if (!is_array($this->specificAllowedStatements) || (is_array($this->specificAllowedStatements) && in_array($verb, $this->specificAllowedStatements))) {
177  $this->log()->debug($this->msg("statement is allowed - " . $verb));
178  $up[] = $singleObj;
179  }
180  }
181  }
182  if ($up === []) { // nothing allowed
183  $this->log()->debug($this->msg("no allowed statements in array - fake response..."));
184  $this->xapiProxyResponse->fakeResponseBlocked("");
185  // $this->xapiProxyResponse->fakeResponseBlocked($ret);
186  } elseif (count($up) !== count($ret)) { // mixed request with allowed and not allowed statements
187  $this->log()->debug($this->msg("mixed with allowed and unallowed statements"));
188  return array($up,$ret);
189  } else {
190  // just return nothing
191  return null;
192  }
193  }
194  return null;
195  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isSubStatementCheck(object $obj)
Definition: XapiProxy.php:293

◆ replacedValues()

XapiProxy\XapiProxy::replacedValues ( )

Definition at line 56 of file XapiProxy.php.

56  : ?array
57  {
58  return $this->replacedValues;
59  }

◆ setRequestParams()

XapiProxy\XapiProxy::setRequestParams ( Request  $request)

Definition at line 36 of file XapiProxy.php.

36  : void
37  {
38  preg_match(self::PARTS_REG, (string) $request->getUri(), $this->cmdParts);
39  }

◆ setStatus()

XapiProxy\XapiProxy::setStatus ( object  $obj)
private

Definition at line 272 of file XapiProxy.php.

272  : void
273  {
274  // if (isset($obj->verb) && isset($obj->actor) && isset($obj->object)) {
275  // $verb = $obj->verb->id;
276  // $score = 'NOT_SET';
277  // if (array_key_exists($verb, $this->sniffVerbs)) {
278  // // check context
279  // if ($this->isSubStatementCheck($obj)) {
280  // $this->log()->debug($this->msg("statement is sub-statement, ignore status verb " . $verb));
281  // return;
282  // }
283  // if (isset($obj->result) && isset($obj->result->score) && isset($obj->result->score->scaled)) {
284  // $score = $obj->result->score->scaled;
285  // }
286  // $this->log()->debug($this->msg("handleLPStatus: " . $this->sniffVerbs[$verb] . " : " . $score));
287  // \ilObjXapiCmi5::handleLPStatusFromProxy($this->client, $this->token, $this->sniffVerbs[$verb], $score);//UK check
288  // }
289  // }
290  }

◆ setValue()

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

Definition at line 258 of file XapiProxy.php.

258  : void
259  {
260  $path_components = explode('.', $path);
261  if (count($path_components) == 1) {
262  if (property_exists($obj, $path_components[0])) {
263  $obj->{$path_components[0]} = $value;
264  }
265  } else {
266  if (property_exists($obj, $path_components[0])) {
267  $this->setValue($obj->{array_shift($path_components)}, implode('.', $path_components), $value);
268  }
269  }
270  }
$path
Definition: ltiservices.php:29
setValue(object &$obj, string $path, string $value)
Definition: XapiProxy.php:258

◆ setXapiProxyRequest()

XapiProxy\XapiProxy::setXapiProxyRequest ( XapiProxyRequest  $xapiProxyRequest)

Definition at line 114 of file XapiProxy.php.

114  : void
115  {
116  $this->xapiProxyRequest = $xapiProxyRequest;
117  }
XapiProxyRequest $xapiProxyRequest
Definition: XapiProxy.php:27

◆ setXapiProxyResponse()

XapiProxy\XapiProxy::setXapiProxyResponse ( XapiProxyResponse  $xapiProxyResponse)

Definition at line 124 of file XapiProxy.php.

124  : void
125  {
126  $this->xapiProxyResponse = $xapiProxyResponse;
127  }
XapiProxyResponse $xapiProxyResponse
Definition: XapiProxy.php:28

◆ specificAllowedStatements()

XapiProxy\XapiProxy::specificAllowedStatements ( )

Definition at line 61 of file XapiProxy.php.

61  : ?array
62  {
64  }

◆ token()

XapiProxy\XapiProxy::token ( )

Definition at line 41 of file XapiProxy.php.

References $token.

41  : string
42  {
43  return $this->token;
44  }

Field Documentation

◆ $xapiProxyRequest

XapiProxyRequest XapiProxy\XapiProxy::$xapiProxyRequest
private

Definition at line 27 of file XapiProxy.php.

◆ $xapiProxyResponse

XapiProxyResponse XapiProxy\XapiProxy::$xapiProxyResponse
private

Definition at line 28 of file XapiProxy.php.


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