ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDownloadZipInteraction.php
Go to the documentation of this file.
1 <?php
28 
36 {
37  public const OPTION_DOWNLOAD = 'download';
38  public const OPTION_CANCEL = 'cancel';
39  private ?ilLogger $logger;
40 
41 
42  public function __construct()
43  {
44  global $DIC;
45  $this->logger = $DIC->logger()->cal();
46  }
47 
48 
52  public function getInputTypes(): array
53  {
54  return [
55  new SingleType(StringValue::class),
56  new SingleType(StringValue::class),
57  ];
58  }
59 
60 
64  #[\Override]
65  public function getRemoveOption(): Option
66  {
67  return new UserInteractionOption('remove', self::OPTION_CANCEL);
68  }
69 
70 
74  public function getOutputType(): Type
75  {
76  return new SingleType(StringValue::class);
77  }
78 
79 
83  public function getOptions(array $input): array
84  {
85  return [
86  new UserInteractionOption('download', self::OPTION_DOWNLOAD),
87  ];
88  }
89 
90 
94  public function interaction(array $input, Option $user_selected_option, Bucket $bucket): Value
95  {
96  global $DIC;
97  $zip_name = $input[1];
98  $download_name = $input[0];
99 
100  $this->logger->debug('User interaction download zip ' . $input[0]->getValue() . ' as '
101  . $input[1]->getValue());
102 
103  if ($user_selected_option->getValue() !== self::OPTION_DOWNLOAD) {
104  $this->logger->info('Download canceled');
105  // delete zip file
106  $filesystem = $DIC->filesystem()->temp();
107 
108  try {
109  $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
110  } catch (InvalidArgumentException) {
111  $path = null;
112  }
113  if (!is_null($path) && $filesystem->has($path)) {
114  $filesystem->deleteDir(dirname($path));
115  }
116 
117  return new ThunkValue();
118  }
119 
120  $this->logger->info("Delivering File.");
121 
122  ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name->getValue());
123 
124  return new ThunkValue();
125  }
126 
127  #[\Override]
128  public function canBeSkipped(array $input): bool
129  {
130  return false;
131  }
132 }
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
getInputTypes()
Type[] A list of types that are taken as input.
global $DIC
Definition: shib_login.php:26
interaction(array $input, Option $user_selected_option, Bucket $bucket)
canBeSkipped(array $input)
Decide whether the UserInteraction is presented to the user and he has to decide or user UserInteract...