11        protected $authToken = NULL;
 
   13        protected $specificAllowedStatements = NULL;
 
   14        protected $replacedValues = NULL;
 
   15        protected $blockSubStatements = 
false;
 
   19        protected $defaultLrsEndpoint = 
'';
 
   20        protected $defaultLrsKey = 
'';
 
   21        protected $defaultLrsSecret = 
'';
 
   23        protected $fallbackLrsEndpoint = 
'';
 
   24        protected $fallbackLrsKey = 
'';
 
   25        protected $fallbackLrsSecret = 
'';
 
   27        const PARTS_REG = 
'/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/';
 
   29        protected $sniffVerbs = array (
 
   30            "http://adlnet.gov/expapi/verbs/completed" => 
"completed",
 
   31            "http://adlnet.gov/expapi/verbs/passed" => 
"passed",
 
   32            "http://adlnet.gov/expapi/verbs/failed" => 
"failed",
 
   33            "http://adlnet.gov/expapi/verbs/satisfied" => 
"passed" 
   36        const TERMINATED_VERB = 
"http://adlnet.gov/expapi/verbs/terminated";
 
   43                $this->table_prefix = 
"xxcf";
 
   46                $this->table_prefix = 
"cmix";
 
   48            preg_match(self::PARTS_REG, 
$GLOBALS[
'DIC']->
http()->request()->getUri(), $this->cmdParts);
 
   49            $this->method = strtolower(
$GLOBALS[
'DIC']->
http()->request()->getMethod());
 
   52        public function log() {
 
   58                return \ilLoggerFactory::getLogger(
'cmix');
 
   62        public function msg($msg) {
 
   64                return "XapiCmi5Plugin: " . $msg;
 
   72            $this->log()->debug($this->msg(
'initLrs'));
 
   74                require_once __DIR__.
'/../class.ilXapiCmi5LrsType.php';
 
   75                require_once __DIR__.
'/../class.ilXapiCmi5AuthToken.php';
 
   77                    $authToken = \ilXapiCmi5AuthToken::getInstanceByToken($this->token);
 
   79                catch (\ilXapiCmi5Exception 
$e) {
 
   80                    $this->log()->error($this->msg(
$e->getMessage()));
 
   81                    header(
'HTTP/1.1 401 Unauthorized');
 
   82                    header(
'Access-Control-Allow-Origin: '.
$_SERVER[
"HTTP_ORIGIN"]);
 
   83                    header(
'Access-Control-Allow-Credentials: true');
 
   86                $this->authToken = $authToken;
 
   87                $this->getLrsTypePlugin();
 
   90                require_once __DIR__.
'/../class.ilCmiXapiLrsType.php';
 
   91                require_once __DIR__.
'/../class.ilCmiXapiAuthToken.php';
 
   96                    $this->log()->error($this->msg(
$e->getMessage()));
 
   97                    header(
'HTTP/1.1 401 Unauthorized');
 
   98                    header(
'Access-Control-Allow-Origin: '.
$_SERVER[
"HTTP_ORIGIN"]);
 
   99                    header(
'Access-Control-Allow-Credentials: true');
 
  103                $this->authToken = $authToken;
 
  110                $lrsType = $this->getLrsTypeAndMoreByToken();
 
  111                if ($lrsType == 
null) {
 
  113                    $GLOBALS[
'DIC']->logger()->root()->log(
"XapiCmi5Plugin: 401 Unauthorized for token");
 
  114                    header(
'HTTP/1.1 401 Unauthorized');
 
  115                    header(
'Access-Control-Allow-Origin: '.
$_SERVER[
"HTTP_ORIGIN"]);
 
  116                    header(
'Access-Control-Allow-Credentials: true');
 
  119                $this->defaultLrsEndpoint = $lrsType->getDefaultLrsEndpoint();
 
  120                $this->defaultLrsKey = $lrsType->getDefaultLrsKey();
 
  121                $this->defaultLrsSecret = $lrsType->getDefaultLrsSecret();
 
  123                $this->fallbackLrsEndpoint = $lrsType->getFallbackLrsEndpoint();
 
  124                $this->fallbackLrsKey = $lrsType->getFallbackLrsKey();
 
  125                $this->fallbackLrsSecret = $lrsType->getFallbackLrsSecret();
 
  127                $this->lrsType = $lrsType;
 
  132                $GLOBALS[
'DIC']->logger()->root()->log(
"XapiCmi5Plugin: " . 
$e->getMessage());
 
  133                header(
'HTTP/1.1 401 Unauthorized');
 
  134                header(
'Access-Control-Allow-Origin: '.
$_SERVER[
"HTTP_ORIGIN"]);
 
  135                header(
'Access-Control-Allow-Credentials: true');
 
  144                $lrsType = $this->getLrsTypeAndMoreByToken();
 
  145                $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
 
  146                $this->defaultLrsKey = $lrsType->getLrsKey();
 
  147                $this->defaultLrsSecret = $lrsType->getLrsSecret();
 
  148                $this->lrsType = $lrsType;
 
  151                $objId = $this->authToken->getObjId();
 
  153                if (!$lrsType->isAvailable()) {
 
  154                    throw new \ilCmiXapiException(
 
  155                        'lrs endpoint (id=' . $this->authToken->getLrsTypeId() . 
') unavailable (responded 401-unauthorized)' 
  159                $this->log()->error($this->msg(
$e->getMessage()));
 
  160                header(
'Access-Control-Allow-Origin: '.
$_SERVER[
"HTTP_ORIGIN"]);
 
  161                header(
'Access-Control-Allow-Credentials: true');
 
  162                header(
'HTTP/1.1 401 Unauthorized');
 
  175            $query =
"SELECT {$this->table_prefix}_settings.lrs_type_id, 
  176                                {$this->table_prefix}_settings.only_moveon,  
  177                                {$this->table_prefix}_settings.achieved,  
  178                                {$this->table_prefix}_settings.answered,  
  179                                {$this->table_prefix}_settings.completed,  
  180                                {$this->table_prefix}_settings.failed,  
  181                                {$this->table_prefix}_settings.initialized,  
  182                                {$this->table_prefix}_settings.passed,  
  183                                {$this->table_prefix}_settings.progressed,  
  184                                {$this->table_prefix}_settings.satisfied,  
  185                                {$this->table_prefix}_settings.c_terminated,  
  186                                {$this->table_prefix}_settings.hide_data,  
  187                                {$this->table_prefix}_settings.c_timestamp,  
  188                                {$this->table_prefix}_settings.duration,  
  189                                {$this->table_prefix}_settings.no_substatements, 
  190                                {$this->table_prefix}_settings.privacy_ident 
  191                        FROM {$this->table_prefix}_settings, {$this->table_prefix}_token  
  192                        WHERE {$this->table_prefix}_settings.obj_id = {$this->table_prefix}_token.obj_id AND {$this->table_prefix}_token.token = " . $db->quote($this->token, 
'text');
 
  195            while ($row = $db->fetchObject(
$res)) 
 
  197                $type_id = $row->lrs_type_id;
 
  199                    $lrs = (
$this->plugin) ? 
new \ilXapiCmi5LrsType($type_id) : new \ilCmiXapiLrsType($type_id);
 
  203                if ((
bool)$row->only_moveon) {
 
  204                    if ((
bool)$row->achieved) {
 
  205                        $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/achieved";
 
  207                    if ((
bool)$row->answered) {
 
  208                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/answered";
 
  209                        $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/answered";
 
  211                    if ((
bool)$row->completed) {
 
  212                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/completed";
 
  213                        $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/completed";
 
  215                    if ((
bool)$row->failed) {
 
  216                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/failed";
 
  218                    if ((
bool)$row->initialized) {
 
  219                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/initialized";
 
  220                        $sarr[] = 
"https://w3id.org/xapi/dod-isd/verbs/initialized";
 
  222                    if ((
bool)$row->passed) {
 
  223                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/passed";
 
  225                    if ((
bool)$row->progressed) {
 
  226                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/progressed";
 
  228                    if ((
bool)$row->satisfied) {
 
  229                        $sarr[] = 
"https://w3id.org/xapi/adl/verbs/satisfied";
 
  231                    if ((
bool)$row->c_terminated) {
 
  232                        $sarr[] = 
"http://adlnet.gov/expapi/verbs/terminated";
 
  234                    if (count($sarr) > 0) {
 
  235                        $this->specificAllowedStatements = $sarr;
 
  236                        $this->log()->debug($this->msg(
'getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements,TRUE))); 
 
  239                if ((
bool)$row->hide_data) {
 
  241                    if ((
bool)$row->c_timestamp) $rarr[
'timestamp'] = 
'1970-01-01T00:00:00.000Z';
 
  242                    if ((
bool)$row->duration) $rarr[
'result.duration'] = 
'PT00.000S';
 
  243                    if (count($rarr) > 0) {
 
  244                        $this->replacedValues = $rarr;
 
  245                        $this->log()->debug($this->msg(
'getReplacedValues: ' . var_export($this->replacedValues,TRUE)));
 
  248                if ((
bool)$row->no_substatements) {
 
  249                    $this->blockSubStatements = 
true;
 
  250                    $this->log()->debug($this->msg(
'getBlockSubStatements: ' . $this->blockSubStatements));
 
  252                $lrs->setPrivacyIdent((
int)$row->privacy_ident);
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
__construct($client, $token, $plugin=false)
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?
static getInstanceByToken($token)
static saveProxySuccess($objId, $usrId, $privacyIdent)
if($_SERVER['argc']< 4) $client
static http()
Fetches the global http state from ILIAS.
foreach($_POST as $key=> $value) $res