ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarDownloadZipInteraction.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
17 
23 {
24  protected const OPTION_DOWNLOAD = 'download';
25  protected const OPTION_CANCEL = 'cancel';
26 
27  private ilLogger $logger;
28 
29  public function __construct()
30  {
31  global $DIC;
32  $this->logger = $DIC->logger()->cal();
33  }
34 
38  public function getInputTypes(): array
39  {
40  return [
41  new SingleType(StringValue::class),
42  new SingleType(StringValue::class),
43  ];
44  }
45 
49  public function getRemoveOption(): Option
50  {
51  return new UserInteractionOption('remove', self::OPTION_CANCEL);
52  }
53 
57  public function getOutputType(): Type
58  {
59  return new SingleType(StringValue::class);
60  }
61 
65  public function getOptions(array $input): array
66  {
67  return [
68  new UserInteractionOption('download', self::OPTION_DOWNLOAD),
69  ];
70  }
71 
75  public function interaction(array $input, Option $user_selected_option, Bucket $bucket): Value
76  {
77  global $DIC;
78  $zip_name = $input[1];
79  $download_name = $input[0];
80 
81  $this->logger->debug('User interaction download zip ' . $input[0]->getValue() . ' as '
82  . $input[1]->getValue());
83 
84  if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
85  $this->logger->info('Download canceled');
86  // delete zip file
87  $filesystem = $DIC->filesystem()->temp();
88 
89  try {
90  $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
91  } catch (InvalidArgumentException $e) {
92  $path = null;
93  }
94  if (!is_null($path) && $filesystem->has($path)) {
95  $filesystem->deleteDir(dirname($path));
96  }
97 
98  // @todo what kind of value is desired
99  return $download_name;
100  }
101 
102  $this->logger->info("Delivering File.");
103 
105  $download_name->getValue(),
106  $zip_name->getValue(),
107  MimeType::APPLICATION__ZIP
108  );
109 
110  // @todo what kind of value is desired
111  return $download_name;
112  }
113 }
interaction(array $input, Option $user_selected_option, Bucket $bucket)
getInputTypes()
Type[] A list of types that are taken as input.
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...