4 require_once __DIR__ .
'/XapiProxyPolyFill.php';
14 $this->log()->debug($this->msg(
'proxy initialized'));
19 preg_match(self::PARTS_REG, $request->getUri(), $this->cmdParts);
34 return $this->lrsType;
39 return $this->replacedValues;
44 return $this->specificAllowedStatements;
49 return $this->blockSubStatements;
54 return $this->cmdParts;
64 return $this->defaultLrsEndpoint;
69 return $this->defaultLrsKey;
74 return $this->defaultLrsSecret;
79 return $this->fallbackLrsEndpoint;
84 return $this->fallbackLrsKey;
89 return $this->fallbackLrsSecret;
94 $this->xapiProxyRequest = $xapiProxyRequest;
99 return $this->xapiProxyRequest;
104 $this->xapiProxyResponse = $xapiProxyResponse;
109 return $this->xapiProxyResponse;
115 if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
116 $this->log()->debug($this->msg(
"all statement are allowed"));
119 $obj = json_decode($body,
false);
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);
130 if (!is_array($this->specificAllowedStatements)) {
133 if (in_array($verb, $this->specificAllowedStatements)) {
134 $this->log()->debug($this->msg(
"statement is allowed, do nothing - " . $verb));
137 $this->log()->debug($this->msg(
"statement is NOT allowed, fake response - " . $verb));
138 $this->xapiProxyResponse->fakeResponseBlocked(null);
142 if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
143 $this->log()->debug($this->msg(
"json is array of statements"));
146 for (
$i = 0;
$i < count($obj);
$i++) {
147 array_push(
$ret, $obj[
$i]->
id);
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));
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]);
159 if (count($up) === 0) {
160 $this->log()->debug($this->msg(
"no allowed statements in array - fake response..."));
161 $this->xapiProxyResponse->fakeResponseBlocked(
$ret);
162 } elseif (count($up) !== count(
$ret)) {
163 $this->log()->debug($this->msg(
"mixed with allowed and unallowed statements"));
164 return array($up,
$ret);
175 $obj = json_decode($body,
false);
177 if (json_last_error() != JSON_ERROR_NONE) {
179 $this->log()->error($this->msg(json_last_error_msg()));
184 if (is_object($obj)) {
185 if (is_array($this->replacedValues)) {
186 foreach ($this->replacedValues as $key => $value) {
187 $this->setValue($obj, $key, $value);
190 $this->handleStatementEvaluation($obj);
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);
200 $this->handleStatementEvaluation($obj[
$i]);
203 return json_encode($obj);
210 require_once __DIR__ .
'/../class.ilObjXapiCmi5.php';
212 $this->setStatus($xapiStatement);
218 $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
219 $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
223 $this->authToken->getObjId(),
224 $this->authToken->getUsrId()
228 if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
230 $this->authToken->delete();
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;
243 if (property_exists($obj, $path_components[0])) {
244 $this->setValue($obj->{array_shift($path_components)}, implode(
'.', $path_components), $value);
251 if (isset($obj->verb) && isset($obj->actor) && isset($obj->object)) {
252 $verb = $obj->verb->id;
254 if (array_key_exists($verb, $this->sniffVerbs)) {
256 if ($this->isSubStatementCheck($obj)) {
257 $this->log()->debug($this->msg(
"statement is sub-statement, ignore status verb " . $verb));
260 if (isset($obj->result) && isset($obj->result->score) && isset($obj->result->score->scaled)) {
261 $score = $obj->result->score->scaled;
263 $this->log()->debug($this->msg(
"handleLPStatus: " . $this->sniffVerbs[$verb] .
" : " . $score));
264 \ilObjXapiCmi5::handleLPStatusFromProxy($this->client, $this->token, $this->sniffVerbs[$verb], $score);
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"));
279 $this->log()->debug($this->msg(
"is not Substatement"));
processStatements($request, $body)
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
setRequestParams($request)
if($_SERVER['argc']< 4) $client
setXapiProxyRequest($xapiProxyRequest)
specificAllowedStatements()
__construct($client, $token, $plugin=false)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
setXapiProxyResponse($xapiProxyResponse)
__construct(Container $dic, ilPlugin $plugin)
isSubStatementCheck($obj)
setValue(&$obj, $path, $value)
handleStatementEvaluation($xapiStatement)