ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilCertificatePdfAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
25 private ?ilLogger $logger = null;
26
27 public function __construct(
28 private readonly ilPdfGenerator $pdf_generator,
30 private readonly string $error_txt = '',
32 ) {
33 global $DIC;
34
35 $this->helper = $helper ?? new ilCertificateUtilHelper();
36 $this->error_handler = $error_handler ?? $DIC['ilErr'];
37 }
38
39 public function withLogger(ilLogger $logger): self
40 {
41 $clone = clone $this;
42 $clone->logger = $logger;
43
44 return $clone;
45 }
46
47 public function createPDF(int $userId, int $objectId): string
48 {
49 return $this->pdf_generator->generateCurrentActiveCertificate($userId, $objectId);
50 }
51
52 public function downloadPdf(int $userId, int $objectId): string
53 {
54 try {
55 $pdf_scalar = $this->createPDF($userId, $objectId);
56
57 $filename = $this->pdf_generator->generateFileName($userId, $objectId);
58
59 $this->helper->deliverData(
60 $pdf_scalar,
62 'application/pdf'
63 );
64 } catch (Throwable $e) {
65 $this->logger?->error(
66 'Error while generating or downloading certificate PDF for user {user_id} and object {object_id}: {error}',
67 [
68 'user_id' => $userId,
69 'object_id' => $objectId,
70 'error' => $e->getMessage(),
71 'exception' => $e
72 ]
73 );
74
75 $this->error_handler->raiseError($this->error_txt, $this->error_handler->MESSAGE);
76 return '';
77 }
78
79 return $pdf_scalar;
80 }
81}
$filename
Definition: buildRTE.php:78
downloadPdf(int $userId, int $objectId)
createPDF(int $userId, int $objectId)
__construct(private readonly ilPdfGenerator $pdf_generator, ?ilCertificateUtilHelper $helper=null, private readonly string $error_txt='', ?ilErrorHandling $error_handler=null)
readonly ilCertificateUtilHelper $helper
readonly ilErrorHandling $error_handler
Just a wrapper class to create Unit Test for other classes.
Error Handling & global info handling.
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26