3 declare(strict_types=1);
    32     protected ?array $specificAllowedStatements = null;
    33     protected ?array $replacedValues = null;
    34     protected bool $blockSubStatements = 
false;
    35     protected array $cmdParts = [];
    38     protected string $defaultLrsEndpoint = 
'';
    39     protected string $defaultLrsKey = 
'';
    40     protected string $defaultLrsSecret = 
'';
    42     protected string $fallbackLrsEndpoint = 
'';
    43     protected string $fallbackLrsKey = 
'';
    44     protected string $fallbackLrsSecret = 
'';
    46     public const PARTS_REG = 
'/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/'; 
    48     protected array $sniffVerbs = array(
    49         "http://adlnet.gov/expapi/verbs/completed" => 
"completed",
    50         "http://adlnet.gov/expapi/verbs/passed" => 
"passed",
    51         "http://adlnet.gov/expapi/verbs/failed" => 
"failed",
    52         "http://adlnet.gov/expapi/verbs/satisfied" => 
"passed"    55     public const TERMINATED_VERB = 
"http://adlnet.gov/expapi/verbs/terminated";
    57     public function __construct(
string $client, 
string $token, ?
bool $plugin = 
false)
    62         $this->table_prefix = $this->plugin ? 
"xxcf" : 
"cmix";
    63         preg_match(self::PARTS_REG, (
string) 
$GLOBALS[
'DIC']->
http()->request()->getUri(), $this->cmdParts);
    64         $this->method = strtolower(
$GLOBALS[
'DIC']->
http()->request()->getMethod());
    73             return \ilLoggerFactory::getLogger(
'cmix');
    77     public function msg(
string $msg): string
    80             return "XapiCmi5Plugin: " . $msg;
    88         $this->log()->debug($this->msg(
'initLrs'));
   107             $this->log()->error($this->msg($e->getMessage()));
   108             header(
'HTTP/1.1 401 Unauthorized');
   109             header(
'Access-Control-Allow-Origin: ' . 
$_SERVER[
"HTTP_ORIGIN"]);
   110             header(
'Access-Control-Allow-Credentials: true');
   114         $this->authToken = $authToken;
   122             $lrsType = $this->getLrsTypeAndMoreByToken();
   123             if ($lrsType == null) {
   125                 $GLOBALS[
'DIC']->logger()->root()->log(
"XapiCmi5Plugin: 401 Unauthorized for token");
   126                 header(
'HTTP/1.1 401 Unauthorized');
   127                 header(
'Access-Control-Allow-Origin: ' . 
$_SERVER[
"HTTP_ORIGIN"]);
   128                 header(
'Access-Control-Allow-Credentials: true');
   139             $this->lrsType = $lrsType;
   142             $GLOBALS[
'DIC']->logger()->root()->log(
"XapiCmi5Plugin: " . $e->getMessage());
   143             header(
'HTTP/1.1 401 Unauthorized');
   144             header(
'Access-Control-Allow-Origin: ' . 
$_SERVER[
"HTTP_ORIGIN"]);
   145             header(
'Access-Control-Allow-Credentials: true');
   156             $lrsType = $this->getLrsTypeAndMoreByToken();
   157             $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
   158             $this->defaultLrsKey = $lrsType->getLrsKey();
   159             $this->defaultLrsSecret = $lrsType->getLrsSecret();
   160             $this->lrsType = $lrsType;
   163             $objId = $this->authToken->getObjId();
   165             if (!$lrsType->isAvailable()) {
   166                 throw new \ilCmiXapiException(
   167                     'lrs endpoint (id=' . $this->authToken->getLrsTypeId() . 
') unavailable (responded 401-unauthorized)'   171             $this->log()->error($this->msg($e->getMessage()));
   172             header(
'Access-Control-Allow-Origin: ' . 
$_SERVER[
"HTTP_ORIGIN"]);
   173             header(
'Access-Control-Allow-Credentials: true');
   174             header(
'HTTP/1.1 401 Unauthorized');
   190         $query = 
"SELECT {$this->table_prefix}_settings.lrs_type_id,   191                                 {$this->table_prefix}_settings.only_moveon,   192                                 {$this->table_prefix}_settings.achieved,   193                                 {$this->table_prefix}_settings.answered,   194                                 {$this->table_prefix}_settings.completed,   195                                 {$this->table_prefix}_settings.failed,   196                                 {$this->table_prefix}_settings.initialized,   197                                 {$this->table_prefix}_settings.passed,   198                                 {$this->table_prefix}_settings.progressed,   199                                 {$this->table_prefix}_settings.satisfied,   200                                 {$this->table_prefix}_settings.c_terminated,   201                                 {$this->table_prefix}_settings.hide_data,   202                                 {$this->table_prefix}_settings.c_timestamp,   203                                 {$this->table_prefix}_settings.duration,   204                                 {$this->table_prefix}_settings.no_substatements,   205                                 {$this->table_prefix}_settings.privacy_ident   206                         FROM {$this->table_prefix}_settings, {$this->table_prefix}_token   207                         WHERE {$this->table_prefix}_settings.obj_id = {$this->table_prefix}_token.obj_id AND {$this->table_prefix}_token.token = " . $db->quote($this->token, 
'text');
   209         $res = $db->query($query);
   210         while ($row = $db->fetchObject(
$res)) {
   211             $type_id = (
int) $row->lrs_type_id;
   214                 $lrs = new \ilCmiXapiLrsType($type_id);
   218             if ((
bool) $row->only_moveon) {
   219                 if ((
bool) $row->achieved) {
   220                     $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/achieved";
   222                 if ((
bool) $row->answered) {
   223                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/answered";
   224                     $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/answered";
   226                 if ((
bool) $row->completed) {
   227                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/completed";
   228                     $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/completed";
   230                 if ((
bool) $row->failed) {
   231                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/failed";
   233                 if ((
bool) $row->initialized) {
   234                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/initialized";
   235                     $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/initialized";
   237                 if ((
bool) $row->passed) {
   238                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/passed";
   240                 if ((
bool) $row->progressed) {
   241                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/progressed";
   243                 if ((
bool) $row->satisfied) {
   244                     $sarr[] = 
"https://w3id.org/xapi/adl/verbs/satisfied";
   246                 if ((
bool) $row->c_terminated) {
   247                     $sarr[] = 
"http://adlnet.gov/expapi/verbs/terminated";
   249                 if (count($sarr) > 0) {
   250                     $this->specificAllowedStatements = $sarr;
   251                     $this->log()->debug($this->msg(
'getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements, 
true)));
   254             if ((
bool) $row->hide_data) {
   256                 if ((
bool) $row->c_timestamp) {
   257                     $rarr[
'timestamp'] = 
'1970-01-01T00:00:00.000Z';
   259                 if ((
bool) $row->duration) {
   260                     $rarr[
'result.duration'] = 
'PT00.000S';
   262                 if (count($rarr) > 0) {
   263                     $this->replacedValues = $rarr;
   264                     $this->log()->debug($this->msg(
'getReplacedValues: ' . var_export($this->replacedValues, 
true)));
   267             if ((
bool) $row->no_substatements) {
   268                 $this->blockSubStatements = 
true;
   269                 $this->log()->debug($this->msg(
'getBlockSubStatements: ' . $this->blockSubStatements));
   271             $lrs->setPrivacyIdent((
int) $row->privacy_ident);
 
static getInstanceByToken(string $token)
 
if(!file_exists('../ilias.ini.php'))
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static http()
Fetches the global http state from ILIAS. 
 
static saveProxySuccess(int $objId, int $usrId, int $privacyIdent)
 
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better? 
 
client()
 description: > This example shows how a Progress Bar can be rendered and used on the client...
 
__construct(string $client, string $token, ?bool $plugin=false)