ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 $installionId=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 24 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  $installionId = IL_INST_ID 
)

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

References $typeInFileName, and ilObject\_lookupType().

34  {
35  // The mapping to types is made to reflect the old behaviour of
36  // the adapters
37  $iliasType = ilObject::_lookupType($this->objectId);
38 
39  $typeInFileName = 'not_defined';
40  if ('crs' === $iliasType) {
41  $typeInFileName = 'course';
42  } elseif ('tst' === $iliasType) {
43  $typeInFileName = 'test';
44  } elseif ('exc' === $iliasType) {
45  $typeInFileName = 'exc';
46  } elseif ('sahs' === $iliasType) {
47  $typeInFileName = 'scorm';
48  }
49 
50  $this->typeInFileName = $typeInFileName;
51  }
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 70 of file class.ilUserCertificateZip.php.

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

◆ createArchiveDirectory()

ilUserCertificateZip::createArchiveDirectory ( )

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

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

Referenced by ilTestEvaluationGUI\exportCertificateArchive().

53  : string
54  {
55  $type = ilObject::_lookupType($this->objectId);
56  $certificateId = $this->objectId;
57 
58  $directory = $this->webDirectory . $this->certificatePath . time() . '__' . $this->installionId . '__' . $type . '__' . $certificateId . '__certificate/';
59  ilFileUtils::makeDirParents($directory);
60 
61  return $directory;
62  }
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:
+ Here is the caller graph for this function:

◆ zipCertificatesInArchiveDirectory()

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

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

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

81  : string
82  {
83  if (!$this->files_added_to_archive) {
84  throw new \ILIAS\Filesystem\Exception\IOException('No files added to archive directory');
85  }
86 
87  $zipFile = time() . '__' . $this->installionId . '__' . $this->typeInFileName . '__' . $this->objectId . '__certificates.zip';
88  $zipFilePath = $this->webDirectory . $this->certificatePath . $zipFile;
89 
90  ilFileUtils::zip($dir, $zipFilePath);
91  ilFileUtils::delDir($dir);
92 
93  if ($deliver) {
94  ilFileDelivery::deliverFileLegacy($zipFilePath, $zipFile, 'application/zip', false, true);
95  }
96 
97  return $zipFilePath;
98  }
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 27 of file class.ilUserCertificateZip.php.

◆ $typeInFileName

readonly string ilUserCertificateZip::$typeInFileName
private

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

Referenced by __construct().


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