ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPdfGenerator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
29 {
32 
33  public function __construct(
34  private readonly ilUserCertificateRepository $certificateRepository,
35  private ?IRSS $irss = null,
36  private ?Filesystem $filesystem = null,
38  ?ilCertificatePdfFileNameFactory $pdfFileNameFactory = null,
39  ?ilLanguage $lng = null,
40  ) {
41  global $DIC;
42 
43  if (null === $irss) {
44  $irss = $DIC->resourceStorage();
45  }
46  $this->irss = $irss;
47 
48  if (null === $this->filesystem) {
49  $filesystem = $DIC->filesystem()->web();
50  }
51  $this->filesystem = $filesystem;
52 
53  if (null === $rpcHelper) {
54  $rpcHelper = new ilCertificateRpcClientFactoryHelper();
55  }
56  $this->rpcHelper = $rpcHelper;
57 
58  if (null === $lng) {
59  $lng = $DIC->language();
60  }
61 
62  if (null === $pdfFileNameFactory) {
63  $pdfFileNameFactory = new ilCertificatePdfFileNameFactory($lng);
64  }
65  $this->pdfFilenameFactory = $pdfFileNameFactory;
66  }
67 
71  public function generate(int $userCertificateId): string
72  {
73  $certificate = $this->certificateRepository->fetchCertificate($userCertificateId);
74 
75  return $this->createPDFScalar($certificate);
76  }
77 
81  public function generateCurrentActiveCertificate(int $userId, int $objId): string
82  {
83  $certificate = $this->certificateRepository->fetchActiveCertificate($userId, $objId);
84 
85  return $this->createPDFScalar($certificate);
86  }
87 
93  public function generateFileName(int $userId, int $objId): string
94  {
95  $certificate = $this->certificateRepository->fetchActiveCertificateForPresentation($userId, $objId);
96 
97  $user = ilObjectFactory::getInstanceByObjId($userId);
98  if (!$user instanceof ilObjUser) {
99  throw new ilException(sprintf('The usr_id "%s" does NOT reference a user', $userId));
100  }
101 
102  return $this->pdfFilenameFactory->create($certificate);
103  }
104 
105  private function createPDFScalar(ilUserCertificate $certificate): string
106  {
107  $certificateContent = $certificate->getCertificateContent();
108 
109  $background_rid = $this->irss->manage()->find($certificate->getCurrentBackgroundImageUsed());
110  $background_src = '';
111  if ($background_rid instanceof ResourceIdentification) {
112  $background_src = $this->irss->consume()->src($background_rid)->getSrc(true);
113 
114  $certificateContent = str_replace(
115  ['[BACKGROUND_IMAGE]'],
116  [$background_src],
117  $certificateContent
118  );
119  } elseif ($this->filesystem->has($certificate->getCurrentBackgroundImageUsed())) {
120  $certificateContent = str_replace(
121  ['[BACKGROUND_IMAGE]', '[CLIENT_WEB_DIR]'],
122  ['[CLIENT_WEB_DIR]' . $certificate->getCurrentBackgroundImageUsed(), 'file://' . CLIENT_WEB_DIR],
123  $certificateContent
124  );
125  }
126 
127  $pdf_base64 = $this->rpcHelper->ilFO2PDF('RPCTransformationHandler', $certificateContent);
128 
129  return $pdf_base64->scalar;
130  }
131 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$objId
Definition: xapitoken.php:57
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
generateFileName(int $userId, int $objId)
generateCurrentActiveCertificate(int $userId, int $objId)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
readonly ilCertificateRpcClientFactoryHelper $rpcHelper
const CLIENT_WEB_DIR
Definition: constants.php:47
__construct(private readonly ilUserCertificateRepository $certificateRepository, private ?IRSS $irss=null, private ?Filesystem $filesystem=null, ?ilCertificateRpcClientFactoryHelper $rpcHelper=null, ?ilCertificatePdfFileNameFactory $pdfFileNameFactory=null, ?ilLanguage $lng=null,)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
global $lng
Definition: privfeed.php:31
readonly ilCertificatePdfFileNameFactory $pdfFilenameFactory
generate(int $userCertificateId)
createPDFScalar(ilUserCertificate $certificate)