ILIAS  release_8 Revision v8.24
class.ilExDownloadSubmissionsZipInteraction.php
Go to the documentation of this file.
1<?php
2
28
33{
34 public const OPTION_DOWNLOAD = 'download';
35 public const OPTION_CANCEL = 'cancel';
36
37 protected ilLogger $logger;
38
39 public function __construct()
40 {
41 $this->logger = $GLOBALS['DIC']->logger()->exc();
42 }
43
44
48 public function getInputTypes(): array
49 {
50 return [
51 new SingleType(StringValue::class),
52 new SingleType(StringValue::class),
53 ];
54 }
55
56 public function getRemoveOption(): Option
57 {
58 return new UserInteractionOption('remove', self::OPTION_CANCEL);
59 }
60
61 public function getOutputType(): Type
62 {
63 return new SingleType(StringValue::class);
64 }
65
69 public function getOptions(array $input): array
70 {
71 return [
72 new UserInteractionOption('download', self::OPTION_DOWNLOAD),
73 ];
74 }
75
76 public function interaction(
77 array $input,
78 Option $user_selected_option,
79 Bucket $bucket
80 ): Value {
81 global $DIC;
82 $download_name = $input[0]; //directory name.
83 $zip_name = $input[1]; // zip job
84
85 $this->logger->debug("Interaction -> input[0] download name MUST BE FULL PATH=> " . $download_name->getValue());
86 $this->logger->debug("Interaction -> input[1] zip name MUST BE THE NAME WITHOUT EXTENSION. => " . $zip_name->getValue());
87
88 if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
89 $this->logger->info('Download canceled');
90 // delete zip file
91 $filesystem = $DIC->filesystem()->temp();
92 try {
93 $path = LegacyPathHelper::createRelativePath($download_name->getValue());
94 } catch (InvalidArgumentException $e) {
95 $path = null;
96 }
97 $this->logger->debug("Path: " . $path);
98 try {
99 if (!is_null($path) && $filesystem->has($path)) {
100 $this->logger->debug("Delete dir: " . dirname($path));
101 $filesystem->deleteDir(dirname($path));
102 }
103 } catch (Exception $e) {
104 }
105
106 return $download_name;
107 }
108
109 $this->logger->info("Delivering File.");
110
111
112 $zip_name = $zip_name->getValue();
113
114 $ending = substr($zip_name, -4);
115 if ($ending != ".zip") {
116 $zip_name .= ".zip";
117 $this->logger->info("Add .zip extension");
118 }
119
120 //Download_name->getValue should return the complete path to the file
121 //Zip name is just an string
122 $this->logger->debug("Deliver: " . $download_name->getValue());
123 $this->logger->debug("As: " . $zip_name);
124 ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name);
125
126 return $download_name;
127 }
128}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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.
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32