ILIAS  release_8 Revision v8.24
ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer Class Reference
+ Inheritance diagram for ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer:
+ Collaboration diagram for ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer:

Public Member Functions

 __construct (array $resources, StreamAccess $stream_access, FileNamePolicy $file_name_policy, string $zip_file_name)
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
 useRevisionTitlesForFileNames (bool $use_revision_titles)
 
 setRevisionNumber (int $revision_number)
 
 overrideFileName (string $file_name)
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
 setRevisionNumber (int $revision_number)
 
 overrideFileName (string $file_name)
 

Protected Attributes

ResourceCollection $collection
 
int $revision_number = null
 
bool $use_revision_titles = false
 
array $resources
 
FileNamePolicy $file_name_policy
 
string $zip_file_name
 

Private Attributes

StreamAccess $stream_access
 

Detailed Description

Definition at line 34 of file DownloadMultipleConsumer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::__construct ( array  $resources,
StreamAccess  $stream_access,
FileNamePolicy  $file_name_policy,
string  $zip_file_name 
)

Member Function Documentation

◆ overrideFileName()

ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::overrideFileName ( string  $file_name)

Implements ILIAS\ResourceStorage\Consumer\DeliveryConsumer.

Definition at line 119 of file DownloadMultipleConsumer.php.

119 : DeliveryConsumer
120 {
121 $this->zip_file_name = $file_name;
122 return $this;
123 }

◆ run()

ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::run ( )

This runs the actual DeliveryConsumer.

E.g. a DownloadConsumer will pass the Stream of a Ressource to the HTTP-Service and download the file.

Implements ILIAS\ResourceStorage\Consumer\DeliveryConsumer.

Definition at line 63 of file DownloadMultipleConsumer.php.

63 : void
64 {
65 global $DIC;
66
67 $directory = CLIENT_DATA_DIR . '/temp';
68 $temp = tempnam($directory, 'zip');
69 $zip = new \ZipArchive();
70 $zip->open($temp, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
71
72 foreach ($this->resources as $resource) {
73 $revision = $this->stream_access->populateRevision($resource->getCurrentRevision());
74 if ($this->use_revision_titles) {
75 $file_name = $this->file_name_policy->prepareFileNameForConsumer($revision->getTitle());
76 } else {
77 $file_name = $this->file_name_policy->prepareFileNameForConsumer(
78 $revision->getInformation()->getTitle()
79 );
80 }
81
82 $zip->addFile($revision->maybeGetToken()->resolveStream()->getMetadata('uri'), $file_name);
83 }
84
85 $zip->close();
86 $response = $DIC->http()->response();
88 $response = $response->withHeader(ResponseHeader::CONNECTION, 'close');
90 $response = $response->withHeader(
92 'attachment'
93 . '; filename="'
94 . $this->zip_file_name
95 . '"'
96 );
97 $fopen = fopen($temp, 'rb');
98 $response = $response->withBody(Streams::ofResource($fopen));
99 $DIC->http()->saveResponse($response);
100 $DIC->http()->sendResponse();
101 fclose($fopen);
102 unlink($temp);
103 $DIC->http()->close();
104 }
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:65
const CLIENT_DATA_DIR
Definition: constants.php:46
global $DIC
Definition: feed.php:28
$response

References $DIC, $response, ILIAS\HTTP\Response\ResponseHeader\ACCEPT_RANGES, ILIAS\FileUpload\MimeType\APPLICATION__ZIP, CLIENT_DATA_DIR, ILIAS\HTTP\Response\ResponseHeader\CONNECTION, ILIAS\HTTP\Response\ResponseHeader\CONTENT_DISPOSITION, ILIAS\HTTP\Response\ResponseHeader\CONTENT_TYPE, and ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ setRevisionNumber()

ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::setRevisionNumber ( int  $revision_number)
Parameters
int$revision_numberof a specific revision. otherwise the latest will be chosen during run()

Implements ILIAS\ResourceStorage\Consumer\DeliveryConsumer.

Definition at line 113 of file DownloadMultipleConsumer.php.

113 : DeliveryConsumer
114 {
115 $this->revision_number = $revision_number;
116 return $this;
117 }

References ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer\$revision_number.

◆ useRevisionTitlesForFileNames()

ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::useRevisionTitlesForFileNames ( bool  $use_revision_titles)

Definition at line 107 of file DownloadMultipleConsumer.php.

107 : self
108 {
109 $this->use_revision_titles = $use_revision_titles;
110 return $this;
111 }

References ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer\$use_revision_titles.

Field Documentation

◆ $collection

ResourceCollection ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$collection
protected

Definition at line 36 of file DownloadMultipleConsumer.php.

◆ $file_name_policy

FileNamePolicy ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$file_name_policy
protected

◆ $resources

array ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$resources
protected

◆ $revision_number

int ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$revision_number = null
protected

◆ $stream_access

StreamAccess ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$stream_access
private

◆ $use_revision_titles

bool ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$use_revision_titles = false
protected

◆ $zip_file_name

string ILIAS\ResourceStorage\Consumer\DownloadMultipleConsumer::$zip_file_name
protected

The documentation for this class was generated from the following file: