ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
XapiProxy\XapiProxyPolyFill Class Reference
+ Inheritance diagram for XapiProxy\XapiProxyPolyFill:
+ Collaboration diagram for XapiProxy\XapiProxyPolyFill:

Public Member Functions

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

Data Fields

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

Protected Attributes

string $client
 
string $token
 
bool $plugin = false
 
string $table_prefix
 
ilCmiXapiLrsType $lrsType = null
 
ilCmiXapiAuthToken $authToken = null
 
int $objId = null
 
array $specificAllowedStatements = null
 
array $replacedValues = null
 
bool $blockSubStatements = false
 
array $cmdParts = []
 
string $method
 
string $defaultLrsEndpoint = ''
 
string $defaultLrsKey = ''
 
string $defaultLrsSecret = ''
 
string $fallbackLrsEndpoint = ''
 
string $fallbackLrsKey = ''
 
string $fallbackLrsSecret = ''
 
array $sniffVerbs
 

Private Member Functions

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

Detailed Description

Definition at line 22 of file XapiProxyPolyFill.php.

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented in XapiProxy\XapiProxy.

Definition at line 57 of file XapiProxyPolyFill.php.

58 {
59 $this->client = $client;
60 $this->token = $token;
61 $this->plugin = $plugin;
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());
65 }
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:54

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

+ Here is the call graph for this function:

Member Function Documentation

◆ getLrsType()

XapiProxy\XapiProxyPolyFill::getLrsType ( )
private
Returns
\ilCmiXapiLrsType|void|null

Definition at line 153 of file XapiProxyPolyFill.php.

154 { // Core new > 6
155 try {
157 $this->defaultLrsEndpoint = $lrsType->getLrsEndpoint();
158 $this->defaultLrsKey = $lrsType->getLrsKey();
159 $this->defaultLrsSecret = $lrsType->getLrsSecret();
160 $this->lrsType = $lrsType;
161 // one query IS better :-)
162 // $lrsType = new ilCmiXapiLrsType($authToken->getLrsTypeId());
163 $objId = $this->authToken->getObjId();
164 $this->objId = $objId;
165 if (!$lrsType->isAvailable()) {
166 throw new \ilCmiXapiException(
167 'lrs endpoint (id=' . $this->authToken->getLrsTypeId() . ') unavailable (responded 401-unauthorized)'
168 );
169 }
170 } catch (\ilCmiXapiException $e) {
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');
175 exit;
176 }
177 \ilCmiXapiUser::saveProxySuccess($this->authToken->getObjId(), $this->authToken->getUsrId(), $this->lrsType->getPrivacyIdent());
178 return $lrsType;
179 }
getLrsTypeAndMoreByToken()
hybrid function, maybe two distinct functions would be better?
static saveProxySuccess(int $objId, int $usrId, int $privacyIdent)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26

References $_SERVER, Vendor\Package\$e, $objId, exit, ILIAS\UI\examples\Symbol\Glyph\Header\header(), and ilCmiXapiUser\saveProxySuccess().

+ Here is the call graph for this function:

◆ getLrsTypeAndMoreByToken()

XapiProxy\XapiProxyPolyFill::getLrsTypeAndMoreByToken ( )
private

hybrid function, maybe two distinct functions would be better?

Returns
\ilCmiXapiLrsType|null

Definition at line 185 of file XapiProxyPolyFill.php.

