ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateVerificationFileService.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{
12 private $language;
13
17 private $database;
18
22 private $logger;
23
27 private $classMap;
28
35 public function __construct(
40 ) {
41 $this->language = $language;
42 $this->database = $database;
43 $this->logger = $logger;
44 $this->classMap = $classMap;
45 }
46
47 public function createFile(ilUserCertificatePresentation $userCertificatePresentation)
48 {
49 $userCertificate = $userCertificatePresentation->getUserCertificate();
50 $objectType = $userCertificate->getObjType();
51
52 $this->language->loadLanguageModule('cert');
53
54 $verificationObjectType = $this->classMap->getVerificationTypeByType($objectType);
55
56 $verificationObject = new ilCertificateVerificationObject($verificationObjectType);
57 $verificationObject->setTitle($userCertificatePresentation->getObjectTitle());
58 $verificationObject->setDescription($userCertificatePresentation->getObjectDescription());
59
60 $objectId = $userCertificate->getObjId();
61 $userId = $userCertificate->getUserId();
62
63 $issueDate = new ilDate($userCertificate->getAcquiredTimestamp(), IL_CAL_UNIX);
64
65 $verificationObject->setProperty('issued_on', $issueDate);
66
67 $ilUserCertificateRepository = new ilUserCertificateRepository($this->database, $this->logger);
68 $pdfGenerator = new ilPdfGenerator($ilUserCertificateRepository, $this->logger);
69
70 $pdfAction = new ilCertificatePdfAction(
71 $this->logger,
72 $pdfGenerator,
74 $this->language->txt('error_creating_certificate_pdf')
75 );
76
77 $certificateScalar = $pdfAction->createPDF($userId, $objectId);
78
79 if ($certificateScalar) {
80 // we need the object id for storing the certificate file
81 $verificationObject->create();
82
83 $path = $this->initStorage($verificationObject->getId(), 'certificate');
84
85 $fileName = $objectType . '_' . $objectId . '_' . $userId . '.pdf';
86
87 if (file_put_contents($path . $fileName, $certificateScalar)) {
88 $verificationObject->setProperty('file', $fileName);
89 $verificationObject->update();
90
91 return $verificationObject;
92 }
93
94 $this->logger->info('File could not be created');
95 $verificationObject->delete();
96 }
97 }
98
104 public function initStorage(int $objectId, string $subDirectory = '')
105 {
106 $storage = new ilVerificationStorageFile($objectId);
107 $storage->create();
108
109 $path = $storage->getAbsolutePath() . "/";
110
111 if ($subDirectory !== '') {
112 $path .= $subDirectory . "/";
113
114 if (!is_dir($path)) {
115 mkdir($path);
116 }
117 }
118
119 return $path;
120 }
121}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Just a wrapper class to create Unit Test for other classes.
createFile(ilUserCertificatePresentation $userCertificatePresentation)
__construct(ilLanguage $language, ilDBInterface $database, ilLogger $logger, ilCertificateVerificationClassMap $classMap)
Class for single dates.
language handling
Component logger with individual log levels by component id.
Interface ilDBInterface.
Class ilPdfGeneratorConstantsTest.