ILIAS  release_8 Revision v8.24
class.ilUserCertificateZip.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private int $objectId;
27 private string $webDirectory;
28 private string $certificatePath;
29 private string $typeInFileName;
30 private string $installionId;
31
32 public function __construct(
33 int $objectId,
34 string $certificatePath,
36 string $installationId = IL_INST_ID
37 ) {
38 $this->objectId = $objectId;
39 $this->certificatePath = $certificatePath;
40 $this->webDirectory = $webDirectory;
41 $this->installionId = $installationId;
42
43 // The mapping to types is made to reflect the old behaviour of
44 // the adapters
45 $iliasType = ilObject::_lookupType($this->objectId);
46
47 $typeInFileName = 'not_defined';
48 if ('crs' === $iliasType) {
49 $typeInFileName = 'course';
50 } elseif ('tst' === $iliasType) {
51 $typeInFileName = 'test';
52 } elseif ('exc' === $iliasType) {
53 $typeInFileName = 'exc';
54 } elseif ('sahs' === $iliasType) {
55 $typeInFileName = 'scorm';
56 }
57
58 $this->typeInFileName = $typeInFileName;
59 }
60
61 public function createArchiveDirectory(): string
62 {
63 $type = ilObject::_lookupType($this->objectId);
64 $certificateId = $this->objectId;
65
66 $directory = $this->webDirectory . $this->certificatePath . time() . '__' . $this->installionId . '__' . $type . '__' . $certificateId . '__certificate/';
68
69 return $directory;
70 }
71
78 public function addPDFtoArchiveDirectory(string $pdfdata, string $dir, string $filename): void
79 {
80 $fh = fopen($dir . $filename, 'wb');
81 fwrite($fh, $pdfdata);
82 fclose($fh);
83 }
84
85 public function zipCertificatesInArchiveDirectory(string $dir, bool $deliver = true): string
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);
92
93 if ($deliver) {
94 ilFileDelivery::deliverFileLegacy($zipFilePath, $zipFile, 'application/zip', false, true);
95 }
96
97 return $zipFilePath;
98 }
99}
$filename
Definition: buildRTE.php:78
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 makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static _lookupType(int $id, bool $reference=false)
__construct(int $objectId, string $certificatePath, string $webDirectory=CLIENT_WEB_DIR, string $installationId=IL_INST_ID)
addPDFtoArchiveDirectory(string $pdfdata, string $dir, string $filename)
Adds PDF data as a file to a given directory.
zipCertificatesInArchiveDirectory(string $dir, bool $deliver=true)
const CLIENT_WEB_DIR
Definition: constants.php:47
const IL_INST_ID
Definition: constants.php:40
$type