ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
XapiProxy\XapiProxyPolyFill Class Reference
+ Inheritance diagram for XapiProxy\XapiProxyPolyFill:
+ Collaboration diagram for XapiProxy\XapiProxyPolyFill:

Public Member Functions

 __construct ($client, $token, $plugin=false)
 
 log ()
 
 msg ($msg)
 
 initLrs ()
 

Data Fields

const PARTS_REG = '/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/'
 
const TERMINATED_VERB = "http://adlnet.gov/expapi/verbs/terminated"
 

Protected Attributes

 $client
 
 $token
 
 $plugin
 
 $table_prefix
 
 $lrsType
 
 $authToken = NULL
 
 $objId = NULL
 
 $specificAllowedStatements = NULL
 
 $replacedValues = NULL
 
 $blockSubStatements = false
 
 $cmdParts
 
 $method
 
 $defaultLrsEndpoint = ''
 
 $defaultLrsKey = ''
 
 $defaultLrsSecret = ''
 
 $fallbackLrsEndpoint = ''
 
 $fallbackLrsKey = ''
 
 $fallbackLrsSecret = ''
 
 $sniffVerbs
 

Private Member Functions

 getLrsTypePlugin ()
 
 getLrsType ()
 
 getLrsTypeAndMoreByToken ()
 hybrid function, maybe two distinct functions would be better? More...
 

Detailed Description

Definition at line 4 of file XapiProxyPolyFill.php.

Constructor & Destructor Documentation

◆ __construct()

XapiProxy\XapiProxyPolyFill::__construct (   $client,
  $token,
  $plugin = false 
)

Definition at line 38 of file XapiProxyPolyFill.php.

References $client, $GLOBALS, XapiProxy\$plugin, $token, and ILIAS\FileDelivery\http().

38  {
39  $this->client = $client;
40  $this->token = $token;
41  $this->plugin = $plugin;
42  if ($this->plugin) {
43  $this->table_prefix = "xxcf";
44  }
45  else {
46  $this->table_prefix = "cmix";
47  }
48  preg_match(self::PARTS_REG, $GLOBALS['DIC']->http()->request()->getUri(), $this->cmdParts);
49  $this->method = strtolower($GLOBALS['DIC']->http()->request()->getMethod());
50  }
static http()
Fetches the global http state from ILIAS.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
+ Here is the call graph for this function:

Member Function Documentation

◆ getLrsType()

XapiProxy\XapiProxyPolyFill::getLrsType ( )
private

Definition at line 141 of file XapiProxyPolyFill.php.

References $_SERVER, Vendor\Package\$e, $objId, exit, and ilCmiXapiUser\saveProxySuccess().

