ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 

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,
ilLogger  $logger = null 
)
Parameters
Filesystem | null$filesystem
ilLogger$logger

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

References $DIC, $filesystem, and $logger.

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

Member Function Documentation

◆ createCertificateFile()

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

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

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

◆ createCertificateFilePath()

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

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

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

◆ deleteCertificateFile()

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

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

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

◆ deleteUserDirectory()

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

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

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

◆ deliverCertificate()

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

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

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

82  {
83  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
84  $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
85 
86  $completePath = $dirPath . '/' . $fileName;
87  if ($this->filesystem->has($completePath)) {
88  $userCertificateRepository = new ilUserCertificateRepository();
89 
90  $userCertificate = $userCertificateRepository->fetchActiveCertificateForPresentation($userId, $objectId);
91 
92  $downloadFilePath = CLIENT_DATA_DIR . '/' . $completePath;
93  $delivery = new \ilFileDelivery($downloadFilePath);
94  $delivery->setMimeType(\ilMimeTypeUtil::APPLICATION__PDF);
95  $delivery->setConvertFileNameToAsci(true);
96  $delivery->setDownloadFileName(\ilFileUtils::getValidFilename($userCertificate->getObjectTitle() . '.pdf'));
97 
98  $delivery->deliver();
99  }
100  }
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 24 of file class.ilPortfolioCertificateFileService.php.

◆ PERSISTENT_CERTIFICATES_DIRECTORY

const ilPortfolioCertificateFileService::PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'

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


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