19 declare(strict_types=1);
61 $this->db = $DIC->database();
160 'ref_id' => array(
'integer', $this->
getRefId()),
161 'obj_id' => array(
'integer', $this->
getObjId()),
162 'usr_id' => array(
'integer', $this->
getUsrId()),
163 'lrs_type_id' => array(
'integer', $this->
getLrsTypeId()),
169 'token' => array(
'text', $this->
getToken()),
178 $DIC->database()->insert(
181 'token' => array(
'text', $a_token),
182 'valid_until' => array(
'timestamp', $a_time),
183 'ref_id' => array(
'integer',
$refId),
184 'obj_id' => array(
'integer',
$objId),
185 'usr_id' => array(
'integer', $usrId),
186 'lrs_type_id' => array(
'integer', $lrsTypeId)
198 DELETE FROM " . self::DB_TABLE_NAME .
" 199 WHERE obj_id = %s AND usr_id = %s 202 $DIC->database()->manipulateF($query, array(
'integer',
'integer'), array($objId, $usrId));
210 DELETE FROM " . self::DB_TABLE_NAME .
" 211 WHERE obj_id = %s AND ref_id = %s AND usr_id = %s 214 $DIC->database()->manipulateF($query, array(
'integer',
'integer',
'integer'), array($objId, $refId, $usrId));
217 public function delete():
void 222 DELETE FROM " . self::DB_TABLE_NAME .
" 223 WHERE obj_id = %s AND ref_id = %s AND usr_id = %s 226 $DIC->database()->manipulateF($query, array(
'integer',
'integer',
'integer'), array($this->
getObjId(), $this->
getRefId(), $this->
getUsrId()));
233 $query =
"DELETE FROM " . self::DB_TABLE_NAME .
" WHERE valid_until < CURRENT_TIMESTAMP";
234 $DIC->database()->manipulate($query);
242 $query =
"SELECT CURRENT_TIMESTAMP";
243 $result = $DIC->database()->query($query);
244 $row = $DIC->database()->fetchAssoc($result);
246 return (
string) $row[
'CURRENT_TIMESTAMP'];
251 return (
new \Ramsey\Uuid\UuidFactory())->uuid4()->toString();
259 $nowTimeDT = self::selectCurrentTimestamp();
264 $newTimeTS = $nowTimeTS + $seconds;
271 $tokenObject = self::getInstanceByObjIdAndRefIdAndUsrId($objId, $refId, $usrId,
false);
273 $tokenObject->update();
275 $token = $tokenObject->getToken();
277 $token = self::createToken();
278 self::insertToken($usrId, $refId, $objId, $lrsTypeId, $token, $newTime->get(
IL_CAL_DATETIME));
283 self::deleteExpiredTokens();
296 SELECT * FROM " . self::DB_TABLE_NAME .
" 297 WHERE token = %s AND valid_until > CURRENT_TIMESTAMP 300 $res = $DIC->database()->queryF($query, array(
'text'), array($token));
302 while ($row = $DIC->database()->fetchAssoc(
$res)) {
303 $tokenObject =
new self();
304 $tokenObject->setToken($token);
305 $tokenObject->setValidUntil((
string) $row[
'valid_until']);
306 $tokenObject->setUsrId((
int) $row[
'usr_id']);
307 $tokenObject->setObjId((
int) $row[
'obj_id']);
308 $tokenObject->setRefId((
int) $row[
'ref_id']);
309 $tokenObject->setLrsTypeId((
int) $row[
'lrs_type_id']);
310 $tokenObject->setCmi5Session((
string) $row[
'cmi5_session']);
311 $tokenObject->setReturnedForCmi5Session((
string) $row[
'returned_for_cmi5_session']);
312 $tokenObject->setCmi5SessionData((
string) $row[
'cmi5_session_data']);
327 $query =
"SELECT * FROM " . self::DB_TABLE_NAME .
" WHERE obj_id = %s AND usr_id = %s";
330 $query .=
" AND valid_until > CURRENT_TIMESTAMP";
333 $result = $DIC->database()->queryF($query, array(
'integer',
'integer'), array($objId, $usrId));
335 $row = $DIC->database()->fetchAssoc($result);
338 $tokenObject =
new self();
339 $tokenObject->setToken($row[
'token']);
340 $tokenObject->setValidUntil($row[
'valid_until']);
341 $tokenObject->setUsrId($row[
'usr_id']);
342 $tokenObject->setObjId($row[
'obj_id']);
343 $tokenObject->setRefId($row[
'ref_id']);
344 $tokenObject->setLrsTypeId($row[
'lrs_type_id']);
345 $tokenObject->setCmi5Session($row[
'cmi5_session']);
346 $tokenObject->setReturnedForCmi5Session($row[
'returned_for_cmi5_session']);
347 $tokenObject->setCmi5SessionData($row[
'cmi5_session_data']);
362 $query =
"SELECT * FROM " . self::DB_TABLE_NAME .
" WHERE obj_id = %s AND ref_id = %s AND usr_id = %s";
365 $query .=
" AND valid_until > CURRENT_TIMESTAMP";
368 $result = $DIC->database()->queryF($query, array(
'integer',
'integer',
'integer'), array($objId, $refId, $usrId));
370 $row = $DIC->database()->fetchAssoc($result);
373 $tokenObject =
new self();
374 $tokenObject->setToken($row[
'token']);
375 $tokenObject->setValidUntil($row[
'valid_until']);
376 $tokenObject->setUsrId((
int) $row[
'usr_id']);
377 $tokenObject->setObjId((
int) $row[
'obj_id']);
378 $tokenObject->setRefId((
int) $row[
'ref_id']);
379 $tokenObject->setLrsTypeId((
int) $row[
'lrs_type_id']);
380 $tokenObject->setCmi5Session($row[
'cmi5_session']);
381 $tokenObject->setReturnedForCmi5Session($row[
'returned_for_cmi5_session']);
382 $tokenObject->setCmi5SessionData((
string) $row[
'cmi5_session_data']);
398 $query =
"SELECT cmi5_session FROM " . self::DB_TABLE_NAME .
" WHERE usr_id = %s AND obj_id = %s";
399 $result = $DIC->database()->queryF($query, array(
'integer',
'integer'), array($usrId, $objId));
401 $query =
"SELECT cmi5_session FROM " . self::DB_TABLE_NAME .
" WHERE usr_id = %s AND obj_id = %s AND ref_id = %s";
402 $result = $DIC->database()->queryF($query, array(
'integer',
'integer',
'integer'), array($usrId, $objId,
$refId));
405 $row = $DIC->database()->fetchAssoc($result);
407 if ($row && $row[
'cmi5_session'] !=
'') {
408 return $row[
'cmi5_session'];
410 throw new ilCmiXapiException(
'no valid cmi5_session found for: ' . $objId .
'/' . $usrId);
418 include
'data/wacsalt.php';
setValidUntil(string $valid_until)
setCmi5SessionData(string $cmi5_session_data)
static getInstanceByToken(string $token)
static getCmi5SessionByUsrIdAndObjIdAndRefId(int $usrId, int $objId, ?int $refId=null)
string $cmi5_session_data
getReturnedForCmi5Session()
static fillToken(int $usrId, int $refId, int $objId, int $lrsTypeId=0)
const OPENSSL_ENCRYPTION_METHOD
setLrsTypeId(int $lrs_type_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getInstanceByObjIdAndRefIdAndUsrId(int $objId, int $refId, int $usrId, bool $checkValid=true)
string $returned_for_cmi5_session
static deleteTokenByObjIdAndUsrId(int $objId, int $usrId)
static selectCurrentTimestamp()
setReturnedForCmi5Session(string $returned_for_cmi5_session)
static getInstanceByObjIdAndUsrId(int $objId, int $usrId, bool $checkValid=true)
setCmi5Session(string $cmi5_session)
static deleteTokenByObjIdAndRefIdAndUsrId(int $objId, int $refId, int $usrId)
static insertToken($usrId, $refId, $objId, $lrsTypeId, $a_token, $a_time)
static deleteExpiredTokens()