141  { // Core new > 6
142  try {
143 
145  $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
146  $this->defaultLrsKey = $lrsType->getLrsKey();
147  $this->defaultLrsSecret = $lrsType->getLrsSecret();
148  $this->lrsType = $lrsType;
149  // one query IS better :-)
150  // $lrsType = new ilCmiXapiLrsType($authToken->getLrsTypeId());
151  $objId = $this->authToken->getObjId();
152  $this->objId = $objId;
153  if (!$lrsType->isAvailable()) {
154  throw new \ilCmiXapiException(
155  'lrs endpoint (id=' . $this->authToken->getLrsTypeId() . ') unavailable (responded 401-unauthorized)'
156  );
157  }
158  } catch (\ilCmiXapiException $e) {
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');
163  exit;
164  }
165  \ilCmiXapiUser::saveProxySuccess($this->authToken->getObjId(), $this->authToken->getUsrId(),$this->lrsType->getPrivacyIdent());
166  return $lrsType;
167  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?
static saveProxySuccess($objId, $usrId, $privacyIdent)
+ Here is the call graph for this function:

◆ getLrsTypeAndMoreByToken()

XapiProxy\XapiProxyPolyFill::getLrsTypeAndMoreByToken ( )
private

hybrid function, maybe two distinct functions would be better?

Definition at line 171 of file XapiProxyPolyFill.php.

References $GLOBALS, XapiProxy\$plugin, $query, and $res.

171  {
172  $type_id = null;
173  $lrs = null;
174  $db = $GLOBALS['DIC']->database();
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');
193 
194  $res = $db->query($query);
195  while ($row = $db->fetchObject($res))
196  {
197  $type_id = $row->lrs_type_id;
198  if ($type_id) {
199  $lrs = ($this->plugin) ? new \ilXapiCmi5LrsType($type_id) : new \ilCmiXapiLrsType($type_id);
200  }
201 
202  $sarr = [];
203  if ((bool)$row->only_moveon) {
204  if ((bool)$row->achieved) {
205  $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/achieved";
206  }
207  if ((bool)$row->answered) {
208  $sarr[] = "http://adlnet.gov/expapi/verbs/answered";
209  $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/answered";
210  }
211  if ((bool)$row->completed) {
212  $sarr[] = "http://adlnet.gov/expapi/verbs/completed";
213  $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/completed";
214  }
215  if ((bool)$row->failed) {
216  $sarr[] = "http://adlnet.gov/expapi/verbs/failed";
217  }
218  if ((bool)$row->initialized) {
219  $sarr[] = "http://adlnet.gov/expapi/verbs/initialized";
220  $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/initialized";
221  }
222  if ((bool)$row->passed) {
223  $sarr[] = "http://adlnet.gov/expapi/verbs/passed";
224  }
225  if ((bool)$row->progressed) {
226  $sarr[] = "http://adlnet.gov/expapi/verbs/progressed";
227  }
228  if ((bool)$row->satisfied) {
229  $sarr[] = "https://w3id.org/xapi/adl/verbs/satisfied";
230  }
231  if ((bool)$row->c_terminated) {
232  $sarr[] = "http://adlnet.gov/expapi/verbs/terminated";
233  }
234  if (count($sarr) > 0) {
235  $this->specificAllowedStatements = $sarr;
236  $this->log()->debug($this->msg('getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements,TRUE)));
237  }
238  }
239  if ((bool)$row->hide_data) {
240  $rarr = array();
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)));
246  }
247  }
248  if ((bool)$row->no_substatements) {
249  $this->blockSubStatements = true;
250  $this->log()->debug($this->msg('getBlockSubStatements: ' . $this->blockSubStatements));
251  }
252  $lrs->setPrivacyIdent((int)$row->privacy_ident);
253  }
254  return $lrs;
255  }
foreach($_POST as $key=> $value) $res
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$query

◆ getLrsTypePlugin()

XapiProxy\XapiProxyPolyFill::getLrsTypePlugin ( )
private

Definition at line 108 of file XapiProxyPolyFill.php.

References $_SERVER, Vendor\Package\$e, $GLOBALS, and exit.

