ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilPortfolioCertificateFileService Class Reference
+ Collaboration diagram for ilPortfolioCertificateFileService:

Public Member Functions

 __construct (Filesystem $filesystem=null, Logger $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)
 

Data Fields

const PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'
 
const CERTIFICATE_FILENAME = 'certificate.pdf'
 

Private Attributes

 $filesystem
 
 $logger
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $DIC, $filesystem, and $logger.

30  {
31  global $DIC;
32 
33  if (null === $filesystem) {
34  $filesystem = $DIC->filesystem()->storage();
35  }
36  $this->filesystem = $filesystem;
37 
38  if (null === $logger) {
39  $logger = $DIC->logger()->root();
40  }
41  $this->logger = $logger;
42  }
global $DIC
Definition: saml.php:7

Member Function Documentation

◆ createCertificateFile()

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

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

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

◆ createCertificateFilePath()

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

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

139  {
140  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId . '/';
141  $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
142  $completePath = $dirPath . $fileName;
143  if ($this->filesystem->has($completePath)) {
144  return CLIENT_DATA_DIR . '/' . $completePath;
145  }
146 
147  throw new ilException(sprintf('Certificate File does not exist in "%"', $completePath));
148  }

◆ deleteCertificateFile()

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

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

121  {
122  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
123 
124  $completePath = $dirPath . '/' . $objectId . '_' . self::CERTIFICATE_FILENAME;
125 
126  if ($this->filesystem->has($completePath)) {
127  $this->filesystem->delete($completePath);
128  }
129  }

◆ deleteUserDirectory()

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

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

106  {
107  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
108 
109  if (true === $this->filesystem->hasDir($dirPath)) {
110  $this->filesystem->deleteDir($dirPath);
111  }
112  }

◆ deliverCertificate()

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

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

References ilMimeTypeUtil\APPLICATION__PDF, and ilFileUtils\getValidFilename().

81  {
82  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
83  $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
84 
85  $completePath = $dirPath . '/' . $fileName;
86  if ($this->filesystem->has($completePath)) {
87  $userCertificateRepository = new ilUserCertificateRepository();
88 
89  $userCertificate = $userCertificateRepository->fetchActiveCertificateForPresentation($userId, $objectId);
90 
91  $downloadFilePath = CLIENT_DATA_DIR . '/' . $completePath;
92  $delivery = new \ilFileDelivery($downloadFilePath);
93  $delivery->setMimeType(\ilMimeTypeUtil::APPLICATION__PDF);
94  $delivery->setConvertFileNameToAsci(true);
95  $delivery->setDownloadFileName(\ilFileUtils::getValidFilename($userCertificate->getObjectTitle() . '.pdf'));
96 
97  $delivery->deliver();
98  }
99  }
static getValidFilename($a_filename)
Get valid filename.
+ Here is the call graph for this function:

Field Documentation

◆ $filesystem

ilPortfolioCertificateFileService::$filesystem
private

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

Referenced by __construct().

◆ $logger

ilPortfolioCertificateFileService::$logger
private

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

Referenced by __construct().

◆ CERTIFICATE_FILENAME

const ilPortfolioCertificateFileService::CERTIFICATE_FILENAME = 'certificate.pdf'

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

◆ PERSISTENT_CERTIFICATES_DIRECTORY

const ilPortfolioCertificateFileService::PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'
Parameters
Filesystem | null$filesystem
Logger | null$logger

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


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