ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExDownloadSubmissionsZipInteraction.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11
16{
17 const OPTION_DOWNLOAD = 'download';
18 const OPTION_CANCEL = 'cancel';
19
23 private $logger = null;
24
25
26 public function __construct()
27 {
28 $this->logger = $GLOBALS['DIC']->logger()->exc();
29 }
30
31
35 public function getInputTypes()
36 {
37 return [
38 new SingleType(StringValue::class),
39 new SingleType(StringValue::class),
40 ];
41 }
42
43
47 public function getRemoveOption()
48 {
49 return new UserInteractionOption('remove', self::OPTION_CANCEL);
50 }
51
52
56 public function getOutputType()
57 {
58 return new SingleType(StringValue::class);
59 }
60
61
65 public function getOptions(array $input)
66 {
67 return [
68 new UserInteractionOption('download', self::OPTION_DOWNLOAD),
69 ];
70 }
71
72
76 public function interaction(array $input, Option $user_selected_option, Bucket $bucket)
77 {
78 global $DIC;
79 $download_name = $input[0]; //directory name.
80 $zip_name = $input[1]; // zip job
81
82 $this->logger->debug("Interaction -> input[0] download name MUST BE FULL PATH=> " . $download_name->getValue());
83 $this->logger->debug("Interaction -> input[1] zip name MUST BE THE NAME WITHOUT EXTENSION. => " . $zip_name->getValue());
84
85 if ($user_selected_option->getValue() != self::OPTION_DOWNLOAD) {
86 $this->logger->info('Download canceled');
87 // delete zip file
88 $filesystem = $DIC->filesystem()->temp();
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 return $input;
99 }
100
101 $this->logger->info("Delivering File.");
102
103
104 $zip_name = $zip_name->getValue();
105
106 $ending = substr($zip_name, -4);
107 if ($ending != ".zip") {
108 $zip_name .= ".zip";
109 $this->logger->info("Add .zip extension");
110 }
111
112 //Download_name->getValue should return the complete path to the file
113 //Zip name is just an string
114 ilFileDelivery::deliverFileAttached($download_name->getValue(), $zip_name);
115
116 return $input;
117 }
118}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
getInputTypes()
Type[] A list of types that are taken as input.
interaction(array $input, Option $user_selected_option, Bucket $bucket)
@inheritDoc
static deliverFileAttached($path_to_file, $download_file_name='', $mime_type='', $delete_file=false)
void
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
global $DIC
Definition: saml.php:7