ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPortfolioCertificateFileService Class Reference
+ Collaboration diagram for ilPortfolioCertificateFileService:

Public Member Functions

 __construct (?Filesystem $filesystem=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

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPortfolioCertificateFileService::__construct ( ?Filesystem  $filesystem = null)

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

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

36  {
37  global $DIC;
38 
39  if (null === $filesystem) {
40  $filesystem = $DIC->filesystem()->storage();
41  }
42  $this->filesystem = $filesystem;
43  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ createCertificateFile()

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

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

References ILIAS\Repository\filesystem().

50  : void
51  {
52  $userCertificateRepository = new ilUserCertificateRepository();
53 
54  $userCertificate = $userCertificateRepository->fetchActiveCertificate($userId, $objectId);
55 
56  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
57  if (!$this->filesystem->hasDir($dirPath)) {
58  $this->filesystem->createDir($dirPath);
59  }
60 
61  $pdfGenerator = new ilPdfGenerator($userCertificateRepository);
62 
63  $pdfScalar = $pdfGenerator->generate($userCertificate->getId());
64 
65  $completePath = $dirPath . '/' . $objectId . '_' . self::CERTIFICATE_FILENAME;
66  if ($this->filesystem->has($completePath)) {
67  $this->filesystem->delete($completePath);
68  }
69 
70  $this->filesystem->write($completePath, $pdfScalar);
71  }
+ Here is the call graph for this function:

◆ createCertificateFilePath()

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

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

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

126  : string
127  {
128  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId . '/';
129  $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
130  $completePath = $dirPath . $fileName;
131  if ($this->filesystem->has($completePath)) {
132  return CLIENT_DATA_DIR . '/' . $completePath;
133  }
134 
135  throw new ilException(sprintf('Certificate File does not exist in "%s"', $completePath));
136  }
const CLIENT_DATA_DIR
Definition: constants.php:46
+ Here is the call graph for this function:

◆ deleteCertificateFile()

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

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

References ILIAS\Repository\filesystem().

112  : void
113  {
114  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
115 
116  $completePath = $dirPath . '/' . $objectId . '_' . self::CERTIFICATE_FILENAME;
117 
118  if ($this->filesystem->has($completePath)) {
119  $this->filesystem->delete($completePath);
120  }
121  }
+ Here is the call graph for this function:

◆ deleteUserDirectory()

ilPortfolioCertificateFileService::deleteUserDirectory ( int  $userId)
Exceptions
IOException

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

References ILIAS\Repository\filesystem().

99  : void
100  {
101  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId;
102 
103  if ($this->filesystem->hasDir($dirPath)) {
104  $this->filesystem->deleteDir($dirPath);
105  }
106  }
+ Here is the call graph for this function:

◆ deliverCertificate()

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

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

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

77  : void
78  {
79  $dirPath = self::PERSISTENT_CERTIFICATES_DIRECTORY . $userId . '/' . $objectId;
80  $fileName = $objectId . '_' . self::CERTIFICATE_FILENAME;
81 
82  $completePath = $dirPath . '/' . $fileName;
83  if ($this->filesystem->has($completePath)) {
84  $userCertificateRepository = new ilUserCertificateRepository();
85 
86  $userCertificate = $userCertificateRepository->fetchActiveCertificateForPresentation($userId, $objectId);
87 
88  $downloadFilePath = CLIENT_DATA_DIR . '/' . $completePath;
90  $downloadFilePath,
91  ilFileUtils::getValidFilename($userCertificate->getObjectTitle() . '.pdf')
92  );
93  }
94  }
static getValidFilename(string $a_filename)
const CLIENT_DATA_DIR
Definition: constants.php:46
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
+ Here is the call graph for this function:

Field Documentation

◆ $filesystem

readonly Filesystem ilPortfolioCertificateFileService::$filesystem
private

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

Referenced by __construct().

◆ CERTIFICATE_FILENAME

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

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

◆ PERSISTENT_CERTIFICATES_DIRECTORY

const ilPortfolioCertificateFileService::PERSISTENT_CERTIFICATES_DIRECTORY = 'PersistentCertificates/'
private

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


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