ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUserCertificateZip.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
9
13 private $objectId;
14
19
24
29
34
35 public function __construct(
36 int $objectId,
37 string $certificatePath,
39 string $installationId = IL_INST_ID
40 ) {
41 $this->objectId = $objectId;
42 $this->certificatePath = $certificatePath;
43 $this->webDirectory = $webDirectory;
44 $this->installionId = $installationId;
45
46 // The mapping to types is made to reflect the old behaviour of
47 // the adapters
48 $iliasType = ilObject::_lookupType($this->objectId);
49
50 $typeInFileName = 'not_defined';
51 if ('crs' === $iliasType) {
52 $typeInFileName = 'course';
53 } elseif ('tst' === $iliasType) {
54 $typeInFileName = 'test';
55 } elseif ('exc' === $iliasType) {
56 $typeInFileName = 'exc';
57 } elseif ('sahs' === $iliasType) {
58 $typeInFileName = 'scorm';
59 }
60
61 $this->typeInFileName = $typeInFileName;
62 }
63
69 public function createArchiveDirectory()
70 {
71 $type = ilObject::_lookupType($this->objectId);
72 $certificateId = $this->objectId;
73
74 $directory = $this->webDirectory . $this->certificatePath . time() . '__' . $this->installionId . '__' . $type . '__' . $certificateId . '__certificate/';
75 ilUtil::makeDirParents($directory);
76
77 return $directory;
78 }
79
87 public function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
88 {
89 $fh = fopen($dir . $filename, 'wb');
90 fwrite($fh, $pdfdata);
91 fclose($fh);
92 }
93
101 public function zipCertificatesInArchiveDirectory($dir, $deliver = true)
102 {
103 $zipFile = time() . '__' . $this->installionId . '__' . $this->typeInFileName . '__' . $this->objectId . '__certificates.zip';
104 $zipFilePath = $this->webDirectory . $this->certificatePath . $zipFile;
105
106 ilUtil::zip($dir, $zipFilePath);
107 ilUtil::delDir($dir);
108
109 if ($deliver) {
110 ilUtil::deliverFile($zipFilePath, $zipFile, 'application/zip', false, true);
111 }
112
113 return $zipFilePath;
114 }
115}
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
static _lookupType($a_id, $a_reference=false)
lookup object type
createArchiveDirectory()
Creates a directory for a zip archive containing multiple certificates.
__construct(int $objectId, string $certificatePath, string $webDirectory=CLIENT_WEB_DIR, string $installationId=IL_INST_ID)
addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
Adds PDF data as a file to a given directory.
zipCertificatesInArchiveDirectory($dir, $deliver=true)
Create a ZIP file from a directory with certificates.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
const CLIENT_WEB_DIR
Definition: constants.php:45
const IL_INST_ID
Definition: constants.php:38
$type