ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  public function getRemoveOption(): Option
65  {
66  return new UserInteractionOption('remove', self::OPTION_CANCEL);
67  }
68 
69 
73  public function getOutputType(): Type
74  {
75  return new SingleType(StringValue::class);
76  }
77 
78 
82  public function getOptions(array $input): array
83  {
84  return [
85  new UserInteractionOption('download', self::OPTION_DOWNLOAD),
86  ];
87  }
88 
89 
93  public function interaction(array $input, Option $user_selected_option, Bucket $bucket): Value
94  {
95  global $DIC;
96  $zip_name = $input[1];
97  $download_name = $input[0];
98 
99  $this->logger->debug('User interaction download zip ' . $input[0]->getValue() . ' as '
100  . $input[1]->getValue());
101 
102  if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
103  $this->logger->info('Download canceled');
104  // delete zip file
105  $filesystem = $DIC->filesystem()->temp();
106 
107  try {
108  $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
109  } catch (InvalidArgumentException $e) {
110  $path = null;
111  }
112  if (!is_null($path) && $filesystem->has($path)) {
113  $filesystem->deleteDir(dirname($path));
114  }
115 
116  return new ThunkValue();
117  }
118 
119  $this->logger->info("Delivering File.");
120 
121  ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name->getValue());
122 
123  return new ThunkValue();
124  }
125 
126  public function canBeSkipped(array $input): bool
127  {
128  return false;
129  }
130 
131 }
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
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.
interaction(array $input, Option $user_selected_option, Bucket $bucket)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
canBeSkipped(array $input)
Decide whether the UserInteraction is presented to the user and he has to decide or user UserInteract...