42 $logger = $DIC->logger()->cert();
48 $defaultTitle = $DIC->language()->txt(
'certificate_no_object_title');
60 $this->logger->info(
'START - saving of user certificate');
65 $id = (int) $this->database->nextId(
'il_cert_user_cert');
67 $objId = $userCertificate->
getObjId();
73 'id' => array(
'integer',
$id),
75 'obj_id' => array(
'integer', $objId),
76 'obj_type' => array(
'text', $userCertificate->
getObjType()),
77 'user_id' => array(
'integer', $userId),
78 'user_name' => array(
'text', $userCertificate->
getUserName()),
82 'valid_until' => array(
'integer', $userCertificate->
getValidUntil()),
83 'version' => array(
'integer',
$version),
85 'currently_active' => array(
'integer', (integer) $userCertificate->
isCurrentlyActive()),
90 $this->logger->debug(sprintf(
'END - Save certificate with following values: %s', json_encode(
$columns, JSON_PRETTY_PRINT)));
92 $this->database->insert(
'il_cert_user_cert',
$columns);
104 $this->logger->info(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
108 il_cert_user_cert.pattern_certificate_id, 109 il_cert_user_cert.obj_id, 110 il_cert_user_cert.obj_type, 111 il_cert_user_cert.user_id, 112 il_cert_user_cert.user_name, 113 il_cert_user_cert.acquired_timestamp, 114 il_cert_user_cert.certificate_content, 115 il_cert_user_cert.template_values, 116 il_cert_user_cert.valid_until, 117 il_cert_user_cert.version, 118 il_cert_user_cert.ilias_version, 119 il_cert_user_cert.currently_active, 120 il_cert_user_cert.background_image_path, 121 il_cert_user_cert.id, 122 il_cert_user_cert.thumbnail_image_path, 123 (CASE WHEN (object_data.title IS NULL) 125 CASE WHEN (object_data_del.title IS NULL) 126 THEN ' . $this->database->quote($this->defaultTitle,
'text') .
' 127 ELSE object_data_del.title 129 ELSE object_data.title 132 FROM il_cert_user_cert 133 LEFT JOIN object_data ON object_data.obj_id = il_cert_user_cert.obj_id 134 LEFT JOIN object_data_del ON object_data_del.obj_id = il_cert_user_cert.obj_id 135 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
' 136 AND currently_active = 1';
138 $query = $this->database->query($sql);
141 while (
$row = $this->database->fetchAssoc(
$query)) {
148 $this->logger->debug(sprintf(
'Actual results:', json_encode(
$result)));
149 $this->logger->info(sprintf(
'END - All active certificates for user: "%s" total: "%s"', $userId, count(
$result)));
161 $this->logger->info(sprintf(
'START - Fetching all active certificates for user: "%s"', $userId));
165 il_cert_user_cert.pattern_certificate_id, 166 il_cert_user_cert.obj_id, 167 il_cert_user_cert.obj_type, 168 il_cert_user_cert.user_id, 169 il_cert_user_cert.user_name, 170 il_cert_user_cert.acquired_timestamp, 171 il_cert_user_cert.certificate_content, 172 il_cert_user_cert.template_values, 173 il_cert_user_cert.valid_until, 174 il_cert_user_cert.version, 175 il_cert_user_cert.ilias_version, 176 il_cert_user_cert.currently_active, 177 il_cert_user_cert.background_image_path, 178 il_cert_user_cert.id, 179 il_cert_user_cert.thumbnail_image_path, 180 (CASE WHEN (object_data.title IS NULL) 182 CASE WHEN (object_data_del.title IS NULL) 183 THEN ' . $this->database->quote($this->defaultTitle,
'text') .
' 184 ELSE object_data_del.title 186 ELSE object_data.title 189 FROM il_cert_user_cert 190 LEFT JOIN object_data ON object_data.obj_id = il_cert_user_cert.obj_id 191 LEFT JOIN object_data_del ON object_data_del.obj_id = il_cert_user_cert.obj_id 192 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
' 193 AND currently_active = 1 194 AND acquired_timestamp >= ' . $this->database->quote($startTimestamp,
'integer') .
' 195 AND acquired_timestamp <= ' . $this->database->quote($endTimeStamp,
'integer');
197 $query = $this->database->query($sql);
200 while (
$row = $this->database->fetchAssoc(
$query)) {
207 $this->logger->debug(sprintf(
'Actual results:', json_encode(
$result)));
208 $this->logger->info(sprintf(
'END - All active certificates for user: "%s" total: "%s"', $userId, count(
$result)));
215 $this->logger->info(sprintf(
'START - Fetching all active certificates for user: "%s" and object: "%s"', $userId, $objectId));
218 FROM il_cert_user_cert 219 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
' 220 AND obj_id = ' . $this->database->quote($objectId,
'integer') .
' 221 AND currently_active = 1';
223 $query = $this->database->query($sql);
225 while (
$row = $this->database->fetchAssoc(
$query)) {
226 $this->logger->debug(sprintf(
'Active certificate values: %s', json_encode(
$row)));
228 $this->logger->info(sprintf(
'END -Found active user certificate for user: "%s" and object: "%s"', $userId, $objectId));
233 throw new ilException(sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId));
244 $this->logger->info(sprintf(
'START - Fetching all active certificates for user: "%s" and object: "%s"', $userId, $objectId));
247 il_cert_user_cert.pattern_certificate_id, 248 il_cert_user_cert.obj_id, 249 il_cert_user_cert.obj_type, 250 il_cert_user_cert.user_id, 251 il_cert_user_cert.user_name, 252 il_cert_user_cert.acquired_timestamp, 253 il_cert_user_cert.certificate_content, 254 il_cert_user_cert.template_values, 255 il_cert_user_cert.valid_until, 256 il_cert_user_cert.version, 257 il_cert_user_cert.ilias_version, 258 il_cert_user_cert.currently_active, 259 il_cert_user_cert.background_image_path, 260 il_cert_user_cert.id, 261 il_cert_user_cert.thumbnail_image_path, 263 (CASE WHEN (object_data.title IS NULL) 265 CASE WHEN (object_data_del.title IS NULL) 266 THEN ' . $this->database->quote($this->defaultTitle,
'text') .
' 267 ELSE object_data_del.title 269 ELSE object_data.title 272 FROM il_cert_user_cert 273 LEFT JOIN object_data ON object_data.obj_id = il_cert_user_cert.obj_id 274 LEFT JOIN object_data_del ON object_data_del.obj_id = il_cert_user_cert.obj_id 275 LEFT JOIN usr_data ON usr_data.usr_id = il_cert_user_cert.user_id 276 WHERE il_cert_user_cert.user_id = ' . $this->database->quote($userId,
'integer') .
' 277 AND il_cert_user_cert.obj_id = ' . $this->database->quote($objectId,
'integer') .
' 278 AND il_cert_user_cert.currently_active = 1';
280 $query = $this->database->query($sql);
282 while (
$row = $this->database->fetchAssoc(
$query)) {
283 $this->logger->debug(sprintf(
'Active certificate values: %s', json_encode(
$row)));
285 $this->logger->info(sprintf(
'END -Found active user certificate for user: "%s" and object: "%s"', $userId, $objectId));
291 throw new ilException(sprintf(
'There is no active entry for user id: "%s" and object id: "%s"', $userId, $objectId));
301 $this->logger->info(sprintf(
'START - Fetching all active certificates for user: "%s" and type: "%s"', $userId, $type));
304 il_cert_user_cert.pattern_certificate_id, 305 il_cert_user_cert.obj_id, 306 il_cert_user_cert.obj_type, 307 il_cert_user_cert.user_id, 308 il_cert_user_cert.user_name, 309 il_cert_user_cert.acquired_timestamp, 310 il_cert_user_cert.certificate_content, 311 il_cert_user_cert.template_values, 312 il_cert_user_cert.valid_until, 313 il_cert_user_cert.version, 314 il_cert_user_cert.ilias_version, 315 il_cert_user_cert.currently_active, 316 il_cert_user_cert.background_image_path, 317 il_cert_user_cert.id, 318 il_cert_user_cert.thumbnail_image_path, 319 (CASE WHEN (object_data.title IS NULL) 321 CASE WHEN (object_data_del.title IS NULL) 322 THEN ' . $this->database->quote($this->defaultTitle,
'text') .
' 323 ELSE object_data_del.title 325 ELSE object_data.title 328 FROM il_cert_user_cert 329 LEFT JOIN object_data ON object_data.obj_id = il_cert_user_cert.obj_id 330 LEFT JOIN object_data_del ON object_data_del.obj_id = il_cert_user_cert.obj_id 331 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
' 332 AND obj_type = ' . $this->database->quote($type,
'text') .
' 333 AND currently_active = 1';
335 $query = $this->database->query($sql);
338 while (
$row = $this->database->fetchAssoc(
$query)) {
345 $this->logger->info(sprintf(
'END - Fetching all active certificates for user: "%s" and type: "%s"', $userId, $type));
357 $this->logger->info(sprintf(
'START - Fetch certificate by id: "%s"', $id));
359 $sql =
'SELECT * FROM il_cert_user_cert WHERE id = ' . $this->database->quote($id,
'integer');
361 $query = $this->database->query($sql);
363 while (
$row = $this->database->fetchAssoc(
$query)) {
364 $this->logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode(
$row)));
366 $this->logger->info(sprintf(
'END - Fetch certificate by id: "%s"', $id));
371 throw new ilException(
'No certificate found for user certificate id: ' . $id);
376 $this->logger->info(sprintf(
'START - Fetch certificate for user("%s") and ids: "%s"', $userId, json_encode($objectIds)));
378 if (0 === count($objectIds)) {
382 $inStatementObjectIds = $this->database->in(
389 $sql =
'SELECT obj_id FROM il_cert_user_cert 390 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
391 ' AND ' . $inStatementObjectIds .
392 ' AND currently_active = ' . $this->database->quote(1,
'integer');
394 $query = $this->database->query($sql);
398 while (
$row = $this->database->fetchAssoc(
$query)) {
399 $this->logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode(
$row)));
408 $this->logger->info(sprintf(
'START - Fetch certificate for object("%s")"', $objectId));
410 $sql =
'SELECT user_id FROM il_cert_user_cert 411 WHERE obj_id = ' . $this->database->quote($objectId,
'integer') .
' 412 AND currently_active = ' . $this->database->quote(1,
'integer');
414 $query = $this->database->query($sql);
418 while (
$row = $this->database->fetchAssoc(
$query)) {
419 $this->logger->debug(sprintf(
'Fetched certificate: "%s"', json_encode(
$row)));
428 $this->logger->info(sprintf(
'START - Delete certificate for user("%s")"', $userId));
430 $sql =
'DELETE FROM il_cert_user_cert WHERE user_id = ' . $this->database->quote($userId,
'integer');
432 $this->database->manipulate($sql);
434 $this->logger->info(sprintf(
'END - Successfully deleted certificate for user("%s")"', $userId));
444 $this->logger->info(sprintf(
445 'START - fetching all certificates of object(user id: "%s", object id: "%s")',
450 $sql =
'SELECT * FROM il_cert_user_cert 451 WHERE user_id = ' . $this->database->quote($userId,
'integer') .
' 452 AND obj_id = ' . $this->database->quote($objId,
'integer');
454 $query = $this->database->query($sql);
457 while (
$row = $this->database->fetchAssoc(
$query)) {
458 $this->logger->debug(sprintf(
459 'Certificate found: "%s")',
460 json_encode(
$row, JSON_PRETTY_PRINT)
463 $this->logger->info(sprintf(
'Certificate: ', json_encode(
$row)));
468 $this->logger->info(sprintf(
469 'END - fetching all certificates of object(user id: "%s", object id: "%s")',
484 $this->logger->info(sprintf(
485 'START - fetching of latest certificates of object(user id: "%s", object id: "%s")',
494 if ($template->getVersion() >
$version) {
499 $this->logger->info(sprintf(
500 'END - fetching of latest certificates of object(user id: "%s", object id: "%s") with verision',
516 $this->logger->info(sprintf(
'START - deactivating previous certificates for user id: "%s" and object id: "%s"', $userId, $objId));
519 UPDATE il_cert_user_cert 520 SET currently_active = 0 521 WHERE obj_id = ' . $this->database->quote($objId,
'integer') .
' 522 AND user_id = ' . $this->database->quote($userId,
'integer');
524 $this->database->manipulate($sql);
526 $this->logger->info(sprintf(
'END - deactivating previous certificates for user id: "%s" and object id: "%s"', $userId, $objId));
536 $row[
'pattern_certificate_id'],
541 (
int)
$row[
'acquired_timestamp'],
542 $row[
'certificate_content'],
543 $row[
'template_values'],
546 $row[
'ilias_version'],
547 $row[
'currently_active'],
548 $row[
'background_image_path'],
549 $row[
'thumbnail_image_path'],
getPatternCertificateId()
createUserCertificate($row)
fetchActiveCertificatesByTypeForPresentation(int $userId, string $type)
fetchActiveCertificatesInIntervalForPresentation(int $userId, int $startTimestamp, int $endTimeStamp)
if(!array_key_exists('StateId', $_REQUEST)) $id
save(ilUserCertificate $userCertificate)
fetchUserIdsWithCertificateForObject(int $objectId)
__construct(\ilDBInterface $database=null, ilLogger $logger=null, string $defaultTitle=null)
fetchActiveCertificate(int $userId, int $objectId)
fetchActiveCertificates(int $userId)
deactivatePreviousCertificates(int $objId, int $userId)
fetchCertificate(int $id)
deleteUserCertificates(int $userId)
fetchCertificatesOfObject(int $objId, int $userId)
Component logger with individual log levels by component id.
fetchObjectIdsWithCertificateForUser(int $userId, array $objectIds)
fetchLatestVersion(int $objId, int $userId)
fetchActiveCertificateForPresentation(int $userId, int $objectId)