ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserCertificateRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
29{
30 public const TABLE_NAME = 'il_cert_user_cert';
31
32 private readonly ilDBInterface $database;
33 private readonly ilLogger $logger;
34 private readonly string $defaultTitle;
35 private readonly ?Factory $uuid_factory;
36
37 public function __construct(
39 ?ilLogger $logger = null,
40 ?string $defaultTitle = null,
41 ?Factory $uuid_factory = null,
42 ) {
43 if (null === $database) {
44 global $DIC;
45 $database = $DIC->database();
46 }
47 $this->database = $database;
48
49 if (null === $logger) {
50 global $DIC;
51 $logger = $DIC->logger()->cert();
52 }
53 $this->logger = $logger;
54
55 if (null === $defaultTitle) {
56 global $DIC;
57 $defaultTitle = $DIC->language()->txt('certificate_no_object_title');
58 }
59
60 $this->defaultTitle = $defaultTitle;
61
62 if (!$uuid_factory) {
64 }
65 $this->uuid_factory = $uuid_factory;
66
67 }
68
72 public function save(ilUserCertificate $userCertificate): ilUserCertificate
73 {
74 $this->logger->debug('START - saving of user certificate');
75
76 $version = (int) $this->fetchLatestVersion($userCertificate->getObjId(), $userCertificate->getUserId());
77 ++$version;
78
79 $id = $this->database->nextId(self::TABLE_NAME);
80
81 $objId = $userCertificate->getObjId();
82 $userId = $userCertificate->getUserId();
83
85
86 $columns = [
87 'id' => ['integer', $id],
88 'pattern_certificate_id' => ['integer', $userCertificate->getPatternCertificateId()],
89 'obj_id' => ['integer', $objId],
90 'obj_type' => ['text', $userCertificate->getObjType()],
91 'usr_id' => ['integer', $userId],
92 'user_name' => ['text', $userCertificate->getUserName()],
93 'acquired_timestamp' => ['integer', $userCertificate->getAcquiredTimestamp()],
94 'certificate_content' => ['clob', $userCertificate->getCertificateContent()],
95 'template_values' => ['clob', $userCertificate->getTemplateValues()],
96 'valid_until' => ['integer', $userCertificate->getValidUntil()],
97 'version' => ['integer', $version],
98 'ilias_version' => ['text', $userCertificate->getIliasVersion()],
99 'currently_active' => ['integer', (int) $userCertificate->isCurrentlyActive()],
100 'background_image_ident' => ['text', $userCertificate->getBackgroundImageIdentification()],
101 'tile_image_ident' => ['text', $userCertificate->getTileImageIdentification()],
102 'certificate_id' => ['text', $userCertificate->getCertificateId()->asString()]
103 ];
104
105 if (
106 $this->database->tableColumnExists('il_cert_user_cert', 'background_image_path') &&
107 $this->database->tableColumnExists('il_cert_user_cert', 'tile_image_path')
108 ) {
109 $columns['background_image_path'] = ['text', $userCertificate->getBackgroundImagePath()];
110 $columns['tile_image_path'] = ['text', $userCertificate->getTileImagePath()];
111 }
112
113 $this->logger->debug(
114 sprintf(
115 'END - Save certificate with following values: %s',
116 json_encode($columns, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
117 )
118 );
119
120 $this->database->insert(self::TABLE_NAME, $columns);
121
122 return $userCertificate->withId($id)->withVersion($version);
123 }
124
128 public function fetchActiveCertificates(int $userId): array
129 {
130 $this->logger->debug(sprintf('START - Fetching all active certificates for user: "%s"', $userId));
131
132 $sql = '
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';
141
142 $query = $this->database->query($sql);
143
144 $result = [];
145 while ($row = $this->database->fetchAssoc($query)) {
146 $userCertificate = $this->createUserCertificate($row);
147
148 $presentation = new ilUserCertificatePresentation(
149 (int) $row['obj_id'],
150 (string) $row['obj_type'],
151 $userCertificate,
152 $row['title'],
153 ''
154 );
155 $result[] = $presentation;
156 }
157
158 $this->logger->debug(sprintf('Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
159 $this->logger->debug(
160 sprintf(
161 'END - All active certificates for user: "%s" total: "%s"',
162 $userId,
163 count($result)
164 )
165 );
166
167 return $result;
168 }
169
174 int $userId,
175 int $startTimestamp,
176 int $endTimeStamp
177 ): array {
178 $this->logger->debug(sprintf('START - Fetching all active certificates for user: "%s"', $userId));
179
180 $sql = '
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');
191
192 $query = $this->database->query($sql);
193
194 $result = [];
195 while ($row = $this->database->fetchAssoc($query)) {
196 $userCertificate = $this->createUserCertificate($row);
197
198 $presentation = new ilUserCertificatePresentation(
199 (int) $row['obj_id'],
200 (string) $row['obj_type'],
201 $userCertificate,
202 $row['title'],
203 ''
204 );
205 $result[] = $presentation;
206 }
207
208 $this->logger->debug(sprintf('Actual results: "%s"', json_encode($result, JSON_THROW_ON_ERROR)));
209 $this->logger->debug(
210 sprintf(
211 'END - All active certificates for user: "%s" total: "%s"',
212 $userId,
213 count($result)
214 )
215 );
216
217 return $result;
218 }
219
223 public function fetchActiveCertificate(int $userId, int $objectId): ilUserCertificate
224 {
225 $this->logger->debug(
226 sprintf(
227 'START - Fetching all active certificates for user: "%s" and object: "%s"',
228 $userId,
229 $objectId
230 )
231 );
232
233 $sql = 'SELECT *
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';
238
239 $query = $this->database->query($sql);
240
241 while ($row = $this->database->fetchAssoc($query)) {
242 $this->logger->debug(sprintf('Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
243
244 $this->logger->debug(
245 sprintf(
246 'END -Found active user certificate for user: "%s" and object: "%s"',
247 $userId,
248 $objectId
249 )
250 );
251
252 return $this->createUserCertificate($row);
253 }
254
255 throw new ilException(
256 sprintf('There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
257 );
258 }
259
263 public function fetchActiveCertificateForPresentation(int $userId, int $objectId): ilUserCertificatePresentation
264 {
265 $this->logger->debug(
266 sprintf(
267 'START - Fetching all active certificates for user: "%s" and object: "%s"',
268 $userId,
269 $objectId
270 )
271 );
272
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';
283
284 $query = $this->database->query($sql);
285
286 while ($row = $this->database->fetchAssoc($query)) {
287 $this->logger->debug(sprintf('Active certificate values: %s', json_encode($row, JSON_THROW_ON_ERROR)));
288
289 $this->logger->debug(
290 sprintf(
291 'END -Found active user certificate for user: "%s" and object: "%s"',
292 $userId,
293 $objectId
294 )
295 );
296
297 $userCertificate = $this->createUserCertificate($row);
298
300 (int) $row['obj_id'],
301 (string) $row['obj_type'],
302 $userCertificate,
303 $row['title'],
304 '',
305 $row['lastname']
306 );
307 }
308
309 throw new ilException(
310 sprintf('There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId)
311 );
312 }
313
317 public function fetchActiveCertificatesByTypeForPresentation(int $userId, string $type): array
318 {
319 $this->logger->debug(
320 sprintf(
321 'START - Fetching all active certificates for user: "%s" and type: "%s"',
322 $userId,
323 $type
324 )
325 );
326
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';
335
336 $query = $this->database->query($sql);
337
338 $result = [];
339 while ($row = $this->database->fetchAssoc($query)) {
340 $userCertificate = $this->createUserCertificate($row);
341
342 $presentation = new ilUserCertificatePresentation(
343 (int) $row['obj_id'],
344 (string) $row['obj_type'],
345 $userCertificate,
346 $row['title'],
347 ''
348 );
349 $result[] = $presentation;
350 }
351
352 $this->logger->debug(
353 sprintf(
354 'END - Fetching all active certificates for user: "%s" and type: "%s"',
355 $userId,
356 $type
357 )
358 );
359
360 return $result;
361 }
362
367 {
368 $this->logger->debug(sprintf('START - Fetch certificate by id: "%s"', $id));
369
370 $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = ' . $this->database->quote($id, 'integer');
371
372 $query = $this->database->query($sql);
373
374 while ($row = $this->database->fetchAssoc($query)) {
375 $this->logger->debug(sprintf('Fetched certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
376
377 $this->logger->debug(sprintf('END - Fetch certificate by id: "%s"', $id));
378
379 return $this->createUserCertificate($row);
380 }
381
382 throw new ilException('No certificate found for user certificate id: ' . $id);
383 }
384
389 public function fetchObjectIdsWithCertificateForUser(int $userId, array $objectIds): array
390 {
391 $this->logger->debug(
392 sprintf(
393 'START - Fetch certificate for user("%s") and ids: "%s"',
394 $userId,
395 json_encode($objectIds, JSON_THROW_ON_ERROR)
396 )
397 );
398
399 if ([] === $objectIds) {
400 return [];
401 }
402
403 $inStatementObjectIds = $this->database->in(
404 'obj_id',
405 $objectIds,
406 false,
407 'integer'
408 );
409
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');
414
415 $query = $this->database->query($sql);
416
417 $result = [];
418
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'];
422 }
423
424 return $result;
425 }
426
430 public function fetchUserIdsWithCertificateForObject(int $objectId): array
431 {
432 $this->logger->debug(sprintf('START - Fetch certificate for object("%s")"', $objectId));
433
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');
437
438 $query = $this->database->query($sql);
439
440 $result = [];
441
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'];
445 }
446
447 return $result;
448 }
449
450 public function deleteUserCertificates(int $userId): void
451 {
452 $this->logger->debug(sprintf('START - Delete certificate for user("%s")"', $userId));
453
454 $sql = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE usr_id = ' . $this->database->quote($userId, 'integer');
455
456 $this->database->manipulate($sql);
457
458 $this->logger->debug(sprintf('END - Successfully deleted certificate for user("%s")"', $userId));
459 }
460
464 private function fetchCertificatesOfObject(int $objId, int $userId): array
465 {
466 $this->logger->debug(
467 sprintf(
468 'START - fetching all certificates of object(user id: "%s", object id: "%s")',
469 $userId,
470 $objId
471 )
472 );
473
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');
477
478 $query = $this->database->query($sql);
479
480 $result = [];
481 while ($row = $this->database->fetchAssoc($query)) {
482 $this->logger->debug(
483 sprintf(
484 'Certificate found: "%s")',
485 json_encode($row, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
486 )
487 );
488
489 $this->logger->debug(sprintf('Certificate: "%s"', json_encode($row, JSON_THROW_ON_ERROR)));
490
491 $result[] = $this->createUserCertificate($row);
492 }
493
494 $this->logger->debug(
495 sprintf(
496 'END - fetching all certificates of object(user id: "%s", object id: "%s")',
497 $userId,
498 $objId
499 )
500 );
501
502 return $result;
503 }
504
505 private function fetchLatestVersion(int $objId, int $userId): string
506 {
507 $this->logger->debug(
508 sprintf(
509 'START - fetching of latest certificates of object(user id: "%s", object id: "%s")',
510 $userId,
511 $objId
512 )
513 );
514
515 $templates = $this->fetchCertificatesOfObject($objId, $userId);
516
517 $version = 0;
518 foreach ($templates as $template) {
519 if ($template->getVersion() > $version) {
520 $version = $template->getVersion();
521 }
522 }
523
524 $this->logger->debug(
525 sprintf(
526 'END - fetching of latest certificates of object(user id: "%s", object id: "%s") with version "%s"',
527 $userId,
528 $objId,
530 )
531 );
532
533 return (string) $version;
534 }
535
536 private function deactivatePreviousCertificates(int $objId, int $userId): void
537 {
538 $this->logger->debug(
539 sprintf(
540 'START - deactivating previous certificates for user id: "%s" and object id: "%s"',
541 $userId,
542 $objId
543 )
544 );
545
546 $sql = '
547UPDATE ' . self::TABLE_NAME . '
548SET currently_active = 0
549WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
550AND usr_id = ' . $this->database->quote($userId, 'integer');
551
552 $this->database->manipulate($sql);
553
554 $this->logger->debug(
555 sprintf(
556 'END - deactivating previous certificates for user id: "%s" and object id: "%s"',
557 $userId,
558 $objId
559 )
560 );
561 }
562
563 public function isResourceUsed(string $relative_image_identification): bool
564 {
565 $this->logger->debug(
566 sprintf(
567 'START - Checking if any certificate template uses background image path "%s"',
568 $relative_image_identification
569 )
570 );
571
572 $result = $this->database->queryF(
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',
576 ['text', 'text'],
577 [$relative_image_identification, $relative_image_identification]
578 );
579
580 $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
581
582 $this->logger->debug(
583 sprintf(
584 'END - Image path "%s" is ' . $exists ? 'in use' : 'unused',
585 $relative_image_identification
586 )
587 );
588
589 return $exists;
590 }
591
595 private function createUserCertificate(array $row): ilUserCertificate
596 {
597 return new ilUserCertificate(
598 (int) $row['pattern_certificate_id'],
599 (int) $row['obj_id'],
600 $row['obj_type'],
601 (int) $row['usr_id'],
602 $row['user_name'],
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'],
610 new CertificateId($row['certificate_id']),
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
616 );
617 }
618
619 public function deleteUserCertificatesForObject(int $userId, int $obj_id): void
620 {
621 $this->logger->debug(
622 sprintf('START - Delete certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
623 );
624
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');
628
629 $this->database->manipulate($sql);
630
631 $this->logger->debug(
632 sprintf('END - Successfully deleted certificate for user("%s") in object (obj_id: %s)"', $userId, $obj_id)
633 );
634 }
635
636 private function overviewTableColumnToDbColumn(string $table_column): string
637 {
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',
644 default => null,
645 };
646
647 if (!$result) {
648 throw new InvalidArgumentException('Invalid table column passed');
649 }
650
651 return $result;
652 }
653
659 string $user_language,
660 array $filter,
661 ?Range $range = null,
662 string $order_field = 'issue_date',
663 string $order_direction = 'ASC'
664 ): array {
665 $order_field = $this->overviewTableColumnToDbColumn($order_field);
666
667 $sql_filters = [];
668 foreach ($filter as $key => $value) {
669 if ($value === null) {
670 continue;
671 }
672
673 $column_name = $this->overviewTableColumnToDbColumn($key);
674
675 if ($key === 'issue_date') {
676 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
677 if ($sql_filter) {
678 $sql_filters[] = $sql_filter;
679 }
680 } else {
681 $sql_filters[] = $this->database->like($column_name, ilDBConstants::T_TEXT, "%$value%");
682 }
683 }
684
685 if ($range) {
686 $this->database->setLimit($range->getLength(), $range->getStart());
687 }
688
689 $result = $this->database->query(
690 'SELECT cert.*, ' .
691 '(CASE
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
695 ELSE ' . $this->database->quote($this->defaultTitle, ilDBConstants::T_TEXT) . '
696 END
697 ) as object, '
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
705 );
706
707 $certificates = [];
708 while ($row = $this->database->fetchAssoc($result)) {
709 $certificates[] = $this->createUserCertificate($row);
710 }
711 return $certificates;
712 }
713
717 private function getIssueDateSqlFilter(string $column_name, array $duration): ?string
718 {
719 if (array_keys($duration) === ["from", "to"] && $duration !== ["from" => null, "to" => null]) {
720 $from = $duration["from"];
721 $to = $duration["to"];
722
723 $sql_filter = "";
724 if ($from && $to) {
725 $sql_filter = $column_name
726 . ' BETWEEN '
727 . $this->database->quote($from->getTimestamp(), ilDBConstants::T_INTEGER)
728 . ' AND '
729 . $this->database->quote($to->getTimestamp(), ilDBConstants::T_INTEGER);
730 }
731
732 if ($from && !$to) {
733 $sql_filter = $column_name
734 . ' >= '
735 . $this->database->quote($from->getTimestamp(), ilDBConstants::T_INTEGER);
736 }
737
738 if (!$from && $to) {
739 $sql_filter = $column_name
740 . ' <= '
741 . $this->database->quote($to->getTimestamp(), ilDBConstants::T_INTEGER);
742 }
743
744 if ($sql_filter) {
745 return $sql_filter;
746 }
747 }
748 return null;
749 }
750
754 public function fetchCertificatesForOverviewCount(array $filter, ?Range $range = null): int
755 {
756 $sql_filters = [];
757 foreach ($filter as $key => $value) {
758 if ($value === null) {
759 continue;
760 }
761
762 $column_name = $key;
763 switch ($key) {
764 case 'issue_date':
765 $column_name = 'acquired_timestamp';
766 break;
767 case 'object':
768 $column_name = 'object_data.title';
769 break;
770 case 'owner':
771 $column_name = 'usr_data.login';
772 break;
773 case 'obj_id':
774 $column_name = 'cert.obj_id';
775 break;
776 }
777
778 if ($key === 'issue_date') {
779 $sql_filter = $this->getIssueDateSqlFilter($column_name, is_array($value) ? $value : []);
780 if ($sql_filter) {
781 $sql_filters[] = $sql_filter;
782 }
783 } else {
784 $sql_filters[] = $this->database->like($column_name, ilDBConstants::T_TEXT, "%$value%");
785 }
786 }
787
788 if ($range) {
789 $this->database->setLimit($range->getLength(), $range->getStart());
790 }
791
792 $result = $this->database->query(
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) : '')
797 );
798
799 return (int) $this->database->fetchAssoc($result)['count'];
800 }
801
803 {
804 return new CertificateId($this->uuid_factory->uuid4AsString());
805 }
806}
$version
Definition: plugin.php:24
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$duration
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.
isResourceUsed(string $relative_image_identification)
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')
fetchActiveCertificateForPresentation(int $userId, int $objectId)
deactivatePreviousCertificates(int $objId, int $userId)
fetchObjectIdsWithCertificateForUser(int $userId, array $objectIds)
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,)
save(ilUserCertificate $userCertificate)
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57