ILIAS  release_8 Revision v8.24
ilPortfolioCertificateFileService Class Reference
+ Collaboration diagram for ilPortfolioCertificateFileService:

Public Member Functions

 __construct (?Filesystem $filesystem=null, ?ilLogger $logger=null)
 
 createCertificateFile (int $userId, int $objectId)
 
 deliverCertificate (int $userId, int $objectId)
 
 deleteUserDirectory (int $userId)
 
 deleteCertificateFile (int $userId, int $objectId)
 
 createCertificateFilePath (int $userId, int $objectId)
 

Private Attributes

Filesystem $filesystem
 
ilLogger $logger
 
const PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'
 
const CERTIFICATE_FILENAME = 'certificate.pdf'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPortfolioCertificateFileService::__construct ( ?Filesystem  $filesystem = null,
?ilLogger  $logger = null 
)

Definition at line 36 of file class.ilPortfolioCertificateFileService.php.

37 {
38 global $DIC;
39
40 if (null === $filesystem) {
41 $filesystem = $DIC->filesystem()->storage();
42 }
43 $this->filesystem = $filesystem;
44
45 if (null === $logger) {
46 $logger = $DIC->logger()->root();
47 }
48 $this->logger = $logger;
49 }
global $DIC
Definition: feed.php:28

References $DIC, $filesystem, $logger, ILIAS\Repository\filesystem(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ createCertificateFile()

ilPortfolioCertificateFileService::createCertificateFile ( int  $userId,
int  $objectId 
)
Parameters
int$userId
int$objectId
Exceptions
FileAlreadyExistsException
IOException
ilException

Definition at line 58 of file class.ilPortfolioCertificateFileService.php.

58 : void
59 {
60 $userCertificateRepository = new ilUserCertificateRepository();
61
62 $userCertificate = $userCertificateRepository->fetchActiveCertificate($userId, $objectId);
63
64 $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
65 if (false === $this->filesystem->hasDir($dirPath)) {
66 $this->filesystem->createDir($dirPath);
67 }
68
69 $pdfGenerator = new ilPdfGenerator($userCertificateRepository, $this->logger);
70
71 $pdfScalar = $pdfGenerator->generate($userCertificate->getId());
72
73 $completePath = $dirPath . '/' . $objectId . '_' . self::CERTIFICATE_FILENAME;
74 if ($this->filesystem->has($completePath)) {
75 $this->filesystem->delete($completePath);
76 }
77
78 $this->filesystem->write($completePath, $pdfScalar);
79 }
Class ilPdfGeneratorConstantsTest.

References CERTIFICATE_FILENAME, ILIAS\Repository\filesystem(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ createCertificateFilePath()

ilPortfolioCertificateFileService::createCertificateFilePath ( int  $userId,
int  $objectId 
)
Parameters
int$userId
int$objectId
Returns
string
Exceptions
ilException

Definition at line 142 of file class.ilPortfolioCertificateFileService.php.

142 : string
143 {
144 $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId . '/';
145 $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
146 $completePath = $dirPath . $fileName;
147 if ($this->filesystem->has($completePath)) {
148 return CLIENT_DATA_DIR . '/' . $completePath;
149 }
150
151 throw new ilException(sprintf('Certificate File does not exist in "%s"', $completePath));
152 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CLIENT_DATA_DIR
Definition: constants.php:46

References CERTIFICATE_FILENAME, CLIENT_DATA_DIR, and ILIAS\Repository\filesystem().

+ Here is the call graph for this function:

◆ deleteCertificateFile()

ilPortfolioCertificateFileService::deleteCertificateFile ( int  $userId,
int  $objectId 
)
Parameters
int$userId
int$objectId
Exceptions
FileNotFoundException
IOException

Definition at line 125 of file class.ilPortfolioCertificateFileService.php.

125 : void
126 {
127 $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
128
129 $completePath = $dirPath . '/' . $objectId . '_' . self::CERTIFICATE_FILENAME;
130
131 if ($this->filesystem->has($completePath)) {
132 $this->filesystem->delete($completePath);
133 }
134 }

References CERTIFICATE_FILENAME, and ILIAS\Repository\filesystem().

+ Here is the call graph for this function:

◆ deleteUserDirectory()

ilPortfolioCertificateFileService::deleteUserDirectory ( int  $userId)
Parameters
int$userId
Exceptions
IOException

Definition at line 110 of file class.ilPortfolioCertificateFileService.php.

110 : void
111 {
112 $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
113
114 if (true === $this->filesystem->hasDir($dirPath)) {
115 $this->filesystem->deleteDir($dirPath);
116 }
117 }

References ILIAS\Repository\filesystem().

+ Here is the call graph for this function:

◆ deliverCertificate()

ilPortfolioCertificateFileService::deliverCertificate ( int  $userId,
int  $objectId 
)
Parameters
int$userId
int$objectId
Exceptions
ilException
ilFileUtilsException

Definition at line 87 of file class.ilPortfolioCertificateFileService.php.

87 : void
88 {
89 $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
90 $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
91
92 $completePath = $dirPath . '/' . $fileName;
93 if ($this->filesystem->has($completePath)) {
94 $userCertificateRepository = new ilUserCertificateRepository();
95
96 $userCertificate = $userCertificateRepository->fetchActiveCertificateForPresentation($userId, $objectId);
97
98 $downloadFilePath = CLIENT_DATA_DIR . '/' . $completePath;
100 $downloadFilePath,
101 ilFileUtils::getValidFilename($userCertificate->getObjectTitle() . '.pdf')
102 );
103 }
104 }
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
static getValidFilename(string $a_filename)

References CERTIFICATE_FILENAME, CLIENT_DATA_DIR, ilFileDelivery\deliverFileAttached(), ILIAS\Repository\filesystem(), and ilFileUtils\getValidFilename().

+ Here is the call graph for this function:

Field Documentation

◆ $filesystem

Filesystem ilPortfolioCertificateFileService::$filesystem
private

Definition at line 31 of file class.ilPortfolioCertificateFileService.php.

Referenced by __construct().

◆ $logger

ilLogger ilPortfolioCertificateFileService::$logger
private

Definition at line 32 of file class.ilPortfolioCertificateFileService.php.

Referenced by __construct().

◆ CERTIFICATE_FILENAME

const ilPortfolioCertificateFileService::CERTIFICATE_FILENAME = 'certificate.pdf'
private

◆ PERSISTENT_CERTIFICATES_DIRECTORY

const ilPortfolioCertificateFileService::PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'
private

Definition at line 33 of file class.ilPortfolioCertificateFileService.php.


The documentation for this class was generated from the following file: