ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DownloadAllZipInteraction.php
Go to the documentation of this file.
1<?php
2
20
30
35{
36 public const OPTION_DOWNLOAD = 'download';
37 public const OPTION_CANCEL = 'cancel';
38
39 private ?\ilLogger $logger = null;
40
41 public function __construct()
42 {
43 global $DIC;
44
45 $this->logger = $DIC->logger()->mcst();
46 }
47
48 public function getInputTypes(): array
49 {
50 return [
51 new SingleType(StringValue::class),
52 new SingleType(StringValue::class)
53 ];
54 }
55
56
58 {
59 return new UserInteractionOption('remove', self::OPTION_CANCEL);
60 }
61
62 public function getOutputType(): SingleType
63 {
64 return new SingleType(StringValue::class);
65 }
66
67 public function getOptions(array $input): array
68 {
69 return [
70 new UserInteractionOption('download', self::OPTION_DOWNLOAD)
71 ];
72 }
73
74 public function interaction(
75 array $input,
76 Option $user_selected_option,
77 Bucket $bucket
79 global $DIC;
80 $download_name = $input[0]; //directory name.
81 $zip_name = $input[1]; // zip job
82
83 $this->logger->debug("Interaction -> input[0] download name MUST BE FULL PATH=> " . $download_name->getValue());
84 $this->logger->debug("Interaction -> input[1] zip name MUST BE THE NAME WITHOUT EXTENSION. => " . $zip_name->getValue());
85
86 if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
87 $this->logger->info('Download canceled');
88 // delete zip file
89 $filesystem = $DIC->filesystem()->temp();
90 try {
91 $path = LegacyPathHelper::createRelativePath($zip_name->getValue());
92 } catch (\InvalidArgumentException $e) {
93 $path = null;
94 }
95 if (!is_null($path) && $filesystem->has($path)) {
96 $filesystem->deleteDir(dirname($path));
97 }
98
99 return new ThunkValue();
100 }
101
102 $this->logger->info("Delivering File.");
103
104
105 $zip_name = $zip_name->getValue();
106
107 $ending = substr($zip_name, -4);
108 if ($ending != ".zip") {
109 $zip_name .= ".zip";
110 $this->logger->info("Add .zip extension");
111 }
112
113 //Download_name->getValue should return the complete path to the file
114 //Zip name is just an string
115 \ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name);
116
117 return new ThunkValue();
118 }
119}
The legacy path helper provides convenient functions for the integration of the filesystem service wi...
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
getRemoveOption()
Option An Option to remove the current task and do some cleanup if possible. This Option is displayed...
interaction(array $input, Option $user_selected_option, Bucket $bucket)
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26