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()]
106 $this->
database->tableColumnExists(
'il_cert_user_cert',
'background_image_path') &&
107 $this->
database->tableColumnExists(
'il_cert_user_cert',
'tile_image_path')
110 $columns[
'tile_image_path'] = [
'text', $userCertificate->
getTileImagePath()];
115 'END - Save certificate with following values: %s',
116 json_encode($columns, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
120 $this->
database->insert(self::TABLE_NAME, $columns);
130 $this->
logger->debug(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
133SELECT ' . self::TABLE_NAME .
'.*,
134il_cert_user_cert.certificate_id,
135 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
136FROM ' . self::TABLE_NAME .
'
137LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
138LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
139WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
140AND currently_active = 1';
142 $query = $this->
database->query($sql);
145 while ($row = $this->
database->fetchAssoc($query)) {
149 (
int) $row[
'obj_id'],
150 (
string) $row[
'obj_type'],
155 $result[] = $presentation;
158 $this->
logger->debug(sprintf(
'Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
161 'END - All active certificates for user: "%s" total: "%s"',
178 $this->
logger->debug(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
181SELECT ' . self::TABLE_NAME .
'.*,
182il_cert_user_cert.certificate_id,
183 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
184FROM ' . self::TABLE_NAME .
'
185LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
186LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
187WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
188AND currently_active = 1
189AND acquired_timestamp >= ' . $this->
database->quote($startTimestamp,
'integer') .
'
190AND acquired_timestamp <= ' . $this->
database->quote($endTimeStamp,
'integer');
192 $query = $this->
database->query($sql);
195 while ($row = $this->
database->fetchAssoc($query)) {
199 (
int) $row[
'obj_id'],
200 (
string) $row[
'obj_type'],
205 $result[] = $presentation;
208 $this->
logger->debug(sprintf(
'Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
211 'END - All active certificates for user: "%s" total: "%s"',
227 'START - Fetching all active certificates for user: "%s" and object: "%s"',
234 FROM ' . self::TABLE_NAME .
'
235 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
236 AND obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
237 AND currently_active = 1';
239 $query = $this->
database->query($sql);
241 while ($row = $this->
database->fetchAssoc($query)) {
242 $this->
logger->debug(sprintf(
'Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
246 'END -Found active user certificate for user: "%s" and object: "%s"',
252 return $this->createUserCertificate($row);
256 sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
267 'START - Fetching all active certificates for user: "%s" and object: "%s"',
273 $sql =
'SELECT ' . self::TABLE_NAME .
'.*,
274 il_cert_user_cert.certificate_id,usr_data.lastname,
275 COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
276 FROM ' . self::TABLE_NAME .
'
277 LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
278 LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
279 LEFT JOIN usr_data ON usr_data.usr_id = ' . self::TABLE_NAME .
'.usr_id
280 WHERE ' . self::TABLE_NAME .
'.usr_id = ' . $this->
database->quote($userId,
'integer') .
'
281 AND ' . self::TABLE_NAME .
'.obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
282 AND ' . self::TABLE_NAME .
'.currently_active = 1';
284 $query = $this->
database->query($sql);
286 while ($row = $this->
database->fetchAssoc($query)) {
287 $this->
logger->debug(sprintf(
'Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
291 'END -Found active user certificate for user: "%s" and object: "%s"',
297 $userCertificate = $this->createUserCertificate($row);
300 (
int) $row[
'obj_id'],
301 (
string) $row[
'obj_type'],
310 sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
321 'START - Fetching all active certificates for user: "%s" and type: "%s"',
327 $sql =
'SELECT ' . self::TABLE_NAME .
'.*,
328 il_cert_user_cert.certificate_id,COALESCE(object_data.title, object_data_del.title, ' . $this->
database->quote($this->defaultTitle,
'text') .
') AS title
329 FROM ' . self::TABLE_NAME .
'
330 LEFT JOIN object_data ON object_data.obj_id = ' . self::TABLE_NAME .
'.obj_id
331 LEFT JOIN object_data_del ON object_data_del.obj_id = ' . self::TABLE_NAME .
'.obj_id
332 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
333 AND obj_type = ' . $this->
database->quote($type,
'text') .
'
334 AND currently_active = 1';
336 $query = $this->
database->query($sql);
339 while ($row = $this->
database->fetchAssoc($query)) {
340 $userCertificate = $this->createUserCertificate($row);
343 (
int) $row[
'obj_id'],
344 (
string) $row[
'obj_type'],
349 $result[] = $presentation;
354 'END - Fetching all active certificates for user: "%s" and type: "%s"',
368 $this->
logger->debug(sprintf(
'START - Fetch certificate by id: "%s"',
$id));
370 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE id = ' . $this->
database->quote($id,
'integer');
372 $query = $this->
database->query($sql);
374 while ($row = $this->
database->fetchAssoc($query)) {
375 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
377 $this->
logger->debug(sprintf(
'END - Fetch certificate by id: "%s"',
$id));
379 return $this->createUserCertificate($row);
382 throw new ilException(
'No certificate found for user certificate id: ' .
$id);
393 'START - Fetch certificate for user("%s") and ids: "%s"',
395 json_encode($objectIds, JSON_THROW_ON_ERROR)
399 if ([] === $objectIds) {
403 $inStatementObjectIds = $this->
database->in(
410 $sql =
'SELECT obj_id FROM ' . self::TABLE_NAME .
'
411 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
412 ' AND ' . $inStatementObjectIds .
413 ' AND currently_active = ' . $this->
database->quote(1,
'integer');
415 $query = $this->
database->query($sql);
419 while ($row = $this->
database->fetchAssoc($query)) {
420 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
421 $result[] = (
int) $row[
'obj_id'];
432 $this->
logger->debug(sprintf(
'START - Fetch certificate for object("%s")"', $objectId));
434 $sql =
'SELECT usr_id FROM ' . self::TABLE_NAME .
'
435 WHERE obj_id = ' . $this->
database->quote($objectId,
'integer') .
'
436 AND currently_active = ' . $this->
database->quote(1,
'integer');
438 $query = $this->
database->query($sql);
442 while ($row = $this->
database->fetchAssoc($query)) {
443 $this->
logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
444 $result[] = (
int) $row[
'usr_id'];
452 $this->
logger->debug(sprintf(
'START - Delete certificate for user("%s")"', $userId));
454 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' WHERE usr_id = ' . $this->
database->quote($userId,
'integer');
458 $this->
logger->debug(sprintf(
'END - Successfully deleted certificate for user("%s")"', $userId));
468 'START - fetching all certificates of object(user id: "%s", object id: "%s")',
474 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
'
475 WHERE usr_id = ' . $this->
database->quote($userId,
'integer') .
'
476 AND obj_id = ' . $this->
database->quote($objId,
'integer');
478 $query = $this->
database->query($sql);
481 while ($row = $this->
database->fetchAssoc($query)) {
484 'Certificate found: "%s")',
485 json_encode($row, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
489 $this->
logger->debug(sprintf(
'Certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
491 $result[] = $this->createUserCertificate($row);
496 'END - fetching all certificates of object(user id: "%s", object id: "%s")',
509 'START - fetching of latest certificates of object(user id: "%s", object id: "%s")',
515 $templates = $this->fetchCertificatesOfObject(
$objId, $userId);
518 foreach ($templates as $template) {
519 if ($template->getVersion() >
$version) {
526 'END - fetching of latest certificates of object(user id: "%s", object id: "%s") with version "%s"',
540 'START - deactivating previous certificates for user id: "%s" and object id: "%s"',
547UPDATE ' . self::TABLE_NAME .
'
548SET currently_active = 0
549WHERE obj_id = ' . $this->
database->quote($objId,
'integer') .
'
550AND usr_id = ' . $this->
database->quote($userId,
'integer');
556 'END - deactivating previous certificates for user id: "%s" and object id: "%s"',
567 'START - Checking if any certificate template uses background image path "%s"',
568 $relative_image_identification
573 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME .
' WHERE
574 (background_image_ident = %s OR tile_image_ident = %s)
575 AND currently_active = 1) AS does_exist',
577 [$relative_image_identification, $relative_image_identification]
580 $exists = (bool) ($this->
database->fetchAssoc($result)[
'does_exist'] ??
false);
584 'END - Image path "%s" is ' . $exists ?
'in use' :
'unused',
585 $relative_image_identification
598 (
int) $row[
'pattern_certificate_id'],
599 (
int) $row[
'obj_id'],
601 (
int) $row[
'usr_id'],
603 (
int) $row[
'acquired_timestamp'],
604 $row[
'certificate_content'],
605 $row[
'template_values'],
606 (
int) $row[
'valid_until'],
607 (
int) $row[
'version'],
608 $row[
'ilias_version'],
609 (
bool) $row[
'currently_active'],
611 (
string) ($row[
'background_image_path'] ??
''),
612 (
string) ($row[
'tile_image_path'] ??
''),
613 (
string) $row[
'background_image_ident'],
614 (
string) $row[
'tile_image_ident'],
615 isset($row[
'id']) ? (
int) $row[
'id'] :
null
622 sprintf(
'START - Delete certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
625 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' ' . PHP_EOL
626 .
' WHERE usr_id = ' . $this->
database->quote($userId,
'integer') . PHP_EOL
627 .
' AND obj_id = ' . $this->
database->quote($obj_id,
'integer');
632 sprintf(
'END - Successfully deleted certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
638 $result = match ($table_column) {
639 'certificate_id' => $table_column,
640 'issue_date' =>
'acquired_timestamp',
641 'object' =>
'object_data.title',
642 'owner' =>
'usr_data.login',
643 'obj_id' =>
'cert.obj_id',
648 throw new InvalidArgumentException(
'Invalid table column passed');
659 string $user_language,
662 string $order_field =
'issue_date',
663 string $order_direction =
'ASC'
665 $order_field = $this->overviewTableColumnToDbColumn($order_field);
668 foreach ($filter as $key => $value) {
669 if ($value ===
null) {
673 $column_name = $this->overviewTableColumnToDbColumn($key);
675 if ($key ===
'issue_date') {
676 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
678 $sql_filters[] = $sql_filter;
692 WHEN (trans.title IS NOT NULL AND LENGTH(trans.title) > 0) THEN trans.title
693 WHEN (object_data.title IS NOT NULL AND LENGTH(object_data.title) > 0) THEN object_data.title
694 WHEN (object_data_del.title IS NOT NULL AND LENGTH(object_data_del.title) > 0) THEN object_data_del.title
698 .
'usr_data.login AS owner FROM il_cert_user_cert AS cert '
699 .
'LEFT JOIN object_data ON object_data.obj_id = cert.obj_id '
700 .
'INNER JOIN usr_data ON usr_data.usr_id = cert.usr_id '
701 .
'LEFT JOIN object_data_del ON object_data_del.obj_id = cert.obj_id '
702 .
'LEFT JOIN object_translation trans ON trans.obj_id = object_data.obj_id AND trans.lang_code = ' . $this->database->quote($user_language,
'text')
703 . ($sql_filters !== [] ?
" WHERE " . implode(
" AND ", $sql_filters) :
"")
704 .
' ORDER BY ' . $order_field .
' ' . $order_direction
708 while ($row = $this->
database->fetchAssoc($result)) {
709 $certificates[] = $this->createUserCertificate($row);
711 return $certificates;
719 if (array_keys(
$duration) === [
"from",
"to"] &&
$duration !== [
"from" =>
null,
"to" =>
null]) {
725 $sql_filter = $column_name
733 $sql_filter = $column_name
739 $sql_filter = $column_name
757 foreach ($filter as $key => $value) {
758 if ($value ===
null) {
765 $column_name =
'acquired_timestamp';
768 $column_name =
'object_data.title';
771 $column_name =
'usr_data.login';
774 $column_name =
'cert.obj_id';
778 if ($key ===
'issue_date') {
779 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
781 $sql_filters[] = $sql_filter;
793 'SELECT COUNT(id) as count FROM il_cert_user_cert AS cert '
794 .
'LEFT JOIN object_data ON object_data.obj_id = cert.obj_id '
795 .
'INNER JOIN usr_data ON usr_data.usr_id = cert.usr_id'
796 . ($sql_filters !== [] ?
' AND ' . implode(
' AND ', $sql_filters) :
'')
799 return (
int) $this->
database->fetchAssoc($result)[
'count'];
804 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()