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

Public Member Functions

 __construct (private readonly int $objectId, private readonly string $certificatePath, private readonly string $webDirectory=CLIENT_WEB_DIR, private readonly string $installationId=IL_INST_ID)
 
 createArchiveDirectory ()
 
 addPDFtoArchiveDirectory (string $pdfdata, string $dir, string $filename)
 Adds PDF data as a file to a given directory. More...
 
 zipCertificatesInArchiveDirectory (string $dir, bool $deliver=true)
 

Private Attributes

readonly string $typeInFileName
 
bool $files_added_to_archive = false
 

Detailed Description

Author
Niels Theen nthee.nosp@m.n@da.nosp@m.tabay.nosp@m..de

Definition at line 26 of file class.ilUserCertificateZip.php.

Constructor & Destructor Documentation

◆ __construct()

ilUserCertificateZip::__construct ( private readonly int  $objectId,
private readonly string  $certificatePath,
private readonly string  $webDirectory = CLIENT_WEB_DIR,
private readonly string  $installationId = IL_INST_ID 
)

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

References $typeInFileName, and ilObject\_lookupType().

36  {
37  // The mapping to types is made to reflect the old behaviour of
38  // the adapters
39  $iliasType = ilObject::_lookupType($this->objectId);
40 
41  $typeInFileName = 'not_defined';
42  if ('crs' === $iliasType) {
43  $typeInFileName = 'course';
44  } elseif ('tst' === $iliasType) {
45  $typeInFileName = 'test';
46  } elseif ('exc' === $iliasType) {
47  $typeInFileName = 'exc';
48  } elseif ('sahs' === $iliasType) {
49  $typeInFileName = 'scorm';
50  }
51 
52  $this->typeInFileName = $typeInFileName;
53  }
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

Member Function Documentation

◆ addPDFtoArchiveDirectory()

ilUserCertificateZip::addPDFtoArchiveDirectory ( string  $pdfdata,
string  $dir,
string  $filename 
)

Adds PDF data as a file to a given directory.

Parameters
string$pdfdataBinary PDF data
string$dirDirectory to contain the PDF data
string$filenameThe filename to save the PDF data

Definition at line 73 of file class.ilUserCertificateZip.php.

73  : void
74  {
75  $fh = fopen($dir . $filename, 'wb');
76  fwrite($fh, $pdfdata);
77  fclose($fh);
78  $this->files_added_to_archive = true;
79  }
$filename
Definition: buildRTE.php:78

◆ createArchiveDirectory()

ilUserCertificateZip::createArchiveDirectory ( )

Definition at line 55 of file class.ilUserCertificateZip.php.

References ilObject\_lookupType(), and ilFileUtils\makeDirParents().

55  : string
56  {
57  $type = ilObject::_lookupType($this->objectId);
58  $certificateId = $this->objectId;
59 
60  $directory = $this->webDirectory . $this->certificatePath . time() .
61  '__' . $this->installationId . '__' . $type . '__' . $certificateId . '__certificate/';
62  ilFileUtils::makeDirParents($directory);
63 
64  return $directory;
65  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ zipCertificatesInArchiveDirectory()

ilUserCertificateZip::zipCertificatesInArchiveDirectory ( string  $dir,
bool  $deliver = true 
)
Exceptions
IOException

Definition at line 84 of file class.ilUserCertificateZip.php.

References ilFileUtils\delDir(), ilFileDelivery\deliverFileLegacy(), and ilFileUtils\zip().

84  : string
85  {
86  if (!$this->files_added_to_archive) {
87  throw new IOException('No files added to archive directory');
88  }
89 
90  $zipFile = time(
91  ) . '__' . $this->installationId . '__' . $this->typeInFileName . '__' . $this->objectId . '__certificates.zip';
92  $zipFilePath = $this->webDirectory . $this->certificatePath . $zipFile;
93 
94  ilFileUtils::zip($dir, $zipFilePath);
95  ilFileUtils::delDir($dir);
96 
97  if ($deliver) {
98  ilFileDelivery::deliverFileLegacy($zipFilePath, $zipFile, 'application/zip', false, true);
99  }
100 
101  return $zipFilePath;
102  }
Indicates general problems with the input or output operations.
Definition: IOException.php:27
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip(string $a_dir, string $a_file, bool $compress_content=false)
+ Here is the call graph for this function:

Field Documentation

◆ $files_added_to_archive

bool ilUserCertificateZip::$files_added_to_archive = false
private

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

◆ $typeInFileName

readonly string ilUserCertificateZip::$typeInFileName
private

Definition at line 28 of file class.ilUserCertificateZip.php.

Referenced by __construct().


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