ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 26 of file XapiProxy.php.

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented from XapiProxy\XapiProxyPolyFill.

Definition at line 31 of file XapiProxy.php.

32 {
34 $this->log()->debug($this->msg('proxy initialized'));
35 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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 67 of file XapiProxy.php.

67 : bool
68 {
70 }

◆ client()

XapiProxy\XapiProxy::client ( )

Definition at line 47 of file XapiProxy.php.

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

References $client.

◆ cmdParts()

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

Definition at line 75 of file XapiProxy.php.

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

◆ getDefaultLrsEndpoint()

XapiProxy\XapiProxy::getDefaultLrsEndpoint ( )

Definition at line 85 of file XapiProxy.php.

85 : string
86 {
88 }

◆ getDefaultLrsKey()

XapiProxy\XapiProxy::getDefaultLrsKey ( )

Definition at line 90 of file XapiProxy.php.

90 : string
91 {
93 }

◆ getDefaultLrsSecret()

XapiProxy\XapiProxy::getDefaultLrsSecret ( )

Definition at line 95 of file XapiProxy.php.

95 : string
96 {
98 }

◆ getFallbackLrsEndpoint()

XapiProxy\XapiProxy::getFallbackLrsEndpoint ( )

Definition at line 100 of file XapiProxy.php.

100 : string
101 {
103 }

◆ getFallbackLrsKey()

XapiProxy\XapiProxy::getFallbackLrsKey ( )

Definition at line 105 of file XapiProxy.php.

105 : string
106 {
108 }

◆ getFallbackLrsSecret()

XapiProxy\XapiProxy::getFallbackLrsSecret ( )

Definition at line 110 of file XapiProxy.php.

110 : string
111 {
113 }

◆ getXapiProxyRequest()

XapiProxy\XapiProxy::getXapiProxyRequest ( )

Definition at line 120 of file XapiProxy.php.

120 : XapiProxyRequest
121 {
123 }
XapiProxyRequest $xapiProxyRequest
Definition: XapiProxy.php:28

◆ getXapiProxyResponse()

XapiProxy\XapiProxy::getXapiProxyResponse ( )

Definition at line 130 of file XapiProxy.php.

130 : XapiProxyResponse
131 {
133 }
XapiProxyResponse $xapiProxyResponse
Definition: XapiProxy.php:29

◆ handleStatementEvaluation()

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

Definition at line 231 of file XapiProxy.php.

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

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

+ Here is the call graph for this function:

◆ isSubStatementCheck()

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

Definition at line 294 of file XapiProxy.php.

294 : bool
295 {
296 $object = \ilObjectFactory::getInstanceByObjId($this->authToken->getObjId()); // get ActivityId in Constructor for better performance, is also used in handleEvaluationStatement
297 $objActivityId = $object->getActivityId();
298 $statementActivityId = $obj->object->id;
299 if ($statementActivityId != $objActivityId) {
300 $this->log()->debug($this->msg("statement object id " . $statementActivityId . " != activityId " . $objActivityId));
301 $this->log()->debug($this->msg("is Substatement"));
302 return true;
303 } else {
304 $this->log()->debug($this->msg("is not Substatement"));
305 return false;
306 }
307 }

References ilObjectFactory\getInstanceByObjId().

+ Here is the call graph for this function:

◆ lrsType()

XapiProxy\XapiProxy::lrsType ( )

Definition at line 52 of file XapiProxy.php.

◆ method()

XapiProxy\XapiProxy::method ( )

Definition at line 80 of file XapiProxy.php.

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

◆ modifyBody()

XapiProxy\XapiProxy::modifyBody ( string  $body)

Definition at line 198 of file XapiProxy.php.

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

◆ processStatements()

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

Definition at line 135 of file XapiProxy.php.

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

◆ replacedValues()

XapiProxy\XapiProxy::replacedValues ( )

Definition at line 57 of file XapiProxy.php.

57 : ?array
58 {
60 }

◆ setRequestParams()

XapiProxy\XapiProxy::setRequestParams ( Request  $request)

Definition at line 37 of file XapiProxy.php.

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

◆ setStatus()

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

Definition at line 273 of file XapiProxy.php.

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

◆ setValue()

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

Definition at line 259 of file XapiProxy.php.

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

References $path.

◆ setXapiProxyRequest()

XapiProxy\XapiProxy::setXapiProxyRequest ( XapiProxyRequest  $xapiProxyRequest)

Definition at line 115 of file XapiProxy.php.

115 : void
116 {
117 $this->xapiProxyRequest = $xapiProxyRequest;
118 }

◆ setXapiProxyResponse()

XapiProxy\XapiProxy::setXapiProxyResponse ( XapiProxyResponse  $xapiProxyResponse)

Definition at line 125 of file XapiProxy.php.

125 : void
126 {
127 $this->xapiProxyResponse = $xapiProxyResponse;
128 }

◆ specificAllowedStatements()

XapiProxy\XapiProxy::specificAllowedStatements ( )

Definition at line 62 of file XapiProxy.php.

62 : ?array
63 {
65 }

◆ token()

XapiProxy\XapiProxy::token ( )

Definition at line 42 of file XapiProxy.php.

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

References $token.

Field Documentation

◆ $xapiProxyRequest

XapiProxyRequest XapiProxy\XapiProxy::$xapiProxyRequest
private

Definition at line 28 of file XapiProxy.php.

◆ $xapiProxyResponse

XapiProxyResponse XapiProxy\XapiProxy::$xapiProxyResponse
private

Definition at line 29 of file XapiProxy.php.


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