186 {
187 $type_id = null;
188 $lrs = null;
189 $db = $GLOBALS['DIC']->database();
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');
208
209 $res = $db->query($query);
210 while ($row = $db->fetchObject($res)) {
211 $type_id = (int) $row->lrs_type_id;
212 if ($type_id) {
213 // $lrs = ($this->plugin) ? new \ilXapiCmi5LrsType($type_id) : new \ilCmiXapiLrsType($type_id);
214 $lrs = new \ilCmiXapiLrsType($type_id);
215 }
216
217 $sarr = [];
218 if ((bool) $row->only_moveon) {
219 if ((bool) $row->achieved) {
220 $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/achieved";
221 }
222 if ((bool) $row->answered) {
223 $sarr[] = "http://adlnet.gov/expapi/verbs/answered";
224 $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/answered";
225 }
226 if ((bool) $row->completed) {
227 $sarr[] = "http://adlnet.gov/expapi/verbs/completed";
228 $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/completed";
229 }
230 if ((bool) $row->failed) {
231 $sarr[] = "http://adlnet.gov/expapi/verbs/failed";
232 }
233 if ((bool) $row->initialized) {
234 $sarr[] = "http://adlnet.gov/expapi/verbs/initialized";
235 $sarr[] = "https://w3id.org/xapi/dod-isd/verbs/initialized";
236 }
237 if ((bool) $row->passed) {
238 $sarr[] = "http://adlnet.gov/expapi/verbs/passed";
239 }
240 if ((bool) $row->progressed) {
241 $sarr[] = "http://adlnet.gov/expapi/verbs/progressed";
242 }
243 if ((bool) $row->satisfied) {
244 $sarr[] = "https://w3id.org/xapi/adl/verbs/satisfied";
245 }
246 if ((bool) $row->c_terminated) {
247 $sarr[] = "http://adlnet.gov/expapi/verbs/terminated";
248 }
249 if (count($sarr) > 0) {
250 $this->specificAllowedStatements = $sarr;
251 $this->log()->debug($this->msg('getSpecificAllowedStatements: ' . var_export($this->specificAllowedStatements, true)));
252 }
253 }
254 if ((bool) $row->hide_data) {
255 $rarr = array();
256 if ((bool) $row->c_timestamp) {
257 $rarr['timestamp'] = '1970-01-01T00:00:00.000Z';
258 }
259 if ((bool) $row->duration) {
260 $rarr['result.duration'] = 'PT00.000S';
261 }
262 if (count($rarr) > 0) {
263 $this->replacedValues = $rarr;
264 $this->log()->debug($this->msg('getReplacedValues: ' . var_export($this->replacedValues, true)));
265 }
266 }
267 if ((bool) $row->no_substatements) {
268 $this->blockSubStatements = true;
269 $this->log()->debug($this->msg('getBlockSubStatements: ' . $this->blockSubStatements));
270 }
271 $lrs->setPrivacyIdent((int) $row->privacy_ident);
272 }
273 return $lrs;
274 }
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))

References $GLOBALS, $res, if, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getLrsTypePlugin()

XapiProxy\XapiProxyPolyFill::getLrsTypePlugin ( )
private

Definition at line 119 of file XapiProxyPolyFill.php.

119 : void
120 {
121 try {
123 if ($lrsType == null) {
124 // why not using $log?
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');
129 exit;
130 }
131 // $this->defaultLrsEndpoint = $lrsType->getDefaultLrsEndpoint();
132 // $this->defaultLrsKey = $lrsType->getDefaultLrsKey();
133 // $this->defaultLrsSecret = $lrsType->getDefaultLrsSecret();
134 //
135 // $this->fallbackLrsEndpoint = $lrsType->getFallbackLrsEndpoint();
136 // $this->fallbackLrsKey = $lrsType->getFallbackLrsKey();
137 // $this->fallbackLrsSecret = $lrsType->getFallbackLrsSecret();
138
139 $this->lrsType = $lrsType;
140 } catch (\Exception $e) {
141 // why not using $log?
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');
146 exit;
147 }
148 }

References $_SERVER, Vendor\Package\$e, $GLOBALS, exit, and ILIAS\UI\examples\Symbol\Glyph\Header\header().

+ Here is the call graph for this function:

◆ initLrs()

XapiProxy\XapiProxyPolyFill::initLrs ( )

Definition at line 86 of file XapiProxyPolyFill.php.

86 : void
87 {
88 $this->log()->debug($this->msg('initLrs'));
89 // if ($this->plugin) {
90 // try {
91 // $authToken = \ilXapiCmi5AuthToken::getInstanceByToken($this->token);
92 // }
93 // catch (\ilXapiCmi5Exception $e) {
94 // $this->log()->error($this->msg($e->getMessage()));
95 // header('HTTP/1.1 401 Unauthorized');
96 // header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
97 // header('Access-Control-Allow-Credentials: true');
98 // exit;
99 // }
100 // $this->authToken = $authToken;
101 // $this->getLrsTypePlugin();
102 // }
103 // else {
104 try {
106 } catch (\ilCmiXapiException $e) {
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');
111 exit;
112 }
113
114 $this->authToken = $authToken;
115 $this->getLrsType();
116 // }
117 }
static getInstanceByToken(string $token)

References $_SERVER, Vendor\Package\$e, exit, ilCmiXapiAuthToken\getInstanceByToken(), and ILIAS\UI\examples\Symbol\Glyph\Header\header().

