ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarDownloadZipInteraction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31
37{
38 protected const OPTION_DOWNLOAD = 'download';
39 protected const OPTION_CANCEL = 'cancel';
40
42
43 public function __construct()
44 {
45 global $DIC;
46 $this->logger = $DIC->logger()->cal();
47 }
48
52 public function getInputTypes(): array
53 {
54 return [
55 new SingleType(StringValue::class),
56 new SingleType(StringValue::class),
57 ];
58 }
59
63 public function getRemoveOption(): Option
64 {
65 return new UserInteractionOption('remove', self::OPTION_CANCEL);
66 }
67
71 public function getOutputType(): Type
72 {
73 return new SingleType(StringValue::class);
74 }
75
79 public function getOptions(array $input): array
80 {
81 return [
82 new UserInteractionOption('download', self::OPTION_DOWNLOAD),
83 ];
84 }
85
89 public function interaction(array $input, Option $user_selected_option, Bucket $bucket): Value
90 {
91 global $DIC;
92 $zip_name = $input[1];
93 $download_name = $input[0];
94
95 $this->logger->debug('User interaction download zip ' . $input[0]->getValue() . ' as '
96 . $input[1]->getValue());
97
98 if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
99 $this->logger->info('Download canceled');
100 // delete zip file
101 $filesystem = $DIC->filesystem()->temp();
102
103 try {
104 $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
105 } catch (InvalidArgumentException $e) {
106 $path = null;
107 }
108 if (!is_null($path) && $filesystem->has($path)) {
109 $filesystem->deleteDir(dirname($path));
110 }
111
112 // @todo what kind of value is desired
113 return $download_name;
114 }
115
116 $this->logger->info("Delivering File.");
117
119 $download_name->getValue(),
120 $zip_name->getValue(),
121 MimeType::APPLICATION__ZIP
122 );
123
124 // @todo what kind of value is desired
125 return $download_name;
126 }
127}
Mime type determination.
Definition: MimeType.php:30
The legacy path helper provides convenient functions for the integration of the filesystem service wi...
getInputTypes()
Type[] A list of types that are taken as input.
interaction(array $input, Option $user_selected_option, Bucket $bucket)
@inheritDoc
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