58 $DIC->ctrl()->redirectToURL($launchLink);
64 $launchLink = $this->
object->getLaunchUrl();
66 if (preg_match(
"/^(https?:\/\/)/",$this->object->getLaunchUrl()) == 1) {
67 $launchLink = $this->
object->getLaunchUrl();
69 $launchLink = implode(
'/', [
74 $launchLink .= DIRECTORY_SEPARATOR . $this->
object->getLaunchUrl();
91 if ($this->object->isBypassProxyEnabled()) {
92 $params[
'endpoint'] = urlencode(rtrim($this->object->getLrsType()->getLrsEndpoint(),
'/') .
'/');
94 $params[
'endpoint'] = urlencode(rtrim(
ILIAS_HTTP_PATH .
'/' . self::XAPI_PROXY_ENDPOINT,
'/') .
'/');
97 if ($this->object->isAuthFetchUrlEnabled()) {
100 if ($this->object->isBypassProxyEnabled()) {
101 $params[
'auth'] = urlencode($this->object->getLrsType()->getBasicAuth());
103 $params[
'auth'] = urlencode(
'Basic ' . base64_encode(
109 $params[
'activity_id'] = urlencode($this->object->getActivityId());
110 $params[
'activityId'] = urlencode($this->object->getActivityId());
111 $params[
'actor'] = urlencode(json_encode($this->object->getStatementActor($this->cmixUser)));
114 $registration = $this->cmixUser->getRegistration();
116 if ($registration ==
'')
120 $params[
'registration'] = $registration;
131 $link = implode(
'/', [
136 $link = iLUtil::appendUrlParameterString($link,
"param={$param}");
148 session_name() => session_id(),
149 'obj_id' => $this->
object->getId(),
150 'ref_id' => $this->
object->getRefId(),
151 'ilClientId' => CLIENT_ID
156 $param = urlencode(base64_encode(openssl_encrypt(
157 json_encode($params),
171 $DIC->user()->getId(),
172 $this->
object->getRefId(),
173 $this->
object->getId(),
174 $this->
object->getLrsType()->getTypeId()
189 $this->cmixUser =
new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->
object->getPrivacyIdent());
191 if ($user_ident ==
'' || $user_ident == null) {
193 $this->cmixUser->setUsrIdent($user_ident);
199 $this->cmixUser->save();
210 $language = $DIC->user()->getLanguage();
213 "languagePreference" =>
"{$language}",
214 "audioPreference" =>
"{$audio}" 228 $lrsType = $this->
object->getLrsType();
229 $defaultLrs = $lrsType->getLrsEndpoint();
231 $defaultBasicAuth = $lrsType->getBasicAuth();
234 'X-Experience-API-Version' =>
'1.0.3',
235 'Authorization' => $defaultBasicAuth,
236 'Content-Type' =>
'application/json;charset=utf-8',
237 'Cache-Control' =>
'no-cache, no-store, must-revalidate' 240 $registration = $this->cmixUser->getRegistration();
242 if ($registration ==
'')
247 $activityId = $this->
object->getActivityId();
251 $defaultAgentProfileUrl = $defaultLrs .
"/agents/profile";
252 $profileParams[
'agent'] = json_encode($this->object->getStatementActor($this->cmixUser));
253 $profileParams[
'profileId'] =
'cmi5LearnerPreferences';
257 $launchDataParams = [];
258 $defaultStateUrl = $defaultLrs .
"/activities/state";
260 $launchDataParams[
'agent'] = json_encode($this->object->getStatementActor($this->cmixUser));
261 $launchDataParams[
'activityId'] = $activityId;
262 $launchDataParams[
'activity_id'] = $activityId;
263 $launchDataParams[
'registration'] = $registration;
264 $launchDataParams[
'stateId'] =
'LMS.LaunchData';
267 $cmi5LearnerPreferences = json_encode($cmi5LearnerPreferencesObj);
268 $lang = $cmi5LearnerPreferencesObj[
'languagePreference'];
271 $oldSession = $tokenObject->getCmi5Session();
272 $oldSessionLaunchedTimestamp =
'';
275 if (!empty($oldSession)) {
276 $oldSessionData = json_decode($tokenObject->getCmi5SessionData());
277 $oldSessionLaunchedTimestamp = $oldSessionData->launchedTimestamp;
278 $tokenObject->delete();
281 $lastStatement = $this->
object->getLastStatement($oldSession);
286 $start =
new DateTime($oldSessionLaunchedTimestamp);
287 $end =
new DateTime($lastStatement[0][
'statement'][
'timestamp']);
288 $diff = $end->diff($start);
298 $lpMode = $this->
object->getLPMode();
305 $tokenObject->setCmi5Session($cmi5_session);
306 $sessionData = array();
307 $sessionData[
'cmi5LearnerPreferences'] = $cmi5LearnerPreferencesObj;
310 $sessionData[
'launchedTimestamp'] = $now->toXapiTimestamp();
311 $tokenObject->setCmi5SessionData(json_encode($sessionData));
312 $tokenObject->update();
313 $defaultStatementsUrl = $defaultLrs .
"/statements";
316 $launchData = json_encode($this->object->getLaunchData($this->cmixUser,
$lang));
317 $launchedStatement = $this->
object->getLaunchedStatement($this->cmixUser);
318 $launchedStatementParams = [];
319 $launchedStatementParams[
'statementId'] = $launchedStatement[
'id'];
324 $abandonedStatement = $this->
object->getAbandonedStatement($oldSession, $duration, $this->cmixUser);
325 $abandonedStatementParams = [];
326 $abandonedStatementParams[
'statementId'] = $abandonedStatement[
'id'];
331 $satisfiedStatement = $this->
object->getSatisfiedStatement($this->cmixUser);
332 $satisfiedStatementParams = [];
333 $satisfiedStatementParams[
'statementId'] = $satisfiedStatement[
'id'];
338 GuzzleHttp\RequestOptions::VERIFY =>
true,
339 GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 10,
340 GuzzleHttp\RequestOptions::HTTP_ERRORS =>
false 346 $cmi5LearnerPreferences
350 $defaultLaunchDataUrl,
356 $defaultLaunchedStatementUrl,
358 json_encode($launchedStatement)
363 $defaultAbandonedStatementUrl,
365 json_encode($abandonedStatement)
371 $defaultSatisfiedStatementUrl,
373 json_encode($satisfiedStatement)
377 $promises[
'defaultProfile'] =
$client->sendAsync($defaultProfileRequest, $req_opts);
378 $promises[
'defaultLaunchData'] =
$client->sendAsync($defaultLaunchDataRequest, $req_opts);
379 $promises[
'defaultLaunchedStatement'] =
$client->sendAsync($defaultLaunchedStatementRequest, $req_opts);
381 $promises[
'defaultAbandonedStatement'] =
$client->sendAsync($defaultAbandonedStatementRequest, $req_opts);
384 $promises[
'defaultSatisfiedStatement'] =
$client->sendAsync($defaultSatisfiedStatementRequest, $req_opts);
388 $responses = GuzzleHttp\Promise\Utils::settle($promises)->wait();
396 $this->
log()->error(
'error:' . $e->getMessage());
398 return array(
'cmi5_session' => $cmi5_session,
'token' =>
$token);
407 return \ilLoggerFactory::getLogger(
'cmix');
static generateRegistration(ilObjCmiXapi $obj, ilObjUser $user)
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
getLaunchParameters($token)
if($_SERVER['argc']< 4) $client
static getInstanceByToken($token)
const OPENSSL_ENCRYPTION_METHOD
const RELATIVE_CONTENT_DIRECTORY_NAMEBASE
__construct(ilObjCmiXapi $object)
buildAuthTokenFetchParam()
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
static generateCMI5Registration($objId, $usrId)
CMI5preLaunch($token)
Prelaunch post cmi5LearnerPreference (agent profile) post LMS.LaunchData.
const XAPI_PROXY_ENDPOINT
static guidv4($data=null)
static fillToken($usrId, $refId, $objId, $lrsTypeId=0)
const LP_MODE_DEACTIVATED
static checkResponse($response, &$body, $allowedStatus=[200, 204])
static getIdent($userIdentMode, ilObjUser $user)
static buildQuery(array $params, $encoding=PHP_QUERY_RFC3986)
getCmi5LearnerPreferences()
static getWebspaceDir($mode="filesystem")
get webspace directory
static dateIntervalToISO860Duration(\DateInterval $d)