12 protected $authToken = null;
14 protected $specificAllowedStatements = null;
15 protected $replacedValues = null;
16 protected $blockSubStatements =
false;
20 protected $defaultLrsEndpoint =
'';
21 protected $defaultLrsKey =
'';
22 protected $defaultLrsSecret =
'';
24 protected $fallbackLrsEndpoint =
'';
25 protected $fallbackLrsKey =
'';
26 protected $fallbackLrsSecret =
'';
28 const PARTS_REG =
'/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/';
30 protected $sniffVerbs = array(
31 "http://adlnet.gov/expapi/verbs/completed" =>
"completed",
32 "http://adlnet.gov/expapi/verbs/passed" =>
"passed",
33 "http://adlnet.gov/expapi/verbs/failed" =>
"failed",
34 "http://adlnet.gov/expapi/verbs/satisfied" =>
"passed" 37 const TERMINATED_VERB =
"http://adlnet.gov/expapi/verbs/terminated";
45 $this->table_prefix =
"xxcf";
47 $this->table_prefix =
"cmix";
49 preg_match(self::PARTS_REG,
$GLOBALS[
'DIC']->
http()->request()->getUri(), $this->cmdParts);
50 $this->method = strtolower(
$GLOBALS[
'DIC']->
http()->request()->getMethod());
59 return \ilLoggerFactory::getLogger(
'cmix');
63 public function msg($msg)
66 return "XapiCmi5Plugin: " . $msg;
74 $this->log()->debug($this->msg(
'initLrs'));
76 require_once __DIR__ .
'/../class.ilXapiCmi5LrsType.php';
77 require_once __DIR__ .
'/../class.ilXapiCmi5AuthToken.php';
79 $authToken = \ilXapiCmi5AuthToken::getInstanceByToken($this->token);
80 }
catch (\ilXapiCmi5Exception
$e) {
81 $this->log()->error($this->msg($e->getMessage()));
82 header(
'HTTP/1.1 401 Unauthorized');
83 header(
'Access-Control-Allow-Origin: ' .
$_SERVER[
"HTTP_ORIGIN"]);
84 header(
'Access-Control-Allow-Credentials: true');
87 $this->authToken = $authToken;
88 $this->getLrsTypePlugin();
90 require_once __DIR__ .
'/../class.ilCmiXapiLrsType.php';
91 require_once __DIR__ .
'/../class.ilCmiXapiAuthToken.php';
95 $this->log()->error($this->msg($e->getMessage()));
96 header(
'HTTP/1.1 401 Unauthorized');
97 header(
'Access-Control-Allow-Origin: ' .
$_SERVER[
"HTTP_ORIGIN"]);
98 header(
'Access-Control-Allow-Credentials: true');
102 $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;
130 $GLOBALS[
'DIC']->logger()->root()->log(
"XapiCmi5Plugin: " . $e->getMessage());
131 header(
'HTTP/1.1 401 Unauthorized');
132 header(
'Access-Control-Allow-Origin: ' .
$_SERVER[
"HTTP_ORIGIN"]);
133 header(
'Access-Control-Allow-Credentials: true');
142 $lrsType = $this->getLrsTypeAndMoreByToken();
143 $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
144 $this->defaultLrsKey = $lrsType->getLrsKey();
145 $this->defaultLrsSecret = $lrsType->getLrsSecret();
146 $this->lrsType = $lrsType;
149 $objId = $this->authToken->getObjId();
151 if (!$lrsType->isAvailable()) {
152 throw new \ilCmiXapiException(
153 'lrs endpoint (id=' . $this->authToken->getLrsTypeId() .
') unavailable (responded 401-unauthorized)' 157 $this->log()->error($this->msg($e->getMessage()));
158 header(
'Access-Control-Allow-Origin: ' .
$_SERVER[
"HTTP_ORIGIN"]);
159 header(
'Access-Control-Allow-Credentials: true');
160 header(
'HTTP/1.1 401 Unauthorized');
174 $query =
"SELECT {$this->table_prefix}_settings.lrs_type_id, 175 {$this->table_prefix}_settings.only_moveon, 176 {$this->table_prefix}_settings.achieved, 177 {$this->table_prefix}_settings.answered, 178 {$this->table_prefix}_settings.completed, 179 {$this->table_prefix}_settings.failed, 180 {$this->table_prefix}_settings.initialized, 181 {$this->table_prefix}_settings.passed, 182 {$this->table_prefix}_settings.progressed, 183 {$this->table_prefix}_settings.satisfied, 184 {$this->table_prefix}_settings.c_terminated, 185 {$this->table_prefix}_settings.hide_data, 186 {$this->table_prefix}_settings.c_timestamp, 187 {$this->table_prefix}_settings.duration, 188 {$this->table_prefix}_settings.no_substatements, 189 {$this->table_prefix}_settings.privacy_ident 190 FROM {$this->table_prefix}_settings, {$this->table_prefix}_token 191 WHERE {$this->table_prefix}_settings.obj_id = {$this->table_prefix}_token.obj_id AND {$this->table_prefix}_token.token = " . $db->quote($this->token,
'text');
194 while ($row = $db->fetchObject(
$res)) {
195 $type_id = $row->lrs_type_id;
197 $lrs = (
$this->plugin) ?
new \ilXapiCmi5LrsType($type_id) : new \ilCmiXapiLrsType($type_id);
201 if ((
bool) $row->only_moveon) {
202 if ((
bool) $row->achieved) {
203 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/achieved";
205 if ((
bool) $row->answered) {
206 $sarr[] =
"http://adlnet.gov/expapi/verbs/answered";
207 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/answered";
209 if ((
bool) $row->completed) {
210 $sarr[] =
"http://adlnet.gov/expapi/verbs/completed";
211 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/completed";
213 if ((
bool) $row->failed) {
214 $sarr[] =
"http://adlnet.gov/expapi/verbs/failed";
216 if ((
bool) $row->initialized) {
217 $sarr[] =
"http://adlnet.gov/expapi/verbs/initialized";
218 $sarr[] =
"https://w3id.org/xapi/dod-isd/verbs/initialized";
220 if ((
bool) $row->passed) {
221 $sarr[] =
"http://adlnet.gov/expapi/verbs/passed";
223 if ((
bool) $row->progressed) {
224 $sarr[] =
"http://adlnet.gov/expapi/verbs/progressed";
226 if ((
bool) $row->satisfied) {
227 $sarr[] =
"https://w3id.org/xapi/adl/verbs/satisfied";
229 if ((
bool) $row->c_terminated) {
230 $sarr[] =
"http://adlnet.gov/expapi/verbs/terminated";
232 if (count($sarr) > 0) {
233 $this->specificAllowedStatements = $sarr;
234 $this->log()->debug($this->msg(
'getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements,
true)));
237 if ((
bool) $row->hide_data) {
239 if ((
bool) $row->c_timestamp) {
240 $rarr[
'timestamp'] =
'1970-01-01T00:00:00.000Z';
242 if ((
bool) $row->duration) {
243 $rarr[
'result.duration'] =
'PT00.000S';
245 if (count($rarr) > 0) {
246 $this->replacedValues = $rarr;
247 $this->log()->debug($this->msg(
'getReplacedValues: ' . var_export($this->replacedValues,
true)));
250 if ((
bool) $row->no_substatements) {
251 $this->blockSubStatements =
true;
252 $this->log()->debug($this->msg(
'getBlockSubStatements: ' . $this->blockSubStatements));
254 $lrs->setPrivacyIdent((
int) $row->privacy_ident);
if($_SERVER['argc']< 4) $client
static getInstanceByToken($token)
static http()
Fetches the global http state from ILIAS.
foreach($_POST as $key=> $value) $res
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?
__construct($client, $token, $plugin=false)
static saveProxySuccess($objId, $usrId, $privacyIdent)