19declare(strict_types=1);
33 protected ?array $specificAllowedStatements =
null;
34 protected ?array $replacedValues =
null;
35 protected bool $blockSubStatements =
false;
36 protected array $cmdParts = [];
39 protected string $defaultLrsEndpoint =
'';
40 protected string $defaultLrsKey =
'';
41 protected string $defaultLrsSecret =
'';
43 protected string $fallbackLrsEndpoint =
'';
44 protected string $fallbackLrsKey =
'';
45 protected string $fallbackLrsSecret =
'';
47 public const PARTS_REG =
'/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/';
49 protected array $sniffVerbs = array(
50 "http://adlnet.gov/expapi/verbs/completed" =>
"completed",
51 "http://adlnet.gov/expapi/verbs/passed" =>
"passed",
52 "http://adlnet.gov/expapi/verbs/failed" =>
"failed",
53 "http://adlnet.gov/expapi/verbs/satisfied" =>
"passed"
56 public const TERMINATED_VERB =
"http://adlnet.gov/expapi/verbs/terminated";
63 $this->table_prefix = $this->plugin ?
"xxcf" :
"cmix";
64 preg_match(self::PARTS_REG, (
string)
$GLOBALS[
'DIC']->
http()->request()->getUri(), $this->cmdParts);
65 $this->method = strtolower(
$GLOBALS[
'DIC']->
http()->request()->getMethod());
70 return \ilLoggerFactory::getLogger(
'cmix');
73 public function msg(
string $msg): string
76 return "XapiCmi5Plugin: " . $msg;
84 $this->log()->debug($this->msg(
'initLrs'));
88 $this->log()->error($this->msg(
$e->getMessage()));
89 header(
'HTTP/1.1 401 Unauthorized');
91 header(
'Access-Control-Allow-Credentials: true');
95 $this->authToken = $authToken;
105 $lrsType = $this->getLrsTypeAndMoreByToken();
106 $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
107 $this->defaultLrsKey = $lrsType->getLrsKey();
108 $this->defaultLrsSecret = $lrsType->getLrsSecret();
109 $this->lrsType = $lrsType;
112 $objId = $this->authToken->getObjId();
114 if (!$lrsType->isAvailable()) {
115 throw new \ilCmiXapiException(
116 'lrs endpoint (id=' . $this->authToken->getLrsTypeId() .
') unavailable (responded 401-unauthorized)'
120 $this->log()->error($this->msg(
$e->getMessage()));
121 header(
'Access-Control-Allow-Origin: ' .
$_SERVER[
"HTTP_ORIGIN"]);
122 header(
'Access-Control-Allow-Credentials: true');
123 header(
'HTTP/1.1 401 Unauthorized');
139 $query =
"SELECT {$this->table_prefix}_settings.lrs_type_id,
140 {$this->table_prefix}_settings.only_moveon,
141 {$this->table_prefix}_settings.achieved,
142 {$this->table_prefix}_settings.answered,
143 {$this->table_prefix}_settings.completed,
144 {$this->table_prefix}_settings.failed,
145 {$this->table_prefix}_settings.initialized,
146 {$this->table_prefix}_settings.passed,
147 {$this->table_prefix}_settings.progressed,
148 {$this->table_prefix}_settings.satisfied,
149 {$this->table_prefix}_settings.c_terminated,
150 {$this->table_prefix}_settings.hide_data,
151 {$this->table_prefix}_settings.c_timestamp,
152 {$this->table_prefix}_settings.duration,
153 {$this->table_prefix}_settings.no_substatements,
154 {$this->table_prefix}_settings.privacy_ident
155 FROM {$this->table_prefix}_settings, {$this->table_prefix}_token
156 WHERE {$this->table_prefix}_settings.obj_id = {$this->table_prefix}_token.obj_id AND {$this->table_prefix}_token.token = " . $db->quote($this->token,
'text');
158 $res = $db->query($query);
159 while ($row = $db->fetchObject(
$res)) {
160 $type_id = (
int) $row->lrs_type_id;
163 $lrs = new \ilCmiXapiLrsType($type_id);
167 if ((
bool) $row->only_moveon) {
168 if ((
bool) $row->achieved) {
169 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/achieved";
171 if ((
bool) $row->answered) {
172 $sarr[] =
"http://adlnet.gov/expapi/verbs/answered";
173 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/answered";
175 if ((
bool) $row->completed) {
176 $sarr[] =
"http://adlnet.gov/expapi/verbs/completed";
177 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/completed";
179 if ((
bool) $row->failed) {
180 $sarr[] =
"http://adlnet.gov/expapi/verbs/failed";
182 if ((
bool) $row->initialized) {
183 $sarr[] =
"http://adlnet.gov/expapi/verbs/initialized";
184 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/initialized";
186 if ((
bool) $row->passed) {
187 $sarr[] =
"http://adlnet.gov/expapi/verbs/passed";
189 if ((
bool) $row->progressed) {
190 $sarr[] =
"http://adlnet.gov/expapi/verbs/progressed";
192 if ((
bool) $row->satisfied) {
193 $sarr[] =
"https://w3id.org/xapi/adl/verbs/satisfied";
195 if ((
bool) $row->c_terminated) {
196 $sarr[] =
"http://adlnet.gov/expapi/verbs/terminated";
198 if (count($sarr) > 0) {
199 $this->specificAllowedStatements = $sarr;
200 $this->log()->debug($this->msg(
'getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements,
true)));
203 if ((
bool) $row->hide_data) {
205 if ((
bool) $row->c_timestamp) {
206 $rarr[
'timestamp'] =
'1970-01-01T00:00:00.000Z';
208 if ((
bool) $row->duration) {
209 $rarr[
'result.duration'] =
'PT00.000S';
211 if (count($rarr) > 0) {
212 $this->replacedValues = $rarr;
213 $this->log()->debug($this->msg(
'getReplacedValues: ' . var_export($this->replacedValues,
true)));
216 if ((
bool) $row->no_substatements) {
217 $this->blockSubStatements =
true;
218 $this->log()->debug($this->msg(
'getBlockSubStatements: ' . $this->blockSubStatements));
220 $lrs->setPrivacyIdent((
int) $row->privacy_ident);
__construct(string $client, string $token, ?bool $plugin=false)
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?
static getInstanceByToken(string $token)
static saveProxySuccess(int $objId, int $usrId, int $privacyIdent)
Component logger with individual log levels by component id.
static http()
Fetches the global http state from ILIAS.
if(!file_exists('../ilias.ini.php'))