+ Here is the call graph for this function:

◆ log()

XapiProxy\XapiProxyPolyFill::log ( )

Definition at line 67 of file XapiProxyPolyFill.php.

67 : \ilLogger
68 {
69 if ($this->plugin) {
70 global $log;
71 return $log;
72 } else {
73 return \ilLoggerFactory::getLogger('cmix');
74 }
75 }
Component logger with individual log levels by component id.
$log
Definition: ltiresult.php:34

References $log.

◆ msg()

XapiProxy\XapiProxyPolyFill::msg ( string  $msg)

Definition at line 77 of file XapiProxyPolyFill.php.

77 : string
78 {
79 if ($this->plugin) {
80 return "XapiCmi5Plugin: " . $msg;
81 } else {
82 return $msg;
83 }
84 }

Field Documentation

◆ $authToken

ilCmiXapiAuthToken XapiProxy\XapiProxyPolyFill::$authToken = null
protected

Definition at line 30 of file XapiProxyPolyFill.php.

◆ $blockSubStatements

bool XapiProxy\XapiProxyPolyFill::$blockSubStatements = false
protected

Definition at line 34 of file XapiProxyPolyFill.php.

◆ $client

string XapiProxy\XapiProxyPolyFill::$client
protected

Definition at line 24 of file XapiProxyPolyFill.php.

◆ $cmdParts

array XapiProxy\XapiProxyPolyFill::$cmdParts = []
protected

Definition at line 35 of file XapiProxyPolyFill.php.

◆ $defaultLrsEndpoint

string XapiProxy\XapiProxyPolyFill::$defaultLrsEndpoint = ''
protected

Definition at line 38 of file XapiProxyPolyFill.php.

◆ $defaultLrsKey

string XapiProxy\XapiProxyPolyFill::$defaultLrsKey = ''
protected

Definition at line 39 of file XapiProxyPolyFill.php.

◆ $defaultLrsSecret

string XapiProxy\XapiProxyPolyFill::$defaultLrsSecret = ''
protected

Definition at line 40 of file XapiProxyPolyFill.php.

◆ $fallbackLrsEndpoint

string XapiProxy\XapiProxyPolyFill::$fallbackLrsEndpoint = ''
protected

Definition at line 42 of file XapiProxyPolyFill.php.

◆ $fallbackLrsKey

string XapiProxy\XapiProxyPolyFill::$fallbackLrsKey = ''
protected

Definition at line 43 of file XapiProxyPolyFill.php.

◆ $fallbackLrsSecret

string XapiProxy\XapiProxyPolyFill::$fallbackLrsSecret = ''
protected

Definition at line 44 of file XapiProxyPolyFill.php.

◆ $lrsType

ilCmiXapiLrsType XapiProxy\XapiProxyPolyFill::$lrsType = null
protected

Definition at line 29 of file XapiProxyPolyFill.php.

◆ $method

string XapiProxy\XapiProxyPolyFill::$method
protected

Definition at line 36 of file XapiProxyPolyFill.php.

◆ $objId

int XapiProxy\XapiProxyPolyFill::$objId = null
protected

Definition at line 31 of file XapiProxyPolyFill.php.

◆ $plugin

bool XapiProxy\XapiProxyPolyFill::$plugin = false
protected

Definition at line 27 of file XapiProxyPolyFill.php.

◆ $replacedValues

array XapiProxy\XapiProxyPolyFill::$replacedValues = null
protected

Definition at line 33 of file XapiProxyPolyFill.php.

◆ $sniffVerbs

array 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 48 of file XapiProxyPolyFill.php.

◆ $specificAllowedStatements

array XapiProxy\XapiProxyPolyFill::$specificAllowedStatements = null
protected

Definition at line 32 of file XapiProxyPolyFill.php.

◆ $table_prefix

string XapiProxy\XapiProxyPolyFill::$table_prefix
protected

Definition at line 28 of file XapiProxyPolyFill.php.

◆ $token

string XapiProxy\XapiProxyPolyFill::$token
protected

Definition at line 25 of file XapiProxyPolyFill.php.

◆ PARTS_REG

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

Definition at line 46 of file XapiProxyPolyFill.php.

◆ TERMINATED_VERB

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

Definition at line 55 of file XapiProxyPolyFill.php.


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