ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 40 of file XapiProxy.php.

◆ client()

XapiProxy\XapiProxy::client ( )

Definition at line 24 of file XapiProxy.php.

References $client.

24  {
25  return $this->client;
26  }

◆ cmdParts()

XapiProxy\XapiProxy::cmdParts ( )

Definition at line 44 of file XapiProxy.php.

◆ getDefaultLrsEndpoint()

XapiProxy\XapiProxy::getDefaultLrsEndpoint ( )

Definition at line 52 of file XapiProxy.php.

◆ getDefaultLrsKey()

XapiProxy\XapiProxy::getDefaultLrsKey ( )

Definition at line 56 of file XapiProxy.php.

◆ getDefaultLrsSecret()

XapiProxy\XapiProxy::getDefaultLrsSecret ( )

Definition at line 60 of file XapiProxy.php.

◆ getFallbackLrsEndpoint()

XapiProxy\XapiProxy::getFallbackLrsEndpoint ( )

Definition at line 64 of file XapiProxy.php.

◆ getFallbackLrsKey()

XapiProxy\XapiProxy::getFallbackLrsKey ( )

Definition at line 68 of file XapiProxy.php.

◆ getFallbackLrsSecret()

XapiProxy\XapiProxy::getFallbackLrsSecret ( )

Definition at line 72 of file XapiProxy.php.

◆ getXapiProxyRequest()

XapiProxy\XapiProxy::getXapiProxyRequest ( )

Definition at line 80 of file XapiProxy.php.

80  {
82  }

◆ getXapiProxyResponse()

XapiProxy\XapiProxy::getXapiProxyResponse ( )

Definition at line 88 of file XapiProxy.php.

88  {
90  }

◆ handleStatementEvaluation()

XapiProxy\XapiProxy::handleStatementEvaluation (   $xapiStatement)
private

Definition at line 189 of file XapiProxy.php.

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

190  {
191  global $DIC;
192  if ($this->plugin) {
193  require_once __DIR__.'/../class.ilObjXapiCmi5.php';
194  // ToDo: handle terminate -> delete session
195  $this->setStatus($xapiStatement);
196  }
197  else {
198  /* @var $object */
199  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId());
200  if( (string)$object->getLaunchMode() === (string)\ilObjCmiXapi::LAUNCH_MODE_NORMAL ) {
201  // ToDo: check function hasContextActivitiesParentNotEqualToObject!
202  $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
203  $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
204 
206  $this->authToken->getObjId(),
207  $this->authToken->getUsrId()
208  );
209  }
210  if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
211  // ToDo : only cmi5 or also xapi? authToken object still used after that?
212  $this->authToken->delete();
213  }
214  }
215  }
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ isSubStatementCheck()

XapiProxy\XapiProxy::isSubStatementCheck (   $obj)
private

Definition at line 250 of file XapiProxy.php.

References ilObjectFactory\getInstanceByObjId().

250  {
251  $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId()); // get ActivityId in Constructor for better performance, is also used in handleEvaluationStatement
252  $objActivityId = $object->getActivityId();
253  $statementActivityId = $obj->object->id;
254  if ($statementActivityId != $objActivityId) {
255  $this->log()->debug($this->msg("statement object id " . $statementActivityId . " != activityId " . $objActivityId));
256  $this->log()->debug($this->msg("is Substatement"));
257  return true;
258  }
259  else {
260  $this->log()->debug($this->msg("is not Substatement"));
261  return false;
262  }
263  }
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 28 of file XapiProxy.php.

◆ method()

XapiProxy\XapiProxy::method ( )

Definition at line 48 of file XapiProxy.php.

48  {
49  return $this->method;
50  }

◆ modifyBody()

XapiProxy\XapiProxy::modifyBody (   $body)

Definition at line 156 of file XapiProxy.php.

References $i.

157  {
158  $obj = json_decode($body, false);
159 
160  if (json_last_error() != JSON_ERROR_NONE) {
161  // JSON is not valid
162  $this->log()->error($this->msg(json_last_error_msg()));
163  return $body;
164  }
165 
166  // $log->debug(json_encode($obj, JSON_PRETTY_PRINT)); // only in DEBUG mode for better performance
167  if (is_object($obj)) {
168  if (is_array($this->replacedValues)) {
169  foreach ($this->replacedValues as $key => $value) {
170  $this->setValue($obj,$key,$value);
171  }
172  }
173  $this->handleStatementEvaluation($obj); // ToDo
174  }
175 
176  if (is_array($obj)) {
177  for ($i = 0; $i < count($obj); $i++) {
178  if (is_array($this->replacedValues)) {
179  foreach ($this->replacedValues as $key => $value) {
180  $this->setValue($obj[$i],$key,$value);
181  }
182  }
183  $this->handleStatementEvaluation($obj[$i]); // ToDo
184  }
185  }
186  return json_encode($obj);
187  }
setValue(&$obj, $path, $value)
Definition: XapiProxy.php:217
handleStatementEvaluation($xapiStatement)
Definition: XapiProxy.php:189
$i
Definition: metadata.php:24

◆ processStatements()

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

Definition at line 92 of file XapiProxy.php.

References $i, and $ret.

92  {
93  // everything is allowed
94  if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
95  $this->log()->debug($this->msg("all statement are allowed"));
96  return NULL;
97  }
98  $obj = json_decode($body, false);
99  // single statement object
100  if (is_object($obj) && isset($obj->verb)) {
101  $this->log()->debug($this->msg("json is object and statement"));
102  $isSubStatement = $this->isSubStatementCheck($obj);
103  $verb = $obj->verb->id;
104  if ($this->blockSubStatements && $isSubStatement) {
105  $this->log()->debug($this->msg("sub-statement is NOT allowed, fake response - " . $verb));
106  $this->xapiProxyResponse->fakeResponseBlocked(NULL);
107  }
108  // $specificAllowedStatements
109  if (!is_array($this->specificAllowedStatements)) {
110  return NULL;
111  }
112  if (in_array($verb,$this->specificAllowedStatements)) {
113  $this->log()->debug($this->msg("statement is allowed, do nothing - " . $verb));
114  return NULL;
115  }
116  else {
117  $this->log()->debug($this->msg("statement is NOT allowed, fake response - " . $verb));
118  $this->xapiProxyResponse->fakeResponseBlocked(NULL);
119  }
120  }
121  // array of statement objects
122  if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
123  $this->log()->debug($this->msg("json is array of statements"));
124  $ret = array();
125  $up = array();
126  for ($i=0; $i<count($obj); $i++) {
127  array_push($ret,$obj[$i]->id); // push every statementid for fakePostResponse
128  $isSubStatement = $this->isSubStatementCheck($obj[$i]);
129  $verb = $obj[$i]->verb->id;
130  if ($this->blockSubStatements && $isSubStatement) {
131  $this->log()->debug($this->msg("sub-statement is NOT allowed - " .$verb));
132  }
133  else {
134  if (!is_array($this->specificAllowedStatements) || (is_array($this->specificAllowedStatements) && in_array($verb,$this->specificAllowedStatements))) {
135  $this->log()->debug($this->msg("statement is allowed - " . $verb));
136  array_push($up,$obj[$i]);
137  }
138  }
139  }
140  if (count($up) === 0) { // nothing allowed
141  $this->log()->debug($this->msg("no allowed statements in array - fake response..."));
142  $this->xapiProxyResponse->fakeResponseBlocked($ret);
143  }
144  elseif (count($up) !== count($ret)) { // mixed request with allowed and not allowed statements
145  $this->log()->debug($this->msg("mixed with allowed and unallowed statements"));
146  return array($up,$ret);
147  }
148  else {
149  // just return nothing
150  return NULL;
151  }
152  }
153  return NULL;
154  }
$ret
Definition: parser.php:6
$i
Definition: metadata.php:24

◆ replacedValues()

XapiProxy\XapiProxy::replacedValues ( )

Definition at line 32 of file XapiProxy.php.

◆ setRequestParams()

XapiProxy\XapiProxy::setRequestParams (   $request)

Definition at line 16 of file XapiProxy.php.

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

◆ setStatus()

XapiProxy\XapiProxy::setStatus (   $obj)
private

Definition at line 231 of file XapiProxy.php.

231  {
232  if (isset($obj->verb) && isset($obj->actor) && isset($obj->object)) {
233  $verb = $obj->verb->id;
234  $score = 'NOT_SET';
235  if (array_key_exists($verb, $this->sniffVerbs)) {
236  // check context
237  if ($this->isSubStatementCheck($obj)) {
238  $this->log()->debug($this->msg("statement is sub-statement, ignore status verb " . $verb));
239  return;
240  }
241  if (isset($obj->result) && isset($obj->result->score) && isset($obj->result->score->scaled)) {
242  $score = $obj->result->score->scaled;
243  }
244  $this->log()->debug($this->msg("handleLPStatus: " . $this->sniffVerbs[$verb] . " : " . $score));
245  \ilObjXapiCmi5::handleLPStatusFromProxy($this->client, $this->token, $this->sniffVerbs[$verb], $score);//UK check
246  }
247  }
248  }

◆ setValue()

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

Definition at line 217 of file XapiProxy.php.

217  {
218  $path_components = explode('.', $path);
219  if (count($path_components) == 1) {
220  if (property_exists($obj,$path_components[0])) {
221  $obj->{$path_components[0]} = $value;
222  }
223  }
224  else {
225  if (property_exists($obj, $path_components[0])) {
226  $this->setValue($obj->{array_shift($path_components)}, implode('.', $path_components), $value);
227  }
228  }
229  }
setValue(&$obj, $path, $value)
Definition: XapiProxy.php:217

◆ setXapiProxyRequest()

XapiProxy\XapiProxy::setXapiProxyRequest (   $xapiProxyRequest)

Definition at line 76 of file XapiProxy.php.

76  {
77  $this->xapiProxyRequest = $xapiProxyRequest;
78  }

◆ setXapiProxyResponse()

XapiProxy\XapiProxy::setXapiProxyResponse (   $xapiProxyResponse)

Definition at line 84 of file XapiProxy.php.

84  {
85  $this->xapiProxyResponse = $xapiProxyResponse;
86  }

◆ specificAllowedStatements()

XapiProxy\XapiProxy::specificAllowedStatements ( )

Definition at line 36 of file XapiProxy.php.

◆ token()

XapiProxy\XapiProxy::token ( )

Definition at line 20 of file XapiProxy.php.

References $token.

20  {
21  return $this->token;
22  }

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: