19declare(strict_types=1);
49 if (
null === $logger) {
55 if (
null === $defaultTitle) {
74 $this->
logger->debug(
'START - saving of user certificate');
87 'id' => [
'integer',
$id],
89 'obj_id' => [
'integer',
$objId],
90 'obj_type' => [
'text', $userCertificate->
getObjType()],
91 'usr_id' => [
'integer', $userId],
92 'user_name' => [
'text', $userCertificate->
getUserName()],
96 'valid_until' => [
'integer', $userCertificate->
getValidUntil()],
102 'certificate_id' => [
'text', $userCertificate->
getCertificateId()->asString()]
107 'END - Save certificate with following values: %s',
108 json_encode($columns, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
112 $this->
database->insert(self::TABLE_NAME, $columns);
122 $this->
logger->debug(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
125SELECT ' . self::TABLE_NAME .
'.*,
126il_cert_user_cert.certificate_id,
127 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
128FROM ' . self::TABLE_NAME .
'
129LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
130LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
131WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
132AND currently_active = 1';
134 $query = $this->
database->query($sql);
137 while ($row = $this->
database->fetchAssoc($query)) {
141 (
int) $row[
'obj_id'],
142 (
string) $row[
'obj_type'],
147 $result[] = $presentation;
150 $this->
logger->debug(sprintf(
'Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
153 'END - All active certificates for user: "%s" total: "%s"',
170 $this->
logger->debug(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
173SELECT ' . self::TABLE_NAME .
'.*,
174il_cert_user_cert.certificate_id,
175 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
176FROM ' . self::TABLE_NAME .
'
177LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
178LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
179WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
180AND currently_active = 1
181AND acquired_timestamp >= ' . $this->
database->quote($startTimestamp,
'integer') .
'
182AND acquired_timestamp <= ' . $this->
database->quote($endTimeStamp,
'integer');
184 $query = $this->
database->query($sql);
187 while ($row = $this->
database->fetchAssoc($query)) {
191 (
int) $row[
'obj_id'],
192 (
string) $row[
'obj_type'],
197 $result[] = $presentation;
200 $this->
logger->debug(sprintf(
'Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
203 'END - All active certificates for user: "%s" total: "%s"',
219 'START - Fetching all active certificates for user: "%s" and object: "%s"',
226 FROM ' . self::TABLE_NAME .
'
227 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
228 AND obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
229 AND currently_active = 1';
231 $query = $this->
database->query($sql);
233 while ($row = $this->
database->fetchAssoc($query)) {
234 $this->
logger->debug(sprintf(
'Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
238 'END -Found active user certificate for user: "%s" and object: "%s"',
244 return $this->createUserCertificate($row);
248 sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
259 'START - Fetching all active certificates for user: "%s" and object: "%s"',
265 $sql =
'SELECT ' . self::TABLE_NAME .
'.*,
266 il_cert_user_cert.certificate_id,usr_data.lastname,
267 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
268 FROM ' . self::TABLE_NAME .
'
269 LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
270 LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
271 LEFT JOIN usr_data ON usr_data.usr_id = ' . self::TABLE_NAME .
'.usr_id
272 WHERE ' . self::TABLE_NAME .
'.usr_id = ' . $this->
database->quote($userId,
'integer') .
'
273 AND ' . self::TABLE_NAME .
'.obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
274 AND ' . self::TABLE_NAME .
'.currently_active = 1';
276 $query = $this->
database->query($sql);
278 while ($row = $this->
database->fetchAssoc($query)) {
279 $this->
logger->debug(sprintf(
'Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
283 'END -Found active user certificate for user: "%s" and object: "%s"',
289 $userCertificate = $this->createUserCertificate($row);
292 (
int) $row[
'obj_id'],
293 (
string) $row[
'obj_type'],
302 sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
313 'START - Fetching all active certificates for user: "%s" and type: "%s"',
319 $sql =
'SELECT ' . self::TABLE_NAME .
'.*,
320 il_cert_user_cert.certificate_id,COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
321 FROM ' . self::TABLE_NAME .
'
322 LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
323 LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
324 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
325 AND obj_type = ' . $this->
database->quote($type,
'text') .
'
326 AND currently_active = 1';
328 $query = $this->
database->query($sql);
331 while ($row = $this->
database->fetchAssoc($query)) {
332 $userCertificate = $this->createUserCertificate($row);
335 (
int) $row[
'obj_id'],
336 (
string) $row[
'obj_type'],
341 $result[] = $presentation;
346 'END - Fetching all active certificates for user: "%s" and type: "%s"',
360 $this->
logger->debug(sprintf(
'START - Fetch certificate by id: "%s"',
$id));
362 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE id = ' . $this->
database->quote($id,
'integer');
364 $query = $this->
database->query($sql);
366 while ($row = $this->
database->fetchAssoc($query)) {
367 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
369 $this->
logger->debug(sprintf(
'END - Fetch certificate by id: "%s"',
$id));
371 return $this->createUserCertificate($row);
374 throw new ilException(
'No certificate found for user certificate id: ' .
$id);
385 'START - Fetch certificate for user("%s") and ids: "%s"',
387 json_encode($objectIds, JSON_THROW_ON_ERROR)
391 if ([] === $objectIds) {
395 $inStatementObjectIds = $this->
database->in(
402 $sql =
'SELECT obj_id FROM ' . self::TABLE_NAME .
'
403 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
404 ' AND ' . $inStatementObjectIds .
405 ' AND currently_active = ' . $this->
database->quote(1,
'integer');
407 $query = $this->
database->query($sql);
411 while ($row = $this->
database->fetchAssoc($query)) {
412 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
413 $result[] = (
int) $row[
'obj_id'];
424 $this->
logger->debug(sprintf(
'START - Fetch certificate for object("%s")"', $objectId));
426 $sql =
'SELECT usr_id FROM ' . self::TABLE_NAME .
'
427 WHERE obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
428 AND currently_active = ' . $this->
database->quote(1,
'integer');
430 $query = $this->
database->query($sql);
434 while ($row = $this->
database->fetchAssoc($query)) {
435 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
436 $result[] = (
int) $row[
'usr_id'];
444 $this->
logger->debug(sprintf(
'START - Delete certificate for user("%s")"', $userId));
446 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' WHERE usr_id = ' . $this->
database->quote($userId,
'integer');
450 $this->
logger->debug(sprintf(
'END - Successfully deleted certificate for user("%s")"', $userId));
460 'START - fetching all certificates of object(user id: "%s", object id: "%s")',
466 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
'
467 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
468 AND obj_id = ' . $this->
database->quote($objId,
'integer');
470 $query = $this->
database->query($sql);
473 while ($row = $this->
database->fetchAssoc($query)) {
476 'Certificate found: "%s")',
477 json_encode($row, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
481 $this->
logger->debug(sprintf(
'Certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
483 $result[] = $this->createUserCertificate($row);
488 'END - fetching all certificates of object(user id: "%s", object id: "%s")',
501 'START - fetching of latest certificates of object(user id: "%s", object id: "%s")',
507 $templates = $this->fetchCertificatesOfObject(
$objId, $userId);
510 foreach ($templates as $template) {
511 if ($template->getVersion() >
$version) {
518 'END - fetching of latest certificates of object(user id: "%s", object id: "%s") with version "%s"',
532 'START - deactivating previous certificates for user id: "%s" and object id: "%s"',
539UPDATE ' . self::TABLE_NAME .
'
540SET currently_active = 0
541WHERE obj_id = ' . $this->
database->quote($objId,
'integer') .
'
542AND usr_id = ' . $this->
database->quote($userId,
'integer');
548 'END - deactivating previous certificates for user id: "%s" and object id: "%s"',
559 'START - Checking if any certificate template uses background image identification "%s"',
560 $relative_image_identification
565 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME .
' WHERE
566 (background_image_ident = %s OR tile_image_ident = %s)
567 AND currently_active = 1) AS does_exist',
569 [$relative_image_identification, $relative_image_identification]
572 $exists = (bool) ($this->
database->fetchAssoc($result)[
'does_exist'] ??
false);
576 'END - Image identification "%s" is ' . $exists ?
'in use' :
'unused',
577 $relative_image_identification
590 (
int) $row[
'pattern_certificate_id'],
591 (
int) $row[
'obj_id'],
593 (
int) $row[
'usr_id'],
595 (
int) $row[
'acquired_timestamp'],
596 $row[
'certificate_content'],
597 $row[
'template_values'],
598 (
int) $row[
'valid_until'],
599 (
int) $row[
'version'],
600 $row[
'ilias_version'],
601 (
bool) $row[
'currently_active'],
603 (
string) $row[
'background_image_ident'],
604 (
string) $row[
'tile_image_ident'],
605 isset($row[
'id']) ? (
int) $row[
'id'] :
null
612 sprintf(
'START - Delete certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
615 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' ' . PHP_EOL
616 .
' WHERE usr_id = ' . $this->
database->quote($userId,
'integer') . PHP_EOL
617 .
' AND obj_id = ' . $this->
database->quote($obj_id,
'integer');
622 sprintf(
'END - Successfully deleted certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
628 $result = match ($table_column) {
629 'certificate_id' => $table_column,
630 'issue_date' =>
'acquired_timestamp',
631 'object' =>
'object_data.title',
632 'owner' =>
'usr_data.login',
633 'obj_id' =>
'cert.obj_id',
638 throw new InvalidArgumentException(
'Invalid table column passed');
649 string $user_language,
652 string $order_field =
'issue_date',
653 string $order_direction =
'ASC'
655 $order_field = $this->overviewTableColumnToDbColumn($order_field);
658 foreach ($filter as $key => $value) {
659 if ($value ===
null) {
663 $column_name = $this->overviewTableColumnToDbColumn($key);
665 if ($key ===
'issue_date') {
666 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
668 $sql_filters[] = $sql_filter;
682 WHEN (trans.title IS NOT NULL AND LENGTH(trans.title) > 0) THEN trans.title
683 WHEN (object_data.title IS NOT NULL AND LENGTH(object_data.title) > 0) THEN object_data.title
684 WHEN (object_data_del.title IS NOT NULL AND LENGTH(object_data_del.title) > 0) THEN object_data_del.title
688 .
'usr_data.login AS owner FROM il_cert_user_cert AS cert '
689 .
'LEFT JOIN object_data ON object_data.obj_id = cert.obj_id '
690 .
'INNER JOIN usr_data ON usr_data.usr_id = cert.usr_id '
691 .
'LEFT JOIN object_data_del ON object_data_del.obj_id = cert.obj_id '
692 .
'LEFT JOIN object_translation trans ON trans.obj_id = object_data.obj_id AND trans.lang_code = ' . $this->database->quote($user_language,
'text')
693 . ($sql_filters !== [] ?
" WHERE " . implode(
" AND ", $sql_filters) :
"")
694 .
' ORDER BY ' . $order_field .
' ' . $order_direction
698 while ($row = $this->
database->fetchAssoc($result)) {
699 $certificates[] = $this->createUserCertificate($row);
701 return $certificates;
709 if (array_keys(
$duration) === [
"from",
"to"] &&
$duration !== [
"from" =>
null,
"to" =>
null]) {
715 $sql_filter = $column_name
723 $sql_filter = $column_name
729 $sql_filter = $column_name
747 foreach ($filter as $key => $value) {
748 if ($value ===
null) {
755 $column_name =
'acquired_timestamp';
758 $column_name =
'object_data.title';
761 $column_name =
'usr_data.login';
764 $column_name =
'cert.obj_id';
768 if ($key ===
'issue_date') {
769 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
771 $sql_filters[] = $sql_filter;
783 'SELECT COUNT(id) as count FROM il_cert_user_cert AS cert '
784 .
'LEFT JOIN object_data ON object_data.obj_id = cert.obj_id '
785 .
'INNER JOIN usr_data ON usr_data.usr_id = cert.usr_id'
786 . ($sql_filters !== [] ?
' AND ' . implode(
' AND ', $sql_filters) :
'')
789 return (
int) $this->
database->fetchAssoc($result)[
'count'];
794 return new CertificateId($this->uuid_factory->uuid4AsString());
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
A simple class to express a naive range of whole positive numbers.
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.
isResourceUsed(string $relative_image_identification)
deleteUserCertificates(int $userId)
fetchCertificate(int $id)
deleteUserCertificatesForObject(int $userId, int $obj_id)
fetchActiveCertificatesInIntervalForPresentation(int $userId, int $startTimestamp, int $endTimeStamp)
fetchCertificatesForOverview(string $user_language, array $filter, ?Range $range=null, string $order_field='issue_date', string $order_direction='ASC')
fetchCertificatesOfObject(int $objId, int $userId)
fetchActiveCertificateForPresentation(int $userId, int $objectId)
readonly Factory $uuid_factory
createUserCertificate(array $row)
deactivatePreviousCertificates(int $objId, int $userId)
fetchActiveCertificates(int $userId)
fetchObjectIdsWithCertificateForUser(int $userId, array $objectIds)
overviewTableColumnToDbColumn(string $table_column)
fetchLatestVersion(int $objId, int $userId)
fetchCertificatesForOverviewCount(array $filter, ?Range $range=null)
fetchActiveCertificatesByTypeForPresentation(int $userId, string $type)
getIssueDateSqlFilter(string $column_name, array $duration)
fetchActiveCertificate(int $userId, int $objectId)
__construct(?ilDBInterface $database=null, ?ilLogger $logger=null, ?string $defaultTitle=null, ?Factory $uuid_factory=null,)
fetchUserIdsWithCertificateForObject(int $objectId)
readonly ilDBInterface $database
readonly string $defaultTitle
readonly ilLogger $logger
save(ilUserCertificate $userCertificate)
getTileImageIdentification()
getBackgroundImageIdentification()
getPatternCertificateId()