ILIAS  release_8 Revision v8.24
class.ilCertificateVerificationFileService.php
Go to the documentation of this file.
1<?php
2
20{
25
26 public function __construct(
31 ) {
32 $this->language = $language;
33 $this->database = $database;
34 $this->logger = $logger;
35 $this->classMap = $classMap;
36 }
37
41 public function createFile(ilUserCertificatePresentation $userCertificatePresentation): ?ilCertificateVerificationObject
42 {
43 $userCertificate = $userCertificatePresentation->getUserCertificate();
44 $objectType = $userCertificate->getObjType();
45
46 $this->language->loadLanguageModule('cert');
47
48 $verificationObjectType = $this->classMap->getVerificationTypeByType($objectType);
49
50 $verificationObject = new ilCertificateVerificationObject($verificationObjectType);
51 $verificationObject->setTitle($userCertificatePresentation->getObjectTitle());
52 $verificationObject->setDescription($userCertificatePresentation->getObjectDescription());
53
54 $objectId = $userCertificate->getObjId();
55 $userId = $userCertificate->getUserId();
56
57 $issueDate = new ilDate($userCertificate->getAcquiredTimestamp(), IL_CAL_UNIX);
58
59 $verificationObject->setProperty('issued_on', $issueDate);
60
61 $ilUserCertificateRepository = new ilUserCertificateRepository($this->database, $this->logger);
62 $pdfGenerator = new ilPdfGenerator($ilUserCertificateRepository, $this->logger);
63
64 $pdfAction = new ilCertificatePdfAction(
65 $this->logger,
66 $pdfGenerator,
68 $this->language->txt('error_creating_certificate_pdf')
69 );
70
71 $certificateScalar = $pdfAction->createPDF($userId, $objectId);
72
73 if ($certificateScalar) {
74 // we need the object id for storing the certificate file
75 $verificationObject->create();
76
77 $path = $this->initStorage($verificationObject->getId(), 'certificate');
78
79 $fileName = $objectType . '_' . $objectId . '_' . $userId . '.pdf';
80
81 if (file_put_contents($path . $fileName, $certificateScalar)) {
82 $verificationObject->setProperty('file', $fileName);
83 $verificationObject->update();
84
85 return $verificationObject;
86 }
87
88 $this->logger->info('File could not be created');
89 $verificationObject->delete();
90 }
91 return null;
92 }
93
94 public function initStorage(int $objectId, string $subDirectory = ''): string
95 {
96 $storage = new ilVerificationStorageFile($objectId);
97 $storage->create();
98
99 $path = $storage->getAbsolutePath() . "/";
100
101 if ($subDirectory !== '') {
102 $path .= $subDirectory . "/";
103
104 if (!is_dir($path)) {
105 mkdir($path);
106 }
107 }
108
109 return $path;
110 }
111}
const IL_CAL_UNIX
Just a wrapper class to create Unit Test for other classes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createFile(ilUserCertificatePresentation $userCertificatePresentation)
__construct(ilLanguage $language, ilDBInterface $database, ilLogger $logger, ilCertificateVerificationClassMap $classMap)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for single dates.
language handling
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$path
Definition: ltiservices.php:32
Class ilPdfGeneratorConstantsTest.