ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCertificatePdfAction.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  private ilLogger $logger;
30  private string $translatedErrorText;
31 
32  public function __construct(
33  ilLogger $logger,
34  ilPdfGenerator $pdfGenerator,
35  ?ilCertificateUtilHelper $ilUtilHelper = null,
36  string $translatedErrorText = '',
37  ?ilErrorHandling $errorHandler = null
38  ) {
39  $this->logger = $logger;
40  $this->pdfGenerator = $pdfGenerator;
41  if (null === $ilUtilHelper) {
42  $ilUtilHelper = new ilCertificateUtilHelper();
43  }
44  $this->ilUtilHelper = $ilUtilHelper;
45 
46  if (null === $errorHandler) {
47  global $DIC;
48  $errorHandler = $DIC['ilErr'];
49  }
50  $this->errorHandler = $errorHandler;
51 
52  $this->translatedErrorText = $translatedErrorText;
53  }
54 
55  public function createPDF(int $userId, int $objectId): string
56  {
57  return $this->pdfGenerator->generateCurrentActiveCertificate($userId, $objectId);
58  }
59 
60  public function downloadPdf(int $userId, int $objectId): string
61  {
62  try {
63  $pdfScalar = $this->createPDF($userId, $objectId);
64 
65  $fileName = $this->pdfGenerator->generateFileName($userId, $objectId);
66 
67  $this->ilUtilHelper->deliverData(
68  $pdfScalar,
69  $fileName,
70  'application/pdf'
71  );
72  } catch (ilException $clientException) {
73  $this->errorHandler->raiseError($this->translatedErrorText, $this->errorHandler->MESSAGE);
74  return '';
75  }
76 
77  return $pdfScalar;
78  }
79 }
Class ilPdfGeneratorConstantsTest.
__construct(ilLogger $logger, ilPdfGenerator $pdfGenerator, ?ilCertificateUtilHelper $ilUtilHelper=null, string $translatedErrorText='', ?ilErrorHandling $errorHandler=null)
global $DIC
Definition: feed.php:28
Just a wrapper class to create Unit Test for other classes.
Error Handling & global info handling uses PEAR error class.
ilCertificateUtilHelper $ilUtilHelper
createPDF(int $userId, int $objectId)
downloadPdf(int $userId, int $objectId)