4 require_once __DIR__.
'/XapiProxyPolyFill.php';
13 $this->log()->debug($this->msg(
'proxy initialized'));
17 preg_match(self::PARTS_REG, $request->getUri(), $this->cmdParts);
29 return $this->lrsType;
33 return $this->replacedValues;
37 return $this->specificAllowedStatements;
41 return $this->blockSubStatements;
45 return $this->cmdParts;
53 return $this->defaultLrsEndpoint;
57 return $this->defaultLrsKey;
61 return $this->defaultLrsSecret;
65 return $this->fallbackLrsEndpoint;
69 return $this->fallbackLrsKey;
73 return $this->fallbackLrsSecret;
77 $this->xapiProxyRequest = $xapiProxyRequest;
81 return $this->xapiProxyRequest;
85 $this->xapiProxyResponse = $xapiProxyResponse;
89 return $this->xapiProxyResponse;
94 if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
95 $this->log()->debug($this->msg(
"all statement are allowed"));
98 $obj = json_decode($body,
false);
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);
109 if (!is_array($this->specificAllowedStatements)) {
112 if (in_array($verb,$this->specificAllowedStatements)) {
113 $this->log()->debug($this->msg(
"statement is allowed, do nothing - " . $verb));
117 $this->log()->debug($this->msg(
"statement is NOT allowed, fake response - " . $verb));
118 $this->xapiProxyResponse->fakeResponseBlocked(NULL);
122 if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
123 $this->log()->debug($this->msg(
"json is array of statements"));
126 for (
$i=0;
$i<count($obj);
$i++) {
127 array_push(
$ret,$obj[
$i]->
id);
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));
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]);
140 if (count($up) === 0) {
141 $this->log()->debug($this->msg(
"no allowed statements in array - fake response..."));
142 $this->xapiProxyResponse->fakeResponseBlocked(
$ret);
144 elseif (count($up) !== count(
$ret)) {
145 $this->log()->debug($this->msg(
"mixed with allowed and unallowed statements"));
146 return array($up,
$ret);
158 $obj = json_decode($body,
false);
160 if (json_last_error() != JSON_ERROR_NONE) {
162 $this->log()->error($this->msg(json_last_error_msg()));
167 if (is_object($obj)) {
168 if (is_array($this->replacedValues)) {
169 foreach ($this->replacedValues as $key => $value) {
170 $this->setValue($obj,$key,$value);
173 $this->handleStatementEvaluation($obj);
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);
183 $this->handleStatementEvaluation($obj[
$i]);
186 return json_encode($obj);
193 require_once __DIR__.
'/../class.ilObjXapiCmi5.php';
195 $this->setStatus($xapiStatement);
202 $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
203 $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
206 $this->authToken->getObjId(),
207 $this->authToken->getUsrId()
210 if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
212 $this->authToken->delete();
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;
225 if (property_exists($obj, $path_components[0])) {
226 $this->setValue($obj->{array_shift($path_components)}, implode(
'.', $path_components), $value);
232 if (isset($obj->verb) && isset($obj->actor) && isset($obj->object)) {
233 $verb = $obj->verb->id;
235 if (array_key_exists($verb, $this->sniffVerbs)) {
237 if ($this->isSubStatementCheck($obj)) {
238 $this->log()->debug($this->msg(
"statement is sub-statement, ignore status verb " . $verb));
241 if (isset($obj->result) && isset($obj->result->score) && isset($obj->result->score->scaled)) {
242 $score = $obj->result->score->scaled;
244 $this->log()->debug($this->msg(
"handleLPStatus: " . $this->sniffVerbs[$verb] .
" : " . $score));
245 \ilObjXapiCmi5::handleLPStatusFromProxy($this->client, $this->token, $this->sniffVerbs[$verb], $score);
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"));
260 $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)