ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPdfGenerator.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
13 
17  private $logger;
18 
22  private $rpcHelper;
23 
28 
33 
40  public function __construct(
41  ilUserCertificateRepository $userCertificateRepository,
44  ilCertificatePdfFileNameFactory $pdfFileNameFactory = null
45  ) {
46  $this->certificateRepository = $userCertificateRepository;
47  $this->logger = $logger;
48 
49  if (null === $rpcHelper) {
51  }
52  $this->rpcHelper = $rpcHelper;
53 
54  if (null === $pdfFileNameFactory) {
55  $pdfFileNameFactory = new ilCertificatePdfFileNameFactory();
56  }
57  $this->pdfFilenameFactory = $pdfFileNameFactory;
58  }
59 
65  public function generate(int $userCertificateId)
66  {
67  $certificate = $this->certificateRepository->fetchCertificate($userCertificateId);
68 
69  return $this->createPDFScalar($certificate);
70  }
71 
78  public function generateCurrentActiveCertificate(int $userId, int $objId) : string
79  {
80  $certificate = $this->certificateRepository->fetchActiveCertificate($userId, $objId);
81 
82  return $this->createPDFScalar($certificate);
83  }
84 
85  public function generateFileName(int $userId, int $objId) : string
86  {
87  $certificate = $this->certificateRepository->fetchActiveCertificateForPresentation($userId, $objId);
88 
90  if (!$user instanceof ilObjUser) {
91  throw new ilException(sprintf('The user_id "%s" does NOT reference a user', $userId));
92  }
93 
94  $pdfFileName = $this->pdfFilenameFactory->create($certificate);
95 
96  return $pdfFileName;
97  }
98 
103  private function createPDFScalar(ilUserCertificate $certificate) : string
104  {
105  $certificateContent = $certificate->getCertificateContent();
106 
107  $certificateContent = str_replace(
108  '[BACKGROUND_IMAGE]',
109  '[CLIENT_WEB_DIR]' . $certificate->getBackgroundImagePath(),
110  $certificateContent
111  );
112  $certificateContent = str_replace(
113  '[CLIENT_WEB_DIR]',
114  CLIENT_WEB_DIR,
115  $certificateContent
116  );
117 
118  $pdf_base64 = $this->rpcHelper->ilFO2PDF('RPCTransformationHandler', $certificateContent);
119 
120  return $pdf_base64->scalar;
121  }
122 }
Class ilPdfGeneratorConstantsTest.
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
__construct(ilUserCertificateRepository $userCertificateRepository, ilLogger $logger, ilCertificateRpcClientFactoryHelper $rpcHelper=null, ilCertificatePdfFileNameFactory $pdfFileNameFactory=null)
generateFileName(int $userId, int $objId)
generateCurrentActiveCertificate(int $userId, int $objId)
$user
Definition: migrateto20.php:57
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Component logger with individual log levels by component id.
generate(int $userCertificateId)
createPDFScalar(ilUserCertificate $certificate)