ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserCertificateApiGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 {
29  public const CMD_DOWNLOAD = 'download';
31  private ServerRequestInterface $request;
34 
35  public function __construct(
36  ?ilLanguage $language = null,
37  ?ServerRequestInterface $request = null,
38  ?ilLogger $certificateLogger = null,
39  ?ilCtrlInterface $ctrl = null
40  ) {
41  global $DIC;
42 
43  if ($language === null) {
44  $language = $DIC->language();
45  }
46  $this->language = $language;
47 
48  if ($request === null) {
49  $request = $DIC->http()->request();
50  }
51  $this->request = $request;
52 
53  if ($certificateLogger === null) {
54  $certificateLogger = $DIC->logger()->cert();
55  }
56  $this->certificateLogger = $certificateLogger;
57 
58  if ($ctrl === null) {
59  $ctrl = $DIC->ctrl();
60  }
61  $this->ctrl = $ctrl;
62 
63  $this->language->loadLanguageModule('cert');
64  }
65 
66  public function executeCommand(): void
67  {
68  $cmd = $this->ctrl->getCmd();
69 
70  switch ($cmd) {
71  case self::CMD_DOWNLOAD:
72  $this->{$cmd}();
73  break;
74 
75  default:
76  break;
77  }
78  }
79 
80  public function download(): void
81  {
82  $userCertificateRepository = new ilUserCertificateRepository(null, $this->certificateLogger);
83  $pdfGenerator = new ilPdfGenerator($userCertificateRepository, $this->certificateLogger);
84 
85  $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
86 
87  $userCertificate = $userCertificateRepository->fetchCertificate($userCertificateId);
88 
89  $pdfAction = new ilCertificatePdfAction(
90  $this->certificateLogger,
91  $pdfGenerator,
93  $this->language->txt('error_creating_certificate_pdf')
94  );
95 
96  $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
97  }
98 }
Class ilPdfGeneratorConstantsTest.
global $DIC
Definition: feed.php:28
__construct(?ilLanguage $language=null, ?ServerRequestInterface $request=null, ?ilLogger $certificateLogger=null, ?ilCtrlInterface $ctrl=null)
Just a wrapper class to create Unit Test for other classes.
downloadPdf(int $userId, int $objectId)