ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDownloadZipInteraction.php
Go to the documentation of this file.
1<?php
2
29
37{
38 public const OPTION_DOWNLOAD = 'download';
39 public const OPTION_CANCEL = 'cancel';
40 private ?ilLogger $logger;
41
42
43 public function __construct()
44 {
45 global $DIC;
46 $this->logger = $DIC->logger()->cal();
47 }
48
49
53 public function getInputTypes(): array
54 {
55 return [
56 new SingleType(StringValue::class),
57 new SingleType(StringValue::class),
58 ];
59 }
60
61
65 #[\Override]
66 public function getRemoveOption(): Option
67 {
68 return new UserInteractionOption('remove', self::OPTION_CANCEL);
69 }
70
71
75 public function getOutputType(): Type
76 {
77 return new SingleType(StringValue::class);
78 }
79
80
84 public function getOptions(array $input): array
85 {
86 return [
87 new UserInteractionOption('download', self::OPTION_DOWNLOAD),
88 ];
89 }
90
91
95 public function interaction(array $input, Option $user_selected_option, Bucket $bucket): Value
96 {
97 global $DIC;
98 $zip_name = $input[1];
99 $download_name = $input[0];
100
101 $this->logger->debug('User interaction download zip ' . $input[0]->getValue() . ' as '
102 . $input[1]->getValue());
103
104 if ($user_selected_option->getValue() !== self::OPTION_DOWNLOAD) {
105 $this->logger->info('Download canceled');
106 // delete zip file
107 $filesystem = $DIC->filesystem()->temp();
108
109 try {
110 $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
111 } catch (InvalidArgumentException) {
112 $path = null;
113 }
114 if (!is_null($path) && $filesystem->has($path)) {
115 $filesystem->deleteDir(dirname($path));
116 }
117
118 return new ThunkValue();
119 }
120
121 $this->logger->info("Delivering File.");
122
123 ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name->getValue());
124
125 return new ThunkValue();
126 }
127
128 #[\Override]
129 public function canBeSkipped(array $input): bool
130 {
131 return false;
132 }
133}
The legacy path helper provides convenient functions for the integration of the filesystem service wi...
interaction(array $input, Option $user_selected_option, Bucket $bucket)
@inheritDoc
getInputTypes()
Type[] A list of types that are taken as input.
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
Component logger with individual log levels by component id.
$path
Definition: ltiservices.php:30
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
global $DIC
Definition: shib_login.php:26