108  {
109  try {
111  if ($lrsType == null) {
112  // why not using $log?
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');
117  exit;
118  }
119  $this->defaultLrsEndpoint = $lrsType->getDefaultLrsEndpoint();
120  $this->defaultLrsKey = $lrsType->getDefaultLrsKey();
121  $this->defaultLrsSecret = $lrsType->getDefaultLrsSecret();
122 
123  $this->fallbackLrsEndpoint = $lrsType->getFallbackLrsEndpoint();
124  $this->fallbackLrsKey = $lrsType->getFallbackLrsKey();
125  $this->fallbackLrsSecret = $lrsType->getFallbackLrsSecret();
126 
127  $this->lrsType = $lrsType;
128  }
129  catch(\Exception $e)
130  {
131  // why not using $log?
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');
136  exit;
137  }
138  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?

◆ initLrs()

XapiProxy\XapiProxyPolyFill::initLrs ( )

Definition at line 71 of file XapiProxyPolyFill.php.

References $_SERVER, Vendor\Package\$e, exit, and ilCmiXapiAuthToken\getInstanceByToken().

71  {
72  $this->log()->debug($this->msg('initLrs'));
73  if ($this->plugin) {
74  require_once __DIR__.'/../class.ilXapiCmi5LrsType.php';
75  require_once __DIR__.'/../class.ilXapiCmi5AuthToken.php';
76  try {
77  $authToken = \ilXapiCmi5AuthToken::getInstanceByToken($this->token);
78  }
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');
84  exit;
85  }
86  $this->authToken = $authToken;
87  $this->getLrsTypePlugin();
88  }
89  else {
90  require_once __DIR__.'/../class.ilCmiXapiLrsType.php';
91  require_once __DIR__.'/../class.ilCmiXapiAuthToken.php';
92  try {
94  }
95  catch (\ilCmiXapiException $e) {
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');
100  exit;
101  }
102 
103  $this->authToken = $authToken;
104  $this->getLrsType();
105  }
106  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ Here is the call graph for this function:

◆ log()

XapiProxy\XapiProxyPolyFill::log ( )

Definition at line 52 of file XapiProxyPolyFill.php.

References $log.

52  {
53  global $log;
54  if ($this->plugin) {
55  return $log;
56  }
57  else {
58  return \ilLoggerFactory::getLogger('cmix');
59  }
60  }
$log
Definition: result.php:15

◆ msg()

XapiProxy\XapiProxyPolyFill::msg (   $msg)

Definition at line 62 of file XapiProxyPolyFill.php.

62  {
63  if ($this->plugin) {
64  return "XapiCmi5Plugin: " . $msg;
65  }
66  else {
67  return $msg;
68  }
69  }

Field Documentation

◆ $authToken

XapiProxy\XapiProxyPolyFill::$authToken = NULL
protected

Definition at line 11 of file XapiProxyPolyFill.php.

◆ $blockSubStatements

XapiProxy\XapiProxyPolyFill::$blockSubStatements = false
protected

Definition at line 15 of file XapiProxyPolyFill.php.

◆ $client

XapiProxy\XapiProxyPolyFill::$client
protected

Definition at line 5 of file XapiProxyPolyFill.php.

◆ $cmdParts

XapiProxy\XapiProxyPolyFill::$cmdParts
protected

Definition at line 16 of file XapiProxyPolyFill.php.

◆ $defaultLrsEndpoint

XapiProxy\XapiProxyPolyFill::$defaultLrsEndpoint = ''
protected

Definition at line 19 of file XapiProxyPolyFill.php.

◆ $defaultLrsKey

XapiProxy\XapiProxyPolyFill::$defaultLrsKey = ''
protected

Definition at line 20 of file XapiProxyPolyFill.php.

◆ $defaultLrsSecret

XapiProxy\XapiProxyPolyFill::$defaultLrsSecret = ''
protected

Definition at line 21 of file XapiProxyPolyFill.php.

◆ $fallbackLrsEndpoint

XapiProxy\XapiProxyPolyFill::$fallbackLrsEndpoint = ''
protected

Definition at line 23 of file XapiProxyPolyFill.php.

◆ $fallbackLrsKey

XapiProxy\XapiProxyPolyFill::$fallbackLrsKey = ''
protected

Definition at line 24 of file XapiProxyPolyFill.php.

◆ $fallbackLrsSecret

XapiProxy\XapiProxyPolyFill::$fallbackLrsSecret = ''
protected

Definition at line 25 of file XapiProxyPolyFill.php.

◆ $lrsType

XapiProxy\XapiProxyPolyFill::$lrsType
protected

Definition at line 10 of file XapiProxyPolyFill.php.

◆ $method

XapiProxy\XapiProxyPolyFill::$method
protected

Definition at line 17 of file XapiProxyPolyFill.php.

◆ $objId

XapiProxy\XapiProxyPolyFill::$objId = NULL
protected

Definition at line 12 of file XapiProxyPolyFill.php.

◆ $plugin

XapiProxy\XapiProxyPolyFill::$plugin
protected

Definition at line 8 of file XapiProxyPolyFill.php.

◆ $replacedValues

XapiProxy\XapiProxyPolyFill::$replacedValues = NULL
protected

Definition at line 14 of file XapiProxyPolyFill.php.

◆ $sniffVerbs

XapiProxy\XapiProxyPolyFill::$sniffVerbs
protected
Initial value:
= array (
"http://adlnet.gov/expapi/verbs/completed" => "completed",
"http://adlnet.gov/expapi/verbs/passed" => "passed",
"http://adlnet.gov/expapi/verbs/failed" => "failed",
"http://adlnet.gov/expapi/verbs/satisfied" => "passed"
)

Definition at line 29 of file XapiProxyPolyFill.php.

◆ $specificAllowedStatements

XapiProxy\XapiProxyPolyFill::$specificAllowedStatements = NULL
protected

Definition at line 13 of file XapiProxyPolyFill.php.

◆ $table_prefix

XapiProxy\XapiProxyPolyFill::$table_prefix
protected

Definition at line 9 of file XapiProxyPolyFill.php.

◆ $token

XapiProxy\XapiProxyPolyFill::$token
protected

Definition at line 6 of file XapiProxyPolyFill.php.

◆ PARTS_REG

const XapiProxy\XapiProxyPolyFill::PARTS_REG = '/^(.*?xapiproxy\.php)(\/([^?]+)?\??(.*))/'

Definition at line 27 of file XapiProxyPolyFill.php.

◆ TERMINATED_VERB

const XapiProxy\XapiProxyPolyFill::TERMINATED_VERB = "http://adlnet.gov/expapi/verbs/terminated"

Definition at line 36 of file XapiProxyPolyFill.php.


The documentation for this class was generated from the following file: